Bug 1486182: Part 2a - Add Services.catMan getter for the category manager. r=mossop
authorKris Maglione <maglione.k@gmail.com>
Fri, 24 Aug 2018 22:13:57 -0700
changeset 488810 a6435d51a3463a46e4a86813bb9f2816d33973f3
parent 488809 8340805509c5503ff44c5d47d7333aa206960a58
child 488811 98c713bc89b77a04b0c23c72f7df2b57b0b613a6
push id9734
push usershindli@mozilla.com
push dateThu, 30 Aug 2018 12:18:07 +0000
treeherdermozilla-beta@71c71ab3afae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs1486182
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1486182: Part 2a - Add Services.catMan getter for the category manager. r=mossop This makes it much easier to update existing consumers of XPCOMUtils.enumerateCategoryEntries to use the category manager directly. It also, unfortunately, requires updating existing category manager consumers to use the Services getter in order to avoid ESLint errors. Differential Revision: https://phabricator.services.mozilla.com/D4278
browser/components/enterprisepolicies/Policies.jsm
browser/components/preferences/in-content/main.js
browser/extensions/pdfjs/content/PdfJs.jsm
devtools/client/jsonview/converter-observer.js
js/xpconnect/tests/unit/test_xpcomutils.js
services/sync/tps/extensions/tps/bootstrap.js
storage/test/unit/test_vacuum.js
testing/specialpowers/content/SpecialPowersObserverAPI.js
testing/specialpowers/content/specialpowersAPI.js
testing/talos/talos/pageloader/bootstrap.js
toolkit/components/extensions/test/xpcshell/test_ext_schemas_privileged.js
toolkit/components/passwordmgr/nsLoginManager.js
toolkit/components/utils/simpleServices.js
toolkit/modules/Services.jsm
toolkit/modules/addons/WebRequest.jsm
toolkit/modules/addons/WebRequestContent.js
toolkit/mozapps/extensions/test/browser/head.js
xpcom/tests/unit/test_bug374754.js
xpcom/tests/unit/test_bug725015.js
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -980,11 +980,12 @@ let ChromeURLBlockPolicy = {
 
 function blockAllChromeURLs() {
   let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
   registrar.registerFactory(ChromeURLBlockPolicy.classID,
                             ChromeURLBlockPolicy.classDescription,
                             ChromeURLBlockPolicy.contractID,
                             ChromeURLBlockPolicy);
 
-  let cm = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
-  cm.addCategoryEntry("content-policy", ChromeURLBlockPolicy.contractID, ChromeURLBlockPolicy.contractID, false, true);
+  Services.catMan.addCategoryEntry("content-policy",
+                                   ChromeURLBlockPolicy.contractID,
+                                   ChromeURLBlockPolicy.contractID, false, true);
 }
--- a/browser/components/preferences/in-content/main.js
+++ b/browser/components/preferences/in-content/main.js
@@ -15,17 +15,16 @@ ChromeUtils.import("resource:///modules/
 ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 ChromeUtils.import("resource://gre/modules/DownloadUtils.jsm");
 ChromeUtils.import("resource://gre/modules/L10nRegistry.jsm");
 ChromeUtils.import("resource://gre/modules/Localization.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"],
 });
 
 // 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";
@@ -2845,32 +2844,32 @@ class HandlerInfoWrapper {
 
     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.
-    gCategoryManager.deleteCategoryEntry("Gecko-Content-Viewers",
+    Services.catMan.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.
-    gCategoryManager.addCategoryEntry(
+    Services.catMan.addCategoryEntry(
       "Gecko-Content-Viewers",
       this.type,
       "@mozilla.org/content/plugin/document-loader-factory;1",
       false,
       true);
   }
 
   store() {
--- a/browser/extensions/pdfjs/content/PdfJs.jsm
+++ b/browser/extensions/pdfjs/content/PdfJs.jsm
@@ -187,19 +187,17 @@ var PdfJs = {
     }
 
     if (!types.includes(PDF_CONTENT_TYPE)) {
       types.push(PDF_CONTENT_TYPE);
     }
     prefs.setCharPref(PREF_DISABLED_PLUGIN_TYPES, types.join(","));
 
     // Update the category manager in case the plugins are already loaded.
-    let categoryManager = Cc["@mozilla.org/categorymanager;1"];
-    categoryManager.getService(Ci.nsICategoryManager).
-                    deleteCategoryEntry("Gecko-Content-Viewers",
+    Services.catMan.deleteCategoryEntry("Gecko-Content-Viewers",
                                         PDF_CONTENT_TYPE,
                                         false);
   },
 
   _isEnabled: function _isEnabled() {
     var disabled = getBoolPref(PREF_DISABLED, true);
     if (disabled) {
       return false;
--- a/devtools/client/jsonview/converter-observer.js
+++ b/devtools/client/jsonview/converter-observer.js
@@ -170,38 +170,34 @@ ConverterObserver.prototype = {
   register: function() {
     const registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
 
     if (!registrar.isCIDRegistered(JSON_SNIFFER_CLASS_ID)) {
       registrar.registerFactory(JSON_SNIFFER_CLASS_ID,
         JSON_SNIFFER_CLASS_DESCRIPTION,
         JSON_SNIFFER_CONTRACT_ID,
         JsonSnifferFactory);
-      const categoryManager = Cc["@mozilla.org/categorymanager;1"]
-        .getService(Ci.nsICategoryManager);
-      categoryManager.addCategoryEntry(CONTENT_SNIFFER_CATEGORY, JSON_VIEW_TYPE,
+      Services.catMan.addCategoryEntry(CONTENT_SNIFFER_CATEGORY, JSON_VIEW_TYPE,
         JSON_SNIFFER_CONTRACT_ID, false, false);
     }
 
     if (!registrar.isCIDRegistered(JSON_VIEW_CLASS_ID)) {
       registrar.registerFactory(JSON_VIEW_CLASS_ID,
         JSON_VIEW_CLASS_DESCRIPTION,
         JSON_VIEW_CONTRACT_ID,
         JsonViewFactory);
     }
   },
 
   unregister: function() {
     const registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
 
     if (registrar.isCIDRegistered(JSON_SNIFFER_CLASS_ID)) {
       registrar.unregisterFactory(JSON_SNIFFER_CLASS_ID, JsonSnifferFactory);
-      const categoryManager = Cc["@mozilla.org/categorymanager;1"]
-        .getService(Ci.nsICategoryManager);
-      categoryManager.deleteCategoryEntry(CONTENT_SNIFFER_CATEGORY,
+      Services.catMan.deleteCategoryEntry(CONTENT_SNIFFER_CATEGORY,
         JSON_VIEW_TYPE, false);
     }
 
     if (registrar.isCIDRegistered(JSON_VIEW_CLASS_ID)) {
       registrar.unregisterFactory(JSON_VIEW_CLASS_ID, JsonViewFactory);
     }
   },
 
--- a/js/xpconnect/tests/unit/test_xpcomutils.js
+++ b/js/xpconnect/tests/unit/test_xpcomutils.js
@@ -4,16 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /**
  * This file tests the methods on XPCOMUtils.jsm.
  */
 
 ChromeUtils.import("resource://gre/modules/Preferences.jsm");
+ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 ////////////////////////////////////////////////////////////////////////////////
 //// Tests
 
 add_test(function test_generateQI_string_names()
 {
     var x = {
--- a/services/sync/tps/extensions/tps/bootstrap.js
+++ b/services/sync/tps/extensions/tps/bootstrap.js
@@ -2,20 +2,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://gre/modules/osfile.jsm");
 
-XPCOMUtils.defineLazyServiceGetter(this, "categoryManager",
-                                   "@mozilla.org/categorymanager;1",
-                                   "nsICategoryManager");
-
 XPCOMUtils.defineLazyServiceGetter(this, "resProto",
                                    "@mozilla.org/network/protocol;1?name=resource",
                                    "nsISubstitutingProtocolHandler");
 
 const Cm = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
 
 const CATMAN_CONTRACTID = "@mozilla.org/categorymanager;1";
 
@@ -31,22 +27,22 @@ TPSCmdLine.prototype = {
   contractID: "@mozilla.org/commandlinehandler/general-startup;1?type=tps",
 
   QueryInterface:   ChromeUtils.generateQI([Ci.nsICommandLineHandler]),
 
   register() {
     Cm.registerFactory(this.classID, this.classDescription,
                        this.contractID, this.factory);
 
-    categoryManager.addCategoryEntry(CATEGORY_NAME, CATEGORY_ENTRY,
+    Services.catMan.addCategoryEntry(CATEGORY_NAME, CATEGORY_ENTRY,
                                      this.contractID, false, true);
   },
 
   unregister() {
-    categoryManager.deleteCategoryEntry(CATEGORY_NAME, CATEGORY_ENTRY,
+    Services.catMan.deleteCategoryEntry(CATEGORY_NAME, CATEGORY_ENTRY,
                                         this.contractID, false);
 
     Cm.unregisterFactory(this.classID, this.factory);
   },
 
   /* nsICmdLineHandler */
   commandLineArgument: "-tps",
   prefNameForStartup: "general.startup.tps",
--- a/storage/test/unit/test_vacuum.js
+++ b/storage/test/unit/test_vacuum.js
@@ -15,18 +15,17 @@ ChromeUtils.import("resource://gre/modul
 function load_test_vacuum_component() {
   const CATEGORY_NAME = "vacuum-participant";
 
   do_load_manifest("vacuumParticipant.manifest");
 
   // This is a lazy check, there could be more participants than just this test
   // we just mind that the test exists though.
   const EXPECTED_ENTRIES = ["vacuumParticipant"];
-  let catMan = Cc["@mozilla.org/categorymanager;1"].
-               getService(Ci.nsICategoryManager);
+  let {catMan} = Services;
   let found = false;
   for (let {data: entry} of catMan.enumerateCategory(CATEGORY_NAME)) {
     print("Check if the found category entry (" + entry + ") is expected.");
     if (EXPECTED_ENTRIES.includes(entry)) {
       print("Check that only one test entry exists.");
       Assert.ok(!found);
       found = true;
     } else {
--- a/testing/specialpowers/content/SpecialPowersObserverAPI.js
+++ b/testing/specialpowers/content/SpecialPowersObserverAPI.js
@@ -255,23 +255,21 @@ SpecialPowersObserverAPI.prototype = {
                      .messageManager;
     mm.sendAsyncMessage(aReplyName, aReplyMsg);
   },
 
   _notifyCategoryAndObservers(subject, topic, data) {
     const serviceMarker = "service,";
 
     // First create observers from the category manager.
-    let cm =
-      Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
 
     let observers = [];
 
-    for (let {data: entry} of cm.enumerateCategory(topic)) {
-      let contractID = cm.getCategoryEntry(topic, entry);
+    for (let {data: entry} of Services.catMan.enumerateCategory(topic)) {
+      let contractID = Services.catMan.getCategoryEntry(topic, entry);
 
       let factoryFunction;
       if (contractID.substring(0, serviceMarker.length) == serviceMarker) {
         contractID = contractID.substring(serviceMarker.length);
         factoryFunction = "getService";
       } else {
         factoryFunction = "createInstance";
       }
--- a/testing/specialpowers/content/specialpowersAPI.js
+++ b/testing/specialpowers/content/specialpowersAPI.js
@@ -1696,25 +1696,23 @@ SpecialPowersAPI.prototype = {
     this._mfl.log(data);
   },
 
   closeLogFile() {
     this._mfl.close();
   },
 
   addCategoryEntry(category, entry, value, persists, replace) {
-    Cc["@mozilla.org/categorymanager;1"].
-      getService(Ci.nsICategoryManager).
-      addCategoryEntry(category, entry, value, persists, replace);
+    Services.catMan
+      .addCategoryEntry(category, entry, value, persists, replace);
   },
 
   deleteCategoryEntry(category, entry, persists) {
-    Cc["@mozilla.org/categorymanager;1"].
-      getService(Ci.nsICategoryManager).
-      deleteCategoryEntry(category, entry, persists);
+    Services.catMan
+      .deleteCategoryEntry(category, entry, persists);
   },
   openDialog(win, args) {
     return win.openDialog.apply(win, args);
   },
   // This is a blocking call which creates and spins a native event loop
   spinEventLoop(win) {
     // simply do a sync XHR back to our windows location.
     var syncXHR = new win.XMLHttpRequest();
--- a/testing/talos/talos/pageloader/bootstrap.js
+++ b/testing/talos/talos/pageloader/bootstrap.js
@@ -38,20 +38,16 @@
  * ***** END LICENSE BLOCK ***** */
 
 // This only implements nsICommandLineHandler, since it needs
 // to handle multiple arguments.
 
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
-XPCOMUtils.defineLazyServiceGetter(this, "categoryManager",
-                                   "@mozilla.org/categorymanager;1",
-                                   "nsICategoryManager");
-
 const Cm = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
 
 const CATMAN_CONTRACTID         = "@mozilla.org/categorymanager;1";
 
 const CATEGORY_NAME = "command-line-handler";
 const CATEGORY_ENTRY = "m-tp";
 
 function PageLoaderCmdLine() {}
@@ -62,22 +58,22 @@ PageLoaderCmdLine.prototype =
   classID:          Components.ID("{8AF052F5-8EFE-4359-8266-E16498A82E8B}"),
   contractID:       "@mozilla.org/commandlinehandler/general-startup;1?type=tp",
   QueryInterface:   ChromeUtils.generateQI([Ci.nsICommandLineHandler]),
 
   register() {
     Cm.registerFactory(this.classID, this.classDescription,
                        this.contractID, this.factory);
 
-    categoryManager.addCategoryEntry(CATEGORY_NAME, CATEGORY_ENTRY,
+    Services.catMan.addCategoryEntry(CATEGORY_NAME, CATEGORY_ENTRY,
                                      this.contractID, false, true);
   },
 
   unregister() {
-    categoryManager.deleteCategoryEntry(CATEGORY_NAME, CATEGORY_ENTRY,
+    Services.catMan.deleteCategoryEntry(CATEGORY_NAME, CATEGORY_ENTRY,
                                         this.contractID, false);
 
     Cm.unregisterFactory(this.classID, this.factory);
   },
 
   /* nsICommandLineHandler */
   handle: function handler_handle(cmdLine) {
     var args = {};
--- a/toolkit/components/extensions/test/xpcshell/test_ext_schemas_privileged.js
+++ b/toolkit/components/extensions/test/xpcshell/test_ext_schemas_privileged.js
@@ -35,19 +35,18 @@ add_task(async function() {
     privileged: {
       url: URL.createObjectURL(new Blob([API.toString()])),
       schema: `data:,${JSON.stringify(schema)}`,
       scopes: ["addon_parent"],
       paths: [["privileged"]],
     },
   };
 
-  const catMan = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
-  catMan.addCategoryEntry("webextension-modules", "test-privileged",
-                          `data:,${JSON.stringify(modules)}`, false, false);
+  Services.catMan.addCategoryEntry("webextension-modules", "test-privileged",
+                                   `data:,${JSON.stringify(modules)}`, false, false);
 
   AddonTestUtils.createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "42");
   await AddonTestUtils.promiseStartupManager();
 
   // Try accessing the privileged namespace.
   async function testOnce() {
     let extension = ExtensionTestUtils.loadExtension({
       manifest: {
@@ -70,10 +69,10 @@ add_task(async function() {
   let result = await testOnce();
   equal(result, false, "Privileged namespace should not be accessible to a regular webextension");
 
   AddonTestUtils.usePrivilegedSignatures = true;
   result = await testOnce();
   equal(result, true, "Privileged namespace should be accessible to a webextension signed with Mozilla Extensions");
 
   await AddonTestUtils.promiseShutdownManager();
-  catMan.deleteCategoryEntry("webextension-modules", "test-privileged", false);
+  Services.catMan.deleteCategoryEntry("webextension-modules", "test-privileged", false);
 });
--- a/toolkit/components/passwordmgr/nsLoginManager.js
+++ b/toolkit/components/passwordmgr/nsLoginManager.js
@@ -108,20 +108,18 @@ LoginManager.prototype = {
   _initStorage() {
     let contractID;
     if (AppConstants.platform == "android") {
       contractID = "@mozilla.org/login-manager/storage/mozStorage;1";
     } else {
       contractID = "@mozilla.org/login-manager/storage/json;1";
     }
     try {
-      let catMan = Cc["@mozilla.org/categorymanager;1"].
-                   getService(Ci.nsICategoryManager);
-      contractID = catMan.getCategoryEntry("login-manager-storage",
-                                           "nsILoginManagerStorage");
+      contractID = Services.catMan.getCategoryEntry("login-manager-storage",
+                                                    "nsILoginManagerStorage");
       log.debug("Found alternate nsILoginManagerStorage with contract ID:", contractID);
     } catch (e) {
       log.debug("No alternate nsILoginManagerStorage registered");
     }
 
     this._storage = Cc[contractID].
                     createInstance(Ci.nsILoginManagerStorage);
     this.initializationPromise = this._storage.initialize();
--- a/toolkit/components/utils/simpleServices.js
+++ b/toolkit/components/utils/simpleServices.js
@@ -16,18 +16,16 @@
 
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 ChromeUtils.defineModuleGetter(this, "NetUtil",
                                "resource://gre/modules/NetUtil.jsm");
 ChromeUtils.defineModuleGetter(this, "Services",
                                "resource://gre/modules/Services.jsm");
 
-XPCOMUtils.defineLazyServiceGetter(this, "catMan", "@mozilla.org/categorymanager;1",
-                                   "nsICategoryManager");
 XPCOMUtils.defineLazyServiceGetter(this, "streamConv", "@mozilla.org/streamConverters;1",
                                    "nsIStreamConverterService");
 const ArrayBufferInputStream = Components.Constructor(
   "@mozilla.org/io/arraybuffer-input-stream;1",
   "nsIArrayBufferInputStream", "setData");
 
 /*
  * This class provides a stream filter for locale messages in CSS files served
@@ -125,17 +123,17 @@ function HttpIndexViewer() {
 HttpIndexViewer.prototype = {
   classID: Components.ID("{742ad274-34c5-43d1-a8b7-293eaf8962d6}"),
   QueryInterface: ChromeUtils.generateQI([Ci.nsIDocumentLoaderFactory]),
 
   createInstance(aCommand, aChannel, aLoadGroup, aContentType, aContainer,
                  aExtraInfo, aDocListenerResult) {
     aChannel.contentType = "text/html";
 
-    let contract = catMan.getCategoryEntry("Gecko-Content-Viewers", "text/html");
+    let contract = Services.catMan.getCategoryEntry("Gecko-Content-Viewers", "text/html");
     let factory = Cc[contract].getService(Ci.nsIDocumentLoaderFactory);
 
     let listener = {};
     let res = factory.createInstance("view", aChannel, aLoadGroup,
                                      "text/html", aContainer, aExtraInfo,
                                      listener);
 
     aDocListenerResult.value =
--- a/toolkit/modules/Services.jsm
+++ b/toolkit/modules/Services.jsm
@@ -55,16 +55,17 @@ XPCOMUtils.defineLazyGetter(Services, "i
   return Cc["@mozilla.org/network/io-service;1"]
            .getService(Ci.nsIIOService)
            .QueryInterface(Ci.nsISpeculativeConnect);
 });
 
 var initTable = {
   appShell: ["@mozilla.org/appshell/appShellService;1", "nsIAppShellService"],
   cache2: ["@mozilla.org/netwerk/cache-storage-service;1", "nsICacheStorageService"],
+  catMan: ["@mozilla.org/categorymanager;1", "nsICategoryManager"],
   clearData: ["@mozilla.org/clear-data-service;1", "nsIClearDataService"],
   cpmm: ["@mozilla.org/childprocessmessagemanager;1", "nsIMessageSender"],
   console: ["@mozilla.org/consoleservice;1", "nsIConsoleService"],
   cookies: ["@mozilla.org/cookiemanager;1", "nsICookieManager"],
   droppedLinkHandler: ["@mozilla.org/content/dropped-link-handler;1", "nsIDroppedLinkHandler"],
   els: ["@mozilla.org/eventlistenerservice;1", "nsIEventListenerService"],
   eTLD: ["@mozilla.org/network/effective-tld-service;1", "nsIEffectiveTLDService"],
   intl: ["@mozilla.org/mozintl;1", "mozIMozIntl"],
--- a/toolkit/modules/addons/WebRequest.jsm
+++ b/toolkit/modules/addons/WebRequest.jsm
@@ -315,23 +315,23 @@ var ChannelEventSink = {
                                           Ci.nsIFactory]),
 
   init() {
     Components.manager.QueryInterface(Ci.nsIComponentRegistrar)
       .registerFactory(this._classID, this._classDescription, this._contractID, this);
   },
 
   register() {
-    let catMan = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
-    catMan.addCategoryEntry("net-channel-event-sinks", this._contractID, this._contractID, false, true);
+    Services.catMan.addCategoryEntry("net-channel-event-sinks",
+                                     this._contractID,
+                                     this._contractID, false, true);
   },
 
   unregister() {
-    let catMan = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
-    catMan.deleteCategoryEntry("net-channel-event-sinks", this._contractID, false);
+    Services.catMan.deleteCategoryEntry("net-channel-event-sinks", this._contractID, false);
   },
 
   // nsIChannelEventSink implementation
   asyncOnChannelRedirect(oldChannel, newChannel, flags, redirectCallback) {
     runLater(() => redirectCallback.onRedirectVerifyCallback(Cr.NS_OK));
     try {
       HttpObserverManager.onChannelReplaced(oldChannel, newChannel);
     } catch (e) {
--- a/toolkit/modules/addons/WebRequestContent.js
+++ b/toolkit/modules/addons/WebRequestContent.js
@@ -61,23 +61,23 @@ var ContentPolicy = {
         if (this.contentPolicies.size == 0) {
           this.unregister();
         }
         break;
     }
   },
 
   register() {
-    let catMan = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
-    catMan.addCategoryEntry("content-policy", this._contractID, this._contractID, false, true);
+    Services.catMan.addCategoryEntry("content-policy",
+                                     this._contractID,
+                                     this._contractID, false, true);
   },
 
   unregister() {
-    let catMan = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
-    catMan.deleteCategoryEntry("content-policy", this._contractID, false);
+    Services.catMan.deleteCategoryEntry("content-policy", this._contractID, false);
   },
 
   shouldLoad(contentLocation, loadInfo, mimeTypeGuess) {
     let policyType = loadInfo.externalContentPolicyType;
     let loadingPrincipal = loadInfo.loadingPrincipal;
     let requestPrincipal = loadInfo.triggeringPrincipal;
     let requestOrigin = null;
     if (loadingPrincipal) {
--- a/toolkit/mozapps/extensions/test/browser/head.js
+++ b/toolkit/mozapps/extensions/test/browser/head.js
@@ -103,18 +103,17 @@ function checkOpenWindows(aWindowID) {
     }
   }
   if (found)
     ok(false, "Found unexpected " + aWindowID + " window still open");
 }
 
 // Tools to disable and re-enable the background update and blocklist timers
 // so that tests can protect themselves from unwanted timer events.
-var gCatMan = Cc["@mozilla.org/categorymanager;1"]
-                .getService(Ci.nsICategoryManager);
+var gCatMan = Services.catMan;
 // Default values from toolkit/mozapps/extensions/extensions.manifest, but disable*UpdateTimer()
 // records the actual value so we can put it back in enable*UpdateTimer()
 var backgroundUpdateConfig = "@mozilla.org/addons/integration;1,getService,addon-background-update-timer,extensions.update.interval,86400";
 var blocklistUpdateConfig = "@mozilla.org/extensions/blocklist;1,getService,blocklist-background-update-timer,extensions.blocklist.interval,86400";
 
 var UTIMER = "update-timer";
 var AMANAGER = "addonManager";
 var BLOCKLIST = "nsBlocklistService";
--- a/xpcom/tests/unit/test_bug374754.js
+++ b/xpcom/tests/unit/test_bug374754.js
@@ -36,16 +36,15 @@ var observer = {
 };
 
 function run_test() {
   do_test_pending();
 
   Services.obs.addObserver(observer, addedTopic);
   Services.obs.addObserver(observer, removedTopic);
 
-  var categoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
-  categoryManager.addCategoryEntry(testCategory, testEntry, testValue, false, true);
-  categoryManager.addCategoryEntry(testCategory, testEntry, testValue, false, true);
-  categoryManager.deleteCategoryEntry(testCategory, testEntry, false);
+  Services.catMan.addCategoryEntry(testCategory, testEntry, testValue, false, true);
+  Services.catMan.addCategoryEntry(testCategory, testEntry, testValue, false, true);
+  Services.catMan.deleteCategoryEntry(testCategory, testEntry, false);
 
   timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
   timer.init(observer, 0, timer.TYPE_ONE_SHOT);
 }
--- a/xpcom/tests/unit/test_bug725015.js
+++ b/xpcom/tests/unit/test_bug725015.js
@@ -15,17 +15,17 @@ function observe_category(subj, topic, d
   try {
     Assert.equal(topic, observerTopic);
     if (data != category)
       return;
 
     var thisentry = subj.QueryInterface(Ci.nsISupportsCString).data;
     Assert.equal(thisentry, entry);
 
-    Assert.equal(Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager).getCategoryEntry(category, entry), contract);
+    Assert.equal(Services.catMan.getCategoryEntry(category, entry), contract);
     Assert.ok(Cc[contract].equals(cid));
   } catch (e) {
     do_throw(e);
   }
   do_test_finished();
 }
 
 function run_test() {