diff --git a/dom/storage/LocalStorageManager.cpp b/dom/storage/LocalStorageManager.cpp index 3991a77eb08c..1cf2d906f4e5 100644 --- a/dom/storage/LocalStorageManager.cpp +++ b/dom/storage/LocalStorageManager.cpp @@ -395,6 +395,11 @@ nsresult LocalStorageManager::Observe(const char* aTopic, return NS_OK; } + if (!strcmp(aTopic, "browser:purge-sessionStorage")) { + // This is only meant for SessionStorageManager. + return NS_OK; + } + // Clear from caches everything that has been stored // while in session-only mode if (!strcmp(aTopic, "session-only-cleared")) { @@ -402,13 +407,6 @@ nsresult LocalStorageManager::Observe(const char* aTopic, 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")) { - ClearCaches(LocalStorageCache::kUnloadComplete, pattern, aOriginScope); - return NS_OK; - } - // Clear all private-browsing caches if (!strcmp(aTopic, "private-browsing-data-cleared")) { ClearCaches(LocalStorageCache::kUnloadPrivate, pattern, EmptyCString()); diff --git a/dom/storage/SessionStorageManager.cpp b/dom/storage/SessionStorageManager.cpp index 8bed2bda3eb3..2cbf0d9098a6 100644 --- a/dom/storage/SessionStorageManager.cpp +++ b/dom/storage/SessionStorageManager.cpp @@ -243,8 +243,8 @@ nsresult SessionStorageManager::Observe( } // Clear everything (including so and pb data) from caches and database - // for the gived domain and subdomains. - if (!strcmp(aTopic, "domain-data-cleared")) { + // for the given domain and subdomains. + if (!strcmp(aTopic, "browser:purge-sessionStorage")) { ClearStorages(eAll, pattern, aOriginScope); return NS_OK; } diff --git a/dom/storage/StorageObserver.cpp b/dom/storage/StorageObserver.cpp index 04fa265eb568..3cc579e3f4d0 100644 --- a/dom/storage/StorageObserver.cpp +++ b/dom/storage/StorageObserver.cpp @@ -59,10 +59,10 @@ nsresult StorageObserver::Init() { obs->AddObserver(sSelf, kStartupTopic, true); obs->AddObserver(sSelf, "cookie-changed", true); obs->AddObserver(sSelf, "perm-changed", true); - obs->AddObserver(sSelf, "browser:purge-domain-data", true); obs->AddObserver(sSelf, "last-pb-context-exited", true); obs->AddObserver(sSelf, "clear-origin-attributes-data", true); obs->AddObserver(sSelf, "extension:purge-localStorage", true); + obs->AddObserver(sSelf, "browser:purge-sessionStorage", true); // Shutdown obs->AddObserver(sSelf, "profile-after-change", true); @@ -135,8 +135,8 @@ void StorageObserver::NoteBackgroundThread(nsIEventTarget* aBackgroundThread) { mBackgroundThread = aBackgroundThread; } -nsresult StorageObserver::ClearMatchingOrigin(const char16_t* aData, - nsACString& aOriginScope) { +nsresult StorageObserver::GetOriginScope(const char16_t* aData, + nsACString& aOriginScope) { nsresult rv; NS_ConvertUTF16toUTF8 domain(aData); @@ -162,17 +162,6 @@ nsresult StorageObserver::ClearMatchingOrigin(const char16_t* aData, return rv; } - if (!NextGenLocalStorageEnabled()) { - if (XRE_IsParentProcess()) { - StorageDBChild* storageChild = StorageDBChild::GetOrCreate(); - if (NS_WARN_IF(!storageChild)) { - return NS_ERROR_FAILURE; - } - - storageChild->SendClearMatchingOrigin(originScope); - } - } - aOriginScope = originScope; return NS_OK; } @@ -309,11 +298,21 @@ StorageObserver::Observe(nsISupports* aSubject, const char* aTopic, if (aData) { nsCString originScope; - rv = ClearMatchingOrigin(aData, originScope); + + rv = GetOriginScope(aData, originScope); if (NS_WARN_IF(NS_FAILED(rv))) { return rv; } + if (XRE_IsParentProcess()) { + StorageDBChild* storageChild = StorageDBChild::GetOrCreate(); + if (NS_WARN_IF(!storageChild)) { + return NS_ERROR_FAILURE; + } + + storageChild->SendClearMatchingOrigin(originScope); + } + Notify(topic, EmptyString(), originScope); } else { StorageDBChild* storageChild = StorageDBChild::GetOrCreate(); @@ -333,16 +332,18 @@ StorageObserver::Observe(nsISupports* aSubject, const char* aTopic, return NS_OK; } - // Clear everything (including so and pb data) from caches and database - // for the given domain and subdomains. - if (!strcmp(aTopic, "browser:purge-domain-data")) { - nsCString originScope; - rv = ClearMatchingOrigin(aData, originScope); - if (NS_WARN_IF(NS_FAILED(rv))) { - return rv; - } + if (!strcmp(aTopic, "browser:purge-sessionStorage")) { + if (aData) { + nsCString originScope; + rv = GetOriginScope(aData, originScope); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + } - Notify("domain-data-cleared", EmptyString(), originScope); + Notify(aTopic, EmptyString(), originScope); + } else { + Notify(aTopic, EmptyString(), EmptyCString()); + } return NS_OK; } diff --git a/dom/storage/StorageObserver.h b/dom/storage/StorageObserver.h index a52aa8b11231..8e1d341baafd 100644 --- a/dom/storage/StorageObserver.h +++ b/dom/storage/StorageObserver.h @@ -53,7 +53,7 @@ class StorageObserver : public nsIObserver, public nsSupportsWeakReference { private: virtual ~StorageObserver() {} - nsresult ClearMatchingOrigin(const char16_t* aData, nsACString& aOriginScope); + nsresult GetOriginScope(const char16_t* aData, nsACString& aOriginScope); static void TestingPrefChanged(const char* aPrefName, void* aClosure); diff --git a/dom/tests/mochitest/localstorage/localStorageCommon.js b/dom/tests/mochitest/localstorage/localStorageCommon.js index 4bb00c197844..635f9c88ecf0 100644 --- a/dom/tests/mochitest/localstorage/localStorageCommon.js +++ b/dom/tests/mochitest/localstorage/localStorageCommon.js @@ -102,7 +102,7 @@ function localStorageClearDomain(domain, callback) return; } - os().notifyObservers(null, "browser:purge-domain-data", domain); + os().notifyObservers(null, "extension:purge-localStorage", domain); SimpleTest.executeSoon(function () { callback(); });