Bug 340895 Move SessionStore preferences to firefox.js (for zeniko, r=mano)

This commit is contained in:
dietrich%mozilla.com 2007-01-05 17:09:56 +00:00
parent 3737d80b97
commit 6e7e2de003
4 changed files with 45 additions and 119 deletions

View File

@ -178,7 +178,7 @@ pref("browser.shell.checkDefaultBrowser", true);
// 0 = blank, 1 = home (browser.startup.homepage), 2 = last visited page, 3 = resume previous browser session
// The behavior of option 3 is detailed at: http://wiki.mozilla.org/Session_Restore
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);
@ -531,3 +531,18 @@ pref("browser.EULA.2.accepted", true);
// if we rev the EULA again, we should bump this so users agree to the new EULA
pref("browser.EULA.version", 2);
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 be saved either 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);

View File

@ -5714,15 +5714,7 @@ var AugmentTabs = {
// listen for tab-context menu showing
this.tabContextMenu.addEventListener("popupshowing", this.onTabContextMenuLoad, false);
// add the tab context menu for undo-close-tab (bz254021)
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)
if (gPrefService.getBoolPref("browser.sessionstore.enabled"))
this._addUndoCloseTabContextMenu();
},

View File

@ -73,17 +73,6 @@ const CLASS_NAME = "Browser Session Startup Service";
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)
@ -107,12 +96,10 @@ SessionStartup.prototype = {
*/
init: function sss_init() {
this._prefBranch = Cc["@mozilla.org/preferences-service;1"].
getService(Ci.nsIPrefService).
getBranch("browser.");
this._prefBranch.QueryInterface(Ci.nsIPrefBranch2);
getService(Ci.nsIPrefService).getBranch("browser.");
// if the service is disabled, do not init
if (!this._getPref("sessionstore.enabled", DEFAULT_ENABLED))
if (!this._prefBranch.getBoolPref("sessionstore.enabled"))
return;
// get file references
@ -122,7 +109,7 @@ SessionStartup.prototype = {
this._sessionFile.append("sessionstore.js");
// only read the session file if config allows possibility of restoring
var resumeFromCrash = this._getPref("sessionstore.resume_from_crash", DEFAULT_RESUME_FROM_CRASH);
var resumeFromCrash = this._prefBranch.getBoolPref("sessionstore.resume_from_crash");
if (resumeFromCrash || this._doResumeSession()) {
// get string containing session state
this._iniString = this._readFile(this._sessionFile);
@ -147,7 +134,7 @@ SessionStartup.prototype = {
if (this._iniString && !this._doRestore) {
this._iniString = null; // reset the state string
}
if (this._getPref("sessionstore.resume_session_once", DEFAULT_RESUME_SESSION_ONCE)) {
if (this._prefBranch.getBoolPref("sessionstore.resume_session_once")) {
this._prefBranch.setBoolPref("sessionstore.resume_session_once", false);
}
@ -229,8 +216,8 @@ SessionStartup.prototype = {
* @returns bool
*/
_doResumeSession: function sss_doResumeSession() {
return this._getPref("startup.page", 1) == 3 ||
this._getPref("sessionstore.resume_session_once", DEFAULT_RESUME_SESSION_ONCE);
return this._prefBranch.getIntPref("startup.page") == 3 ||
this._prefBranch.getBoolPref("sessionstore.resume_session_once");
},
/**
@ -240,14 +227,19 @@ SessionStartup.prototype = {
*/
_doRecoverSession: function sss_doRecoverSession() {
// do not prompt or resume, post-crash
if (!this._getPref("sessionstore.resume_from_crash", DEFAULT_RESUME_FROM_CRASH))
if (!this._prefBranch.getBoolPref("sessionstore.resume_from_crash"))
return false;
// if the prompt fails, recover anyway
var recover = true;
// allow extensions to hook in a more elaborate restore prompt
// XXXzeniko drop this when we're using our own dialog instead of a standard prompt
var dialogURI = this._getPref("sessionstore.restore_prompt_uri");
var dialogURI = null;
try {
dialogURI = this._prefBranch.getCharPref("sessionstore.restore_prompt_uri");
}
catch (ex) { }
try {
if (dialogURI) { // extension provided dialog
@ -306,31 +298,6 @@ 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

View File

@ -68,30 +68,6 @@ 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",
@ -147,10 +123,10 @@ SessionStoreService.prototype = {
_loadState: STATE_STOPPED,
// minimal interval between two save operations (in milliseconds)
_interval: DEFAULT_INTERVAL,
_interval: 1000,
// when crash recovery is disabled, session data is not written to disk
_resume_from_crash: DEFAULT_RESUME_FROM_CRASH,
_resume_from_crash: true,
// time in milliseconds (Date.now()) when the session was last written to file
_lastSaveTime: 0,
@ -186,7 +162,7 @@ SessionStoreService.prototype = {
this._prefBranch.QueryInterface(Ci.nsIPrefBranch2);
// if the service is disabled, do not init
if (!this._getPref("sessionstore.enabled", DEFAULT_ENABLED))
if (!this._prefBranch.getBoolPref("sessionstore.enabled"))
return;
var observerService = Cc["@mozilla.org/observer-service;1"].
@ -197,11 +173,11 @@ SessionStoreService.prototype = {
}, this);
// get interval from prefs - used often, so caching/observing instead of fetching on-demand
this._interval = this._getPref("sessionstore.interval", DEFAULT_INTERVAL);
this._interval = this._prefBranch.getIntPref("sessionstore.interval");
this._prefBranch.addObserver("sessionstore.interval", this, true);
// get crash recovery state from prefs and allow for proper reaction to state changes
this._resume_from_crash = this._getPref("sessionstore.resume_from_crash", DEFAULT_RESUME_FROM_CRASH);
this._resume_from_crash = this._prefBranch.getBoolPref("sessionstore.resume_from_crash");
this._prefBranch.addObserver("sessionstore.resume_from_crash", this, true);
// observe prefs changes so we can modify stored data to match
@ -338,11 +314,11 @@ SessionStoreService.prototype = {
case "sessionstore.max_tabs_undo":
var ix;
for (ix in this._windows) {
this._windows[ix]._closedTabs.splice(this._getPref("sessionstore.max_tabs_undo", DEFAULT_MAX_TABS_UNDO));
this._windows[ix]._closedTabs.splice(this._prefBranch.getIntPref("sessionstore.max_tabs_undo"));
}
break;
case "sessionstore.interval":
this._interval = this._getPref("sessionstore.interval", this._interval);
this._interval = this._prefBranch.getIntPref("sessionstore.interval");
// reset timer and save
if (this._saveTimer) {
this._saveTimer.cancel();
@ -563,8 +539,9 @@ 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 (this._getPref("sessionstore.max_tabs_undo", DEFAULT_MAX_TABS_UNDO) == 0) {
if (maxTabsUndo == 0) {
return;
}
@ -580,7 +557,6 @@ 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);
@ -872,7 +848,7 @@ SessionStoreService.prototype = {
entry.scroll = x.value + "," + y.value;
try {
var prefPostdata = this._getPref("sessionstore.postdata", DEFAULT_POSTDATA);
var prefPostdata = this._prefBranch.getIntPref("sessionstore.postdata");
if (prefPostdata && aEntry.postData && this._checkPrivacyLevel(aEntry.URI.schemeIs("https"))) {
aEntry.postData.QueryInterface(Ci.nsISeekableStream).
seek(Ci.nsISeekableStream.NS_SEEK_SET, 0);
@ -1781,7 +1757,8 @@ 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._getPref("chromeURL", null), "_blank", "chrome,dialog=no,all", argString);
openWindow(null, this._prefBranch.getCharPref("chromeURL"), "_blank",
"chrome,dialog=no,all", argString);
window.__SS_state = aState;
var _this = this;
@ -1797,8 +1774,8 @@ SessionStoreService.prototype = {
* @returns bool
*/
_doResumeSession: function sss_doResumeSession() {
return this._getPref("startup.page", 1) == 3 ||
this._getPref("sessionstore.resume_session_once", DEFAULT_RESUME_SESSION_ONCE);
return this._prefBranch.getIntPref("startup.page") == 3 ||
this._prefBranch.getBoolPref("sessionstore.resume_session_once");
},
/**
@ -1825,7 +1802,7 @@ SessionStoreService.prototype = {
* @returns bool
*/
_checkPrivacyLevel: function sss_checkPrivacyLevel(aIsHTTPS) {
return this._getPref("sessionstore.privacy_level", DEFAULT_PRIVACY_LEVEL) < (aIsHTTPS ? PRIVACY_ENCRYPTED : PRIVACY_FULL);
return this._prefBranch.getIntPref("sessionstore.privacy_level") < (aIsHTTPS ? PRIVACY_ENCRYPTED : PRIVACY_FULL);
},
/**
@ -1980,31 +1957,6 @@ 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