Bug 558774: use Services.jsm in browser glue, r=dao

This commit is contained in:
Gavin Sharp 2010-04-12 10:33:10 -04:00
Родитель fe8c6093ad
Коммит ff8cc7c5bf
1 изменённых файлов: 108 добавлений и 153 удалений

Просмотреть файл

@ -50,6 +50,7 @@ const Cu = Components.utils;
const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; const XULNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
Cu.import("resource://gre/modules/XPCOMUtils.jsm"); Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
const PREF_EM_NEW_ADDONS_LIST = "extensions.newAddons"; const PREF_EM_NEW_ADDONS_LIST = "extensions.newAddons";
const PREF_PLUGINS_NOTIFYUSER = "plugins.update.notifyUser"; const PREF_PLUGINS_NOTIFYUSER = "plugins.update.notifyUser";
@ -77,14 +78,6 @@ const BrowserGlueServiceFactory = {
// Constructor // Constructor
function BrowserGlue() { function BrowserGlue() {
XPCOMUtils.defineLazyServiceGetter(this, "_prefs",
"@mozilla.org/preferences-service;1",
"nsIPrefBranch");
XPCOMUtils.defineLazyServiceGetter(this, "_bundleService",
"@mozilla.org/intl/stringbundle;1",
"nsIStringBundleService");
XPCOMUtils.defineLazyServiceGetter(this, "_idleService", XPCOMUtils.defineLazyServiceGetter(this, "_idleService",
"@mozilla.org/widget/idleservice;1", "@mozilla.org/widget/idleservice;1",
"nsIIdleService"); "nsIIdleService");
@ -97,17 +90,10 @@ function BrowserGlue() {
XPCOMUtils.defineLazyGetter(this, "_sanitizer", XPCOMUtils.defineLazyGetter(this, "_sanitizer",
function() { function() {
let sanitizerScope = {}; let sanitizerScope = {};
Cc["@mozilla.org/moz/jssubscript-loader;1"]. Services.scriptloader.loadSubScript("chrome://browser/content/sanitize.js", sanitizerScope);
getService(Ci.mozIJSSubScriptLoader).
loadSubScript("chrome://browser/content/sanitize.js", sanitizerScope);
return sanitizerScope.Sanitizer; return sanitizerScope.Sanitizer;
}); });
// The observer service is immediately used in _init(), so there's no reason
// to have a getter.
this._observerService = Cc["@mozilla.org/observer-service;1"].
getService(Ci.nsIObserverService);
this._init(); this._init();
} }
@ -128,12 +114,12 @@ BrowserGlue.prototype = {
if (!this._saveSession && !aForce) if (!this._saveSession && !aForce)
return; return;
this._prefs.setBoolPref("browser.sessionstore.resume_session_once", true); Services.prefs.setBoolPref("browser.sessionstore.resume_session_once", true);
// This method can be called via [NSApplication terminate:] on Mac, which // This method can be called via [NSApplication terminate:] on Mac, which
// ends up causing prefs not to be flushed to disk, so we need to do that // ends up causing prefs not to be flushed to disk, so we need to do that
// explicitly here. See bug 497652. // explicitly here. See bug 497652.
this._prefs.QueryInterface(Ci.nsIPrefService).savePrefFile(null); Services.prefs.savePrefFile(null);
}, },
// nsIObserver implementation // nsIObserver implementation
@ -153,10 +139,8 @@ BrowserGlue.prototype = {
break; break;
case "browser:purge-session-history": case "browser:purge-session-history":
// reset the console service's error buffer // reset the console service's error buffer
const cs = Cc["@mozilla.org/consoleservice;1"]. Services.console.logStringMessage(null); // clear the console (in case it's open)
getService(Ci.nsIConsoleService); Services.console.reset();
cs.logStringMessage(null); // clear the console (in case it's open)
cs.reset();
break; break;
case "quit-application-requested": case "quit-application-requested":
this._onQuitRequest(subject, data); this._onQuitRequest(subject, data);
@ -184,10 +168,10 @@ BrowserGlue.prototype = {
break; break;
case "places-init-complete": case "places-init-complete":
this._initPlaces(); this._initPlaces();
this._observerService.removeObserver(this, "places-init-complete"); Services.obs.removeObserver(this, "places-init-complete");
this._isPlacesInitObserver = false; this._isPlacesInitObserver = false;
// no longer needed, since history was initialized completely. // no longer needed, since history was initialized completely.
this._observerService.removeObserver(this, "places-database-locked"); Services.obs.removeObserver(this, "places-database-locked");
this._isPlacesLockedObserver = false; this._isPlacesLockedObserver = false;
// Now apply distribution customized bookmarks. // Now apply distribution customized bookmarks.
@ -198,7 +182,7 @@ BrowserGlue.prototype = {
this._isPlacesDatabaseLocked = true; this._isPlacesDatabaseLocked = true;
// Stop observing, so further attempts to load history service // Stop observing, so further attempts to load history service
// will not show the prompt. // will not show the prompt.
this._observerService.removeObserver(this, "places-database-locked"); Services.obs.removeObserver(this, "places-database-locked");
this._isPlacesLockedObserver = false; this._isPlacesLockedObserver = false;
break; break;
case "idle": case "idle":
@ -206,21 +190,20 @@ BrowserGlue.prototype = {
this._backupBookmarks(); this._backupBookmarks();
break; break;
case "distribution-customization-complete": case "distribution-customization-complete":
this._observerService Services.obs.removeObserver(this, "distribution-customization-complete");
.removeObserver(this, "distribution-customization-complete");
// Customization has finished, we don't need the customizer anymore. // Customization has finished, we don't need the customizer anymore.
delete this._distributionCustomizer; delete this._distributionCustomizer;
break; break;
case "bookmarks-restore-success": case "bookmarks-restore-success":
case "bookmarks-restore-failed": case "bookmarks-restore-failed":
this._observerService.removeObserver(this, "bookmarks-restore-success"); Services.obs.removeObserver(this, "bookmarks-restore-success");
this._observerService.removeObserver(this, "bookmarks-restore-failed"); Services.obs.removeObserver(this, "bookmarks-restore-failed");
if (topic == "bookmarks-restore-success" && data == "html-initial") if (topic == "bookmarks-restore-success" && data == "html-initial")
this.ensurePlacesDefaultQueriesInitialized(); this.ensurePlacesDefaultQueriesInitialized();
break; break;
case "browser-glue-test": // used by tests case "browser-glue-test": // used by tests
if (data == "post-update-notification") { if (data == "post-update-notification") {
if (this._prefs.prefHasUserValue("app.update.postupdate")) if (Services.prefs.prefHasUserValue("app.update.postupdate"))
this._showUpdateNotification(); this._showUpdateNotification();
break; break;
} }
@ -231,48 +214,46 @@ BrowserGlue.prototype = {
// initialization (called on application startup) // initialization (called on application startup)
_init: function BG__init() { _init: function BG__init() {
// observer registration // observer registration
const osvr = this._observerService; Services.obs.addObserver(this, "xpcom-shutdown", false);
osvr.addObserver(this, "xpcom-shutdown", false); Services.obs.addObserver(this, "prefservice:after-app-defaults", false);
osvr.addObserver(this, "prefservice:after-app-defaults", false); Services.obs.addObserver(this, "final-ui-startup", false);
osvr.addObserver(this, "final-ui-startup", false); Services.obs.addObserver(this, "sessionstore-windows-restored", false);
osvr.addObserver(this, "sessionstore-windows-restored", false); Services.obs.addObserver(this, "browser:purge-session-history", false);
osvr.addObserver(this, "browser:purge-session-history", false); Services.obs.addObserver(this, "quit-application-requested", false);
osvr.addObserver(this, "quit-application-requested", false); Services.obs.addObserver(this, "quit-application-granted", false);
osvr.addObserver(this, "quit-application-granted", false);
#ifdef OBSERVE_LASTWINDOW_CLOSE_TOPICS #ifdef OBSERVE_LASTWINDOW_CLOSE_TOPICS
osvr.addObserver(this, "browser-lastwindow-close-requested", false); Services.obs.addObserver(this, "browser-lastwindow-close-requested", false);
osvr.addObserver(this, "browser-lastwindow-close-granted", false); Services.obs.addObserver(this, "browser-lastwindow-close-granted", false);
#endif #endif
osvr.addObserver(this, "session-save", false); Services.obs.addObserver(this, "session-save", false);
osvr.addObserver(this, "places-init-complete", false); Services.obs.addObserver(this, "places-init-complete", false);
this._isPlacesInitObserver = true; this._isPlacesInitObserver = true;
osvr.addObserver(this, "places-database-locked", false); Services.obs.addObserver(this, "places-database-locked", false);
this._isPlacesLockedObserver = true; this._isPlacesLockedObserver = true;
osvr.addObserver(this, "distribution-customization-complete", false); Services.obs.addObserver(this, "distribution-customization-complete", false);
}, },
// cleanup (called on application shutdown) // cleanup (called on application shutdown)
_dispose: function BG__dispose() { _dispose: function BG__dispose() {
// observer removal // observer removal
const osvr = this._observerService; Services.obs.removeObserver(this, "xpcom-shutdown");
osvr.removeObserver(this, "xpcom-shutdown"); Services.obs.removeObserver(this, "prefservice:after-app-defaults");
osvr.removeObserver(this, "prefservice:after-app-defaults"); Services.obs.removeObserver(this, "final-ui-startup");
osvr.removeObserver(this, "final-ui-startup"); Services.obs.removeObserver(this, "sessionstore-windows-restored");
osvr.removeObserver(this, "sessionstore-windows-restored"); Services.obs.removeObserver(this, "browser:purge-session-history");
osvr.removeObserver(this, "browser:purge-session-history"); Services.obs.removeObserver(this, "quit-application-requested");
osvr.removeObserver(this, "quit-application-requested"); Services.obs.removeObserver(this, "quit-application-granted");
osvr.removeObserver(this, "quit-application-granted");
#ifdef OBSERVE_LASTWINDOW_CLOSE_TOPICS #ifdef OBSERVE_LASTWINDOW_CLOSE_TOPICS
osvr.removeObserver(this, "browser-lastwindow-close-requested"); Services.obs.removeObserver(this, "browser-lastwindow-close-requested");
osvr.removeObserver(this, "browser-lastwindow-close-granted"); Services.obs.removeObserver(this, "browser-lastwindow-close-granted");
#endif #endif
osvr.removeObserver(this, "session-save"); Services.obs.removeObserver(this, "session-save");
if (this._isIdleObserver) if (this._isIdleObserver)
this._idleService.removeIdleObserver(this, BOOKMARKS_BACKUP_IDLE_TIME); this._idleService.removeIdleObserver(this, BOOKMARKS_BACKUP_IDLE_TIME);
if (this._isPlacesInitObserver) if (this._isPlacesInitObserver)
osvr.removeObserver(this, "places-init-complete"); Services.obs.removeObserver(this, "places-init-complete");
if (this._isPlacesLockedObserver) if (this._isPlacesLockedObserver)
osvr.removeObserver(this, "places-database-locked"); Services.obs.removeObserver(this, "places-database-locked");
}, },
_onAppDefaults: function BG__onAppDefaults() { _onAppDefaults: function BG__onAppDefaults() {
@ -285,13 +266,9 @@ BrowserGlue.prototype = {
_onProfileStartup: function BG__onProfileStartup() { _onProfileStartup: function BG__onProfileStartup() {
this._sanitizer.onStartup(); this._sanitizer.onStartup();
// check if we're in safe mode // check if we're in safe mode
var app = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo). if (Services.appinfo.inSafeMode) {
QueryInterface(Ci.nsIXULRuntime); Services.ww.openWindow(null, "chrome://browser/content/safeMode.xul",
if (app.inSafeMode) { "_blank", "chrome,centerscreen,modal,resizable=no", null);
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
getService(Ci.nsIWindowWatcher);
ww.openWindow(null, "chrome://browser/content/safeMode.xul",
"_blank", "chrome,centerscreen,modal,resizable=no", null);
} }
// apply distribution customizations // apply distribution customizations
@ -301,24 +278,20 @@ BrowserGlue.prototype = {
// handle any UI migration // handle any UI migration
this._migrateUI(); this._migrateUI();
var ioService = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService2);
// if ioService is managing the offline status, then ioservice.offline // if ioService is managing the offline status, then ioservice.offline
// is already set correctly. We will continue to allow the ioService // is already set correctly. We will continue to allow the ioService
// to manage its offline state until the user uses the "Work Offline" UI. // to manage its offline state until the user uses the "Work Offline" UI.
if (!ioService.manageOfflineStatus) { if (!Services.io.manageOfflineStatus) {
// set the initial state // set the initial state
try { try {
ioService.offline = this._prefs.getBoolPref("browser.offline"); Services.io.offline = Services.prefs.getBoolPref("browser.offline");
} }
catch (e) { catch (e) {
ioService.offline = false; Services.io.offline = false;
} }
} }
this._observerService Services.obs.notifyObservers(null, "browser-ui-startup-complete", "");
.notifyObservers(null, "browser-ui-startup-complete", "");
}, },
// profile shutdown handler (contains profile cleanup routines) // profile shutdown handler (contains profile cleanup routines)
@ -348,11 +321,11 @@ BrowserGlue.prototype = {
this._showRightsNotification(); this._showRightsNotification();
// Show update notification, if needed. // Show update notification, if needed.
if (this._prefs.prefHasUserValue("app.update.postupdate")) if (Services.prefs.prefHasUserValue("app.update.postupdate"))
this._showUpdateNotification(); this._showUpdateNotification();
// If new add-ons were installed during startup open the add-ons manager. // If new add-ons were installed during startup open the add-ons manager.
if (this._prefs.prefHasUserValue(PREF_EM_NEW_ADDONS_LIST)) { if (Services.prefs.prefHasUserValue(PREF_EM_NEW_ADDONS_LIST)) {
var args = Cc["@mozilla.org/supports-array;1"]. var args = Cc["@mozilla.org/supports-array;1"].
createInstance(Ci.nsISupportsArray); createInstance(Ci.nsISupportsArray);
var str = Cc["@mozilla.org/supports-string;1"]. var str = Cc["@mozilla.org/supports-string;1"].
@ -361,14 +334,12 @@ BrowserGlue.prototype = {
args.AppendElement(str); args.AppendElement(str);
var str = Cc["@mozilla.org/supports-string;1"]. var str = Cc["@mozilla.org/supports-string;1"].
createInstance(Ci.nsISupportsString); createInstance(Ci.nsISupportsString);
str.data = this._prefs.getCharPref(PREF_EM_NEW_ADDONS_LIST); str.data = Services.prefs.getCharPref(PREF_EM_NEW_ADDONS_LIST);
args.AppendElement(str); args.AppendElement(str);
const EMURL = "chrome://mozapps/content/extensions/extensions.xul"; const EMURL = "chrome://mozapps/content/extensions/extensions.xul";
const EMFEATURES = "chrome,menubar,extra-chrome,toolbar,dialog=no,resizable"; const EMFEATURES = "chrome,menubar,extra-chrome,toolbar,dialog=no,resizable";
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"]. Services.ww.openWindow(null, EMURL, "_blank", EMFEATURES, args);
getService(Ci.nsIWindowWatcher); Services.prefs.clearUserPref(PREF_EM_NEW_ADDONS_LIST);
ww.openWindow(null, EMURL, "_blank", EMFEATURES, args);
this._prefs.clearUserPref(PREF_EM_NEW_ADDONS_LIST);
} }
// Load the "more info" page for a locked places.sqlite // Load the "more info" page for a locked places.sqlite
@ -382,7 +353,7 @@ BrowserGlue.prototype = {
// If there are plugins installed that are outdated, and the user hasn't // If there are plugins installed that are outdated, and the user hasn't
// been warned about them yet, open the plugins update page. // been warned about them yet, open the plugins update page.
if (this._prefs.getBoolPref(PREF_PLUGINS_NOTIFYUSER)) if (Services.prefs.getBoolPref(PREF_PLUGINS_NOTIFYUSER))
this._showPluginUpdatePage(); this._showPluginUpdatePage();
#ifdef XP_WIN #ifdef XP_WIN
@ -404,12 +375,9 @@ BrowserGlue.prototype = {
if ((aCancelQuit instanceof Ci.nsISupportsPRBool) && aCancelQuit.data) if ((aCancelQuit instanceof Ci.nsISupportsPRBool) && aCancelQuit.data)
return; return;
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
getService(Ci.nsIWindowMediator);
var windowcount = 0; var windowcount = 0;
var pagecount = 0; var pagecount = 0;
var browserEnum = wm.getEnumerator("navigator:browser"); var browserEnum = Services.wm.getEnumerator("navigator:browser");
while (browserEnum.hasMoreElements()) { while (browserEnum.hasMoreElements()) {
windowcount++; windowcount++;
@ -432,14 +400,14 @@ BrowserGlue.prototype = {
// browser.warnOnRestart specifically covers app-initiated restarts where we restart the app // browser.warnOnRestart specifically covers app-initiated restarts where we restart the app
// browser.tabs.warnOnClose is the global "warn when closing multiple tabs" pref // browser.tabs.warnOnClose is the global "warn when closing multiple tabs" pref
var sessionWillBeSaved = this._prefs.getIntPref("browser.startup.page") == 3 || var sessionWillBeSaved = Services.prefs.getIntPref("browser.startup.page") == 3 ||
this._prefs.getBoolPref("browser.sessionstore.resume_session_once"); Services.prefs.getBoolPref("browser.sessionstore.resume_session_once");
if (sessionWillBeSaved || !this._prefs.getBoolPref("browser.warnOnQuit")) if (sessionWillBeSaved || !Services.prefs.getBoolPref("browser.warnOnQuit"))
showPrompt = false; showPrompt = false;
else if (aQuitType == "restart") else if (aQuitType == "restart")
showPrompt = this._prefs.getBoolPref("browser.warnOnRestart"); showPrompt = Services.prefs.getBoolPref("browser.warnOnRestart");
else else
showPrompt = this._prefs.getBoolPref("browser.tabs.warnOnClose"); showPrompt = Services.prefs.getBoolPref("browser.tabs.warnOnClose");
} catch (ex) {} } catch (ex) {}
// Never show a prompt inside the private browsing mode // Never show a prompt inside the private browsing mode
@ -449,8 +417,8 @@ BrowserGlue.prototype = {
if (!showPrompt || inPrivateBrowsing) if (!showPrompt || inPrivateBrowsing)
return false; return false;
var quitBundle = this._bundleService.createBundle("chrome://browser/locale/quitDialog.properties"); var quitBundle = Services.strings.createBundle("chrome://browser/locale/quitDialog.properties");
var brandBundle = this._bundleService.createBundle("chrome://branding/locale/brand.properties"); var brandBundle = Services.strings.createBundle("chrome://branding/locale/brand.properties");
var appName = brandBundle.GetStringFromName("brandShortName"); var appName = brandBundle.GetStringFromName("brandShortName");
var quitDialogTitle = quitBundle.formatStringFromName(aQuitType + "DialogTitle", var quitDialogTitle = quitBundle.formatStringFromName(aQuitType + "DialogTitle",
@ -467,8 +435,7 @@ BrowserGlue.prototype = {
message = quitBundle.formatStringFromName("message", message = quitBundle.formatStringFromName("message",
[appName], 1); [appName], 1);
var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"]. var promptService = Services.prompt;
getService(Ci.nsIPromptService);
var flags = promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0 + var flags = promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0 +
promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_1 + promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_1 +
@ -487,7 +454,7 @@ BrowserGlue.prototype = {
button2Title = quitBundle.GetStringFromName("quitTitle"); button2Title = quitBundle.GetStringFromName("quitTitle");
} }
var mostRecentBrowserWindow = wm.getMostRecentWindow("navigator:browser"); var mostRecentBrowserWindow = Services.wm.getMostRecentWindow("navigator:browser");
var buttonChoice = var buttonChoice =
promptService.confirmEx(mostRecentBrowserWindow, quitDialogTitle, message, promptService.confirmEx(mostRecentBrowserWindow, quitDialogTitle, message,
flags, button0Title, button1Title, button2Title, flags, button0Title, button1Title, button2Title,
@ -496,7 +463,7 @@ BrowserGlue.prototype = {
switch (buttonChoice) { switch (buttonChoice) {
case 2: // Quit case 2: // Quit
if (neverAsk.value) if (neverAsk.value)
this._prefs.setBoolPref("browser.tabs.warnOnClose", false); Services.prefs.setBoolPref("browser.tabs.warnOnClose", false);
break; break;
case 1: // Cancel case 1: // Cancel
aCancelQuit.QueryInterface(Ci.nsISupportsPRBool); aCancelQuit.QueryInterface(Ci.nsISupportsPRBool);
@ -506,10 +473,10 @@ BrowserGlue.prototype = {
this._saveSession = true; this._saveSession = true;
if (neverAsk.value) { if (neverAsk.value) {
if (aQuitType == "restart") if (aQuitType == "restart")
this._prefs.setBoolPref("browser.warnOnRestart", false); Services.prefs.setBoolPref("browser.warnOnRestart", false);
else { else {
// always save state when shutting down // always save state when shutting down
this._prefs.setIntPref("browser.startup.page", 3); Services.prefs.setIntPref("browser.startup.page", 3);
} }
} }
break; break;
@ -528,11 +495,11 @@ BrowserGlue.prototype = {
// Look for an unconditional override pref. If set, do what it says. // Look for an unconditional override pref. If set, do what it says.
// (true --> never show, false --> always show) // (true --> never show, false --> always show)
try { try {
return !this._prefs.getBoolPref("browser.rights.override"); return !Services.prefs.getBoolPref("browser.rights.override");
} catch (e) { } } catch (e) { }
// Ditto, for the legacy EULA pref. // Ditto, for the legacy EULA pref.
try { try {
return !this._prefs.getBoolPref("browser.EULA.override"); return !Services.prefs.getBoolPref("browser.EULA.override");
} catch (e) { } } catch (e) { }
#ifndef OFFICIAL_BUILD #ifndef OFFICIAL_BUILD
@ -541,15 +508,15 @@ BrowserGlue.prototype = {
#endif #endif
// Look to see if the user has seen the current version or not. // Look to see if the user has seen the current version or not.
var currentVersion = this._prefs.getIntPref("browser.rights.version"); var currentVersion = Services.prefs.getIntPref("browser.rights.version");
try { try {
return !this._prefs.getBoolPref("browser.rights." + currentVersion + ".shown"); return !Services.prefs.getBoolPref("browser.rights." + currentVersion + ".shown");
} catch (e) { } } catch (e) { }
// Legacy: If the user accepted a EULA, we won't annoy them with the // Legacy: If the user accepted a EULA, we won't annoy them with the
// equivalent about:rights page until the version changes. // equivalent about:rights page until the version changes.
try { try {
return !this._prefs.getBoolPref("browser.EULA." + currentVersion + ".accepted"); return !Services.prefs.getBoolPref("browser.EULA." + currentVersion + ".accepted");
} catch (e) { } } catch (e) { }
// We haven't shown the notification before, so do so now. // We haven't shown the notification before, so do so now.
@ -562,8 +529,8 @@ BrowserGlue.prototype = {
var browser = win.gBrowser; // for closure in notification bar callback var browser = win.gBrowser; // for closure in notification bar callback
var notifyBox = browser.getNotificationBox(); var notifyBox = browser.getNotificationBox();
var brandBundle = this._bundleService.createBundle("chrome://branding/locale/brand.properties"); var brandBundle = Services.strings.createBundle("chrome://branding/locale/brand.properties");
var rightsBundle = this._bundleService.createBundle("chrome://global/locale/aboutRights.properties"); var rightsBundle = Services.strings.createBundle("chrome://global/locale/aboutRights.properties");
var buttonLabel = rightsBundle.GetStringFromName("buttonLabel"); var buttonLabel = rightsBundle.GetStringFromName("buttonLabel");
var buttonAccessKey = rightsBundle.GetStringFromName("buttonAccessKey"); var buttonAccessKey = rightsBundle.GetStringFromName("buttonAccessKey");
@ -582,15 +549,15 @@ BrowserGlue.prototype = {
]; ];
// Set pref to indicate we've shown the notification. // Set pref to indicate we've shown the notification.
var currentVersion = this._prefs.getIntPref("browser.rights.version"); var currentVersion = Services.prefs.getIntPref("browser.rights.version");
this._prefs.setBoolPref("browser.rights." + currentVersion + ".shown", true); Services.prefs.setBoolPref("browser.rights." + currentVersion + ".shown", true);
var box = notifyBox.appendNotification(notifyRightsText, "about-rights", null, notifyBox.PRIORITY_INFO_LOW, buttons); var box = notifyBox.appendNotification(notifyRightsText, "about-rights", null, notifyBox.PRIORITY_INFO_LOW, buttons);
box.persistence = 3; // arbitrary number, just so bar sticks around for a bit box.persistence = 3; // arbitrary number, just so bar sticks around for a bit
}, },
_showUpdateNotification: function BG__showUpdateNotification() { _showUpdateNotification: function BG__showUpdateNotification() {
this._prefs.clearUserPref("app.update.postupdate"); Services.prefs.clearUserPref("app.update.postupdate");
var um = Cc["@mozilla.org/updates/update-manager;1"]. var um = Cc["@mozilla.org/updates/update-manager;1"].
getService(Ci.nsIUpdateManager); getService(Ci.nsIUpdateManager);
@ -610,10 +577,8 @@ BrowserGlue.prototype = {
var formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"]. var formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"].
getService(Ci.nsIURLFormatter); getService(Ci.nsIURLFormatter);
var browserBundle = this._bundleService. var browserBundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
createBundle("chrome://browser/locale/browser.properties"); var brandBundle = Services.strings.createBundle("chrome://branding/locale/brand.properties");
var brandBundle = this._bundleService.
createBundle("chrome://branding/locale/brand.properties");
var appName = brandBundle.GetStringFromName("brandShortName"); var appName = brandBundle.GetStringFromName("brandShortName");
function getNotifyString(aPropData) { function getNotifyString(aPropData) {
@ -706,7 +671,7 @@ BrowserGlue.prototype = {
}, },
_showPluginUpdatePage: function BG__showPluginUpdatePage() { _showPluginUpdatePage: function BG__showPluginUpdatePage() {
this._prefs.setBoolPref(PREF_PLUGINS_NOTIFYUSER, false); Services.prefs.setBoolPref(PREF_PLUGINS_NOTIFYUSER, false);
var formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"]. var formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"].
getService(Ci.nsIURLFormatter); getService(Ci.nsIURLFormatter);
@ -766,7 +731,7 @@ BrowserGlue.prototype = {
var importBookmarksHTML = false; var importBookmarksHTML = false;
try { try {
importBookmarksHTML = importBookmarksHTML =
this._prefs.getBoolPref("browser.places.importBookmarksHTML"); Services.prefs.getBoolPref("browser.places.importBookmarksHTML");
if (importBookmarksHTML) if (importBookmarksHTML)
importBookmarks = true; importBookmarks = true;
} catch(ex) {} } catch(ex) {}
@ -776,7 +741,7 @@ BrowserGlue.prototype = {
var restoreDefaultBookmarks = false; var restoreDefaultBookmarks = false;
try { try {
restoreDefaultBookmarks = restoreDefaultBookmarks =
this._prefs.getBoolPref("browser.bookmarks.restore_default_bookmarks"); Services.prefs.getBoolPref("browser.bookmarks.restore_default_bookmarks");
if (restoreDefaultBookmarks) { if (restoreDefaultBookmarks) {
// Ensure that we already have a bookmarks backup for today. // Ensure that we already have a bookmarks backup for today.
this._backupBookmarks(); this._backupBookmarks();
@ -826,14 +791,14 @@ BrowserGlue.prototype = {
// smart bookmarks are disabled. // smart bookmarks are disabled.
var autoExportHTML = false; var autoExportHTML = false;
try { try {
autoExportHTML = this._prefs.getBoolPref("browser.bookmarks.autoExportHTML"); autoExportHTML = Services.prefs.getBoolPref("browser.bookmarks.autoExportHTML");
} catch(ex) {} } catch(ex) {}
var smartBookmarksVersion = 0; var smartBookmarksVersion = 0;
try { try {
smartBookmarksVersion = this._prefs.getIntPref("browser.places.smartBookmarksVersion"); smartBookmarksVersion = Services.prefs.getIntPref("browser.places.smartBookmarksVersion");
} catch(ex) {} } catch(ex) {}
if (!autoExportHTML && smartBookmarksVersion != -1) if (!autoExportHTML && smartBookmarksVersion != -1)
this._prefs.setIntPref("browser.places.smartBookmarksVersion", 0); Services.prefs.setIntPref("browser.places.smartBookmarksVersion", 0);
// Get bookmarks.html file location // Get bookmarks.html file location
var dirService = Cc["@mozilla.org/file/directory_service;1"]. var dirService = Cc["@mozilla.org/file/directory_service;1"].
@ -851,8 +816,8 @@ BrowserGlue.prototype = {
if (bookmarksFile.exists()) { if (bookmarksFile.exists()) {
// Add an import observer. It will ensure that smart bookmarks are // Add an import observer. It will ensure that smart bookmarks are
// created once the operation is complete. // created once the operation is complete.
this._observerService.addObserver(this, "bookmarks-restore-success", false); Services.obs.addObserver(this, "bookmarks-restore-success", false);
this._observerService.addObserver(this, "bookmarks-restore-failed", false); Services.obs.addObserver(this, "bookmarks-restore-failed", false);
// Import from bookmarks.html file. // Import from bookmarks.html file.
try { try {
@ -862,8 +827,8 @@ BrowserGlue.prototype = {
} catch (err) { } catch (err) {
// Report the error, but ignore it. // Report the error, but ignore it.
Cu.reportError("Bookmarks.html file could be corrupt. " + err); Cu.reportError("Bookmarks.html file could be corrupt. " + err);
this._observerService.removeObserver(this, "bookmarks-restore-success"); Services.obs.removeObserver(this, "bookmarks-restore-success");
this._observerService.removeObserver(this, "bookmarks-restore-failed"); Services.obs.removeObserver(this, "bookmarks-restore-failed");
} }
} }
else else
@ -871,10 +836,10 @@ BrowserGlue.prototype = {
// Reset preferences, so we won't try to import again at next run // Reset preferences, so we won't try to import again at next run
if (importBookmarksHTML) if (importBookmarksHTML)
this._prefs.setBoolPref("browser.places.importBookmarksHTML", false); Services.prefs.setBoolPref("browser.places.importBookmarksHTML", false);
if (restoreDefaultBookmarks) if (restoreDefaultBookmarks)
this._prefs.setBoolPref("browser.bookmarks.restore_default_bookmarks", Services.prefs.setBoolPref("browser.bookmarks.restore_default_bookmarks",
false); false);
} }
// Initialize bookmark archiving on idle. // Initialize bookmark archiving on idle.
@ -900,7 +865,7 @@ BrowserGlue.prototype = {
// on the legacy format. // on the legacy format.
var autoExportHTML = false; var autoExportHTML = false;
try { try {
autoExportHTML = this._prefs.getBoolPref("browser.bookmarks.autoExportHTML"); autoExportHTML = Services.prefs.getBoolPref("browser.bookmarks.autoExportHTML");
} catch(ex) { /* Don't export */ } } catch(ex) { /* Don't export */ }
if (autoExportHTML) { if (autoExportHTML) {
@ -924,7 +889,7 @@ BrowserGlue.prototype = {
new Date() - PlacesUtils.backups.getDateForFile(lastBackupFile) > BOOKMARKS_BACKUP_INTERVAL) { new Date() - PlacesUtils.backups.getDateForFile(lastBackupFile) > BOOKMARKS_BACKUP_INTERVAL) {
let maxBackups = BOOKMARKS_BACKUP_MAX_BACKUPS; let maxBackups = BOOKMARKS_BACKUP_MAX_BACKUPS;
try { try {
maxBackups = this._prefs.getIntPref("browser.bookmarks.max_backups"); maxBackups = Services.prefs.getIntPref("browser.bookmarks.max_backups");
} }
catch(ex) { /* Use default. */ } catch(ex) { /* Use default. */ }
@ -936,9 +901,9 @@ BrowserGlue.prototype = {
* Show the notificationBox for a locked places database. * Show the notificationBox for a locked places database.
*/ */
_showPlacesLockedNotificationBox: function BG__showPlacesLockedNotificationBox() { _showPlacesLockedNotificationBox: function BG__showPlacesLockedNotificationBox() {
var brandBundle = this._bundleService.createBundle("chrome://branding/locale/brand.properties"); var brandBundle = Services.strings.createBundle("chrome://branding/locale/brand.properties");
var applicationName = brandBundle.GetStringFromName("brandShortName"); var applicationName = brandBundle.GetStringFromName("brandShortName");
var placesBundle = this._bundleService.createBundle("chrome://browser/locale/places/places.properties"); var placesBundle = Services.strings.createBundle("chrome://browser/locale/places/places.properties");
var title = placesBundle.GetStringFromName("lockPrompt.title"); var title = placesBundle.GetStringFromName("lockPrompt.title");
var text = placesBundle.formatStringFromName("lockPrompt.text", [applicationName], 1); var text = placesBundle.formatStringFromName("lockPrompt.text", [applicationName], 1);
var buttonText = placesBundle.GetStringFromName("lockPromptInfoButton.label"); var buttonText = placesBundle.GetStringFromName("lockPromptInfoButton.label");
@ -973,7 +938,7 @@ BrowserGlue.prototype = {
_migrateUI: function BG__migrateUI() { _migrateUI: function BG__migrateUI() {
var migration = 0; var migration = 0;
try { try {
migration = this._prefs.getIntPref("browser.migration.version"); migration = Services.prefs.getIntPref("browser.migration.version");
} catch(ex) {} } catch(ex) {}
if (migration == 0) { if (migration == 0) {
@ -1017,7 +982,7 @@ BrowserGlue.prototype = {
this._dataSource = null; this._dataSource = null;
// update the migration version // update the migration version
this._prefs.setIntPref("browser.migration.version", 1); Services.prefs.setIntPref("browser.migration.version", 1);
} }
}, },
@ -1072,7 +1037,7 @@ BrowserGlue.prototype = {
// By default, if the pref is not set up, we must create Smart Bookmarks // By default, if the pref is not set up, we must create Smart Bookmarks
var smartBookmarksCurrentVersion = 0; var smartBookmarksCurrentVersion = 0;
try { try {
smartBookmarksCurrentVersion = this._prefs.getIntPref(SMART_BOOKMARKS_PREF); smartBookmarksCurrentVersion = Services.prefs.getIntPref(SMART_BOOKMARKS_PREF);
} catch(ex) { /* no version set, new profile */ } } catch(ex) { /* no version set, new profile */ }
// bail out if we don't have to create or update Smart Bookmarks // bail out if we don't have to create or update Smart Bookmarks
@ -1087,9 +1052,7 @@ BrowserGlue.prototype = {
var callback = { var callback = {
_uri: function BG_EPDQI__uri(aSpec) { _uri: function BG_EPDQI__uri(aSpec) {
return Cc["@mozilla.org/network/io-service;1"]. return Services.io.newURI(aSpec, null, null);
getService(Ci.nsIIOService).
newURI(aSpec, null, null);
}, },
runBatched: function BG_EPDQI_runBatched() { runBatched: function BG_EPDQI_runBatched() {
@ -1097,9 +1060,7 @@ BrowserGlue.prototype = {
var bookmarksMenuIndex = 0; var bookmarksMenuIndex = 0;
var bookmarksToolbarIndex = 0; var bookmarksToolbarIndex = 0;
var placesBundle = Cc["@mozilla.org/intl/stringbundle;1"]. var placesBundle = Services.strings.createBundle("chrome://browser/locale/places/places.properties");
getService(Ci.nsIStringBundleService).
createBundle("chrome://browser/locale/places/places.properties");
// MOST VISITED // MOST VISITED
var smart = {queryId: "MostVisited", // don't change this var smart = {queryId: "MostVisited", // don't change this
@ -1207,8 +1168,8 @@ BrowserGlue.prototype = {
Components.utils.reportError(ex); Components.utils.reportError(ex);
} }
finally { finally {
this._prefs.setIntPref(SMART_BOOKMARKS_PREF, SMART_BOOKMARKS_VERSION); Services.prefs.setIntPref(SMART_BOOKMARKS_PREF, SMART_BOOKMARKS_VERSION);
this._prefs.QueryInterface(Ci.nsIPrefService).savePrefFile(null); Services.prefs.savePrefFile(null);
} }
}, },
@ -1218,21 +1179,18 @@ BrowserGlue.prototype = {
// this returns the most recent non-popup browser window // this returns the most recent non-popup browser window
getMostRecentBrowserWindow: function BG_getMostRecentBrowserWindow() { getMostRecentBrowserWindow: function BG_getMostRecentBrowserWindow() {
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
getService(Ci.nsIWindowMediator);
function isFullBrowserWindow(win) { function isFullBrowserWindow(win) {
return !win.closed && return !win.closed &&
!win.document.documentElement.getAttribute("chromehidden"); !win.document.documentElement.getAttribute("chromehidden");
} }
#ifdef BROKEN_WM_Z_ORDER #ifdef BROKEN_WM_Z_ORDER
var win = wm.getMostRecentWindow("navigator:browser"); var win = Services.wm.getMostRecentWindow("navigator:browser");
// if we're lucky, this isn't a popup, and we can just return this // if we're lucky, this isn't a popup, and we can just return this
if (win && !isFullBrowserWindow(win)) { if (win && !isFullBrowserWindow(win)) {
win = null; win = null;
let windowList = wm.getEnumerator("navigator:browser"); let windowList = Services.wm.getEnumerator("navigator:browser");
// this is oldest to newest, so this gets a bit ugly // this is oldest to newest, so this gets a bit ugly
while (windowList.hasMoreElements()) { while (windowList.hasMoreElements()) {
let nextWin = windowList.getNext(); let nextWin = windowList.getNext();
@ -1242,7 +1200,7 @@ BrowserGlue.prototype = {
} }
return win; return win;
#else #else
var windowList = wm.getZOrderDOMWindowEnumerator("navigator:browser", true); var windowList = Services.wm.getZOrderDOMWindowEnumerator("navigator:browser", true);
while (windowList.hasMoreElements()) { while (windowList.hasMoreElements()) {
let win = windowList.getNext(); let win = windowList.getNext();
if (isFullBrowserWindow(win)) if (isFullBrowserWindow(win))
@ -1282,9 +1240,7 @@ GeolocationPrompt.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIGeolocationPrompt]), QueryInterface: XPCOMUtils.generateQI([Ci.nsIGeolocationPrompt]),
prompt: function GP_prompt(request) { prompt: function GP_prompt(request) {
var pm = Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager); var result = Services.perms.testExactPermission(request.requestingURI, "geo");
var result = pm.testExactPermission(request.requestingURI, "geo");
if (result == Ci.nsIPermissionManager.ALLOW_ACTION) { if (result == Ci.nsIPermissionManager.ALLOW_ACTION) {
request.allow(); request.allow();
@ -1298,9 +1254,9 @@ GeolocationPrompt.prototype = {
function setPagePermission(uri, allow) { function setPagePermission(uri, allow) {
if (allow == true) if (allow == true)
pm.add(uri, "geo", Ci.nsIPermissionManager.ALLOW_ACTION); Services.perms.add(uri, "geo", Ci.nsIPermissionManager.ALLOW_ACTION);
else else
pm.add(uri, "geo", Ci.nsIPermissionManager.DENY_ACTION); Services.perms.add(uri, "geo", Ci.nsIPermissionManager.DENY_ACTION);
} }
function getChromeWindow(aWindow) { function getChromeWindow(aWindow) {
@ -1323,8 +1279,7 @@ GeolocationPrompt.prototype = {
var notification = notificationBox.getNotificationWithValue("geolocation"); var notification = notificationBox.getNotificationWithValue("geolocation");
if (!notification) { if (!notification) {
var bundleService = Cc["@mozilla.org/intl/stringbundle;1"].getService(Ci.nsIStringBundleService); var browserBundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
var browserBundle = bundleService.createBundle("chrome://browser/locale/browser.properties");
var buttons = [{ var buttons = [{
label: browserBundle.GetStringFromName("geolocation.shareLocation"), label: browserBundle.GetStringFromName("geolocation.shareLocation"),