Bug 506111 - consolidate getService calls in browser.js. r=dao

This commit is contained in:
Ehsan Akhgari 2009-07-29 08:22:12 +02:00
parent cf30b610c0
commit 219ec79cb2
4 changed files with 112 additions and 204 deletions

View File

@ -549,9 +549,7 @@ var PlacesCommandHook = {
* UnfiledBookmarks and Tags. * UnfiledBookmarks and Tags.
*/ */
showPlacesOrganizer: function PCH_showPlacesOrganizer(aLeftPaneRoot) { showPlacesOrganizer: function PCH_showPlacesOrganizer(aLeftPaneRoot) {
var wm = Cc["@mozilla.org/appshell/window-mediator;1"]. var organizer = gWindowMediator.getMostRecentWindow("Places:Organizer");
getService(Ci.nsIWindowMediator);
var organizer = wm.getMostRecentWindow("Places:Organizer");
if (!organizer) { if (!organizer) {
// No currently open places window, so open one with the specified mode. // No currently open places window, so open one with the specified mode.
openDialog("chrome://browser/content/places/places.xul", openDialog("chrome://browser/content/places/places.xul",
@ -575,18 +573,12 @@ var PlacesCommandHook = {
// Helper object for the history menu. // Helper object for the history menu.
var HistoryMenu = { var HistoryMenu = {
get _ss() {
delete this._ss;
return this._ss = Cc["@mozilla.org/browser/sessionstore;1"].
getService(Ci.nsISessionStore);
},
toggleRecentlyClosedTabs: function PHM_toggleRecentlyClosedTabs() { toggleRecentlyClosedTabs: function PHM_toggleRecentlyClosedTabs() {
// enable/disable the Recently Closed Tabs sub menu // enable/disable the Recently Closed Tabs sub menu
var undoPopup = document.getElementById("historyUndoPopup"); var undoPopup = document.getElementById("historyUndoPopup");
// no restorable tabs, so disable menu // no restorable tabs, so disable menu
if (this._ss.getClosedTabCount(window) == 0) if (gSessionStore.getClosedTabCount(window) == 0)
undoPopup.parentNode.setAttribute("disabled", true); undoPopup.parentNode.setAttribute("disabled", true);
else else
undoPopup.parentNode.removeAttribute("disabled"); undoPopup.parentNode.removeAttribute("disabled");
@ -617,7 +609,7 @@ var HistoryMenu = {
undoPopup.removeChild(undoPopup.firstChild); undoPopup.removeChild(undoPopup.firstChild);
// no restorable tabs, so make sure menu is disabled, and return // no restorable tabs, so make sure menu is disabled, and return
if (this._ss.getClosedTabCount(window) == 0) { if (gSessionStore.getClosedTabCount(window) == 0) {
undoPopup.parentNode.setAttribute("disabled", true); undoPopup.parentNode.setAttribute("disabled", true);
return; return;
} }
@ -626,7 +618,7 @@ var HistoryMenu = {
undoPopup.parentNode.removeAttribute("disabled"); undoPopup.parentNode.removeAttribute("disabled");
// populate menu // populate menu
var undoItems = eval("(" + this._ss.getClosedTabData(window) + ")"); var undoItems = eval("(" + gSessionStore.getClosedTabData(window) + ")");
for (var i = 0; i < undoItems.length; i++) { for (var i = 0; i < undoItems.length; i++) {
var m = document.createElement("menuitem"); var m = document.createElement("menuitem");
m.setAttribute("label", undoItems[i].title); m.setAttribute("label", undoItems[i].title);
@ -663,7 +655,7 @@ var HistoryMenu = {
let undoPopup = document.getElementById("historyUndoWindowPopup"); let undoPopup = document.getElementById("historyUndoWindowPopup");
// no restorable windows, so disable menu // no restorable windows, so disable menu
if (this._ss.getClosedWindowCount() == 0) if (gSessionStore.getClosedWindowCount() == 0)
undoPopup.parentNode.setAttribute("disabled", true); undoPopup.parentNode.setAttribute("disabled", true);
else else
undoPopup.parentNode.removeAttribute("disabled"); undoPopup.parentNode.removeAttribute("disabled");
@ -683,7 +675,7 @@ var HistoryMenu = {
undoPopup.removeChild(undoPopup.firstChild); undoPopup.removeChild(undoPopup.firstChild);
// no restorable windows, so make sure menu is disabled, and return // no restorable windows, so make sure menu is disabled, and return
if (this._ss.getClosedWindowCount() == 0) { if (gSessionStore.getClosedWindowCount() == 0) {
undoPopup.parentNode.setAttribute("disabled", true); undoPopup.parentNode.setAttribute("disabled", true);
return; return;
} }
@ -692,7 +684,7 @@ var HistoryMenu = {
undoPopup.parentNode.removeAttribute("disabled"); undoPopup.parentNode.removeAttribute("disabled");
// populate menu // populate menu
let undoItems = JSON.parse(this._ss.getClosedWindowData()); let undoItems = JSON.parse(gSessionStore.getClosedWindowData());
for (let i = 0; i < undoItems.length; i++) { for (let i = 0; i < undoItems.length; i++) {
let undoItem = undoItems[i]; let undoItem = undoItems[i];
let otherTabsCount = undoItem.tabs.length - 1; let otherTabsCount = undoItem.tabs.length - 1;

View File

@ -77,12 +77,6 @@ var FullZoom = {
getService(Ci.nsIContentPrefService); 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 // browser.zoom.siteSpecific preference cache
_siteSpecificPref: undefined, _siteSpecificPref: undefined,
@ -125,9 +119,7 @@ var FullZoom = {
// We disable site-specific preferences in Private Browsing mode, because the // We disable site-specific preferences in Private Browsing mode, because the
// content preferences module is disabled // content preferences module is disabled
let os = Cc["@mozilla.org/observer-service;1"]. gObserverService.addObserver(this, "private-browsing", true);
getService(Ci.nsIObserverService);
os.addObserver(this, "private-browsing", true);
// Retrieve the initial status of the Private Browsing mode. // Retrieve the initial status of the Private Browsing mode.
this._inPrivateBrowsing = Cc["@mozilla.org/privatebrowsing;1"]. this._inPrivateBrowsing = Cc["@mozilla.org/privatebrowsing;1"].
@ -135,19 +127,17 @@ var FullZoom = {
privateBrowsingEnabled; privateBrowsingEnabled;
this._siteSpecificPref = this._siteSpecificPref =
this._prefBranch.getBoolPref("browser.zoom.siteSpecific"); gPrefService.getBoolPref("browser.zoom.siteSpecific");
this.updateBackgroundTabs = this.updateBackgroundTabs =
this._prefBranch.getBoolPref("browser.zoom.updateBackgroundTabs"); gPrefService.getBoolPref("browser.zoom.updateBackgroundTabs");
// Listen for changes to the browser.zoom branch so we can enable/disable // 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. // updating background tabs and per-site saving and restoring of zoom levels.
this._prefBranch.addObserver("browser.zoom.", this, true); gPrefService.addObserver("browser.zoom.", this, true);
}, },
destroy: function FullZoom_destroy() { destroy: function FullZoom_destroy() {
let os = Cc["@mozilla.org/observer-service;1"]. gObserverService.removeObserver(this, "private-browsing");
getService(Ci.nsIObserverService); gPrefService.removeObserver("browser.zoom.", this);
os.removeObserver(this, "private-browsing");
this._prefBranch.removeObserver("browser.zoom.", this);
this._cps.removeObserver(this.name, this); this._cps.removeObserver(this.name, this);
window.removeEventListener("DOMMouseScroll", this, false); window.removeEventListener("DOMMouseScroll", this, false);
delete this._cps; delete this._cps;
@ -213,11 +203,11 @@ var FullZoom = {
switch(aData) { switch(aData) {
case "browser.zoom.siteSpecific": case "browser.zoom.siteSpecific":
this._siteSpecificPref = this._siteSpecificPref =
this._prefBranch.getBoolPref("browser.zoom.siteSpecific"); gPrefService.getBoolPref("browser.zoom.siteSpecific");
break; break;
case "browser.zoom.updateBackgroundTabs": case "browser.zoom.updateBackgroundTabs":
this.updateBackgroundTabs = this.updateBackgroundTabs =
this._prefBranch.getBoolPref("browser.zoom.updateBackgroundTabs"); gPrefService.getBoolPref("browser.zoom.updateBackgroundTabs");
break; break;
} }
break; break;

View File

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

View File

@ -46,7 +46,7 @@ var ContentAreaUtils = {
delete this.ioService; delete this.ioService;
return this.ioService = return this.ioService =
Components.classes["@mozilla.org/network/io-service;1"] Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService); .getService(Components.interfaces.nsIIOService2);
} }
} }