diff --git a/browser/app/profile/firefox.js b/browser/app/profile/firefox.js index 3e00c35e8ab1..db56f2b3fdc9 100644 --- a/browser/app/profile/firefox.js +++ b/browser/app/profile/firefox.js @@ -181,9 +181,10 @@ pref("general.autoScroll", true); // is the default browser. pref("browser.shell.checkDefaultBrowser", true); -// 0 = blank, 1 = home (browser.startup.homepage), 2 = last, 3 = last session +// 0 = blank, 1 = home (browser.startup.homepage), 2 = last +// XXXBlake Remove this stupid pref pref("browser.startup.page", 1); -pref("browser.startup.homepage", "resource:/browserconfig.properties"); +pref("browser.startup.homepage", "resource:/browserconfig.properties"); pref("browser.cache.disk.capacity", 50000); pref("browser.enable_automatic_image_resizing", true); @@ -516,18 +517,3 @@ pref("browser.safebrowsing.provider.0.reportGenericURL", "http://{moz:locale}.ph pref("browser.safebrowsing.provider.0.reportErrorURL", "http://{moz:locale}.phish-error.mozilla.com/?hl={moz:locale}"); pref("browser.safebrowsing.provider.0.reportPhishURL", "http://{moz:locale}.phish-report.mozilla.com/?hl={moz:locale}"); #endif - -pref("browser.sessionstore.enabled", true); -pref("browser.sessionstore.resume_from_crash", true); -pref("browser.sessionstore.resume_session_once", false); - -// minimal interval between two save operations in milliseconds -pref("browser.sessionstore.interval", 10000); -// maximum amount of POSTDATA to be saved in bytes per history entry (-1 = all of it) -// (NB: POSTDATA will either be saved entirely or not at all) -pref("browser.sessionstore.postdata", 0); -// on which sites to save text data, POSTDATA and cookies -// 0 = everywhere, 1 = unencrypted sites, 2 = nowhere -pref("browser.sessionstore.privacy_level", 1); -// how many tabs can be reopened (per window) -pref("browser.sessionstore.max_tabs_undo", 10); diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index a44fecbd8e88..0fa1bf275899 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -6808,7 +6808,14 @@ var AugmentTabs = { this.tabContextMenu.addEventListener("popupshowing", this.onTabContextMenuLoad, false); // add the tab context menu for undo-close-tab (bz254021) - if (gPrefService.getBoolPref("browser.sessionstore.enabled")) { + var ssEnabled = true; + var prefBranch = Cc["@mozilla.org/preferences-service;1"]. + getService(Ci.nsIPrefBranch); + try { + ssEnabled = prefBranch.getBoolPref("browser.sessionstore.enabled"); + } catch (ex) {} + + if (ssEnabled) this._addUndoCloseTabContextMenu(); }, diff --git a/browser/components/sessionstore/src/nsSessionStartup.js b/browser/components/sessionstore/src/nsSessionStartup.js index ef35247bc816..bec000759526 100644 --- a/browser/components/sessionstore/src/nsSessionStartup.js +++ b/browser/components/sessionstore/src/nsSessionStartup.js @@ -79,6 +79,17 @@ const STATE_QUITTING = -1; const STATE_STOPPED_STR = "stopped"; const STATE_RUNNING_STR = "running"; +/* :::::::: Pref Defaults :::::::::::::::::::: */ + +// whether the service is enabled +const DEFAULT_ENABLED = true; + +// resume the current session at startup just this once +const DEFAULT_RESUME_SESSION_ONCE = false; + +// resume the current session at startup if it had previously crashed +const DEFAULT_RESUME_FROM_CRASH = true; + function debug(aMsg) { aMsg = ("SessionStartup: " + aMsg).replace(/\S{80}/g, "$&\n"); Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService) @@ -105,10 +116,12 @@ SessionStartup.prototype = { */ init: function sss_init() { this._prefBranch = Cc["@mozilla.org/preferences-service;1"]. - getService(Ci.nsIPrefService).getBranch("browser."); + getService(Ci.nsIPrefService). + getBranch("browser."); + this._prefBranch.QueryInterface(Ci.nsIPrefBranch2); // if the service is disabled, do not init - if (!this._prefBranch.getBoolPref("sessionstore.enabled")) + if (!this._getPref("sessionstore.enabled", DEFAULT_ENABLED)) return; // get file references @@ -120,7 +133,7 @@ SessionStartup.prototype = { this._sessionFileBackup.append("sessionstore.bak"); // only read the session file if config allows possibility of restoring - var resumeFromCrash = this._prefBranch.getBoolPref("sessionstore.resume_from_crash"); + var resumeFromCrash = this._getPref("sessionstore.resume_from_crash", DEFAULT_RESUME_FROM_CRASH); if (resumeFromCrash || this._doResumeSession()) { // get string containing session state this._iniString = this._readFile(this._getSessionFile()); @@ -150,7 +163,7 @@ SessionStartup.prototype = { delete this._initialState; // delete state this._iniString = null; // reset the state string } - if (this._prefBranch.getBoolPref("sessionstore.resume_session_once")) { + if (this._getPref("sessionstore.resume_session_once", DEFAULT_RESUME_SESSION_ONCE)) { this._prefBranch.setBoolPref("sessionstore.resume_session_once", false); } @@ -245,8 +258,8 @@ SessionStartup.prototype = { * @returns bool */ _doResumeSession: function sss_doResumeSession() { - return this._prefBranch.getIntPref("startup.page") == 3 || - this._prefBranch.getBoolPref("sessionstore.resume_session_once"); + return this._getPref("startup.page", 1) == 3 || + this._getPref("sessionstore.resume_session_once", DEFAULT_RESUME_SESSION_ONCE); }, /** @@ -256,19 +269,14 @@ SessionStartup.prototype = { */ _doRecoverSession: function sss_doRecoverSession() { // do not prompt or resume, post-crash - if (!this._prefBranch.getBoolPref("sessionstore.resume_from_crash")) + if (!this._getPref("sessionstore.resume_from_crash", DEFAULT_RESUME_FROM_CRASH)) return false; // if the prompt fails, recover anyway var recover = true; - - //XXXzeniko drop this when we're using our own dialog instead of a standard prompt // allow extensions to hook in a more elaborate restore prompt - var dialogURI; - try { - dialogURI = this._prefBranch.getCharPref("sessionstore.restore_prompt_uri"); - } - catch (ex) { } + //zeniko: drop this when we're using our own dialog instead of a standard prompt + var dialogURI = this._getPref("sessionstore.restore_prompt_uri"); try { if (dialogURI) { // extension provided dialog @@ -327,6 +335,31 @@ SessionStartup.prototype = { /* ........ Storage API .............. */ + /** + * basic pref reader + * @param aName + * @param aDefault + * @param aUseRootBranch + */ + _getPref: function sss_getPref(aName, aDefault) { + var pb = this._prefBranch; + try { + switch (pb.getPrefType(aName)) { + case pb.PREF_STRING: + return pb.getCharPref(aName); + case pb.PREF_BOOL: + return pb.getBoolPref(aName); + case pb.PREF_INT: + return pb.getIntPref(aName); + default: + return aDefault; + } + } + catch(ex) { + return aDefault; + } + }, + /** * reads a file into a string * @param aFile diff --git a/browser/components/sessionstore/src/nsSessionStore.js b/browser/components/sessionstore/src/nsSessionStore.js index 831c52730d2c..1aef02824267 100644 --- a/browser/components/sessionstore/src/nsSessionStore.js +++ b/browser/components/sessionstore/src/nsSessionStore.js @@ -68,6 +68,30 @@ const PRIVACY_NONE = 0; const PRIVACY_ENCRYPTED = 1; const PRIVACY_FULL = 2; +/* :::::::: Pref Defaults :::::::::::::::::::: */ + +// whether the service is enabled +const DEFAULT_ENABLED = true; + +// minimal interval between two save operations (in milliseconds) +const DEFAULT_INTERVAL = 10000; + +// maximum number of closed tabs remembered (per window) +const DEFAULT_MAX_TABS_UNDO = 10; + +// maximal amount of POSTDATA to be stored (in bytes, -1 = all of it) +const DEFAULT_POSTDATA = 0; + +// on which sites to save text data, POSTDATA and cookies +// (0 = everywhere, 1 = unencrypted sites, 2 = nowhere) +const DEFAULT_PRIVACY_LEVEL = PRIVACY_ENCRYPTED; + +// resume the current session at startup just this once +const DEFAULT_RESUME_SESSION_ONCE = false; + +// resume the current session at startup if it had previously crashed +const DEFAULT_RESUME_FROM_CRASH = true; + // global notifications observed const OBSERVING = [ "domwindowopened", "domwindowclosed", @@ -119,7 +143,7 @@ SessionStoreService.prototype = { _loadState: STATE_STOPPED, // minimal interval between two save operations (in milliseconds) - _interval: 10000, + _interval: DEFAULT_INTERVAL, // time in milliseconds (Date.now()) when the session was last written to file _lastSaveTime: 0, @@ -150,7 +174,7 @@ SessionStoreService.prototype = { this._prefBranch.QueryInterface(Ci.nsIPrefBranch2); // if the service is disabled, do not init - if (!this._prefBranch.getBoolPref("sessionstore.enabled")) + if (!this._getPref("sessionstore.enabled", DEFAULT_ENABLED)) return; var observerService = Cc["@mozilla.org/observer-service;1"]. @@ -161,7 +185,7 @@ SessionStoreService.prototype = { }, this); // get interval from prefs - used often, so caching/observing instead of fetching on-demand - this._interval = this._prefBranch.getIntPref("sessionstore.interval"); + this._interval = this._getPref("sessionstore.interval", DEFAULT_INTERVAL); this._prefBranch.addObserver("sessionstore.interval", this, true); // observe prefs changes so we can modify stored data to match @@ -293,11 +317,11 @@ SessionStoreService.prototype = { case "sessionstore.max_tabs_undo": var ix; for (ix in this._windows) { - this._windows[ix]._closedTabs.splice(this._prefBranch.getIntPref("sessionstore.max_tabs_undo")); + this._windows[ix]._closedTabs.splice(this._getPref("sessionstore.max_tabs_undo", DEFAULT_MAX_TABS_UNDO)); } break; case "sessionstore.interval": - this._interval = this._prefBranch.getIntPref("sessionstore.interval"); + this._interval = this._getPref("sessionstore.interval", this._interval); // reset timer and save if (this._saveTimer) { this._saveTimer.cancel(); @@ -504,9 +528,8 @@ SessionStoreService.prototype = { * TabPanel reference */ onTabClose: function sss_onTabClose(aWindow, aTab) { - var maxTabsUndo = this._prefBranch.getIntPref("sessionstore.max_tabs_undo"); // don't update our internal state if we don't have to - if (maxTabsUndo == 0) { + if (this._getPref("sessionstore.max_tabs_undo", DEFAULT_MAX_TABS_UNDO) == 0) { return; } @@ -522,6 +545,7 @@ SessionStoreService.prototype = { title: aTab.getAttribute("label"), pos: aTab._tPos }); + var maxTabsUndo = this._getPref("sessionstore.max_tabs_undo", DEFAULT_MAX_TABS_UNDO); var length = this._windows[aWindow.__SSi]._closedTabs.length; if (length > maxTabsUndo) this._windows[aWindow.__SSi]._closedTabs.splice(maxTabsUndo, length - maxTabsUndo); @@ -840,7 +864,7 @@ SessionStoreService.prototype = { entry.scroll = x.value + "," + y.value; try { - var prefPostdata = this._prefBranch.getIntPref("sessionstore.postdata"); + var prefPostdata = this._getPref("sessionstore.postdata", DEFAULT_POSTDATA); if (prefPostdata && aEntry.postData && this._checkPrivacyLevel(aEntry.URI.schemeIs("https"))) { aEntry.postData.QueryInterface(Ci.nsISeekableStream). seek(Ci.nsISeekableStream.NS_SEEK_SET, 0); @@ -1728,8 +1752,7 @@ SessionStoreService.prototype = { //XXXzeniko shouldn't it be possible to set the window's dimensions here (as feature)? var window = Cc["@mozilla.org/embedcomp/window-watcher;1"]. getService(Ci.nsIWindowWatcher). - openWindow(null, this._prefBranch.getCharPref("chromeURL"), "_blank", - "chrome,dialog=no,all", argString); + openWindow(null, this._getPref("chromeURL", null), "_blank", "chrome,dialog=no,all", argString); window.__SS_state = aState; var _this = this; @@ -1745,8 +1768,8 @@ SessionStoreService.prototype = { * @returns bool */ _doResumeSession: function sss_doResumeSession() { - return this._prefBranch.getIntPref("startup.page") == 3 || - this._prefBranch.getBoolPref("sessionstore.resume_session_once"); + return this._getPref("startup.page", 1) == 3 || + this._getPref("sessionstore.resume_session_once", DEFAULT_RESUME_SESSION_ONCE); }, /** @@ -1773,7 +1796,7 @@ SessionStoreService.prototype = { * @returns bool */ _checkPrivacyLevel: function sss_checkPrivacyLevel(aIsHTTPS) { - return this._prefBranch.getIntPref("sessionstore.privacy_level") < (aIsHTTPS ? PRIVACY_ENCRYPTED : PRIVACY_FULL); + return this._getPref("sessionstore.privacy_level", DEFAULT_PRIVACY_LEVEL) < (aIsHTTPS ? PRIVACY_ENCRYPTED : PRIVACY_FULL); }, /** @@ -1854,6 +1877,31 @@ SessionStoreService.prototype = { /* ........ Storage API .............. */ + /** + * basic pref reader + * @param aName + * @param aDefault + * @param aUseRootBranch + */ + _getPref: function sss_getPref(aName, aDefault) { + var pb = this._prefBranch; + try { + switch (pb.getPrefType(aName)) { + case pb.PREF_STRING: + return pb.getCharPref(aName); + case pb.PREF_BOOL: + return pb.getBoolPref(aName); + case pb.PREF_INT: + return pb.getIntPref(aName); + default: + return aDefault; + } + } + catch(ex) { + return aDefault; + } + }, + /** * write file to disk * @param aFile