Skip to content

Commit

Permalink
Bug 1300647 - Part 1 - Don't bother reloading a zombified tab if we'r…
Browse files Browse the repository at this point in the history
…e about to exit the app. r=ahunt

When pressing the back button reaches the beginning of session history for a tab opened from an external app, we both close the tab and send Firefox into background. Closing the tab leads to some other tab getting selected instead - if that other tab was zombified, this means that we'll then start restoring it.

This behaviour is
- visibly distracting, as that other tab will be visible for a split second while it starts reloading before Firefox finally disappears into the background
- wasteful of resources - while restoring a zombified tab is usually done from cache, at the very least we'll waste some CPU cycles reloading a tab even though we're in background

Therefore, in this situation the UI now alerts the session store that it needn't bother restoring that other tab if it's in a zombie state. Instead, we'll restore it the next time Firefox comes into foreground - if the tab is still selected by then.

MozReview-Commit-ID: 3FcjCZrJ0Ds

--HG--
extra : rebase_source : d071884dd1e78b7da470b042e244093e797dde61
  • Loading branch information
buttercookie42 committed Sep 13, 2016
1 parent d4e73bb commit d54010e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
5 changes: 5 additions & 0 deletions mobile/android/base/java/org/mozilla/gecko/GeckoApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -2521,6 +2521,11 @@ public void run() {

if (tab.isExternal()) {
moveTaskToBack(true);
Tab nextSelectedTab = Tabs.getInstance().getNextTab(tab);
if (nextSelectedTab != null) {
int nextSelectedTabId = nextSelectedTab.getId();
GeckoAppShell.notifyObservers("Tab:KeepZombified", Integer.toString(nextSelectedTabId));
}
tabs.closeTab(tab);
return;
}
Expand Down
44 changes: 38 additions & 6 deletions mobile/android/components/SessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ SessionStore.prototype = {
// Whether or not to send notifications for changes to the closed tabs.
_notifyClosedTabs: false,

// If we're simultaneously closing both a tab and Firefox, we don't want
// to bother reloading the newly selected tab if it is zombified.
// The Java UI will tell us which tab to watch out for.
_keepAsZombieTabId: -1,

init: function ss_init() {
loggingEnabled = Services.prefs.getBoolPref("browser.sessionstore.debug_logging");

Expand Down Expand Up @@ -141,6 +146,7 @@ SessionStore.prototype = {
observerService.addObserver(this, "quit-application", true);
observerService.addObserver(this, "Session:Restore", true);
observerService.addObserver(this, "Session:NotifyLocationChange", true);
observerService.addObserver(this, "Tab:KeepZombified", true);
observerService.addObserver(this, "application-background", true);
observerService.addObserver(this, "application-foreground", true);
observerService.addObserver(this, "ClosedTabs:StartNotifications", true);
Expand Down Expand Up @@ -284,6 +290,13 @@ SessionStore.prototype = {
}
break;
}
case "Tab:KeepZombified": {
if (aData >= 0) {
this._keepAsZombieTabId = aData;
log("Tab:KeepZombified " + aData);
}
break;
}
case "application-background":
// We receive this notification when Android's onPause callback is
// executed. After onPause, the application may be terminated at any
Expand All @@ -301,6 +314,15 @@ SessionStore.prototype = {
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");
let tab = window.BrowserApp.selectedTab;

if (tab.browser.__SS_restore) {
this._restoreZombieTab(tab.browser, tab.id);
}
break;
case "ClosedTabs:StartNotifications":
this._notifyClosedTabs = true;
Expand Down Expand Up @@ -667,13 +689,14 @@ SessionStore.prototype = {

// Restore the resurrected browser
if (aBrowser.__SS_restore) {
let data = aBrowser.__SS_data;
this._restoreTab(data, aBrowser);

delete aBrowser.__SS_restore;
aBrowser.removeAttribute("pending");
log("onTabSelect() restored zombie tab " + tabId);
if (tabId != this._keepAsZombieTabId) {
this._restoreZombieTab(aBrowser, tabId);
} else {
log("keeping as zombie tab " + tabId);
}
}
// The tab id passed through Tab:KeepZombified is valid for one TabSelect only.
this._keepAsZombieTabId = -1;

log("onTabSelect() ran for tab " + tabId);
this.saveStateDelayed();
Expand All @@ -687,6 +710,15 @@ SessionStore.prototype = {
}
},

_restoreZombieTab: function ss_restoreZombieTab(aBrowser, aTabId) {
let data = aBrowser.__SS_data;
this._restoreTab(data, aBrowser);

delete aBrowser.__SS_restore;
aBrowser.removeAttribute("pending");
log("restoring zombie tab " + aTabId);
},

onTabInput: function ss_onTabInput(aWindow, aBrowser) {
// If this browser belongs to a zombie tab or the initial restore hasn't yet finished,
// skip any session save activity.
Expand Down

0 comments on commit d54010e

Please sign in to comment.