Bug 853779 - Ensure we don't lose sessions when starting with a private window only; r=yoric

This commit is contained in:
Tim Taubert 2013-10-15 11:52:08 -07:00
parent c3a0d9a21d
commit 26b2532a5c
2 changed files with 26 additions and 10 deletions

View File

@ -202,15 +202,6 @@ let SessionSaverInternal = {
}
}
#ifndef XP_MACOSX
// Don't save invalid states.
// Looks like we currently have private windows, only.
if (state.windows.length == 0) {
stopWatchCancel("COLLECT_DATA_MS", "COLLECT_DATA_LONGEST_OP_MS");
return;
}
#endif
// Remove private windows from the list of closed windows.
for (let i = state._closedWindows.length - 1; i >= 0; i--) {
if (state._closedWindows[i].isPrivate) {
@ -218,6 +209,13 @@ let SessionSaverInternal = {
}
}
// Make sure that we keep the previous session if we started with a single
// private window and no non-private windows have been opened, yet.
if (state.deferredInitialState) {
state.windows = state.deferredInitialState.windows || [];
delete state.deferredInitialState;
}
#ifndef XP_MACOSX
// We want to restore closed windows that are marked with _shouldRestore.
// We're doing this here because we want to control this only when saving

View File

@ -728,7 +728,7 @@ let SessionStoreInternal = {
// We're starting with a single private window. Save the state we
// actually wanted to restore so that we can do it later in case
// the user opens another, non-private window.
this._deferredInitialState = aInitialState;
this._deferredInitialState = gSessionStartup.state;
// Nothing to restore now, notify observers things are complete.
Services.obs.notifyObservers(null, NOTIFY_WINDOWS_RESTORED, "");
@ -1346,6 +1346,9 @@ let SessionStoreInternal = {
// Don't include the last session state in getBrowserState().
delete state.lastSessionState;
// Don't include any deferred initial state.
delete state.deferredInitialState;
return this._toJSONString(state);
},
@ -2074,6 +2077,13 @@ let SessionStoreInternal = {
state.lastSessionState = this._lastSessionState;
}
// If we were called by the SessionSaver and started with only a private
// window we want to pass the deferred initial state to not lose the
// previous session.
if (this._deferredInitialState) {
state.deferredInitialState = this._deferredInitialState;
}
return state;
},
@ -3524,6 +3534,14 @@ let SessionStoreInternal = {
* @returns [defaultState, state]
*/
_prepDataForDeferredRestore: function ssi_prepDataForDeferredRestore(state) {
// Make sure that we don't modify the global state as provided by
// nsSessionStartup.state. Converting the object to a JSON string and
// parsing it again is the easiest way to do that, although not the most
// efficient one. Deferred sessions that don't have automatic session
// restore enabled tend to be a lot smaller though so that this shouldn't
// be a big perf hit.
state = JSON.parse(JSON.stringify(state));
let defaultState = { windows: [], selectedWindow: 1 };
state.selectedWindow = state.selectedWindow || 1;