Bug 670040: Make nsISessionStartup.state a jsval to save repeatedly stringifying/parsing the initial state. r=zpao
This commit is contained in:
@@ -89,7 +89,7 @@ function SessionStartup() {
|
||||
SessionStartup.prototype = {
|
||||
|
||||
// the state to restore at startup
|
||||
_iniString: null,
|
||||
_initialState: null,
|
||||
_sessionType: Ci.nsISessionStartup.NO_SESSION,
|
||||
|
||||
/* ........ Global Event Handlers .............. */
|
||||
@@ -121,31 +121,30 @@ SessionStartup.prototype = {
|
||||
return;
|
||||
|
||||
// get string containing session state
|
||||
this._iniString = this._readStateFile(sessionFile);
|
||||
if (!this._iniString)
|
||||
let iniString = this._readStateFile(sessionFile);
|
||||
if (!iniString)
|
||||
return;
|
||||
|
||||
// parse the session state into a JS object
|
||||
let initialState;
|
||||
try {
|
||||
// remove unneeded braces (added for compatibility with Firefox 2.0 and 3.0)
|
||||
if (this._iniString.charAt(0) == '(')
|
||||
this._iniString = this._iniString.slice(1, -1);
|
||||
if (iniString.charAt(0) == '(')
|
||||
iniString = iniString.slice(1, -1);
|
||||
try {
|
||||
initialState = JSON.parse(this._iniString);
|
||||
this._initialState = JSON.parse(iniString);
|
||||
}
|
||||
catch (exJSON) {
|
||||
var s = new Cu.Sandbox("about:blank");
|
||||
initialState = Cu.evalInSandbox("(" + this._iniString + ")", s);
|
||||
this._iniString = JSON.stringify(initialState);
|
||||
this._initialState = Cu.evalInSandbox("(" + iniString + ")", s);
|
||||
}
|
||||
}
|
||||
catch (ex) { debug("The session file is invalid: " + ex); }
|
||||
|
||||
let resumeFromCrash = prefBranch.getBoolPref("sessionstore.resume_from_crash");
|
||||
let lastSessionCrashed =
|
||||
initialState && initialState.session && initialState.session.state &&
|
||||
initialState.session.state == STATE_RUNNING_STR;
|
||||
this._initialState && this._initialState.session &&
|
||||
this._initialState.session.state &&
|
||||
this._initialState.session.state == STATE_RUNNING_STR;
|
||||
|
||||
// Report shutdown success via telemetry. Shortcoming here are
|
||||
// being-killed-by-OS-shutdown-logic, shutdown freezing after
|
||||
@@ -158,17 +157,17 @@ SessionStartup.prototype = {
|
||||
this._sessionType = Ci.nsISessionStartup.RECOVER_SESSION;
|
||||
else if (!lastSessionCrashed && doResumeSession)
|
||||
this._sessionType = Ci.nsISessionStartup.RESUME_SESSION;
|
||||
else if (initialState)
|
||||
else if (this._initialState)
|
||||
this._sessionType = Ci.nsISessionStartup.DEFER_SESSION;
|
||||
else
|
||||
this._iniString = null; // reset the state string
|
||||
this._initialState = null; // reset the state
|
||||
|
||||
// wait for the first browser window to open
|
||||
// Don't reset the initial window's default args (i.e. the home page(s))
|
||||
// if all stored tabs are pinned.
|
||||
if (this.doRestore() &&
|
||||
(!initialState.windows ||
|
||||
!initialState.windows.every(function (win)
|
||||
(!this._initialState.windows ||
|
||||
!this._initialState.windows.every(function (win)
|
||||
win.tabs.every(function (tab) tab.pinned))))
|
||||
Services.obs.addObserver(this, "domwindowopened", true);
|
||||
|
||||
@@ -204,8 +203,8 @@ SessionStartup.prototype = {
|
||||
break;
|
||||
case "sessionstore-windows-restored":
|
||||
Services.obs.removeObserver(this, "sessionstore-windows-restored");
|
||||
// free _iniString after nsSessionStore is done with it
|
||||
this._iniString = null;
|
||||
// free _initialState after nsSessionStore is done with it
|
||||
this._initialState = null;
|
||||
this._sessionType = Ci.nsISessionStartup.NO_SESSION;
|
||||
break;
|
||||
}
|
||||
@@ -254,7 +253,7 @@ SessionStartup.prototype = {
|
||||
* Get the session state as a string
|
||||
*/
|
||||
get state() {
|
||||
return this._iniString;
|
||||
return this._initialState;
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user