зеркало из https://github.com/mozilla/gecko-dev.git
Bug 460546 - nsBrowserGlue should use a smart getter for the pref service. r=gavin
This commit is contained in:
Родитель
ccec8d49a8
Коммит
6b70009ffa
|
@ -73,13 +73,19 @@ function BrowserGlue() {
|
|||
}
|
||||
|
||||
BrowserGlue.prototype = {
|
||||
__prefs: null,
|
||||
get _prefs() {
|
||||
if (!this.__prefs)
|
||||
this.__prefs = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefBranch);
|
||||
return this.__prefs;
|
||||
},
|
||||
|
||||
_saveSession: false,
|
||||
|
||||
_setPrefToSaveSession: function()
|
||||
{
|
||||
var prefBranch = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefBranch);
|
||||
prefBranch.setBoolPref("browser.sessionstore.resume_session_once", true);
|
||||
this._prefs.setBoolPref("browser.sessionstore.resume_session_once", true);
|
||||
},
|
||||
|
||||
// nsIObserver implementation
|
||||
|
@ -177,11 +183,9 @@ BrowserGlue.prototype = {
|
|||
{
|
||||
// Check to see if the EULA must be shown on startup
|
||||
|
||||
var prefBranch = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefBranch);
|
||||
var mustDisplayEULA = false;
|
||||
try {
|
||||
mustDisplayEULA = !prefBranch.getBoolPref("browser.EULA.override");
|
||||
mustDisplayEULA = !this._prefs.getBoolPref("browser.EULA.override");
|
||||
} catch (e) {
|
||||
// Pref might not exist
|
||||
}
|
||||
|
@ -189,8 +193,8 @@ BrowserGlue.prototype = {
|
|||
// Make sure it hasn't already been accepted
|
||||
if (mustDisplayEULA) {
|
||||
try {
|
||||
var EULAVersion = prefBranch.getIntPref("browser.EULA.version");
|
||||
mustDisplayEULA = !prefBranch.getBoolPref("browser.EULA." + EULAVersion + ".accepted");
|
||||
var EULAVersion = this._prefs.getIntPref("browser.EULA.version");
|
||||
mustDisplayEULA = !this._prefs.getBoolPref("browser.EULA." + EULAVersion + ".accepted");
|
||||
} catch(ex) {
|
||||
}
|
||||
}
|
||||
|
@ -240,10 +244,8 @@ BrowserGlue.prototype = {
|
|||
// Browser startup complete. All initial windows have opened.
|
||||
_onBrowserStartup: function()
|
||||
{
|
||||
var prefBranch = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefBranch);
|
||||
// If new add-ons were installed during startup open the add-ons manager.
|
||||
if (prefBranch.prefHasUserValue(PREF_EM_NEW_ADDONS_LIST)) {
|
||||
if (this._prefs.prefHasUserValue(PREF_EM_NEW_ADDONS_LIST)) {
|
||||
var args = Cc["@mozilla.org/supports-array;1"].
|
||||
createInstance(Ci.nsISupportsArray);
|
||||
var str = Cc["@mozilla.org/supports-string;1"].
|
||||
|
@ -252,14 +254,14 @@ BrowserGlue.prototype = {
|
|||
args.AppendElement(str);
|
||||
var str = Cc["@mozilla.org/supports-string;1"].
|
||||
createInstance(Ci.nsISupportsString);
|
||||
str.data = prefBranch.getCharPref(PREF_EM_NEW_ADDONS_LIST);
|
||||
str.data = this._prefs.getCharPref(PREF_EM_NEW_ADDONS_LIST);
|
||||
args.AppendElement(str);
|
||||
const EMURL = "chrome://mozapps/content/extensions/extensions.xul";
|
||||
const EMFEATURES = "chrome,menubar,extra-chrome,toolbar,dialog=no,resizable";
|
||||
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
|
||||
getService(Ci.nsIWindowWatcher);
|
||||
ww.openWindow(null, EMURL, "_blank", EMFEATURES, args);
|
||||
prefBranch.clearUserPref(PREF_EM_NEW_ADDONS_LIST);
|
||||
this._prefs.clearUserPref(PREF_EM_NEW_ADDONS_LIST);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -291,22 +293,20 @@ BrowserGlue.prototype = {
|
|||
if (aQuitType != "restart")
|
||||
aQuitType = "quit";
|
||||
|
||||
var prefBranch = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefBranch);
|
||||
var showPrompt = true;
|
||||
try {
|
||||
// browser.warnOnQuit is a hidden global boolean to override all quit prompts
|
||||
// browser.warnOnRestart specifically covers app-initiated restarts where we restart the app
|
||||
// browser.tabs.warnOnClose is the global "warn when closing multiple tabs" pref
|
||||
|
||||
var sessionWillBeSaved = prefBranch.getIntPref("browser.startup.page") == 3 ||
|
||||
prefBranch.getBoolPref("browser.sessionstore.resume_session_once");
|
||||
if (sessionWillBeSaved || !prefBranch.getBoolPref("browser.warnOnQuit"))
|
||||
var sessionWillBeSaved = this._prefs.getIntPref("browser.startup.page") == 3 ||
|
||||
this._prefs.getBoolPref("browser.sessionstore.resume_session_once");
|
||||
if (sessionWillBeSaved || !this._prefs.getBoolPref("browser.warnOnQuit"))
|
||||
showPrompt = false;
|
||||
else if (aQuitType == "restart")
|
||||
showPrompt = prefBranch.getBoolPref("browser.warnOnRestart");
|
||||
showPrompt = this._prefs.getBoolPref("browser.warnOnRestart");
|
||||
else
|
||||
showPrompt = prefBranch.getBoolPref("browser.tabs.warnOnClose");
|
||||
showPrompt = this._prefs.getBoolPref("browser.tabs.warnOnClose");
|
||||
} catch (ex) {}
|
||||
|
||||
if (!showPrompt)
|
||||
|
@ -360,7 +360,7 @@ BrowserGlue.prototype = {
|
|||
switch (buttonChoice) {
|
||||
case 2: // Quit
|
||||
if (neverAsk.value)
|
||||
prefBranch.setBoolPref("browser.tabs.warnOnClose", false);
|
||||
this._prefs.setBoolPref("browser.tabs.warnOnClose", false);
|
||||
break;
|
||||
case 1: // Cancel
|
||||
aCancelQuit.QueryInterface(Ci.nsISupportsPRBool);
|
||||
|
@ -370,10 +370,10 @@ BrowserGlue.prototype = {
|
|||
this._saveSession = true;
|
||||
if (neverAsk.value) {
|
||||
if (aQuitType == "restart")
|
||||
prefBranch.setBoolPref("browser.warnOnRestart", false);
|
||||
this._prefs.setBoolPref("browser.warnOnRestart", false);
|
||||
else {
|
||||
// always save state when shutting down
|
||||
prefBranch.setIntPref("browser.startup.page", 3);
|
||||
this._prefs.setIntPref("browser.startup.page", 3);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -425,13 +425,10 @@ BrowserGlue.prototype = {
|
|||
var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
|
||||
getService(Ci.nsINavHistoryService);
|
||||
|
||||
var prefBranch = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefBranch);
|
||||
|
||||
var importBookmarks = false;
|
||||
var restoreDefaultBookmarks = false;
|
||||
try {
|
||||
restoreDefaultBookmarks = prefBranch.getBoolPref("browser.bookmarks.restore_default_bookmarks");
|
||||
restoreDefaultBookmarks = this._prefs.getBoolPref("browser.bookmarks.restore_default_bookmarks");
|
||||
} catch(ex) {}
|
||||
|
||||
if (restoreDefaultBookmarks) {
|
||||
|
@ -442,7 +439,7 @@ BrowserGlue.prototype = {
|
|||
}
|
||||
else {
|
||||
try {
|
||||
importBookmarks = prefBranch.getBoolPref("browser.places.importBookmarksHTML");
|
||||
importBookmarks = this._prefs.getBoolPref("browser.places.importBookmarksHTML");
|
||||
} catch(ex) {}
|
||||
}
|
||||
|
||||
|
@ -465,7 +462,7 @@ BrowserGlue.prototype = {
|
|||
// if there's no JSON backup or we are restoring default bookmarks
|
||||
|
||||
// ensurePlacesDefaultQueriesInitialized() is called by import.
|
||||
prefBranch.setIntPref("browser.places.smartBookmarksVersion", 0);
|
||||
this._prefs.setIntPref("browser.places.smartBookmarksVersion", 0);
|
||||
|
||||
var dirService = Cc["@mozilla.org/file/directory_service;1"].
|
||||
getService(Ci.nsIProperties);
|
||||
|
@ -486,9 +483,9 @@ BrowserGlue.prototype = {
|
|||
// Report the error, but ignore it.
|
||||
Cu.reportError(err);
|
||||
}
|
||||
prefBranch.setBoolPref("browser.places.importBookmarksHTML", false);
|
||||
this._prefs.setBoolPref("browser.places.importBookmarksHTML", false);
|
||||
if (restoreDefaultBookmarks)
|
||||
prefBranch.setBoolPref("browser.bookmarks.restore_default_bookmarks",
|
||||
this._prefs.setBoolPref("browser.bookmarks.restore_default_bookmarks",
|
||||
false);
|
||||
}
|
||||
}
|
||||
|
@ -512,11 +509,9 @@ BrowserGlue.prototype = {
|
|||
|
||||
// Backup bookmarks to bookmarks.html to support apps that depend
|
||||
// on the legacy format.
|
||||
var prefs = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefBranch);
|
||||
var autoExportHTML = false;
|
||||
try {
|
||||
autoExportHTML = prefs.getBoolPref("browser.bookmarks.autoExportHTML");
|
||||
autoExportHTML = this._prefs.getBoolPref("browser.bookmarks.autoExportHTML");
|
||||
} catch(ex) {
|
||||
Components.utils.reportError(ex);
|
||||
}
|
||||
|
@ -541,10 +536,8 @@ BrowserGlue.prototype = {
|
|||
if (!lastBackup ||
|
||||
Date.now() - lastBackup.lastModifiedTime > BOOKMARKS_ARCHIVE_INTERVAL) {
|
||||
var maxBackups = 5;
|
||||
var prefs = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefBranch);
|
||||
try {
|
||||
maxBackups = prefs.getIntPref("browser.bookmarks.max_backups");
|
||||
maxBackups = this._prefs.getIntPref("browser.bookmarks.max_backups");
|
||||
} catch(ex) {}
|
||||
|
||||
PlacesUtils.archiveBookmarksFile(maxBackups, false /* don't force */);
|
||||
|
@ -552,11 +545,9 @@ BrowserGlue.prototype = {
|
|||
},
|
||||
|
||||
_migrateUI: function bg__migrateUI() {
|
||||
var prefBranch = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
|
||||
|
||||
var migration = 0;
|
||||
try {
|
||||
migration = prefBranch.getIntPref("browser.migration.version");
|
||||
migration = this._prefs.getIntPref("browser.migration.version");
|
||||
} catch(ex) {}
|
||||
|
||||
if (migration == 0) {
|
||||
|
@ -600,7 +591,7 @@ BrowserGlue.prototype = {
|
|||
this._dataSource = null;
|
||||
|
||||
// update the migration version
|
||||
prefBranch.setIntPref("browser.migration.version", 1);
|
||||
this._prefs.setIntPref("browser.migration.version", 1);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -645,14 +636,11 @@ BrowserGlue.prototype = {
|
|||
// XXX should this be a pref? see bug #399268
|
||||
const MAX_RESULTS = 10;
|
||||
|
||||
var prefBranch = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefBranch);
|
||||
|
||||
// get current smart bookmarks version
|
||||
// By default, if the pref is not set up, we must create Smart Bookmarks
|
||||
var smartBookmarksCurrentVersion = 0;
|
||||
try {
|
||||
smartBookmarksCurrentVersion = prefBranch.getIntPref(SMART_BOOKMARKS_PREF);
|
||||
smartBookmarksCurrentVersion = this._prefs.getIntPref(SMART_BOOKMARKS_PREF);
|
||||
} catch(ex) {}
|
||||
|
||||
// bail out if we don't have to create or update Smart Bookmarks
|
||||
|
@ -772,8 +760,8 @@ BrowserGlue.prototype = {
|
|||
Components.utils.reportError(ex);
|
||||
}
|
||||
finally {
|
||||
prefBranch.setIntPref(SMART_BOOKMARKS_PREF, SMART_BOOKMARKS_VERSION);
|
||||
prefBranch.QueryInterface(Ci.nsIPrefService).savePrefFile(null);
|
||||
this._prefs.setIntPref(SMART_BOOKMARKS_PREF, SMART_BOOKMARKS_VERSION);
|
||||
this._prefs.QueryInterface(Ci.nsIPrefService).savePrefFile(null);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче