Bug 900910 - Initialize SessionStore earlier to catch windows opened immediately after startup. r=ttaubert

This commit is contained in:
Steven MacLeod
2013-10-17 14:26:25 -04:00
parent efc7adff58
commit 5f765388c6
2 changed files with 32 additions and 24 deletions

View File

@@ -472,6 +472,7 @@ BrowserGlue.prototype = {
ShumwayUtils.init(); ShumwayUtils.init();
webrtcUI.init(); webrtcUI.init();
AboutHome.init(); AboutHome.init();
SessionStore.init();
if (Services.prefs.getBoolPref("browser.tabs.remote")) if (Services.prefs.getBoolPref("browser.tabs.remote"))
ContentClick.init(); ContentClick.init();
@@ -612,7 +613,6 @@ BrowserGlue.prototype = {
} }
#endif #endif
SessionStore.init(aWindow);
this._trackSlowStartup(); this._trackSlowStartup();
// Offer to reset a user's profile if it hasn't been used for 60 days. // Offer to reset a user's profile if it hasn't been used for 60 days.

View File

@@ -156,8 +156,8 @@ this.SessionStore = {
SessionStoreInternal.canRestoreLastSession = val; SessionStoreInternal.canRestoreLastSession = val;
}, },
init: function ss_init(aWindow) { init: function ss_init() {
SessionStoreInternal.init(aWindow); SessionStoreInternal.init();
}, },
getBrowserState: function ss_getBrowserState() { getBrowserState: function ss_getBrowserState() {
@@ -368,15 +368,11 @@ let SessionStoreInternal = {
/** /**
* Initialize the sessionstore service. * Initialize the sessionstore service.
*/ */
init: function (aWindow) { init: function () {
if (this._initialized) { if (this._initialized) {
throw new Error("SessionStore.init() must only be called once!"); throw new Error("SessionStore.init() must only be called once!");
} }
if (!aWindow) {
throw new Error("SessionStore.init() must be called with a valid window.");
}
this._disabledForMultiProcess = Services.prefs.getBoolPref("browser.tabs.remote"); this._disabledForMultiProcess = Services.prefs.getBoolPref("browser.tabs.remote");
if (this._disabledForMultiProcess) { if (this._disabledForMultiProcess) {
this._deferredInitialized.resolve(); this._deferredInitialized.resolve();
@@ -390,20 +386,6 @@ let SessionStoreInternal = {
this._initPrefs(); this._initPrefs();
this._initialized = true; this._initialized = true;
// Wait until nsISessionStartup has finished reading the session data.
gSessionStartup.onceInitialized.then(() => {
// Parse session data and start restoring.
let initialState = this.initSession();
// Start tracking the given (initial) browser window.
if (!aWindow.closed) {
this.onLoad(aWindow, initialState);
}
// Let everyone know we're done.
this._deferredInitialized.resolve();
}, Cu.reportError);
}, },
initSession: function ssi_initSession() { initSession: function ssi_initSession() {
@@ -489,7 +471,6 @@ let SessionStoreInternal = {
this._prefBranch.setBoolPref("sessionstore.resume_session_once", false); this._prefBranch.setBoolPref("sessionstore.resume_session_once", false);
this._performUpgradeBackup(); this._performUpgradeBackup();
this._sessionInitialized = true;
return state; return state;
}, },
@@ -876,7 +857,34 @@ let SessionStoreInternal = {
onOpen: function ssi_onOpen(aWindow) { onOpen: function ssi_onOpen(aWindow) {
let onload = () => { let onload = () => {
aWindow.removeEventListener("load", onload); aWindow.removeEventListener("load", onload);
this.onLoad(aWindow);
if (this._sessionInitialized) {
this.onLoad(aWindow);
return;
}
// We can't call this.onLoad since initialization
// hasn't completed, so we'll wait until it is done.
// Even if additional windows are opened and wait
// for initialization as well, the first opened
// window should execute first, and this.onLoad
// will be called with the initialState.
gSessionStartup.onceInitialized.then(() => {
if (aWindow.closed) {
return;
}
if (this._sessionInitialized) {
this.onLoad(aWindow);
} else {
let initialState = this.initSession();
this._sessionInitialized = true;
this.onLoad(aWindow, initialState);
// Let everyone know we're done.
this._deferredInitialized.resolve();
}
}, Cu.reportError);
}; };
aWindow.addEventListener("load", onload); aWindow.addEventListener("load", onload);