69 const Cc = Components.classes;
70 const Ci = Components.interfaces;
71 const Cr = Components.results;
72 Components.utils.import(
"resource://gre/modules/XPCOMUtils.jsm");
77 aMsg = (
"SessionStartup: " + aMsg).replace(/\S{80}/g,
"$&\n");
78 Cc[
"@mozilla.org/consoleservice;1"].getService(
Ci.nsIConsoleService)
79 .logStringMessage(aMsg);
91 _sessionType:
Ci.nsISessionStartup.NO_SESSION,
98 init:
function sss_init() {
100 let pbs =
Cc[
"@mozilla.org/privatebrowsing;1"].
105 let prefBranch =
Cc[
"@mozilla.org/preferences-service;1"].
109 var dirService =
Cc[
"@mozilla.org/file/directory_service;1"].
111 let sessionFile = dirService.get(
"ProfD",
Ci.nsILocalFile);
112 sessionFile.append(
"sessionstore.js");
114 let doResumeSession = prefBranch.getBoolPref(
"sessionstore.resume_session_once") ||
115 prefBranch.getIntPref(
"startup.page") == 3;
118 var resumeFromCrash = prefBranch.getBoolPref(
"sessionstore.resume_from_crash");
119 if (!resumeFromCrash && !doResumeSession || !sessionFile.exists())
123 this._iniString = this._readStateFile(sessionFile);
124 if (!this._iniString)
129 var s =
new Components.utils.Sandbox(
"about:blank");
130 var initialState = Components.utils.evalInSandbox(
"(" + this._iniString +
")", s);
132 catch (ex) {
debug(
"The session file is invalid: " + ex); }
134 let lastSessionCrashed =
135 initialState && initialState.session && initialState.session.state &&
139 if (lastSessionCrashed && resumeFromCrash)
140 this._sessionType =
Ci.nsISessionStartup.RECOVER_SESSION;
141 else if (!lastSessionCrashed && doResumeSession)
142 this._sessionType =
Ci.nsISessionStartup.RESUME_SESSION;
144 this._iniString =
null;
146 if (this._sessionType !=
Ci.nsISessionStartup.NO_SESSION) {
150 observerService.addObserver(
this,
"domwindowopened",
true);
151 observerService.addObserver(
this,
"browser:purge-session-history",
true);
158 observe:
function sss_observe(aSubject, aTopic,
aData) {
164 observerService.addObserver(
this,
"final-ui-startup",
true);
165 observerService.addObserver(
this,
"quit-application",
true);
167 case "final-ui-startup":
168 observerService.removeObserver(
this,
"final-ui-startup");
169 observerService.removeObserver(
this,
"quit-application");
172 case "quit-application":
174 observerService.removeObserver(
this,
"final-ui-startup");
175 observerService.removeObserver(
this,
"quit-application");
177 case "domwindowopened":
180 window.addEventListener(
"load",
function() {
181 self._onWindowOpened(window);
182 window.removeEventListener(
"load",
arguments.callee,
false);
185 case "browser:purge-session-history":
187 this._iniString =
null;
188 this._sessionType =
Ci.nsISessionStartup.NO_SESSION;
190 observerService.removeObserver(
this,
"browser:purge-session-history");
199 _onWindowOpened:
function sss_onWindowOpened(aWindow) {
200 var wType = aWindow.document.documentElement.getAttribute(
"windowtype");
201 if (wType !=
"navigator:browser")
218 var defaultArgs =
Cc[
"@mozilla.org/browser/clh;1"].
220 if (aWindow.arguments && aWindow.arguments[0] &&
221 aWindow.arguments[0] == defaultArgs)
222 aWindow.arguments[0] =
null;
226 observerService.removeObserver(
this,
"domwindowopened");
235 return this._iniString;
242 doRestore:
function sss_doRestore() {
243 return this._sessionType !=
Ci.nsISessionStartup.NO_SESSION;
250 return this._sessionType;
262 _readStateFile:
function sss_readStateFile(aFile) {
263 var stateString =
Cc[
"@mozilla.org/supports-string;1"].
265 stateString.data = this._readFile(aFile) ||
"";
269 observerService.notifyObservers(stateString,
"sessionstore-state-read",
"");
271 return stateString.data;
280 _readFile:
function sss_readFile(aFile) {
282 var stream =
Cc[
"@mozilla.org/network/file-input-stream;1"].
284 stream.init(aFile, 0x01, 0, 0);
285 var cvstream =
Cc[
"@mozilla.org/intl/converter-input-stream;1"].
287 cvstream.init(stream,
"UTF-8", 1024,
Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
291 while (cvstream.readString(4096, data)) {
292 content += data.value;
296 return content.replace(/\r\n?/g,
"\n");
298 catch (ex) { Components.utils.reportError(ex); }
305 Ci.nsISupportsWeakReference,
306 Ci.nsISessionStartup]),
308 classID: Components.ID(
"{ec7a6c20-e081-11da-8ad9-0800200c9a66}"),
309 contractID:
"@mozilla.org/browser/sessionstartup;1",
314 { category:
"app-startup",
service:
true }
static nsCOMPtr< nsIObserverService > observerService
function NSGetModule(aCompMgr, aFileSpec) XPCOMUtils.generateModule([SessionStartup])
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
sbOSDControlService prototype QueryInterface
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
getService(Ci.sbIFaceplateManager)
return!aWindow arguments!aWindow arguments[0]
function SessionStartup()
sbDeviceFirmwareAutoCheckForUpdate prototype classID
sbWindowsAutoPlayServiceCfg _xpcom_categories
_updateTextAndScrollDataForFrame aData
sbDeviceFirmwareAutoCheckForUpdate prototype observe