Bug 384654, Clean up nsBrowserGlue.js, r=mano

This commit is contained in:
flamingice%sourmilk.net 2007-06-16 21:23:17 +00:00
Родитель b9a1f67441
Коммит 304846bf0f
1 изменённых файлов: 70 добавлений и 68 удалений

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

@ -35,7 +35,9 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
const Ci = Components.interfaces;
const Cc = Components.classes;
const Cr = Components.results;
// Constructor // Constructor
@ -49,7 +51,7 @@ BrowserGlue.prototype = {
QueryInterface: function(iid) QueryInterface: function(iid)
{ {
xpcomCheckInterfaces(iid, kServiceIIds, Components.results.NS_ERROR_NO_INTERFACE); xpcomCheckInterfaces(iid, kServiceIIds, Cr.NS_ERROR_NO_INTERFACE);
return this; return this;
} }
, ,
@ -71,8 +73,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 = Components.classes["@mozilla.org/consoleservice;1"] const cs = Cc["@mozilla.org/consoleservice;1"].
.getService(Components.interfaces.nsIConsoleService); getService(Ci.nsIConsoleService);
cs.logStringMessage(null); // clear the console (in case it's open) cs.logStringMessage(null); // clear the console (in case it's open)
cs.reset(); cs.reset();
break; break;
@ -81,9 +83,9 @@ BrowserGlue.prototype = {
break; break;
case "quit-application-granted": case "quit-application-granted":
if (this._saveSession) { if (this._saveSession) {
var prefService = Components.classes["@mozilla.org/preferences-service;1"] var prefBranch = Cc["@mozilla.org/preferences-service;1"].
.getService(Components.interfaces.nsIPrefBranch); getService(Ci.nsIPrefBranch);
prefService.setBoolPref("browser.sessionstore.resume_session_once", true); prefBranch.setBoolPref("browser.sessionstore.resume_session_once", true);
} }
break; break;
} }
@ -93,8 +95,8 @@ BrowserGlue.prototype = {
_init: function() _init: function()
{ {
// observer registration // observer registration
const osvr = Components.classes['@mozilla.org/observer-service;1'] const osvr = Cc['@mozilla.org/observer-service;1'].
.getService(Components.interfaces.nsIObserverService); getService(Ci.nsIObserverService);
osvr.addObserver(this, "profile-before-change", false); osvr.addObserver(this, "profile-before-change", false);
osvr.addObserver(this, "profile-change-teardown", false); osvr.addObserver(this, "profile-change-teardown", false);
osvr.addObserver(this, "xpcom-shutdown", false); osvr.addObserver(this, "xpcom-shutdown", false);
@ -108,8 +110,8 @@ BrowserGlue.prototype = {
_dispose: function() _dispose: function()
{ {
// observer removal // observer removal
const osvr = Components.classes['@mozilla.org/observer-service;1'] const osvr = Cc['@mozilla.org/observer-service;1'].
.getService(Components.interfaces.nsIObserverService); getService(Ci.nsIObserverService);
osvr.removeObserver(this, "profile-before-change"); osvr.removeObserver(this, "profile-before-change");
osvr.removeObserver(this, "profile-change-teardown"); osvr.removeObserver(this, "profile-change-teardown");
osvr.removeObserver(this, "xpcom-shutdown"); osvr.removeObserver(this, "xpcom-shutdown");
@ -125,27 +127,27 @@ BrowserGlue.prototype = {
// check to see if the EULA must be shown on startup // check to see if the EULA must be shown on startup
try { try {
var mustDisplayEULA = true; var mustDisplayEULA = true;
var prefService = Components.classes["@mozilla.org/preferences-service;1"] var prefBranch = Cc["@mozilla.org/preferences-service;1"].
.getService(Components.interfaces.nsIPrefBranch); getService(Ci.nsIPrefBranch);
var EULAVersion = prefService.getIntPref("browser.EULA.version"); var EULAVersion = prefBranch.getIntPref("browser.EULA.version");
mustDisplayEULA = !prefService.getBoolPref("browser.EULA." + EULAVersion + ".accepted"); mustDisplayEULA = !prefBranch.getBoolPref("browser.EULA." + EULAVersion + ".accepted");
} catch(ex) { } catch(ex) {
} }
if (mustDisplayEULA) { if (mustDisplayEULA) {
var ww2 = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] var ww2 = Cc["@mozilla.org/embedcomp/window-watcher;1"].
.getService(Components.interfaces.nsIWindowWatcher); getService(Ci.nsIWindowWatcher);
ww2.openWindow(null, "chrome://browser/content/EULA.xul", ww2.openWindow(null, "chrome://browser/content/EULA.xul",
"_blank", "chrome,centerscreen,modal,resizable=yes", null); "_blank", "chrome,centerscreen,modal,resizable=yes", null);
} }
this.Sanitizer.onStartup(); this.Sanitizer.onStartup();
// check if we're in safe mode // check if we're in safe mode
var app = Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULAppInfo) var app = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo).
.QueryInterface(Components.interfaces.nsIXULRuntime); QueryInterface(Ci.nsIXULRuntime);
if (app.inSafeMode) { if (app.inSafeMode) {
var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
.getService(Components.interfaces.nsIWindowWatcher); getService(Ci.nsIWindowWatcher);
ww.openWindow(null, "chrome://browser/content/safeMode.xul", ww.openWindow(null, "chrome://browser/content/safeMode.xul",
"_blank", "chrome,centerscreen,modal,resizable=no", null); "_blank", "chrome,centerscreen,modal,resizable=no", null);
} }
@ -172,8 +174,8 @@ BrowserGlue.prototype = {
{ {
// here we enter last survival area, in order to avoid multiple // here we enter last survival area, in order to avoid multiple
// "quit-application" notifications caused by late window closings // "quit-application" notifications caused by late window closings
const appStartup = Components.classes['@mozilla.org/toolkit/app-startup;1'] const appStartup = Cc['@mozilla.org/toolkit/app-startup;1'].
.getService(Components.interfaces.nsIAppStartup); getService(Ci.nsIAppStartup);
try { try {
appStartup.enterLastWindowClosingSurvivalArea(); appStartup.enterLastWindowClosingSurvivalArea();
@ -187,8 +189,8 @@ BrowserGlue.prototype = {
_onQuitRequest: function(aCancelQuit) _onQuitRequest: function(aCancelQuit)
{ {
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
.getService(Components.interfaces.nsIWindowMediator); getService(Ci.nsIWindowMediator);
var windowcount = 0; var windowcount = 0;
var pagecount = 0; var pagecount = 0;
var browserEnum = wm.getEnumerator("navigator:browser"); var browserEnum = wm.getEnumerator("navigator:browser");
@ -205,21 +207,21 @@ BrowserGlue.prototype = {
if (pagecount < 2) if (pagecount < 2)
return; return;
var prefService = Components.classes["@mozilla.org/preferences-service;1"] var prefBranch = Cc["@mozilla.org/preferences-service;1"].
.getService(Components.interfaces.nsIPrefBranch); getService(Ci.nsIPrefBranch);
var showPrompt = true; var showPrompt = true;
try { try {
if (prefService.getIntPref("browser.startup.page") == 3 || if (prefBranch.getIntPref("browser.startup.page") == 3 ||
prefService.getBoolPref("browser.sessionstore.resume_session_once")) prefBranch.getBoolPref("browser.sessionstore.resume_session_once"))
showPrompt = false; showPrompt = false;
else else
showPrompt = prefService.getBoolPref("browser.warnOnQuit"); showPrompt = prefBranch.getBoolPref("browser.warnOnQuit");
} catch (ex) {} } catch (ex) {}
var buttonChoice = 0; var buttonChoice = 0;
if (showPrompt) { if (showPrompt) {
var bundleService = Components.classes["@mozilla.org/intl/stringbundle;1"] var bundleService = Cc["@mozilla.org/intl/stringbundle;1"].
.getService(Components.interfaces.nsIStringBundleService); getService(Ci.nsIStringBundleService);
var quitBundle = bundleService.createBundle("chrome://browser/locale/quitDialog.properties"); var quitBundle = bundleService.createBundle("chrome://browser/locale/quitDialog.properties");
var brandBundle = bundleService.createBundle("chrome://branding/locale/brand.properties"); var brandBundle = bundleService.createBundle("chrome://branding/locale/brand.properties");
@ -238,8 +240,8 @@ BrowserGlue.prototype = {
var message = quitBundle.formatStringFromName("message", var message = quitBundle.formatStringFromName("message",
[appName], 1); [appName], 1);
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] var promptService = Cc["@mozilla.org/embedcomp/prompt-service;1"].
.getService(Components.interfaces.nsIPromptService); 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 +
@ -253,17 +255,17 @@ BrowserGlue.prototype = {
switch (buttonChoice) { switch (buttonChoice) {
case 0: case 0:
if (neverAsk.value) if (neverAsk.value)
prefService.setBoolPref("browser.warnOnQuit", false); prefBranch.setBoolPref("browser.warnOnQuit", false);
break; break;
case 1: case 1:
aCancelQuit.QueryInterface(Components.interfaces.nsISupportsPRBool); aCancelQuit.QueryInterface(Ci.nsISupportsPRBool);
aCancelQuit.data = true; aCancelQuit.data = true;
break; break;
case 2: case 2:
// could also set browser.warnOnQuit to false here, // could also set browser.warnOnQuit to false here,
// but not setting it is a little safer. // but not setting it is a little safer.
if (neverAsk.value) if (neverAsk.value)
prefService.setIntPref("browser.startup.page", 3); prefBranch.setIntPref("browser.startup.page", 3);
break; break;
} }
@ -275,9 +277,9 @@ BrowserGlue.prototype = {
get Sanitizer() get Sanitizer()
{ {
if(typeof(Sanitizer) != "function") { // we should dynamically load the script if(typeof(Sanitizer) != "function") { // we should dynamically load the script
Components.classes["@mozilla.org/moz/jssubscript-loader;1"] Cc["@mozilla.org/moz/jssubscript-loader;1"].
.getService(Components.interfaces.mozIJSSubScriptLoader) getService(Ci.mozIJSSubScriptLoader).
.loadSubScript("chrome://browser/content/sanitize.js", null); loadSubScript("chrome://browser/content/sanitize.js", null);
} }
return Sanitizer; return Sanitizer;
}, },
@ -292,39 +294,39 @@ BrowserGlue.prototype = {
// the browser.places.importBookmarksHTML pref, as // the browser.places.importBookmarksHTML pref, as
// nsNavHistory::ForceMigrateBookmarksDB() will set that pref // nsNavHistory::ForceMigrateBookmarksDB() will set that pref
// if we need to force a migration (due to a schema change) // if we need to force a migration (due to a schema change)
var histsvc = Components.classes["@mozilla.org/browser/nav-history-service;1"] var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"].
.getService(Components.interfaces.nsINavHistoryService); getService(Ci.nsINavHistoryService);
var importBookmarks = false; var importBookmarks = false;
try { try {
var prefService = Components.classes["@mozilla.org/preferences-service;1"] var prefBranch = Cc["@mozilla.org/preferences-service;1"].
.getService(Components.interfaces.nsIPrefBranch); getService(Ci.nsIPrefBranch);
importBookmarks = prefService.getBoolPref("browser.places.importBookmarksHTML"); importBookmarks = prefBranch.getBoolPref("browser.places.importBookmarksHTML");
} catch(ex) {} } catch(ex) {}
if (!importBookmarks) if (!importBookmarks)
return; return;
var dirService = Components.classes["@mozilla.org/file/directory_service;1"] var dirService = Cc["@mozilla.org/file/directory_service;1"].
.getService(Components.interfaces.nsIProperties); getService(Ci.nsIProperties);
var bookmarksFile = dirService.get("BMarks", Components.interfaces.nsILocalFile); var bookmarksFile = dirService.get("BMarks", Ci.nsILocalFile);
if (bookmarksFile.exists()) { if (bookmarksFile.exists()) {
// import the file // import the file
try { try {
var importer = var importer =
Components.classes["@mozilla.org/browser/places/import-export-service;1"] Cc["@mozilla.org/browser/places/import-export-service;1"].
.getService(Components.interfaces.nsIPlacesImportExportService); getService(Ci.nsIPlacesImportExportService);
importer.importHTMLFromFile(bookmarksFile, true); importer.importHTMLFromFile(bookmarksFile, true);
} catch(ex) { } catch(ex) {
} finally { } finally {
prefService.setBoolPref("browser.places.importBookmarksHTML", false); prefBranch.setBoolPref("browser.places.importBookmarksHTML", false);
} }
// backup pre-places bookmarks.html // backup pre-places bookmarks.html
// XXXtodo remove this before betas, after import/export is solid // XXXtodo remove this before betas, after import/export is solid
var profDir = dirService.get("ProfD", Components.interfaces.nsILocalFile); var profDir = dirService.get("ProfD", Ci.nsILocalFile);
var bookmarksBackup = profDir.clone(); var bookmarksBackup = profDir.clone();
bookmarksBackup.append("bookmarks.preplaces.html"); bookmarksBackup.append("bookmarks.preplaces.html");
if (!bookmarksBackup.exists()) { if (!bookmarksBackup.exists()) {
@ -347,8 +349,8 @@ BrowserGlue.prototype = {
#ifdef MOZ_PLACES_BOOKMARKS #ifdef MOZ_PLACES_BOOKMARKS
// backup bookmarks to bookmarks.html // backup bookmarks to bookmarks.html
var importer = var importer =
Components.classes["@mozilla.org/browser/places/import-export-service;1"] Cc["@mozilla.org/browser/places/import-export-service;1"].
.getService(Components.interfaces.nsIPlacesImportExportService); getService(Ci.nsIPlacesImportExportService);
importer.backupBookmarksFile(); importer.backupBookmarksFile();
#endif #endif
}, },
@ -377,10 +379,10 @@ const kServiceCId = Components.ID(kServiceId);
// interfaces implemented by this component // interfaces implemented by this component
const kServiceIIds = [ const kServiceIIds = [
Components.interfaces.nsIObserver, Ci.nsIObserver,
Components.interfaces.nsISupports, Ci.nsISupports,
Components.interfaces.nsISupportsWeakReference, Ci.nsISupportsWeakReference,
Components.interfaces.nsIBrowserGlue Ci.nsIBrowserGlue
]; ];
// categories which this component is registered in // categories which this component is registered in
@ -391,10 +393,10 @@ const kServiceFactory = {
_instance: null, _instance: null,
createInstance: function (outer, iid) createInstance: function (outer, iid)
{ {
if (outer != null) throw Components.results.NS_ERROR_NO_AGGREGATION; if (outer != null) throw Cr.NS_ERROR_NO_AGGREGATION;
xpcomCheckInterfaces(iid, kServiceIIds, xpcomCheckInterfaces(iid, kServiceIIds,
Components.results.NS_ERROR_INVALID_ARG); Cr.NS_ERROR_INVALID_ARG);
return this._instance == null ? return this._instance == null ?
this._instance = new kServiceConstructor() : this._instance; this._instance = new kServiceConstructor() : this._instance;
} }
@ -415,15 +417,15 @@ var Module = {
registerSelf: function(compMgr, fileSpec, location, type) registerSelf: function(compMgr, fileSpec, location, type)
{ {
if (!this.registered) { if (!this.registered) {
compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar) compMgr.QueryInterface(Ci.nsIComponentRegistrar)
.registerFactoryLocation(kServiceCId, .registerFactoryLocation(kServiceCId,
kServiceName, kServiceName,
kServiceCtrId, kServiceCtrId,
fileSpec, fileSpec,
location, location,
type); type);
const catman = Components.classes['@mozilla.org/categorymanager;1'] const catman = Cc['@mozilla.org/categorymanager;1'].
.getService(Components.interfaces.nsICategoryManager); getService(Ci.nsICategoryManager);
var len = kServiceCats.length; var len = kServiceCats.length;
for (var j = 0; j < len; j++) { for (var j = 0; j < len; j++) {
catman.addCategoryEntry(kServiceCats[j], catman.addCategoryEntry(kServiceCats[j],
@ -435,10 +437,10 @@ var Module = {
unregisterSelf: function(compMgr, fileSpec, location) unregisterSelf: function(compMgr, fileSpec, location)
{ {
compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar) compMgr.QueryInterface(Ci.nsIComponentRegistrar)
.unregisterFactoryLocation(kServiceCId, fileSpec); .unregisterFactoryLocation(kServiceCId, fileSpec);
const catman = Components.classes['@mozilla.org/categorymanager;1'] const catman = Cc['@mozilla.org/categorymanager;1'].
.getService(Components.interfaces.nsICategoryManager); getService(Ci.nsICategoryManager);
var len = kServiceCats.length; var len = kServiceCats.length;
for (var j = 0; j < len; j++) { for (var j = 0; j < len; j++) {
catman.deleteCategoryEntry(kServiceCats[j], kServiceCtrId, true); catman.deleteCategoryEntry(kServiceCats[j], kServiceCtrId, true);
@ -450,8 +452,8 @@ var Module = {
if(cid.equals(kServiceCId)) if(cid.equals(kServiceCId))
return kServiceFactory; return kServiceFactory;
throw Components.results[ throw Cr[
iid.equals(Components.interfaces.nsIFactory) iid.equals(Ci.nsIFactory)
? "NS_ERROR_NO_INTERFACE" ? "NS_ERROR_NO_INTERFACE"
: "NS_ERROR_NOT_IMPLEMENTED" : "NS_ERROR_NOT_IMPLEMENTED"
]; ];