Bug 1480951 - Make SessionStore respect sessionStorage.clear(). r=mikedeboer a=RyanVM
authorMike Conley <mconley@mozilla.com>
Wed, 05 Sep 2018 14:52:00 -0400
changeset 492397 736735078dd5a335d6293bc2a206d13f6a09f901
parent 492396 7296296be48395ff3fd0706364b72cec35b2774e
child 492398 586d84ba47a6f937fd498d8a98d06ebd7b85a96f
push id1815
push userffxbld-merge
push dateMon, 15 Oct 2018 10:40:45 +0000
treeherdermozilla-release@18d4c09e9378 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer, RyanVM
bugs1480951
milestone63.0
Bug 1480951 - Make SessionStore respect sessionStorage.clear(). r=mikedeboer a=RyanVM Differential Revision: https://phabricator.services.mozilla.com/D5066
browser/components/sessionstore/ContentSessionStore.jsm
browser/components/sessionstore/TabStateCache.jsm
--- a/browser/components/sessionstore/ContentSessionStore.jsm
+++ b/browser/components/sessionstore/ContentSessionStore.jsm
@@ -519,17 +519,25 @@ class SessionStorageListener extends Han
     let uri = Services.io.newURI(url);
     let domain = uri.prePath;
     if (!this._changes) {
       this._changes = {};
     }
     if (!this._changes[domain]) {
       this._changes[domain] = {};
     }
-    this._changes[domain][key] = newValue;
+
+    // If the key isn't defined, then .clear() was called, and we send
+    // up null for this domain to indicate that storage has been cleared
+    // for it.
+    if (!key) {
+      this._changes[domain] = null;
+    } else {
+      this._changes[domain][key] = newValue;
+    }
 
     this.messageQueue.push("storagechange", () => {
       let tmp = this._changes;
       // If there were multiple changes we send them merged.
       // First one will collect all the changes the rest of
       // these messages will be ignored.
       this.resetChanges();
       return tmp;
--- a/browser/components/sessionstore/TabStateCache.jsm
+++ b/browser/components/sessionstore/TabStateCache.jsm
@@ -72,27 +72,33 @@ var TabStateCacheInternal = {
    */
   updatePartialStorageChange(data, change) {
     if (!data.storage) {
       data.storage = {};
     }
 
     let storage = data.storage;
     for (let domain of Object.keys(change)) {
-      for (let key of Object.keys(change[domain])) {
-        let value = change[domain][key];
-        if (value === null) {
-          if (storage[domain] && storage[domain][key]) {
-            delete storage[domain][key];
+      if (!change[domain]) {
+        // We were sent null in place of the change object, which means
+        // we should delete session storage entirely for this domain.
+        delete storage[domain];
+      } else {
+        for (let key of Object.keys(change[domain])) {
+          let value = change[domain][key];
+          if (value === null) {
+            if (storage[domain] && storage[domain][key]) {
+              delete storage[domain][key];
+            }
+          } else {
+            if (!storage[domain]) {
+              storage[domain] = {};
+            }
+            storage[domain][key] = value;
           }
-        } else {
-          if (!storage[domain]) {
-            storage[domain] = {};
-          }
-          storage[domain][key] = value;
         }
       }
     }
   },
 
   /**
    * Helper function used by update (see below). For message size
    * optimization sometimes we don't update the whole browser history