Bug 1044556 - Part 1 - Notify the session store about tab zombifications. r=sebastian

The session store relies on a few event listeners to track the history and life cycle of a tab. Under memory pressure, background tabs are zombified in order to reduce our memory usage. This involves destroying the original tab object and then recreating it as a delay loaded tab.

As the session store is never told about this, it will keep the event listeners for the old tab objects - which have now been destroyed - alive and won't receive any future events for the new tab objects. This means that once a zombification has been triggered, the session history for those tabs will become effectively frozen, so after the next zombification or a session restore, the tab will reload the wrong page.

Therefore this patch introduces two new events which are sent during the tab zombification process and allow the session store to detach its event listeners from the old tab object before it is going to be destroyed and subsequently reattach its listeners to the new tab object.

MozReview-Commit-ID: 6xZtsCNZbQY

--HG--
extra : transplant_source : %7D%BB%D6%BA%D9%F6%B8%0E%7D%F6%0A%26%A0Y%3E%1Dr%7B%F1%C5
This commit is contained in:
Jan Henning 2016-03-18 11:40:26 +01:00
parent 0137da4b04
commit 13436d1f56
2 changed files with 25 additions and 1 deletions

View File

@ -54,6 +54,11 @@ var MemoryObserver = {
});
}
// Notify the session store that the original tab object is going to be destroyed
let evt = document.createEvent("UIEvents");
evt.initUIEvent("TabPreZombify", true, false, window, null);
browser.dispatchEvent(evt);
// We need this data to correctly create and position the new browser
// If this browser is already a zombie, fallback to the session data
let currentURL = browser.__SS_restore ? data.entries[0].url : browser.currentURI.spec;
@ -69,6 +74,11 @@ var MemoryObserver = {
browser.__SS_extdata = extra;
browser.__SS_restore = true;
browser.setAttribute("pending", "true");
// Notify the session store to reattach its listeners to the new tab object
evt = document.createEvent("UIEvents");
evt.initUIEvent("TabPostZombify", true, false, window, null);
browser.dispatchEvent(evt);
},
gc: function() {

View File

@ -213,6 +213,16 @@ SessionStore.prototype = {
this.onTabRemove(window, browser);
break;
}
case "TabPreZombify": {
let browser = aEvent.target;
this.onTabRemove(window, browser, true);
break;
}
case "TabPostZombify": {
let browser = aEvent.target;
this.onTabAdd(window, browser, true);
break;
}
case "TabSelect": {
let browser = aEvent.target;
this.onTabSelect(window, browser);
@ -277,11 +287,13 @@ SessionStore.prototype = {
for (let i = 0; i < tabs.length; i++)
this.onTabAdd(aWindow, tabs[i].browser, true);
// Notification of tab add/remove/selection
// Notification of tab add/remove/selection/zombification
let browsers = aWindow.document.getElementById("browsers");
browsers.addEventListener("TabOpen", this, true);
browsers.addEventListener("TabClose", this, true);
browsers.addEventListener("TabSelect", this, true);
browsers.addEventListener("TabPreZombify", this, true);
browsers.addEventListener("TabPostZombify", this, true);
},
onWindowClose: function ss_onWindowClose(aWindow) {
@ -293,6 +305,8 @@ SessionStore.prototype = {
browsers.removeEventListener("TabOpen", this, true);
browsers.removeEventListener("TabClose", this, true);
browsers.removeEventListener("TabSelect", this, true);
browsers.removeEventListener("TabPreZombify", this, true);
browsers.removeEventListener("TabPostZombify", this, true);
if (this._loadState == STATE_RUNNING) {
// Update all window data for a last time