diff --git a/browser/base/content/browser-places.js b/browser/base/content/browser-places.js index 956aea934bc..1fa8f3caf5c 100644 --- a/browser/base/content/browser-places.js +++ b/browser/base/content/browser-places.js @@ -549,7 +549,9 @@ var PlacesCommandHook = { * UnfiledBookmarks and Tags. */ showPlacesOrganizer: function PCH_showPlacesOrganizer(aLeftPaneRoot) { - var organizer = gWindowMediator.getMostRecentWindow("Places:Organizer"); + var wm = Cc["@mozilla.org/appshell/window-mediator;1"]. + getService(Ci.nsIWindowMediator); + var organizer = wm.getMostRecentWindow("Places:Organizer"); if (!organizer) { // No currently open places window, so open one with the specified mode. openDialog("chrome://browser/content/places/places.xul", @@ -573,12 +575,18 @@ var PlacesCommandHook = { // Helper object for the history menu. var HistoryMenu = { + get _ss() { + delete this._ss; + return this._ss = Cc["@mozilla.org/browser/sessionstore;1"]. + getService(Ci.nsISessionStore); + }, + toggleRecentlyClosedTabs: function PHM_toggleRecentlyClosedTabs() { // enable/disable the Recently Closed Tabs sub menu var undoPopup = document.getElementById("historyUndoPopup"); // no restorable tabs, so disable menu - if (gSessionStore.getClosedTabCount(window) == 0) + if (this._ss.getClosedTabCount(window) == 0) undoPopup.parentNode.setAttribute("disabled", true); else undoPopup.parentNode.removeAttribute("disabled"); @@ -609,7 +617,7 @@ var HistoryMenu = { undoPopup.removeChild(undoPopup.firstChild); // no restorable tabs, so make sure menu is disabled, and return - if (gSessionStore.getClosedTabCount(window) == 0) { + if (this._ss.getClosedTabCount(window) == 0) { undoPopup.parentNode.setAttribute("disabled", true); return; } @@ -618,7 +626,7 @@ var HistoryMenu = { undoPopup.parentNode.removeAttribute("disabled"); // populate menu - var undoItems = eval("(" + gSessionStore.getClosedTabData(window) + ")"); + var undoItems = eval("(" + this._ss.getClosedTabData(window) + ")"); for (var i = 0; i < undoItems.length; i++) { var m = document.createElement("menuitem"); m.setAttribute("label", undoItems[i].title); @@ -655,7 +663,7 @@ var HistoryMenu = { let undoPopup = document.getElementById("historyUndoWindowPopup"); // no restorable windows, so disable menu - if (gSessionStore.getClosedWindowCount() == 0) + if (this._ss.getClosedWindowCount() == 0) undoPopup.parentNode.setAttribute("disabled", true); else undoPopup.parentNode.removeAttribute("disabled"); @@ -675,7 +683,7 @@ var HistoryMenu = { undoPopup.removeChild(undoPopup.firstChild); // no restorable windows, so make sure menu is disabled, and return - if (gSessionStore.getClosedWindowCount() == 0) { + if (this._ss.getClosedWindowCount() == 0) { undoPopup.parentNode.setAttribute("disabled", true); return; } @@ -684,7 +692,7 @@ var HistoryMenu = { undoPopup.parentNode.removeAttribute("disabled"); // populate menu - let undoItems = JSON.parse(gSessionStore.getClosedWindowData()); + let undoItems = JSON.parse(this._ss.getClosedWindowData()); for (let i = 0; i < undoItems.length; i++) { let undoItem = undoItems[i]; let otherTabsCount = undoItem.tabs.length - 1; diff --git a/browser/base/content/browser-textZoom.js b/browser/base/content/browser-textZoom.js index ba7a4a00e38..d947ebdd359 100644 --- a/browser/base/content/browser-textZoom.js +++ b/browser/base/content/browser-textZoom.js @@ -77,6 +77,12 @@ var FullZoom = { getService(Ci.nsIContentPrefService); }, + get _prefBranch FullZoom_get__prefBranch() { + delete this._prefBranch; + return this._prefBranch = Cc["@mozilla.org/preferences-service;1"]. + getService(Ci.nsIPrefBranch2); + }, + // browser.zoom.siteSpecific preference cache _siteSpecificPref: undefined, @@ -119,7 +125,9 @@ var FullZoom = { // We disable site-specific preferences in Private Browsing mode, because the // content preferences module is disabled - gObserverService.addObserver(this, "private-browsing", true); + let os = Cc["@mozilla.org/observer-service;1"]. + getService(Ci.nsIObserverService); + os.addObserver(this, "private-browsing", true); // Retrieve the initial status of the Private Browsing mode. this._inPrivateBrowsing = Cc["@mozilla.org/privatebrowsing;1"]. @@ -127,17 +135,19 @@ var FullZoom = { privateBrowsingEnabled; this._siteSpecificPref = - gPrefService.getBoolPref("browser.zoom.siteSpecific"); + this._prefBranch.getBoolPref("browser.zoom.siteSpecific"); this.updateBackgroundTabs = - gPrefService.getBoolPref("browser.zoom.updateBackgroundTabs"); + this._prefBranch.getBoolPref("browser.zoom.updateBackgroundTabs"); // Listen for changes to the browser.zoom branch so we can enable/disable // updating background tabs and per-site saving and restoring of zoom levels. - gPrefService.addObserver("browser.zoom.", this, true); + this._prefBranch.addObserver("browser.zoom.", this, true); }, destroy: function FullZoom_destroy() { - gObserverService.removeObserver(this, "private-browsing"); - gPrefService.removeObserver("browser.zoom.", this); + let os = Cc["@mozilla.org/observer-service;1"]. + getService(Ci.nsIObserverService); + os.removeObserver(this, "private-browsing"); + this._prefBranch.removeObserver("browser.zoom.", this); this._cps.removeObserver(this.name, this); window.removeEventListener("DOMMouseScroll", this, false); delete this._cps; @@ -203,11 +213,11 @@ var FullZoom = { switch(aData) { case "browser.zoom.siteSpecific": this._siteSpecificPref = - gPrefService.getBoolPref("browser.zoom.siteSpecific"); + this._prefBranch.getBoolPref("browser.zoom.siteSpecific"); break; case "browser.zoom.updateBackgroundTabs": this.updateBackgroundTabs = - gPrefService.getBoolPref("browser.zoom.updateBackgroundTabs"); + this._prefBranch.getBoolPref("browser.zoom.updateBackgroundTabs"); break; } break; diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 8dcba6a119a..2cae4f4b2d5 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -116,20 +116,10 @@ var gEditUIVisible = true; }); }); -[ - ["gPrefService", "preferences-service;1", "nsIPrefBranch2"], - ["gPermissionManager", "permissionmanager;1", "nsIPermissionManager"], - ["gObserverService", "observer-service;1", "nsIObserverService"], - ["gWindowMediator", "appshell/window-mediator;1", "nsIWindowMediator"], - ["gPromptService", "embedcomp/prompt-service;1", "nsIPromptService"], - ["gSearchService", "browser/search-service;1", "nsIBrowserSearchService"], - ["gSessionStore", "browser/sessionstore;1", "nsISessionStore"], -].forEach(function (service) { - let [name, cid, iface] = service; - window.__defineGetter__(name, function () { - delete window[name]; - return window[name] = Cc["@mozilla.org/" + cid].getService(Ci[iface]); - }); +__defineGetter__("gPrefService", function() { + delete this.gPrefService; + return this.gPrefService = Cc["@mozilla.org/preferences-service;1"]. + getService(Ci.nsIPrefBranch2); }); __defineGetter__("PluralForm", function() { @@ -324,6 +314,7 @@ function findChildShell(aDocument, aDocShell, aSoughtURI) { const gPopupBlockerObserver = { _reportButton: null, + _kIPM: Components.interfaces.nsIPermissionManager, onUpdatePageReport: function (aEvent) { @@ -392,9 +383,11 @@ const gPopupBlockerObserver = { toggleAllowPopupsForSite: function (aEvent) { var currentURI = gBrowser.selectedBrowser.webNavigation.currentURI; + var pm = Components.classes["@mozilla.org/permissionmanager;1"] + .getService(this._kIPM); var shouldBlock = aEvent.target.getAttribute("block") == "true"; - var perm = shouldBlock ? gPermissionManager.DENY_ACTION : gPermissionManager.ALLOW_ACTION; - gPermissionManager.add(currentURI, "popup", perm); + var perm = shouldBlock ? this._kIPM.DENY_ACTION : this._kIPM.ALLOW_ACTION; + pm.add(currentURI, "popup", perm); gBrowser.getNotificationBox().removeCurrentNotification(); }, @@ -415,7 +408,8 @@ const gPopupBlockerObserver = { try { blockedPopupAllowSite.removeAttribute("hidden"); - if (gPermissionManager.testPermission(uri, "popup") == gPermissionManager.ALLOW_ACTION) { + var pm = Cc["@mozilla.org/permissionmanager;1"].getService(this._kIPM); + if (pm.testPermission(uri, "popup") == this._kIPM.ALLOW_ACTION) { // Offer an item to block popups for this site, if a whitelist entry exists // already for it. let blockString = gNavigatorBundle.getFormattedString("popupBlock", [uri.host]); @@ -530,7 +524,9 @@ const gPopupBlockerObserver = { permissionType : "popup", windowTitle : bundlePreferences.getString("popuppermissionstitle"), introText : bundlePreferences.getString("popuppermissionstext") }; - var existingWindow = gWindowMediator.getMostRecentWindow("Browser:Permissions"); + var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] + .getService(Components.interfaces.nsIWindowMediator); + var existingWindow = wm.getMostRecentWindow("Browser:Permissions"); if (existingWindow) { existingWindow.initWithParams(params); existingWindow.focus(); @@ -1027,7 +1023,9 @@ function BrowserStartup() { // Certain kinds of automigration rely on this notification to complete their // tasks BEFORE the browser window is shown. - gObserverService.notifyObservers(null, "browser-window-before-show", ""); + Cc["@mozilla.org/observer-service;1"] + .getService(Ci.nsIObserverService) + .notifyObservers(null, "browser-window-before-show", ""); // Set a sane starting width/height for all resolutions on new profiles. if (!document.documentElement.hasAttribute("width")) { @@ -1155,7 +1153,8 @@ function prepareForStartup() { // progress notifications for back/forward button updating webNavigation.sessionHistory = Components.classes["@mozilla.org/browser/shistory;1"] .createInstance(Components.interfaces.nsISHistory); - gObserverService.addObserver(gBrowser.browsers[0], "browser:purge-session-history", false); + var os = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService); + os.addObserver(gBrowser.browsers[0], "browser:purge-session-history", false); // remove the disablehistory attribute so the browser cleans up, as // though it had done this work itself @@ -1184,8 +1183,9 @@ function prepareForStartup() { } function delayedStartup(isLoadingBlank, mustLoadSidebar) { - gObserverService.addObserver(gSessionHistoryObserver, "browser:purge-session-history", false); - gObserverService.addObserver(gXPInstallObserver, "xpinstall-install-blocked", false); + var os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService); + os.addObserver(gSessionHistoryObserver, "browser:purge-session-history", false); + os.addObserver(gXPInstallObserver, "xpinstall-install-blocked", false); BrowserOffline.init(); OfflineApps.init(); @@ -1259,10 +1259,13 @@ function delayedStartup(isLoadingBlank, mustLoadSidebar) { [brandShortName]); var checkboxLabel = shellBundle.getFormattedString("setDefaultBrowserDontAsk", [brandShortName]); + const IPS = Components.interfaces.nsIPromptService; + var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] + .getService(IPS); var checkEveryTime = { value: shouldCheck }; - var rv = gPromptService.confirmEx(window, promptTitle, promptMessage, - gPromptService.STD_YES_NO_BUTTONS, - null, null, null, checkboxLabel, checkEveryTime); + var rv = ps.confirmEx(window, promptTitle, promptMessage, + IPS.STD_YES_NO_BUTTONS, + null, null, null, checkboxLabel, checkEveryTime); if (rv == 0) shell.setDefaultBrowser(true, false); shell.shouldCheckDefaultBrowser = checkEveryTime.value; @@ -1299,7 +1302,9 @@ function delayedStartup(isLoadingBlank, mustLoadSidebar) { // initialize the session-restore service (in case it's not already running) if (document.documentElement.getAttribute("windowtype") == "navigator:browser") { try { - gSessionStore.init(window); + var ss = Cc["@mozilla.org/browser/sessionstore;1"]. + getService(Ci.nsISessionStore); + ss.init(window); } catch(ex) { dump("nsSessionStore could not be initialized: " + ex + "\n"); } @@ -1381,8 +1386,10 @@ function BrowserShutdown() Components.utils.reportError(ex); } - gObserverService.removeObserver(gSessionHistoryObserver, "browser:purge-session-history"); - gObserverService.removeObserver(gXPInstallObserver, "xpinstall-install-blocked"); + var os = Components.classes["@mozilla.org/observer-service;1"] + .getService(Components.interfaces.nsIObserverService); + os.removeObserver(gSessionHistoryObserver, "browser:purge-session-history"); + os.removeObserver(gXPInstallObserver, "xpinstall-install-blocked"); try { gBrowser.removeProgressListener(window.XULBrowserWindow); @@ -1406,7 +1413,9 @@ function BrowserShutdown() DownloadMonitorPanel.uninit(); gPrivateBrowsingUI.uninit(); - var enumerator = gWindowMediator.getEnumerator(null); + var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(); + var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator); + var enumerator = windowManagerInterface.getEnumerator(null); enumerator.getNext(); if (!enumerator.hasMoreElements()) { document.persist("sidebar-box", "sidebarcommand"); @@ -1899,6 +1908,8 @@ function getShortcutOrURI(aURL, aPostDataRef) { var shortcutURL = null; var keyword = aURL; var param = ""; + var searchService = Cc["@mozilla.org/browser/search-service;1"]. + getService(Ci.nsIBrowserSearchService); var offset = aURL.indexOf(" "); if (offset > 0) { @@ -1909,7 +1920,7 @@ function getShortcutOrURI(aURL, aPostDataRef) { if (!aPostDataRef) aPostDataRef = {}; - var engine = gSearchService.getEngineByAlias(keyword); + var engine = searchService.getEngineByAlias(keyword); if (engine) { var submission = engine.getSubmission(param, null); aPostDataRef.value = submission.postData; @@ -2276,7 +2287,9 @@ function PageProxyClickHandler(aEvent) function BrowserImport() { #ifdef XP_MACOSX - var win = gWindowMediator.getMostRecentWindow("Browser:MigrationWizard"); + var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] + .getService(Components.interfaces.nsIWindowMediator); + var win = wm.getMostRecentWindow("Browser:MigrationWizard"); if (win) win.focus(); else { @@ -2422,10 +2435,12 @@ function BrowserOnCommand(event) { */ function getMeOutOfHere() { // Get the start page from the *default* pref branch, not the user's + var prefs = Cc["@mozilla.org/preferences-service;1"] + .getService(Ci.nsIPrefService).getDefaultBranch(null); var url = "about:blank"; try { - url = gPrefService.getComplexValue("browser.startup.homepage", - Ci.nsIPrefLocalizedString).data; + url = prefs.getComplexValue("browser.startup.homepage", + Ci.nsIPrefLocalizedString).data; // If url is a pipe-delimited set of pages, just take the first one. if (url.indexOf("|") != -1) url = url.split("|")[0]; @@ -2711,11 +2726,12 @@ var homeButtonObserver = { function openHomeDialog(aURL) { + var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService); var promptTitle = gNavigatorBundle.getString("droponhometitle"); var promptMsg = gNavigatorBundle.getString("droponhomemsg"); - var pressedVal = gPromptService.confirmEx(window, promptTitle, promptMsg, - gPromptService.STD_YES_NO_BUTTONS, - null, null, null, null, {value:0}); + var pressedVal = promptService.confirmEx(window, promptTitle, promptMsg, + promptService.STD_YES_NO_BUTTONS, + null, null, null, null, {value:0}); if (pressedVal == 0) { try { @@ -2967,7 +2983,9 @@ const BrowserSearch = { // to the list of hidden engines rather than to the main list. // XXX This will need to be changed when engines are identified by URL; // see bug 335102. - if (gSearchService.getEngineByName(engine.title)) + var searchService = Cc["@mozilla.org/browser/search-service;1"]. + getService(Ci.nsIBrowserSearchService); + if (searchService.getEngineByName(engine.title)) hidden = true; var engines = (hidden ? browser.hiddenEngines : browser.engines) || []; @@ -3043,7 +3061,9 @@ const BrowserSearch = { searchBar.select(); searchBar.focus(); } else { - let searchForm = gSearchService.defaultEngine.searchForm; + var ss = Cc["@mozilla.org/browser/search-service;1"]. + getService(Ci.nsIBrowserSearchService); + var searchForm = ss.defaultEngine.searchForm; loadURI(searchForm, null, null, false); } }, @@ -3060,14 +3080,16 @@ const BrowserSearch = { * tab. */ loadSearch: function BrowserSearch_search(searchText, useNewTab) { + var ss = Cc["@mozilla.org/browser/search-service;1"]. + getService(Ci.nsIBrowserSearchService); var engine; // If the search bar is visible, use the current engine, otherwise, fall // back to the default engine. if (isElementVisible(this.searchBar)) - engine = gSearchService.currentEngine; + engine = ss.currentEngine; else - engine = gSearchService.defaultEngine; + engine = ss.defaultEngine; var submission = engine.getSubmission(searchText, null); // HTML response @@ -3199,7 +3221,9 @@ function BrowserDownloadsUI() function toOpenWindowByType(inType, uri, features) { - var topWindow = gWindowMediator.getMostRecentWindow(inType); + var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(); + var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator); + var topWindow = windowManagerInterface.getMostRecentWindow(inType); if (topWindow) topWindow.focus(); @@ -3211,7 +3235,9 @@ function toOpenWindowByType(inType, uri, features) function toOpenDialogByTypeAndUrl(inType, relatedUrl, windowUri, features, extraArgument) { - var windows = gWindowMediator.getEnumerator(inType); + var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(); + var windowManagerInterface = windowManager.QueryInterface(Components.interfaces.nsIWindowMediator); + var windows = windowManagerInterface.getEnumerator(inType); // Check for windows matching the url while (windows.hasMoreElements()) { @@ -4229,6 +4255,8 @@ var XULBrowserWindow = { gBrowser.mCurrentBrowser.engines = null; var uri = aRequest.QueryInterface(Ci.nsIChannel).URI; + var observerService = Cc["@mozilla.org/observer-service;1"] + .getService(Ci.nsIObserverService); if (gURLBar && gURLBar.value == "" && @@ -4236,7 +4264,7 @@ var XULBrowserWindow = { URLBarSetURI(uri); try { - gObserverService.notifyObservers(content, "StartDocumentLoad", uri.spec); + observerService.notifyObservers(content, "StartDocumentLoad", uri.spec); } catch (e) { } }, @@ -4244,9 +4272,12 @@ var XULBrowserWindow = { endDocumentLoad: function (aRequest, aStatus) { var urlStr = aRequest.QueryInterface(Ci.nsIChannel).originalURI.spec; + var observerService = Cc["@mozilla.org/observer-service;1"] + .getService(Ci.nsIObserverService); + var notification = Components.isSuccessCode(aStatus) ? "EndDocumentLoad" : "FailDocumentLoad"; try { - gObserverService.notifyObservers(content, notification, urlStr); + observerService.notifyObservers(content, notification, urlStr); } catch (e) { } } @@ -5006,12 +5037,14 @@ function SelectDetector(event, doReload) } try { + var pref = Components.classes["@mozilla.org/preferences-service;1"] + .getService(Components.interfaces.nsIPrefBranch); var str = Components.classes["@mozilla.org/supports-string;1"] .createInstance(Components.interfaces.nsISupportsString); str.data = prefvalue; - gPrefService.setComplexValue("intl.charset.detector", - Ci.nsISupportsString, str); + pref.setComplexValue("intl.charset.detector", + Components.interfaces.nsISupportsString, str); if (doReload) window.content.location.reload(); } catch (ex) { @@ -5069,8 +5102,10 @@ function UpdateCharsetDetector() var prefvalue; try { - prefvalue = gPrefService.getComplexValue("intl.charset.detector", - Ci.nsIPrefLocalizedString).data; + var pref = Components.classes["@mozilla.org/preferences-service;1"] + .getService(Components.interfaces.nsIPrefBranch); + prefvalue = pref.getComplexValue("intl.charset.detector", + Components.interfaces.nsIPrefLocalizedString).data; } catch (ex) { prefvalue = ""; @@ -5100,7 +5135,8 @@ function UpdateMenus(event) function CreateMenu(node) { - gObserverService.notifyObservers(null, "charsetmenu-selected", node); + var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService); + observerService.notifyObservers(null, "charsetmenu-selected", node); } function charsetLoadListener (event) @@ -5221,51 +5257,59 @@ var BrowserOffline = { if (!this._uiElement) this._uiElement = document.getElementById("goOfflineMenuitem"); - gObserverService.addObserver(this, "network:offline-status-changed", false); + var os = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService); + os.addObserver(this, "network:offline-status-changed", false); - // if IO Service is managing the offline status, then IOService.offline - // is already set correctly. We will continue to allow the IO Service + var ioService = Components.classes["@mozilla.org/network/io-service;1"]. + getService(Components.interfaces.nsIIOService2); + + // if ioService is managing the offline status, then ioservice.offline + // is already set correctly. We will continue to allow the ioService // to manage its offline state until the user uses the "Work Offline" UI. - if (!ContentAreaUtils.ioService.manageOfflineStatus) { + if (!ioService.manageOfflineStatus) { // set the initial state var isOffline = false; try { isOffline = gPrefService.getBoolPref("browser.offline"); } catch (e) { } - ContentAreaUtils.ioService.offline = isOffline; + ioService.offline = isOffline; } - this._updateOfflineUI(ContentAreaUtils.ioService.offline); + this._updateOfflineUI(ioService.offline); }, uninit: function () { try { - gObserverService.removeObserver(this, "network:offline-status-changed"); + var os = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService); + os.removeObserver(this, "network:offline-status-changed"); } catch (ex) { } }, toggleOfflineStatus: function () { + var ioService = Components.classes["@mozilla.org/network/io-service;1"]. + getService(Components.interfaces.nsIIOService2); + // Stop automatic management of the offline status try { - ContentAreaUtils.ioService.manageOfflineStatus = false; + ioService.manageOfflineStatus = false; } catch (ex) { } - if (!ContentAreaUtils.ioService.offline && !this._canGoOffline()) { + if (!ioService.offline && !this._canGoOffline()) { this._updateOfflineUI(false); return; } - ContentAreaUtils.ioService.offline = !ContentAreaUtils.ioService.offline; + ioService.offline = !ioService.offline; // Save the current state for later use as the initial state // (if there is no netLinkService) - gPrefService.setBoolPref("browser.offline", ContentAreaUtils.ioService.offline); + gPrefService.setBoolPref("browser.offline", ioService.offline); }, ///////////////////////////////////////////////////////////////////////////// @@ -5282,15 +5326,18 @@ var BrowserOffline = { // BrowserOffline Implementation Methods _canGoOffline: function () { - try { - let cancelGoOffline = Cc["@mozilla.org/supports-PRBool;1"].createInstance(Ci.nsISupportsPRBool); - gObserverService.notifyObservers(cancelGoOffline, "offline-requested", null); + var os = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService); + if (os) { + try { + var cancelGoOffline = Components.classes["@mozilla.org/supports-PRBool;1"].createInstance(Components.interfaces.nsISupportsPRBool); + os.notifyObservers(cancelGoOffline, "offline-requested", null); - // Something aborted the quit process. - if (cancelGoOffline.data) - return false; - } - catch (ex) { + // Something aborted the quit process. + if (cancelGoOffline.data) + return false; + } + catch (ex) { + } } return true; }, @@ -5311,14 +5358,18 @@ var OfflineApps = { // OfflineApps Public Methods init: function () { - gObserverService.addObserver(this, "dom-storage-warn-quota-exceeded", false); - gObserverService.addObserver(this, "offline-cache-update-completed", false); + var obs = Cc["@mozilla.org/observer-service;1"]. + getService(Ci.nsIObserverService); + obs.addObserver(this, "dom-storage-warn-quota-exceeded", false); + obs.addObserver(this, "offline-cache-update-completed", false); }, uninit: function () { - gObserverService.removeObserver(this, "dom-storage-warn-quota-exceeded"); - gObserverService.removeObserver(this, "offline-cache-update-completed"); + var obs = Cc["@mozilla.org/observer-service;1"]. + getService(Ci.nsIObserverService); + obs.removeObserver(this, "dom-storage-warn-quota-exceeded"); + obs.removeObserver(this, "offline-cache-update-completed"); }, handleEvent: function(event) { @@ -5411,8 +5462,10 @@ var OfflineApps = { // Now that we've warned once, prevent the warning from showing up // again. - gPermissionManager.add(aURI, "offline-app", - Ci.nsIOfflineCacheUpdateService.ALLOW_NO_WARN); + var pm = Cc["@mozilla.org/permissionmanager;1"]. + getService(Ci.nsIPermissionManager); + pm.add(aURI, "offline-app", + Ci.nsIOfflineCacheUpdateService.ALLOW_NO_WARN); }, // XXX: duplicated in preferences/advanced.js @@ -5443,8 +5496,11 @@ var OfflineApps = { }, _checkUsage: function(aURI) { + var pm = Cc["@mozilla.org/permissionmanager;1"]. + getService(Ci.nsIPermissionManager); + // if the user has already allowed excessive usage, don't bother checking - if (gPermissionManager.testExactPermission(aURI, "offline-app") != + if (pm.testExactPermission(aURI, "offline-app") != Ci.nsIOfflineCacheUpdateService.ALLOW_NO_WARN) { var usage = this._getOfflineAppUsage(aURI.asciiHost); var warnQuota = gPrefService.getIntPref("offline-apps.quota.warn"); @@ -5466,10 +5522,12 @@ var OfflineApps = { aContentWindow); var currentURI = aContentWindow.document.documentURIObject; + var pm = Cc["@mozilla.org/permissionmanager;1"]. + getService(Ci.nsIPermissionManager); // don't bother showing UI if the user has already made a decision - if (gPermissionManager.testExactPermission(currentURI, "offline-app") != - gPermissionManager.UNKNOWN_ACTION) + if (pm.testExactPermission(currentURI, "offline-app") != + Ci.nsIPermissionManager.UNKNOWN_ACTION) return; try { @@ -5523,8 +5581,10 @@ var OfflineApps = { }, allowSite: function(aDocument) { - gPermissionManager.add(aDocument.documentURIObject, "offline-app", - gPermissionManager.ALLOW_ACTION); + var pm = Cc["@mozilla.org/permissionmanager;1"]. + getService(Ci.nsIPermissionManager); + pm.add(aDocument.documentURIObject, "offline-app", + Ci.nsIPermissionManager.ALLOW_ACTION); // When a site is enabled while loading, manifest resources will // start fetching immediately. This one time we need to do it @@ -5533,8 +5593,10 @@ var OfflineApps = { }, disallowSite: function(aDocument) { - gPermissionManager.add(aDocument.documentURIObject, "offline-app", - gPermissionManager.DENY_ACTION); + var pm = Cc["@mozilla.org/permissionmanager;1"]. + getService(Ci.nsIPermissionManager); + pm.add(aDocument.documentURIObject, "offline-app", + Ci.nsIPermissionManager.DENY_ACTION); }, manage: function() { @@ -5645,7 +5707,9 @@ var MailIntegration = { function BrowserOpenAddonsMgr(aPane) { const EMTYPE = "Extension:Manager"; - var theEM = gWindowMediator.getMostRecentWindow(EMTYPE); + var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] + .getService(Components.interfaces.nsIWindowMediator); + var theEM = wm.getMostRecentWindow(EMTYPE); if (theEM) { theEM.focus(); if (aPane) @@ -6136,8 +6200,10 @@ function undoCloseTab(aIndex) { blankTabToRemove = gBrowser.selectedTab; var tab = null; - if (gSessionStore.getClosedTabCount(window) > (aIndex || 0)) { - tab = gSessionStore.undoCloseTab(window, aIndex || 0); + var ss = Cc["@mozilla.org/browser/sessionstore;1"]. + getService(Ci.nsISessionStore); + if (ss.getClosedTabCount(window) > (aIndex || 0)) { + tab = ss.undoCloseTab(window, aIndex || 0); if (blankTabToRemove) gBrowser.removeTab(blankTabToRemove); @@ -6153,11 +6219,13 @@ function undoCloseTab(aIndex) { * @returns a reference to the reopened window. */ function undoCloseWindow(aIndex) { - let win = null; - if (gSessionStore.getClosedWindowCount() > (aIndex || 0)) - win = gSessionStore.undoCloseWindow(aIndex || 0); + let ss = Cc["@mozilla.org/browser/sessionstore;1"]. + getService(Ci.nsISessionStore); + let window = null; + if (ss.getClosedWindowCount() > (aIndex || 0)) + window = ss.undoCloseWindow(aIndex || 0); - return win; + return window; } /** @@ -6712,11 +6780,14 @@ function getBrowser() gBrowser; function getNavToolbox() gNavToolbox; let gPrivateBrowsingUI = { + _observerService: null, _privateBrowsingService: null, _privateBrowsingAutoStarted: false, init: function PBUI_init() { - gObserverService.addObserver(this, "private-browsing", false); + this._observerService = Cc["@mozilla.org/observer-service;1"]. + getService(Ci.nsIObserverService); + this._observerService.addObserver(this, "private-browsing", false); this._privateBrowsingService = Cc["@mozilla.org/privatebrowsing;1"]. getService(Ci.nsIPrivateBrowsingService); @@ -6726,7 +6797,7 @@ let gPrivateBrowsingUI = { }, uninit: function PBUI_unint() { - gObserverService.removeObserver(this, "private-browsing"); + this._observerService.removeObserver(this, "private-browsing"); }, observe: function PBUI_observe(aSubject, aTopic, aData) { @@ -6764,9 +6835,12 @@ let gPrivateBrowsingUI = { #endif var message = pbBundle.formatStringFromName("privateBrowsingMessage", [appName], 1); - var flags = gPromptService.BUTTON_TITLE_IS_STRING * gPromptService.BUTTON_POS_0 + - gPromptService.BUTTON_TITLE_IS_STRING * gPromptService.BUTTON_POS_1 + - gPromptService.BUTTON_POS_0_DEFAULT; + var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"]. + getService(Ci.nsIPromptService); + + var flags = promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0 + + promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_1 + + promptService.BUTTON_POS_0_DEFAULT; var neverAsk = {value:false}; var button0Title = pbBundle.GetStringFromName("privateBrowsingYesTitle"); @@ -6774,9 +6848,9 @@ let gPrivateBrowsingUI = { var neverAskText = pbBundle.GetStringFromName("privateBrowsingNeverAsk"); var result; - var choice = gPromptService.confirmEx(null, dialogTitle, header + message, - flags, button0Title, button1Title, null, - neverAskText, neverAsk); + var choice = promptService.confirmEx(null, dialogTitle, header + message, + flags, button0Title, button1Title, null, + neverAskText, neverAsk); switch (choice) { case 0: // Start Private Browsing diff --git a/toolkit/content/contentAreaUtils.js b/toolkit/content/contentAreaUtils.js index 32a424e3da4..83cbad59841 100644 --- a/toolkit/content/contentAreaUtils.js +++ b/toolkit/content/contentAreaUtils.js @@ -46,7 +46,7 @@ var ContentAreaUtils = { delete this.ioService; return this.ioService = Components.classes["@mozilla.org/network/io-service;1"] - .getService(Components.interfaces.nsIIOService2); + .getService(Components.interfaces.nsIIOService); } }