Bug 1322316 - Split SessionStorage and LocalStorage implementation - part 7 - SessionStorageManager must be a StorageObserverSink, r=asuth
This commit is contained in:
@@ -16,10 +16,22 @@ using namespace StorageUtils;
|
|||||||
NS_IMPL_ISUPPORTS(SessionStorageManager, nsIDOMStorageManager)
|
NS_IMPL_ISUPPORTS(SessionStorageManager, nsIDOMStorageManager)
|
||||||
|
|
||||||
SessionStorageManager::SessionStorageManager()
|
SessionStorageManager::SessionStorageManager()
|
||||||
{}
|
{
|
||||||
|
StorageObserver* observer = StorageObserver::Self();
|
||||||
|
NS_ASSERTION(observer, "No StorageObserver, cannot observe private data delete notifications!");
|
||||||
|
|
||||||
|
if (observer) {
|
||||||
|
observer->AddSink(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
SessionStorageManager::~SessionStorageManager()
|
SessionStorageManager::~SessionStorageManager()
|
||||||
{}
|
{
|
||||||
|
StorageObserver* observer = StorageObserver::Self();
|
||||||
|
if (observer) {
|
||||||
|
observer->RemoveSink(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
SessionStorageManager::PrecacheStorage(nsIPrincipal* aPrincipal,
|
SessionStorageManager::PrecacheStorage(nsIPrincipal* aPrincipal,
|
||||||
@@ -197,5 +209,69 @@ SessionStorageManager::GetLocalStorageForPrincipal(nsIPrincipal* aPrincipal,
|
|||||||
return NS_ERROR_UNEXPECTED;
|
return NS_ERROR_UNEXPECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
SessionStorageManager::ClearStorages(const OriginAttributesPattern& aPattern,
|
||||||
|
const nsACString& aOriginScope)
|
||||||
|
{
|
||||||
|
for (auto iter1 = mOATable.Iter(); !iter1.Done(); iter1.Next()) {
|
||||||
|
OriginAttributes oa;
|
||||||
|
DebugOnly<bool> ok = oa.PopulateFromSuffix(iter1.Key());
|
||||||
|
MOZ_ASSERT(ok);
|
||||||
|
if (!aPattern.Matches(oa)) {
|
||||||
|
// This table doesn't match the given origin attributes pattern
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
OriginKeyHashTable* table = iter1.Data();
|
||||||
|
for (auto iter2 = table->Iter(); !iter2.Done(); iter2.Next()) {
|
||||||
|
if (aOriginScope.IsEmpty() ||
|
||||||
|
StringBeginsWith(iter2.Key(), aOriginScope)) {
|
||||||
|
iter2.Data()->Clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
SessionStorageManager::Observe(const char* aTopic,
|
||||||
|
const nsAString& aOriginAttributesPattern,
|
||||||
|
const nsACString& aOriginScope)
|
||||||
|
{
|
||||||
|
OriginAttributesPattern pattern;
|
||||||
|
if (!pattern.Init(aOriginAttributesPattern)) {
|
||||||
|
NS_ERROR("Cannot parse origin attributes pattern");
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear everything, caches + database
|
||||||
|
if (!strcmp(aTopic, "cookie-cleared")) {
|
||||||
|
ClearStorages(pattern, EmptyCString());
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear from caches everything that has been stored
|
||||||
|
// while in session-only mode
|
||||||
|
if (!strcmp(aTopic, "session-only-cleared")) {
|
||||||
|
ClearStorages(pattern, aOriginScope);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear everything (including so and pb data) from caches and database
|
||||||
|
// for the gived domain and subdomains.
|
||||||
|
if (!strcmp(aTopic, "domain-data-cleared")) {
|
||||||
|
ClearStorages(pattern, aOriginScope);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strcmp(aTopic, "profile-change")) {
|
||||||
|
// For case caches are still referenced - clear them completely
|
||||||
|
ClearStorages(pattern, EmptyCString());
|
||||||
|
mOATable.Clear();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
} // dom namespace
|
} // dom namespace
|
||||||
} // mozilla namespace
|
} // mozilla namespace
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "nsIDOMStorageManager.h"
|
#include "nsIDOMStorageManager.h"
|
||||||
#include "nsClassHashtable.h"
|
#include "nsClassHashtable.h"
|
||||||
#include "nsRefPtrHashtable.h"
|
#include "nsRefPtrHashtable.h"
|
||||||
|
#include "StorageObserver.h"
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
namespace dom {
|
namespace dom {
|
||||||
@@ -17,6 +18,7 @@ namespace dom {
|
|||||||
class SessionStorageCache;
|
class SessionStorageCache;
|
||||||
|
|
||||||
class SessionStorageManager final : public nsIDOMStorageManager
|
class SessionStorageManager final : public nsIDOMStorageManager
|
||||||
|
, public StorageObserverSink
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SessionStorageManager();
|
SessionStorageManager();
|
||||||
@@ -27,6 +29,16 @@ public:
|
|||||||
private:
|
private:
|
||||||
~SessionStorageManager();
|
~SessionStorageManager();
|
||||||
|
|
||||||
|
// StorageObserverSink, handler to various chrome clearing notification
|
||||||
|
nsresult
|
||||||
|
Observe(const char* aTopic,
|
||||||
|
const nsAString& aOriginAttributesPattern,
|
||||||
|
const nsACString& aOriginScope) override;
|
||||||
|
|
||||||
|
void
|
||||||
|
ClearStorages(const OriginAttributesPattern& aPattern,
|
||||||
|
const nsACString& aOriginScope);
|
||||||
|
|
||||||
typedef nsRefPtrHashtable<nsCStringHashKey, SessionStorageCache> OriginKeyHashTable;
|
typedef nsRefPtrHashtable<nsCStringHashKey, SessionStorageCache> OriginKeyHashTable;
|
||||||
nsClassHashtable<nsCStringHashKey, OriginKeyHashTable> mOATable;
|
nsClassHashtable<nsCStringHashKey, OriginKeyHashTable> mOATable;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user