Bug 1351739 - Part 4 - Handle selected tab temporarily being undefined. r?sebastian,nechen draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Sun, 09 Apr 2017 19:49:02 +0200
changeset 562368 c1951bcfeeed3559f8084e16b7b33582cfc277a3
parent 562367 60d0d7ff3cd7496a25a34be40aa70a827f12ea48
child 562369 a59fe9f98e2b8c8f9e38200f9eff91c40ee896e3
push id54016
push usermozilla@buttercookie.de
push dateThu, 13 Apr 2017 20:43:59 +0000
reviewerssebastian, nechen
bugs1351739
milestone55.0a1
Bug 1351739 - Part 4 - Handle selected tab temporarily being undefined. r?sebastian,nechen 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
@@ -399,19 +399,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;