Bug 1333567 - Send the notification expected by the session store when restarting, too. r?sebastian draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Wed, 25 Jan 2017 20:31:30 +0100
changeset 466846 93b941ef580296abd497ce662d9f83edf9de7cfa
parent 466327 8ccda93dabb3d72ab73685f007ded2159d4438a2
child 543534 c58ccc983ff0b2bee0b0e5395c7c69d2eaab74fe
push id43015
push usermozilla@buttercookie.de
push dateThu, 26 Jan 2017 18:25:38 +0000
reviewerssebastian
bugs1333567, 1228593
milestone54.0a1
Bug 1333567 - Send the notification expected by the session store when restarting, too. r?sebastian Since bug 1228593, the mobile session store - once again flushes its data when we are quitting, to make sure the latest state (including any potential cleaning of history/tabs) is flushed to disk - ignores windows/tabs closing as a byproduct of shutdown The latter point is dependent on a new shutdown notification introduced in that bug. Because we forgot to add that notification to the restart code used for add-on updates, in that case the session store currently doesn't enter shutdown mode and therefore records the window being closed during shutdown before flushing its data to disk, which means that all open tabs are lost. MozReview-Commit-ID: LgtdQoYwacM
mobile/android/chrome/content/browser.js
mobile/android/components/SessionStore.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -1378,17 +1378,17 @@ var BrowserApp = {
     let evt = document.createEvent("UIEvents");
     evt.initUIEvent("TabSelect", true, false, window, null);
     aTab.browser.dispatchEvent(evt);
   },
 
   quit: function quit(aClear = { sanitize: {}, dontSaveSession: false }) {
     // Notify all windows that an application quit has been requested.
     let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
-    Services.obs.notifyObservers(cancelQuit, "quit-application-requested", "restart");
+    Services.obs.notifyObservers(cancelQuit, "quit-application-requested", null);
 
     // Quit aborted.
     if (cancelQuit.data) {
       return;
     }
 
     Services.obs.notifyObservers(null, "quit-application-proceeding", null);
 
@@ -5476,16 +5476,17 @@ var XPInstallObserver = {
       label: Strings.browser.GetStringFromName("notificationRestart.button"),
       callback: function() {
         // Notify all windows that an application quit has been requested
         let cancelQuit = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool);
         Services.obs.notifyObservers(cancelQuit, "quit-application-requested", "restart");
 
         // If nothing aborted, quit the app
         if (cancelQuit.data == false) {
+          Services.obs.notifyObservers(null, "quit-application-proceeding", null);
           let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
           appStartup.quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit);
         }
       },
       positive: true
     }];
 
     let message = Strings.browser.GetStringFromName("notificationRestart.normal");
--- a/mobile/android/components/SessionStore.js
+++ b/mobile/android/components/SessionStore.js
@@ -998,20 +998,22 @@ SessionStore.prototype = {
     } else {
       log("_saveState() writing empty normal data");
     }
     this._writeFile(this._sessionFile, this._sessionFileTemp, normalData, aAsync);
 
     // If we have private data, send it to Java; otherwise, send null to
     // indicate that there is no private data
     let window = Services.wm.getMostRecentWindow("navigator:browser");
-    window.WindowEventDispatcher.sendRequest({
-      type: "PrivateBrowsing:Data",
-      session: (privateData.windows.length > 0 && privateData.windows[0].tabs.length > 0) ? JSON.stringify(privateData) : null
-    });
+    if (window) { // can be null if we're restarting
+      window.WindowEventDispatcher.sendRequest({
+        type: "PrivateBrowsing:Data",
+        session: (privateData.windows.length > 0 && privateData.windows[0].tabs.length > 0) ? JSON.stringify(privateData) : null
+      });
+    }
 
     this._lastSaveTime = Date.now();
   },
 
   _getCurrentState: function ss_getCurrentState() {
     this._forEachBrowserWindow((aWindow) => {
       this._collectWindowData(aWindow);
     });