Bug 1343603 - Part 1 - Immediately clear cached session store history data when clearing history. r?ahunt draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Thu, 02 Mar 2017 20:29:52 +0100
changeset 492070 772c218b9dbd789b9b284a31e47cff7cff22a144
parent 491131 03b30a61a2094acb8657cd749911366b1b1cf82e
child 492071 13108723994408f3a8cc61c21bf9870fe9d1cc0d
push id47518
push usermozilla@buttercookie.de
push dateThu, 02 Mar 2017 19:37:09 +0000
reviewersahunt
bugs1343603, 1337940
milestone54.0a1
Bug 1343603 - Part 1 - Immediately clear cached session store history data when clearing history. r?ahunt The session store keeps a serialised copy of a tab's session history around so that the gathering of the data (which can be somewhat expensive) can be decoupled from writing it to disk. When the user clears Firefox's history, we therefore need to discard this data as well (except for the currently open entry), so it doesn't stick around until the next time some navigation/history change occurs in that tab. Otherwise, if Firefox or just the tab is closed before the purged state has been re-collected by the session store, the supposedly purged session history will resurface when the tab is restored again. Bug 1337940 means that we'll now catch the history notifications caused by the session history being purged, however - we still need to handle zombified tabs separately, since as far as the rest of Gecko is concerned, those simply consist of a plain "about:blank" browser with the true state being stashed away in the session store data, so the purging of the live session history data won't have any real effect - the history purging on the tab happens after the session store receives the "browser:purge-session-history" notification, meaning that these changes received through the regular history notifications won't get written to disk immediately Therefore we now explicitly purge the session history data of all tabs in our notification handler, so this state can then immediately be saved to disk. MozReview-Commit-ID: KkR0Tif9BBk
mobile/android/components/SessionStore.js
--- a/mobile/android/components/SessionStore.js
+++ b/mobile/android/components/SessionStore.js
@@ -237,16 +237,32 @@ SessionStore.prototype = {
       case "browser:purge-session-tabs":
       case "browser:purge-session-history": // catch sanitization
         log(aTopic);
         this._clearDisk();
 
         // Clear all data about closed tabs
         this._forgetClosedTabs();
 
+        // Clear all cached session history data.
+        if (aTopic == "browser:purge-session-history") {
+          this._forEachBrowserWindow((window) => {
+            let tabs = window.BrowserApp.tabs;
+            for (let i = 0; i < tabs.length; i++) {
+              let data = tabs[i].browser.__SS_data;
+              let sHistory = data.entries;
+              // Copy the current history entry to the end...
+              sHistory.push(sHistory[data.index - 1]);
+              // ... and then remove everything else.
+              sHistory.splice(0, sHistory.length - 1);
+              data.index = 1;
+            }
+          });
+        }
+
         if (this._loadState == STATE_RUNNING) {
           // Save the purged state immediately
           this.saveState();
         } else if (this._loadState <= STATE_QUITTING) {
           this.saveStateDelayed();
           if (this._loadState == STATE_QUITTING_FLUSHED) {
             this.flushPendingState();
           }