Bug 1483440 - Part 1 - Remove purge-domain-data, add purge-sessionStorage notification. r=baku
authorJohann Hofmann <jhofmann@mozilla.com>
Thu, 17 Jan 2019 17:40:35 +0000
changeset 511412 6f9d7c3c98fa22919f7b5d45554ad2224a2cdc81
parent 511411 0f7827253b525066d50ad05a3cfe7d18f4df0124
child 511413 170f979a5f7d570780bb45872ce1ab4c8138ceec
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1483440
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1483440 - Part 1 - Remove purge-domain-data, add purge-sessionStorage notification. r=baku The browser:purge-domain-data notification had two different intentions, - to clear session store information and - to clear all localStorage and sessionStorage Firing the notification accomplished both at the same time, which from a user perspective is of course totally not understandable. This commit removes purge-domain-data in favor of the two distinct purge-localStorage and purge-sessionStorage events. This gives callers more granular choice on what they want to clear. Differential Revision: https://phabricator.services.mozilla.com/D16460
dom/storage/LocalStorageManager.cpp
dom/storage/SessionStorageManager.cpp
dom/storage/StorageObserver.cpp
dom/storage/StorageObserver.h
dom/tests/mochitest/localstorage/localStorageCommon.js
--- a/dom/storage/LocalStorageManager.cpp
+++ b/dom/storage/LocalStorageManager.cpp
@@ -390,30 +390,28 @@ nsresult LocalStorageManager::Observe(co
   }
 
   // Clear everything, caches + database
   if (!strcmp(aTopic, "extension:purge-localStorage-caches")) {
     ClearCaches(LocalStorageCache::kUnloadComplete, pattern, aOriginScope);
     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")) {
     ClearCaches(LocalStorageCache::kUnloadSession, 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")) {
-    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());
     return NS_OK;
   }
 
   // Clear localStorage data beloging to an origin pattern
   if (!strcmp(aTopic, "origin-attr-pattern-cleared")) {
--- a/dom/storage/SessionStorageManager.cpp
+++ b/dom/storage/SessionStorageManager.cpp
@@ -238,18 +238,18 @@ nsresult SessionStorageManager::Observe(
   // Clear from caches everything that has been stored
   // while in session-only mode
   if (!strcmp(aTopic, "session-only-cleared")) {
     ClearStorages(eSessionOnly, 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")) {
+  // for the given domain and subdomains.
+  if (!strcmp(aTopic, "browser:purge-sessionStorage")) {
     ClearStorages(eAll, pattern, aOriginScope);
     return NS_OK;
   }
 
   if (!strcmp(aTopic, "profile-change")) {
     // For case caches are still referenced - clear them completely
     ClearStorages(eAll, pattern, EmptyCString());
     mOATable.Clear();
--- a/dom/storage/StorageObserver.cpp
+++ b/dom/storage/StorageObserver.cpp
@@ -54,20 +54,20 @@ nsresult StorageObserver::Init() {
 
   sSelf = new StorageObserver();
   NS_ADDREF(sSelf);
 
   // Chrome clear operations.
   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);
   if (XRE_IsParentProcess()) {
     obs->AddObserver(sSelf, "profile-before-change", true);
   }
 
   // Testing
@@ -130,18 +130,18 @@ void StorageObserver::Notify(const char*
     sink->Observe(aTopic, aOriginAttributesPattern, aOriginScope);
   }
 }
 
 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);
 
   nsAutoCString convertedDomain;
   nsCOMPtr<nsIIDNService> converter = do_GetService(NS_IDNSERVICE_CONTRACTID);
   if (converter) {
     // Convert the domain name to the ACE format
@@ -157,27 +157,16 @@ nsresult StorageObserver::ClearMatchingO
   }
 
   nsCString originScope;
   rv = CreateReversedDomain(convertedDomain, originScope);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     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;
 }
 
 NS_IMETHODIMP
 StorageObserver::Observe(nsISupports* aSubject, const char* aTopic,
                          const char16_t* aData) {
   nsresult rv;
@@ -304,21 +293,31 @@ StorageObserver::Observe(nsISupports* aS
     if (NextGenLocalStorageEnabled()) {
       return NS_OK;
     }
 
     const char topic[] = "extension:purge-localStorage-caches";
 
     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();
       if (NS_WARN_IF(!storageChild)) {
         return NS_ERROR_FAILURE;
       }
 
       storageChild->AsyncClearAll();
@@ -328,27 +327,29 @@ StorageObserver::Observe(nsISupports* aS
       }
 
       Notify(topic);
     }
 
     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(aTopic, EmptyString(), originScope);
+    } else {
+      Notify(aTopic, EmptyString(), EmptyCString());
     }
 
-    Notify("domain-data-cleared", EmptyString(), originScope);
-
     return NS_OK;
   }
 
   // Clear all private-browsing caches
   if (!strcmp(aTopic, "last-pb-context-exited")) {
     if (NextGenLocalStorageEnabled()) {
       return NS_OK;
     }
--- a/dom/storage/StorageObserver.h
+++ b/dom/storage/StorageObserver.h
@@ -48,17 +48,17 @@ class StorageObserver : public nsIObserv
               const nsAString& aOriginAttributesPattern = EmptyString(),
               const nsACString& aOriginScope = EmptyCString());
 
   void NoteBackgroundThread(nsIEventTarget* aBackgroundThread);
 
  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);
 
   static StorageObserver* sSelf;
 
   nsCOMPtr<nsIEventTarget> mBackgroundThread;
 
   // Weak references
--- a/dom/tests/mochitest/localstorage/localStorageCommon.js
+++ b/dom/tests/mochitest/localstorage/localStorageCommon.js
@@ -97,17 +97,17 @@ function localStorageClearDomain(domain,
     let qms = SpecialPowers.Services.qms;
     let principal = SpecialPowers.wrap(document).nodePrincipal;
     let request = qms.clearStoragesForPrincipal(principal, "default", "ls");
     let cb = SpecialPowers.wrapCallback(callback);
     request.callback = cb;
     return;
   }
 
-  os().notifyObservers(null, "browser:purge-domain-data", domain);
+  os().notifyObservers(null, "extension:purge-localStorage", domain);
   SimpleTest.executeSoon(function () {
     callback();
   });
 }
 
 function os()
 {
   return SpecialPowers.Services.obs;