--- a/browser/components/preferences/in-content/main.js
+++ b/browser/components/preferences/in-content/main.js
@@ -12,16 +12,23 @@ ChromeUtils.import("resource://gre/modul
ChromeUtils.import("resource://gre/modules/FileUtils.jsm");
ChromeUtils.import("resource:///modules/ShellService.jsm");
ChromeUtils.import("resource:///modules/TransientPrefs.jsm");
ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
ChromeUtils.import("resource://gre/modules/DownloadUtils.jsm");
ChromeUtils.defineModuleGetter(this, "CloudStorage",
"resource://gre/modules/CloudStorage.jsm");
+XPCOMUtils.defineLazyServiceGetters(this, {
+ gCategoryManager: ["@mozilla.org/categorymanager;1", "nsICategoryManager"],
+ gHandlerService: ["@mozilla.org/uriloader/handler-service;1", "nsIHandlerService"],
+ gMIMEService: ["@mozilla.org/mime;1", "nsIMIMEService"],
+ gWebContentContentConverterService: ["@mozilla.org/embeddor.implemented/web-content-handler-registrar;1", "nsIWebContentConverterService"],
+});
+
// Constants & Enumeration Values
const TYPE_MAYBE_FEED = "application/vnd.mozilla.maybe.feed";
const TYPE_MAYBE_VIDEO_FEED = "application/vnd.mozilla.maybe.video.feed";
const TYPE_MAYBE_AUDIO_FEED = "application/vnd.mozilla.maybe.audio.feed";
const TYPE_PDF = "application/pdf";
const PREF_PDFJS_DISABLED = "pdfjs.disabled";
const TOPIC_PDFJS_HANDLER_CHANGED = "pdfjs:handlerChanged";
@@ -279,25 +286,16 @@ var gMainPane = {
return this._list = document.getElementById("handlersView");
},
get _filter() {
delete this._filter;
return this._filter = document.getElementById("filter");
},
- _mimeSvc: Cc["@mozilla.org/mime;1"].
- getService(Ci.nsIMIMEService),
-
- _helperAppSvc: Cc["@mozilla.org/uriloader/external-helper-app-service;1"].
- getService(Ci.nsIExternalHelperAppService),
-
- _handlerSvc: Cc["@mozilla.org/uriloader/handler-service;1"].
- getService(Ci.nsIHandlerService),
-
_backoffIndex: 0,
/**
* Initialization of this.
*/
init() {
function setEventListener(aId, aEventType, aCallback) {
document.getElementById(aId)
@@ -1415,30 +1413,30 @@ var gMainPane = {
let mimeTypes = navigator.mimeTypes;
for (let mimeType of mimeTypes) {
let handlerInfoWrapper;
if (mimeType.type in this._handledTypes) {
handlerInfoWrapper = this._handledTypes[mimeType.type];
} else {
let wrappedHandlerInfo =
- this._mimeSvc.getFromTypeAndExtension(mimeType.type, null);
+ gMIMEService.getFromTypeAndExtension(mimeType.type, null);
handlerInfoWrapper = new HandlerInfoWrapper(mimeType.type, wrappedHandlerInfo);
handlerInfoWrapper.handledOnlyByPlugin = true;
this._handledTypes[mimeType.type] = handlerInfoWrapper;
}
handlerInfoWrapper.pluginName = mimeType.enabledPlugin.name;
}
},
/**
* Load the set of handlers defined by the application datastore.
*/
_loadApplicationHandlers() {
- var wrappedHandlerInfos = this._handlerSvc.enumerate();
+ var wrappedHandlerInfos = gHandlerService.enumerate();
while (wrappedHandlerInfos.hasMoreElements()) {
let wrappedHandlerInfo =
wrappedHandlerInfos.getNext().QueryInterface(Ci.nsIHandlerInfo);
let type = wrappedHandlerInfo.type;
let handlerInfoWrapper;
if (type in this._handledTypes)
handlerInfoWrapper = this._handledTypes[type];
@@ -2099,17 +2097,17 @@ var gMainPane = {
};
if (AppConstants.platform == "win") {
var params = {};
var handlerInfo = this._handledTypes[this._list.selectedItem.type];
if (isFeedType(handlerInfo.type)) {
// MIME info will be null, create a temp object.
- params.mimeInfo = this._mimeSvc.getFromTypeAndExtension(handlerInfo.type,
+ params.mimeInfo = gMIMEService.getFromTypeAndExtension(handlerInfo.type,
handlerInfo.primaryExtension);
} else {
params.mimeInfo = handlerInfo.wrappedHandlerInfo;
}
params.title = this._prefsBundle.getString("fpTitleChooseApp");
params.description = handlerInfo.description;
params.filename = null;
@@ -2631,22 +2629,16 @@ HandlerInfoWrapper.prototype = {
// The wrapped nsIHandlerInfo object. In general, this object is private,
// but there are a couple cases where callers access it directly for things
// we haven't (yet?) implemented, so we make it a public property.
wrappedHandlerInfo: null,
// Convenience Utils
- _handlerSvc: Cc["@mozilla.org/uriloader/handler-service;1"].
- getService(Ci.nsIHandlerService),
-
- _categoryMgr: Cc["@mozilla.org/categorymanager;1"].
- getService(Ci.nsICategoryManager),
-
element(aID) {
return document.getElementById(aID);
},
// nsIHandlerInfo
// The MIME type or protocol scheme.
@@ -2851,44 +2843,44 @@ HandlerInfoWrapper.prototype = {
if (!disabledPluginTypes.includes(this.type))
disabledPluginTypes.push(this.type);
Services.prefs.setCharPref(PREF_DISABLED_PLUGIN_TYPES,
disabledPluginTypes.join(","));
// Update the category manager so existing browser windows update.
- this._categoryMgr.deleteCategoryEntry("Gecko-Content-Viewers",
+ gCategoryManager.deleteCategoryEntry("Gecko-Content-Viewers",
this.type,
false);
},
enablePluginType() {
var disabledPluginTypes = this._getDisabledPluginTypes();
var type = this.type;
disabledPluginTypes = disabledPluginTypes.filter(v => v != type);
Services.prefs.setCharPref(PREF_DISABLED_PLUGIN_TYPES,
disabledPluginTypes.join(","));
// Update the category manager so existing browser windows update.
- this._categoryMgr.
- addCategoryEntry("Gecko-Content-Viewers",
+ gCategoryManager.addCategoryEntry(
+ "Gecko-Content-Viewers",
this.type,
"@mozilla.org/content/plugin/document-loader-factory;1",
false,
true);
},
// Storage
store() {
- this._handlerSvc.store(this.wrappedHandlerInfo);
+ gHandlerService.store(this.wrappedHandlerInfo);
},
// Icons
get smallIcon() {
return this._getIcon(16);
},
@@ -2926,24 +2918,16 @@ HandlerInfoWrapper.prototype = {
function FeedHandlerInfo(aMIMEType) {
HandlerInfoWrapper.call(this, aMIMEType, null);
}
FeedHandlerInfo.prototype = {
__proto__: HandlerInfoWrapper.prototype,
- // Convenience Utils
-
- _converterSvc:
- Cc["@mozilla.org/embeddor.implemented/web-content-handler-registrar;1"].
- getService(Ci.nsIWebContentConverterService),
-
- _shellSvc: AppConstants.HAVE_SHELL_SERVICE ? getShellService() : null,
-
// nsIHandlerInfo
get description() {
return this.element("bundlePreferences").getString(this._appPrefLabel);
},
get preferredApplicationHandler() {
switch (Preferences.get(this._prefSelectedReader).value) {
@@ -2953,17 +2937,17 @@ FeedHandlerInfo.prototype = {
return getLocalHandlerApp(file);
return null;
case "web":
var uri = Preferences.get(this._prefSelectedWeb).value;
if (!uri)
return null;
- return this._converterSvc.getWebContentHandlerByURI(this.type, uri);
+ return gWebContentContentConverterService.getWebContentHandlerByURI(this.type, uri);
case "bookmarks":
default:
// When the pref is set to bookmarks, we handle feeds internally,
// we don't forward them to a local or web handler app, so there is
// no preferred handler.
return null;
}
@@ -2977,17 +2961,17 @@ FeedHandlerInfo.prototype = {
Preferences.get(this._prefSelectedWeb).value = aNewValue.uri;
Preferences.get(this._prefSelectedReader).value = "web";
// Make the web handler be the new "auto handler" for feeds.
// Note: we don't have to unregister the auto handler when the user picks
// a non-web handler (local app, Live Bookmarks, etc.) because the service
// only uses the "auto handler" when the selected reader is a web handler.
// We also don't have to unregister it when the user turns on "always ask"
// (i.e. preview in browser), since that also overrides the auto handler.
- this._converterSvc.setAutoHandler(this.type, aNewValue);
+ gWebContentContentConverterService.setAutoHandler(this.type, aNewValue);
}
},
_possibleApplicationHandlers: null,
get possibleApplicationHandlers() {
if (this._possibleApplicationHandlers)
return this._possibleApplicationHandlers;
@@ -3032,34 +3016,34 @@ FeedHandlerInfo.prototype = {
if (preferredAppFile) {
let preferredApp = getLocalHandlerApp(preferredAppFile);
let defaultApp = this._defaultApplicationHandler;
if (!defaultApp || !defaultApp.equals(preferredApp))
this._possibleApplicationHandlers.appendElement(preferredApp);
}
// Add the registered web handlers. There can be any number of these.
- var webHandlers = this._converterSvc.getContentHandlers(this.type);
+ var webHandlers = gWebContentContentConverterService.getContentHandlers(this.type);
for (let webHandler of webHandlers)
this._possibleApplicationHandlers.appendElement(webHandler);
return this._possibleApplicationHandlers;
},
__defaultApplicationHandler: undefined,
get _defaultApplicationHandler() {
if (typeof this.__defaultApplicationHandler != "undefined")
return this.__defaultApplicationHandler;
var defaultFeedReader = null;
if (AppConstants.HAVE_SHELL_SERVICE) {
try {
- defaultFeedReader = this._shellSvc.defaultFeedReader;
+ defaultFeedReader = getShellService().defaultFeedReader;
} catch (ex) {
- // no default reader or _shellSvc is null
+ // no default reader or getShellService() is null
}
}
if (defaultFeedReader) {
let handlerApp = Cc["@mozilla.org/uriloader/local-handler-app;1"].
createInstance(Ci.nsIHandlerApp);
handlerApp.name = getFileDisplayName(defaultFeedReader);
handlerApp.QueryInterface(Ci.nsILocalHandlerApp);
@@ -3071,20 +3055,20 @@ FeedHandlerInfo.prototype = {
}
return this.__defaultApplicationHandler;
},
get hasDefaultHandler() {
if (AppConstants.HAVE_SHELL_SERVICE) {
try {
- if (this._shellSvc.defaultFeedReader)
+ if (getShellService().defaultFeedReader)
return true;
} catch (ex) {
- // no default reader or _shellSvc is null
+ // no default reader or getShellService() is null
}
}
return false;
},
get defaultDescription() {
if (this.hasDefaultHandler)
@@ -3191,17 +3175,18 @@ FeedHandlerInfo.prototype = {
var preferredAppFile = pref.value;
if (preferredAppFile) {
let preferredApp = getLocalHandlerApp(preferredAppFile);
if (app.equals(preferredApp))
pref.reset();
}
} else {
app.QueryInterface(Ci.nsIWebContentHandlerInfo);
- this._converterSvc.removeContentHandler(app.contentType, app.uri);
+ gWebContentContentConverterService.removeContentHandler(app.contentType,
+ app.uri);
}
}
this._possibleApplicationHandlers._removed = [];
},
// Icons