Bug 1351739 - Part 4 - Handle selected tab temporarily being undefined. r?sebastian,walkingice draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Sun, 09 Apr 2017 19:49:02 +0200
changeset 569636 78baa9118e7e3d35fd0b85ace07dd79ac5a6cfb5
parent 569635 15f98966a64ddd86700fc193f17fd0898786a463
child 569637 6c49e349f10443a8657c0e9834cf4ce7fa13d6a0
push id56240
push usermozilla@buttercookie.de
push dateThu, 27 Apr 2017 18:44:39 +0000
reviewerssebastian, walkingice
bugs1351739
milestone55.0a1
Bug 1351739 - Part 4 - Handle selected tab temporarily being undefined. r?sebastian,walkingice This can happen if closing a tab (via the back button) simultaneously also triggered an activity switch (by selecting the parent tab). In that case the tab is closed, but formal selection of the new tab only completes after we've switched activities. At the moment activity switching might trigger an application-background/foreground cycle, which means we could hit the selected tab temporarily being undefined in Gecko. MozReview-Commit-ID: 6p4cOqj29HX
mobile/android/components/SessionStore.js
--- a/mobile/android/components/SessionStore.js
+++ b/mobile/android/components/SessionStore.js
@@ -225,16 +225,18 @@ SessionStore.prototype = {
             type: "Tabs:TabsOpened"
           });
         }
         break;
       }
     }
   },
 
+  // Removal of line below tracked by bug 1360287
+  // eslint-disable-next-line complexity
   observe: function ss_observe(aSubject, aTopic, aData) {
     let observerService = Services.obs;
     switch (aTopic) {
       case "app-startup":
         EventDispatcher.instance.registerListener(this, [
           "ClosedTabs:StartNotifications",
           "ClosedTabs:StopNotifications",
           "Session:Restore",
@@ -399,19 +401,21 @@ SessionStore.prototype = {
         // Reset minimum interval between session store writes back to default.
         log("application-foreground");
         this._interval = Services.prefs.getIntPref("browser.sessionstore.interval");
         this._minSaveDelay = MINIMUM_SAVE_DELAY;
 
         // If we skipped restoring a zombified tab before backgrounding,
         // we might have to do it now instead.
         let window = Services.wm.getMostRecentWindow("navigator:browser");
-        if (window) { // Might not yet be ready during a cold startup.
+        if (window && window.BrowserApp) { // Might not yet be ready during a cold startup.
           let tab = window.BrowserApp.selectedTab;
-          this.restoreZombieTab(tab);
+          if (tab) { // Can be null if closing a tab triggered an activity switch.
+            this.restoreZombieTab(tab);
+          }
         }
         break;
       case "last-pb-context-exited":
         // Clear private closed tab data when we leave private browsing.
         for (let window of Object.values(this._windows)) {
           window.closedTabs = window.closedTabs.filter(tab => !tab.isPrivate);
         }
         this._lastClosedTabIndex = -1;