Bug 1460392 - Port bug 1457027 to TB: Part 2 - Define services using defineLazyServiceGetters. r=aceman
authorRichard Marti <richard.marti@gmail.com>
Sat, 22 Sep 2018 09:23:27 +0200
changeset 33262 e490dff436ddb355e7c6532e01adee7725d5aaf8
parent 33261 1dfd8879d65bea1103a01da0ef8edbd378925677
child 33263 be4843f65ece5191f3c54d25adf03352cec1c729
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersaceman
bugs1460392, 1457027
Bug 1460392 - Port bug 1457027 to TB: Part 2 - Define services using defineLazyServiceGetters. r=aceman
mail/components/preferences/applications.js
--- a/mail/components/preferences/applications.js
+++ b/mail/components/preferences/applications.js
@@ -31,16 +31,23 @@ var kActionUsePlugin = 5;
 var APP_ICON_ATTR_NAME = "appHandlerIcon";
 
 // CloudFile account tools used by gCloudFileTab.
 ChromeUtils.import("resource:///modules/cloudFileAccounts.js");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 
+XPCOMUtils.defineLazyServiceGetters(this, {
+  gCategoryManager: ["@mozilla.org/categorymanager;1", "nsICategoryManager"],
+  gHandlerService: ["@mozilla.org/uriloader/handler-service;1", "nsIHandlerService"],
+  gMIMEService: ["@mozilla.org/mime;1", "nsIMIMEService"],
+});
+
+
 // ---------
 // Utilities
 
 function getDisplayNameForFile(aFile) {
   if (AppConstants.platform == "win") {
     if (aFile instanceof Ci.nsILocalFileWin) {
       try {
         return aFile.getVersionInfoField("FileDescription");
@@ -118,22 +125,16 @@ function HandlerInfoWrapper(aType, aHand
 }
 
 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),
-
   // --------------
   // nsIHandlerInfo
 
   // The MIME type or protocol scheme.
   _type: null,
   get type() {
     return this._type;
   },
@@ -344,21 +345,21 @@ HandlerInfoWrapper.prototype = {
       false, true
     );
   },
 
   // -------
   // Storage
 
   store() {
-    this._handlerSvc.store(this.wrappedHandlerInfo);
+    gHandlerService.store(this.wrappedHandlerInfo);
   },
 
   remove() {
-    this._handlerSvc.remove(this.wrappedHandlerInfo);
+    gHandlerService.remove(this.wrappedHandlerInfo);
   },
 
   // -----
   // Icons
 
   get smallIcon() {
     return this._getIcon(16);
   },
@@ -833,24 +834,16 @@ var gApplicationsPane = {
   // Convenience & Performance Shortcuts
 
   // These get defined by init().
   _brandShortName: null,
   _prefsBundle: null,
   _list: null,
   _filter: null,
 
-  _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),
-
   // ----------------------------
   // Initialization & Destruction
 
   init() {
     // Initialize shortcuts to some commonly accessed elements & values.
     this._brandShortName =
       document.getElementById("bundleBrand").getString("brandShortName");
     this._prefsBundle = document.getElementById("bundlePreferences");
@@ -969,32 +962,32 @@ var gApplicationsPane = {
       for (let j = 0; j < plugin.length; ++j) {
         let type = plugin[j].type;
 
         let handlerInfoWrapper;
         if (type in this._handledTypes)
           handlerInfoWrapper = this._handledTypes[type];
         else {
           let wrappedHandlerInfo =
-            this._mimeSvc.getFromTypeAndExtension(type, null);
+            gMIMEService.getFromTypeAndExtension(type, null);
           handlerInfoWrapper = new HandlerInfoWrapper(type, wrappedHandlerInfo);
           handlerInfoWrapper.handledOnlyByPlugin = true;
           this._handledTypes[type] = handlerInfoWrapper;
         }
 
         handlerInfoWrapper.plugin = plugin;
       }
     }
   },
 
   /**
    * 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];