Bug 1478124: Part 8a - Update toolkit module to use a static component manifest. r=froydnj
☠☠ backed out by 1e042fc7de3d ☠ ☠
authorKris Maglione <maglione.k@gmail.com>
Sun, 16 Dec 2018 16:03:00 -0800
changeset 455928 d94039b199437180309264cb4c206ae7ebb7d21d
parent 455927 5d85deac61c2ee54a69525de8bdfff4be72d224c
child 455929 b0444e0bc801f828b49f9953a73498cf5ff5024b
push id35463
push usershindli@mozilla.com
push dateTue, 29 Jan 2019 21:38:17 +0000
treeherdermozilla-central@4440fbf71c72 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1478124
milestone67.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 1478124: Part 8a - Update toolkit module to use a static component manifest. r=froydnj Differential Revision: https://phabricator.services.mozilla.com/D15039
dom/base/WindowDestroyedEvent.cpp
dom/base/nsGlobalWindowInner.cpp
dom/base/nsGlobalWindowOuter.cpp
dom/ipc/ContentParent.cpp
dom/notification/Notification.cpp
extensions/pref/autoconfig/src/nsReadConfig.cpp
netwerk/url-classifier/AsyncUrlChannelClassifier.cpp
netwerk/url-classifier/nsChannelClassifier.cpp
toolkit/components/build/components.conf
toolkit/components/build/moz.build
toolkit/components/build/nsToolkitCompsCID.h
toolkit/components/build/nsToolkitCompsModule.cpp
toolkit/components/build/nsToolkitCompsModule.h
toolkit/components/filewatcher/NativeFileWatcherNotSupported.h
toolkit/components/places/nsAnnotationService.h
toolkit/components/reputationservice/ApplicationReputation.cpp
toolkit/components/reputationservice/LoginReputation.cpp
toolkit/components/reputationservice/LoginReputationIPC.cpp
toolkit/components/url-classifier/Classifier.cpp
toolkit/components/url-classifier/ProtocolParser.cpp
toolkit/components/url-classifier/nsCheckSummedOutputStream.h
toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
toolkit/components/url-classifier/nsUrlClassifierDBService.h
toolkit/components/url-classifier/nsUrlClassifierPrefixSet.cpp
toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp
toolkit/components/url-classifier/tests/gtest/Common.cpp
toolkit/components/url-classifier/tests/gtest/TestUrlClassifierTableUpdateV4.cpp
toolkit/xre/ProfileReset.cpp
toolkit/xre/nsAppRunner.cpp
toolkit/xre/nsXREDirProvider.cpp
widget/android/nsAppShell.cpp
widget/cocoa/nsMenuBarX.mm
widget/windows/nsWindow.cpp
--- a/dom/base/WindowDestroyedEvent.cpp
+++ b/dom/base/WindowDestroyedEvent.cpp
@@ -7,20 +7,20 @@
 #include "WindowDestroyedEvent.h"
 
 #include "nsJSUtils.h"
 #include "jsapi.h"
 #include "js/Wrapper.h"
 #include "nsIPrincipal.h"
 #include "nsISupportsPrimitives.h"
 #include "nsIAppStartup.h"
-#include "nsToolkitCompsCID.h"
 #include "nsCOMPtr.h"
 #include "nsContentUtils.h"
 #include "xpcpublic.h"
+#include "mozilla/Components.h"
 
 namespace mozilla {
 
 struct BrowserCompartmentMatcher : public js::CompartmentFilter {
   bool match(JS::Compartment* aC) const override {
     return !xpc::MightBeWebContentCompartment(aC);
   }
 };
@@ -60,18 +60,17 @@ WindowDestroyedEvent::Run() {
     wrapper->SetData(mID);
     observerService->NotifyObservers(wrapper, mTopic.get(), nullptr);
   }
 
   switch (mPhase) {
     case Phase::Destroying: {
       bool skipNukeCrossCompartment = false;
 #ifndef DEBUG
-      nsCOMPtr<nsIAppStartup> appStartup =
-          do_GetService(NS_APPSTARTUP_CONTRACTID);
+      nsCOMPtr<nsIAppStartup> appStartup = components::AppStartup::Service();
 
       if (appStartup) {
         appStartup->GetShuttingDown(&skipNukeCrossCompartment);
       }
 #endif
 
       if (!skipNukeCrossCompartment) {
         // The compartment nuking phase might be too expensive, so do that
--- a/dom/base/nsGlobalWindowInner.cpp
+++ b/dom/base/nsGlobalWindowInner.cpp
@@ -144,20 +144,16 @@
 #include "nsIScriptError.h"
 #include "nsIControllers.h"
 #include "nsIControllerContext.h"
 #include "nsGlobalWindowCommands.h"
 #include "nsQueryObject.h"
 #include "nsContentUtils.h"
 #include "nsCSSProps.h"
 #include "nsIURIFixup.h"
-#ifndef DEBUG
-#  include "nsIAppStartup.h"
-#  include "nsToolkitCompsCID.h"
-#endif
 #include "nsCDefaultURIFixup.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/EventStateManager.h"
 #include "nsIObserverService.h"
 #include "nsFocusManager.h"
 #include "nsIXULWindow.h"
 #include "nsITimedChannel.h"
 #include "nsServiceManagerUtils.h"
--- a/dom/base/nsGlobalWindowOuter.cpp
+++ b/dom/base/nsGlobalWindowOuter.cpp
@@ -148,20 +148,16 @@
 #include "nsIControllers.h"
 #include "nsIControllerContext.h"
 #include "nsGlobalWindowCommands.h"
 #include "nsQueryObject.h"
 #include "nsContentUtils.h"
 #include "nsCSSProps.h"
 #include "nsIURIFixup.h"
 #include "nsIURIMutator.h"
-#ifndef DEBUG
-#  include "nsIAppStartup.h"
-#  include "nsToolkitCompsCID.h"
-#endif
 #include "nsCDefaultURIFixup.h"
 #include "mozilla/EventDispatcher.h"
 #include "mozilla/EventStateManager.h"
 #include "nsIObserverService.h"
 #include "nsFocusManager.h"
 #include "nsIXULWindow.h"
 #include "nsITimedChannel.h"
 #include "nsServiceManagerUtils.h"
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -28,16 +28,17 @@
 #include "imgIContainer.h"
 #if defined(XP_WIN) && defined(ACCESSIBILITY)
 #  include "mozilla/a11y/AccessibleWrap.h"
 #  include "mozilla/a11y/Compatibility.h"
 #endif
 #include "mozilla/AntiTrackingCommon.h"
 #include "mozilla/BasePrincipal.h"
 #include "mozilla/ClearOnShutdown.h"
+#include "mozilla/Components.h"
 #include "mozilla/StyleSheetInlines.h"
 #include "mozilla/DataStorage.h"
 #include "mozilla/devtools/HeapSnapshotTempFileHelperParent.h"
 #include "mozilla/docshell/OfflineCacheUpdateParent.h"
 #include "mozilla/dom/BrowsingContext.h"
 #include "mozilla/dom/ChromeBrowsingContext.h"
 #include "mozilla/dom/ClientManager.h"
 #include "mozilla/dom/ClientOpenWindowOpActors.h"
@@ -174,17 +175,16 @@
 #include "mozilla/dom/ProcessMessageManager.h"
 #include "mozilla/dom/nsMixedContentBlocker.h"
 #include "nsMemoryInfoDumper.h"
 #include "nsMemoryReporterManager.h"
 #include "nsScriptError.h"
 #include "nsServiceManagerUtils.h"
 #include "nsStyleSheetService.h"
 #include "nsThreadUtils.h"
-#include "nsToolkitCompsCID.h"
 #include "nsWidgetsCID.h"
 #include "PreallocatedProcessManager.h"
 #include "ProcessPriorityManager.h"
 #include "SandboxHal.h"
 #include "SourceSurfaceRawData.h"
 #include "TabParent.h"
 #include "URIUtils.h"
 #include "nsIWebBrowserChrome.h"
@@ -3789,32 +3789,30 @@ mozilla::ipc::IPCResult ContentParent::R
   }
   nsCOMPtr<nsIPrincipal> principal;
   nsresult rv = aAlert->GetPrincipal(getter_AddRefs(principal));
   if (NS_WARN_IF(NS_FAILED(rv)) ||
       !HasNotificationPermission(IPC::Principal(principal))) {
     return IPC_OK();
   }
 
-  nsCOMPtr<nsIAlertsService> sysAlerts(
-      do_GetService(NS_ALERTSERVICE_CONTRACTID));
+  nsCOMPtr<nsIAlertsService> sysAlerts(components::Alerts::Service());
   if (sysAlerts) {
     sysAlerts->ShowAlert(aAlert, this);
   }
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult ContentParent::RecvCloseAlert(
     const nsString& aName, const IPC::Principal& aPrincipal) {
   if (!HasNotificationPermission(aPrincipal)) {
     return IPC_OK();
   }
 
-  nsCOMPtr<nsIAlertsService> sysAlerts(
-      do_GetService(NS_ALERTSERVICE_CONTRACTID));
+  nsCOMPtr<nsIAlertsService> sysAlerts(components::Alerts::Service());
   if (sysAlerts) {
     sysAlerts->CloseAlert(aName, aPrincipal);
   }
 
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult ContentParent::RecvDisableNotifications(
--- a/dom/notification/Notification.cpp
+++ b/dom/notification/Notification.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
 #include "mozilla/dom/Notification.h"
 
+#include "mozilla/Components.h"
 #include "mozilla/Encoding.h"
 #include "mozilla/EventStateManager.h"
 #include "mozilla/JSONWriter.h"
 #include "mozilla/Move.h"
 #include "mozilla/OwningNonNull.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 #include "mozilla/StaticPrefs.h"
@@ -50,17 +51,16 @@
 #include "nsISimpleEnumerator.h"
 #include "nsIUUIDGenerator.h"
 #include "nsIXPConnect.h"
 #include "nsNetUtil.h"
 #include "nsProxyRelease.h"
 #include "nsServiceManagerUtils.h"
 #include "nsStructuredCloneContainer.h"
 #include "nsThreadUtils.h"
-#include "nsToolkitCompsCID.h"
 #include "nsXULAppAPI.h"
 
 namespace mozilla {
 namespace dom {
 
 struct NotificationStrings {
   const nsString mID;
   const nsString mTitle;
@@ -648,18 +648,17 @@ bool NotificationTelemetryService::GetNo
   return true;
 }
 
 void NotificationTelemetryService::RecordDNDSupported() {
   if (mDNDRecorded) {
     return;
   }
 
-  nsCOMPtr<nsIAlertsService> alertService =
-      do_GetService(NS_ALERTSERVICE_CONTRACTID);
+  nsCOMPtr<nsIAlertsService> alertService = components::Alerts::Service();
   if (!alertService) {
     return;
   }
 
   nsCOMPtr<nsIAlertsDoNotDisturb> alertServiceDND =
       do_QueryInterface(alertService);
   if (!alertServiceDND) {
     return;
@@ -1406,18 +1405,17 @@ void Notification::ShowInternal() {
   mozilla::Swap(ownership, mTempRef);
   MOZ_ASSERT(ownership->GetNotification() == this);
 
   nsresult rv = PersistNotification();
   if (NS_FAILED(rv)) {
     NS_WARNING("Could not persist Notification");
   }
 
-  nsCOMPtr<nsIAlertsService> alertService =
-      do_GetService(NS_ALERTSERVICE_CONTRACTID);
+  nsCOMPtr<nsIAlertsService> alertService = components::Alerts::Service();
 
   ErrorResult result;
   NotificationPermission permission = NotificationPermission::Denied;
   if (mWorkerPrivate) {
     permission = GetPermissionInternal(mWorkerPrivate->GetPrincipal(), result);
   } else {
     permission = GetPermissionInternal(GetOwner(), result);
   }
@@ -1947,18 +1945,17 @@ void Notification::CloseInternal() {
   // of this function. This is relevant when the call is from
   // NotificationTask::Run().
   UniquePtr<NotificationRef> ownership;
   mozilla::Swap(ownership, mTempRef);
 
   SetAlertName();
   UnpersistNotification();
   if (!mIsClosed) {
-    nsCOMPtr<nsIAlertsService> alertService =
-        do_GetService(NS_ALERTSERVICE_CONTRACTID);
+    nsCOMPtr<nsIAlertsService> alertService = components::Alerts::Service();
     if (alertService) {
       nsAutoString alertName;
       GetAlertName(alertName);
       alertService->CloseAlert(alertName, GetPrincipal());
     }
   }
 }
 
--- a/extensions/pref/autoconfig/src/nsReadConfig.cpp
+++ b/extensions/pref/autoconfig/src/nsReadConfig.cpp
@@ -1,35 +1,37 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
 #include "nsReadConfig.h"
 #include "nsJSConfigTriggers.h"
 
+#include "mozilla/Components.h"
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsIAppStartup.h"
 #include "nsContentUtils.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsIComponentManager.h"
 #include "nsIFile.h"
 #include "nsIObserverService.h"
 #include "nsIPrefBranch.h"
 #include "nsIPrefService.h"
 #include "nsIPromptService.h"
 #include "nsIServiceManager.h"
 #include "nsIStringBundle.h"
-#include "nsToolkitCompsCID.h"
 #include "nsNetUtil.h"
 #include "nsString.h"
 #include "nsCRT.h"
 #include "nspr.h"
 #include "nsXULAppAPI.h"
 
+using namespace mozilla;
+
 extern bool sandboxEnabled;
 
 extern mozilla::LazyLogModule MCD;
 
 extern nsresult CentralizedAdminPrefManagerInit(bool aSandboxEnabled);
 extern nsresult CentralizedAdminPrefManagerFinish();
 
 static nsresult DisplayError(void) {
@@ -96,17 +98,17 @@ NS_IMETHODIMP nsReadConfig::Observe(nsIS
                               "https://support.mozilla.org/products/"
                               "firefox-enterprise for more information."),
             nsIScriptError::warningFlag, NS_LITERAL_CSTRING("autoconfig"),
             nullptr);
       } else {
         rv = DisplayError();
         if (NS_FAILED(rv)) {
           nsCOMPtr<nsIAppStartup> appStartup =
-              do_GetService(NS_APPSTARTUP_CONTRACTID);
+              components::AppStartup::Service();
           if (appStartup) appStartup->Quit(nsIAppStartup::eAttemptQuit);
         }
       }
     }
   }
   return rv;
 }
 
--- a/netwerk/url-classifier/AsyncUrlChannelClassifier.cpp
+++ b/netwerk/url-classifier/AsyncUrlChannelClassifier.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set expandtab ts=4 sw=2 sts=2 cin: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
 #include "Classifier.h"
+#include "mozilla/Components.h"
 #include "mozilla/ErrorNames.h"
 #include "mozilla/net/AsyncUrlChannelClassifier.h"
 #include "mozilla/net/UrlClassifierCommon.h"
 #include "mozilla/net/UrlClassifierFeatureFactory.h"
 #include "mozilla/net/UrlClassifierFeatureResult.h"
 #include "nsContentUtils.h"
 #include "nsIChannel.h"
 #include "nsIHttpChannel.h"
@@ -87,17 +88,17 @@ class URIData {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aURI);
   MOZ_ASSERT(aInnermostURI);
 
   RefPtr<URIData> data = new URIData();
   data->mURI = aURI;
 
   nsCOMPtr<nsIUrlClassifierUtils> utilsService =
-      do_GetService(NS_URLCLASSIFIERUTILS_CONTRACTID);
+      components::UrlClassifierUtils::Service();
   if (NS_WARN_IF(!utilsService)) {
     return NS_ERROR_FAILURE;
   }
 
   nsresult rv = utilsService->GetKeyForURI(aInnermostURI, data->mURISpec);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return rv;
   }
--- a/netwerk/url-classifier/nsChannelClassifier.cpp
+++ b/netwerk/url-classifier/nsChannelClassifier.cpp
@@ -19,16 +19,17 @@
 #include "nsISupportsPriority.h"
 #include "nsNetUtil.h"
 #include "nsXULAppAPI.h"
 #include "nsQueryObject.h"
 #include "nsIUrlClassifierDBService.h"
 #include "nsIUrlClassifierFeature.h"
 #include "nsPrintfCString.h"
 
+#include "mozilla/Components.h"
 #include "mozilla/ErrorNames.h"
 #include "mozilla/Logging.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/net/UrlClassifierCommon.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "mozilla/Services.h"
 
 namespace mozilla {
@@ -364,17 +365,17 @@ nsresult nsChannelClassifier::SendThreat
   if (!Preferences::GetBool(reportEnablePref.get(), false)) {
     LOG((
         "nsChannelClassifier::SendThreatHitReport data sharing disabled for %s",
         provider.get()));
     return NS_OK;
   }
 
   nsCOMPtr<nsIURIClassifier> uriClassifier =
-      do_GetService(NS_URLCLASSIFIERDBSERVICE_CONTRACTID);
+      components::UrlClassifierDB::Service();
   if (!uriClassifier) {
     return NS_ERROR_UNEXPECTED;
   }
 
   nsresult rv =
       uriClassifier->SendThreatHitReport(aChannel, aProvider, aList, aFullHash);
   NS_ENSURE_SUCCESS(rv, rv);
 
new file mode 100644
--- /dev/null
+++ b/toolkit/components/build/components.conf
@@ -0,0 +1,207 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# 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/.
+
+IS_ANDROID = buildconfig.substs['MOZ_WIDGET_TOOLKIT'] == 'android'
+IS_WINDOWS = buildconfig.substs['MOZ_WIDGET_TOOLKIT'] == 'windows'
+
+MOZ_HAS_TERMINATOR = not IS_ANDROID
+
+Classes = [
+    {
+        'name': 'AddonContentPolicy',
+        'cid': '{c26a8241-ecf4-4aed-9f3c-f1f5c713b9a5}',
+        'contract_ids': ['@mozilla.org/addons/content-policy;1'],
+        'type': 'AddonContentPolicy',
+        'headers': ['mozilla/AddonContentPolicy.h'],
+        'categories': {'content-policy': '@mozilla.org/addons/content-policy;1'},
+    },
+    {
+        'cid': '{17a59a6b-92b8-42e5-bce0-ab434c7a7135}',
+        'contract_ids': ['@mozilla.org/addons/addon-manager-startup;1'],
+        'singleton': True,
+        'type': 'mozilla::AddonManagerStartup',
+        'headers': ['mozilla/AddonManagerStartup.h'],
+        'constructor': 'mozilla::AddonManagerStartup::GetInstance',
+    },
+    {
+        'name': 'AlertNotification',
+        'cid': '{9a7b7a41-0b47-47f7-b61b-15a210d6f020}',
+        'contract_ids': ['@mozilla.org/alert-notification;1'],
+        'type': 'mozilla::AlertNotification',
+        'headers': ['mozilla/AlertNotification.h'],
+    },
+    {
+        'name': 'ApplicationReputation',
+        'cid': '{d21b4c33-716f-4117-8041-2770b59ff8a6}',
+        'contract_ids': ['@mozilla.org/reputationservice/application-reputation-service;1'],
+        'singleton': True,
+        'type': 'ApplicationReputationService',
+        'headers': ['/toolkit/components/reputationservice/ApplicationReputation.h'],
+        'constructor': 'ApplicationReputationService::GetSingleton',
+    },
+    {
+        'name': 'DownloadPlatform',
+        'cid': '{649a14c9-fe5c-48ec-9c85-00cad9ccf32e}',
+        'contract_ids': ['@mozilla.org/toolkit/download-platform;1'],
+        'type': 'DownloadPlatform',
+        'headers': ['/toolkit/components/downloads/DownloadPlatform.h'],
+    },
+    {
+        'name': 'ExtensionPolicy',
+        'cid': '{562de129-8338-482c-bb96-a1ff09ee53cc}',
+        'contract_ids': ['@mozilla.org/addons/policy-service;1'],
+        'singleton': True,
+        'type': 'mozilla::ExtensionPolicyService',
+        'headers': ['mozilla/ExtensionPolicyService.h'],
+        'constructor': 'mozilla::ExtensionPolicyService::GetInstance',
+    },
+    {
+        'cid': '{15686f9d-483e-4361-98cd-37f1e8f1e61d}',
+        'contract_ids': ['@mozilla.org/toolkit/finalizationwitness;1'],
+        'type': 'mozilla::FinalizationWitnessService',
+        'headers': ['mozilla/FinalizationWitnessService.h'],
+        'init_method': 'Init',
+    },
+    {
+        'name': 'LoginReputation',
+        'cid': '{91fa9e67-1427-4ee9-8ee0-1a6ed578bee1}',
+        'contract_ids': ['@mozilla.org/reputationservice/login-reputation-service;1'],
+        'singleton': True,
+        'type': 'mozilla::LoginReputationService',
+        'headers': ['/toolkit/components/reputationservice/LoginReputation.h'],
+        'constructor': 'mozilla::LoginReputationService::GetSingleton',
+    },
+    {
+        'name': 'NativeFileWatcher',
+        'cid': '{6f488507-469d-4350-a68d-99c807be0a78}',
+        'contract_ids': ['@mozilla.org/toolkit/filewatcher/native-file-watcher;1'],
+        'type': 'mozilla::NativeFileWatcherService',
+        'headers': ['NativeFileWatcherWin.h' if IS_WINDOWS else 'NativeFileWatcherNotSupported.h'],
+        'init_method': 'Init',
+    },
+    {
+        'cid': '{63a69303-8a64-45a9-848c-d4e2792794e6}',
+        'contract_ids': ['@mozilla.org/toolkit/osfile/native-internals;1'],
+        'type': 'mozilla::NativeOSFileInternalsService',
+        'headers': ['mozilla/NativeOSFileInternals.h'],
+    },
+    {
+        'name': 'Alerts',
+        'cid': '{a0ccaaf8-09da-44d8-b250-9ac3e93c8117}',
+        'contract_ids': ['@mozilla.org/alerts-service;1'],
+        'type': 'nsAlertsService',
+        'headers': ['/toolkit/components/alerts/nsAlertsService.h'],
+        'overridable': True,
+    },
+    {
+        'name': 'AppStartup',
+        'cid': '{7dd4d320-c84b-4624-8d45-7bb9b2356977}',
+        'contract_ids': ['@mozilla.org/toolkit/app-startup;1'],
+        'type': 'nsAppStartup',
+        'headers': ['/toolkit/components/startup/nsAppStartup.h'],
+        'init_method': 'Init',
+    },
+    {
+        'cid': '{6356aa16-7916-4215-a825-cbc2692ca87a}',
+        'contract_ids': ['@mozilla.org/appshell/component/browser-status-filter;1'],
+        'type': 'nsBrowserStatusFilter',
+        'headers': ['/toolkit/components/statusfilter/nsBrowserStatusFilter.h'],
+    },
+    {
+        'name': 'FindService',
+        'cid': '{5060b803-340e-11d5-be5b-b3e063ec6a3c}',
+        'contract_ids': ['@mozilla.org/find/find_service;1'],
+        'type': 'nsFindService',
+        'headers': ['/toolkit/components/find/nsFindService.h'],
+    },
+    {
+        'name': 'TypeAheadFind',
+        'cid': '{e7f70966-9a37-48d7-8aeb-35998f31090e}',
+        'contract_ids': ['@mozilla.org/typeaheadfind;1'],
+        'type': 'nsTypeAheadFind',
+        'headers': ['/toolkit/components/typeaheadfind/nsTypeAheadFind.h'],
+    },
+    {
+        'name': 'UrlClassifierDB',
+        'cid': '{7a258022-6765-11e5-b379-b37b1f2354be}',
+        'contract_ids': [
+            '@mozilla.org/uriclassifierservice',
+            '@mozilla.org/url-classifier/dbservice;1',
+        ],
+        'type': 'nsISupports',
+        'legacy_constructor': 'nsUrlClassifierDBServiceConstructor',
+        'headers': ['/toolkit/components/build/nsToolkitCompsModule.h'],
+    },
+    {
+        'name': 'UrlClassifierPrefixSet',
+        'cid': '{3d8579f0-75fa-4e00-ba41-38661d5b5d17}',
+        'contract_ids': ['@mozilla.org/url-classifier/prefixset;1'],
+        'type': 'nsUrlClassifierPrefixSet',
+        'headers': ['nsUrlClassifierPrefixSet.h'],
+    },
+    {
+        'name': 'UrlClassifierStreamUpdater',
+        'cid': '{e1797597-f4d6-4dd3-a1e1-745ad352cd80}',
+        'contract_ids': ['@mozilla.org/url-classifier/streamupdater;1'],
+        'type': 'nsUrlClassifierStreamUpdater',
+        'headers': ['/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.h'],
+    },
+    {
+        'name': 'UrlClassifierUtils',
+        'cid': '{b7b2ccec-7912-4ea6-a548-b038447004bd}',
+        'contract_ids': ['@mozilla.org/url-classifier/utils;1'],
+        'type': 'nsUrlClassifierUtils',
+        'headers': ['/toolkit/components/url-classifier/nsUrlClassifierUtils.h'],
+        'init_method': 'Init',
+    },
+    {
+        'name': 'UserInfo',
+        'cid': '{14c13684-1dd2-11b2-9463-bb10ba742554}',
+        'contract_ids': ['@mozilla.org/userinfo;1'],
+        'type': 'nsUserInfo',
+        'headers': ['/toolkit/components/startup/nsUserInfo.h'],
+    },
+]
+
+if defined('MOZ_UPDATER') and not IS_ANDROID:
+    Classes += [
+        {
+            'cid': '{f3dcf644-79e8-4f59-a1bb-878454488ef9}',
+            'contract_ids': ['@mozilla.org/updates/update-processor;1'],
+            'type': 'nsUpdateProcessor',
+            'headers': ['/toolkit/xre/nsUpdateDriver.h'],
+        },
+    ]
+
+if not defined('MOZ_DISABLE_PARENTAL_CONTROLS'):
+    Classes += [
+        {
+            'cid': '{580530e5-118c-4bc7-ab88-bc2cd2b97223}',
+            'contract_ids': ['@mozilla.org/parental-controls-service;1'],
+            'type': 'nsParentalControlsService',
+            'headers': ['/toolkit/components/parentalcontrols/nsParentalControlsService.h'],
+        },
+    ]
+
+if MOZ_HAS_TERMINATOR:
+    Classes += [
+        {
+            'cid': '{2e59cc70-f83a-412f-89d4-453885837217}',
+            'contract_ids': ['@mozilla.org/toolkit/shutdown-terminator;1'],
+            'type': 'mozilla::nsTerminator',
+            'headers': ['nsTerminator.h'],
+        },
+    ]
+
+if defined('ENABLE_TESTS'):
+    Classes += [
+        {
+            'cid': '{aaa3f7f2-8ef0-41ec-8d03-aed667cf7fa2}',
+            'contract_ids': ['@mozilla.org/telemetry/geckoview-testing;1'],
+            'type': 'TelemetryGeckoViewTestingImpl',
+            'headers': ['/toolkit/components/telemetry/geckoview/TelemetryGeckoViewTesting.h'],
+        },
+    ]
--- a/toolkit/components/build/moz.build
+++ b/toolkit/components/build/moz.build
@@ -10,32 +10,20 @@ with Files('**'):
 EXPORTS += [
     'nsToolkitCompsCID.h',
 ]
 
 SOURCES += [
     'nsToolkitCompsModule.cpp',
 ]
 
+XPCOM_MANIFESTS += [
+    'components.conf',
+]
+
 FINAL_LIBRARY = 'xul'
 
 LOCAL_INCLUDES += [
-    '../../xre',
-    '../alerts',
-    '../downloads',
-    '../find',
-    '../perfmonitoring',
-    '../protobuf',
-    '../reputationservice',
-    '../startup',
-    '../statusfilter',
-    '../telemetry',
-    '../typeaheadfind',
     '../url-classifier',
 ]
 
-if not CONFIG['MOZ_DISABLE_PARENTAL_CONTROLS']:
-    LOCAL_INCLUDES += [
-        '../parentalcontrols',
-    ]
-
 if CONFIG['CC_TYPE'] == 'clang-cl':
     AllowCompilerWarnings()  # workaround for bug 1090497
--- a/toolkit/components/build/nsToolkitCompsCID.h
+++ b/toolkit/components/build/nsToolkitCompsCID.h
@@ -1,103 +1,53 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
-#define NS_ALERTSERVICE_CONTRACTID "@mozilla.org/alerts-service;1"
-
 // This separate service uses the same nsIAlertsService interface,
 // but instead sends a notification to a platform alerts API
 // if available. Using a separate CID allows us to overwrite the XUL
 // alerts service at runtime.
 #define NS_SYSTEMALERTSERVICE_CONTRACTID "@mozilla.org/system-alerts-service;1"
 
 #define NS_AUTOCOMPLETECONTROLLER_CONTRACTID \
   "@mozilla.org/autocomplete/controller;1"
 
 #define NS_AUTOCOMPLETESIMPLERESULT_CONTRACTID \
   "@mozilla.org/autocomplete/simple-result;1"
 
 #define NS_AUTOCOMPLETEMDBRESULT_CONTRACTID \
   "@mozilla.org/autocomplete/mdb-result;1"
 
-#define NS_DOWNLOADPLATFORM_CONTRACTID \
-  "@mozilla.org/toolkit/download-platform;1"
-
 #define NS_FORMHISTORY_CONTRACTID "@mozilla.org/satchel/form-history;1"
 
 #define NS_FORMFILLCONTROLLER_CONTRACTID \
   "@mozilla.org/satchel/form-fill-controller;1"
 
 #define NS_FORMHISTORYAUTOCOMPLETE_CONTRACTID \
   "@mozilla.org/autocomplete/search;1?name=form-history"
 
-#define NS_TYPEAHEADFIND_CONTRACTID "@mozilla.org/typeaheadfind;1"
-
-#define NS_PARENTALCONTROLSSERVICE_CONTRACTID \
-  "@mozilla.org/parental-controls-service;1"
-
-#define NS_URLCLASSIFIERPREFIXSET_CONTRACTID \
-  "@mozilla.org/url-classifier/prefixset;1"
-
-#define NS_URLCLASSIFIERDBSERVICE_CONTRACTID \
-  "@mozilla.org/url-classifier/dbservice;1"
-
-#define NS_URLCLASSIFIERSTREAMUPDATER_CONTRACTID \
-  "@mozilla.org/url-classifier/streamupdater;1"
-
-#define NS_URLCLASSIFIERUTILS_CONTRACTID "@mozilla.org/url-classifier/utils;1"
-
 #define NS_URLCLASSIFIERHASHCOMPLETER_CONTRACTID \
   "@mozilla.org/url-classifier/hashcompleter;1"
 
 #define NS_NAVHISTORYSERVICE_CONTRACTID \
   "@mozilla.org/browser/nav-history-service;1"
 
 #define NS_ANNOTATIONSERVICE_CONTRACTID \
   "@mozilla.org/browser/annotation-service;1"
 
 #define NS_NAVBOOKMARKSSERVICE_CONTRACTID \
   "@mozilla.org/browser/nav-bookmarks-service;1"
 
 #define NS_TAGGINGSERVICE_CONTRACTID "@mozilla.org/browser/tagging-service;1"
 
 #define NS_FAVICONSERVICE_CONTRACTID "@mozilla.org/browser/favicon-service;1"
 
-#define NS_APPSTARTUP_CONTRACTID "@mozilla.org/toolkit/app-startup;1"
-
-#if defined(MOZ_UPDATER) && !defined(MOZ_WIDGET_ANDROID)
-#  define NS_UPDATEPROCESSOR_CONTRACTID \
-    "@mozilla.org/updates/update-processor;1"
-#endif
-
-#define NS_ADDONCONTENTPOLICY_CONTRACTID "@mozilla.org/addons/content-policy;1"
-
-#if defined(ENABLE_TESTS)
-#  define NS_TELEMETRYGECKOVIEWTESTING_CONTRACTID \
-    "@mozilla.org/telemetry/geckoview-testing;1"
-#endif
-
 /////////////////////////////////////////////////////////////////////////////
 
-#define ALERT_NOTIFICATION_CID                       \
-  {                                                  \
-    0x9a7b7a41, 0x0b47, 0x47f7, {                    \
-      0xb6, 0x1b, 0x15, 0xa2, 0x10, 0xd6, 0xf0, 0x20 \
-    }                                                \
-  }
-
-// {A0CCAAF8-09DA-44D8-B250-9AC3E93C8117}
-#define NS_ALERTSSERVICE_CID                         \
-  {                                                  \
-    0xa0ccaaf8, 0x9da, 0x44d8, {                     \
-      0xb2, 0x50, 0x9a, 0xc3, 0xe9, 0x3c, 0x81, 0x17 \
-    }                                                \
-  }
-
 // {84E11F80-CA55-11DD-AD8B-0800200C9A66}
 #define NS_SYSTEMALERTSSERVICE_CID                   \
   {                                                  \
     0x84e11f80, 0xca55, 0x11dd, {                    \
       0xad, 0x8b, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 \
     }                                                \
   }
 
@@ -120,87 +70,40 @@
 // {7A6F70B6-2BBD-44b5-9304-501352D44AB5}
 #define NS_AUTOCOMPLETEMDBRESULT_CID                \
   {                                                 \
     0x7a6f70b6, 0x2bbd, 0x44b5, {                   \
       0x93, 0x4, 0x50, 0x13, 0x52, 0xd4, 0x4a, 0xb5 \
     }                                               \
   }
 
-#define NS_DOWNLOADPLATFORM_CID                      \
-  {                                                  \
-    0x649a14c9, 0xfe5c, 0x48ec, {                    \
-      0x9c, 0x85, 0x00, 0xca, 0xd9, 0xcc, 0xf3, 0x2e \
-    }                                                \
-  }
-
 // {895DB6C7-DBDF-40ea-9F64-B175033243DC}
 #define NS_FORMFILLCONTROLLER_CID                   \
   {                                                 \
     0x895db6c7, 0xdbdf, 0x40ea, {                   \
       0x9f, 0x64, 0xb1, 0x75, 0x3, 0x32, 0x43, 0xdc \
     }                                               \
   }
 
 // {59648a91-5a60-4122-8ff2-54b839c84aed}
 #define NS_GLOBALHISTORY_CID                         \
   {                                                  \
     0x59648a91, 0x5a60, 0x4122, {                    \
       0x8f, 0xf2, 0x54, 0xb8, 0x39, 0xc8, 0x4a, 0xed \
     }                                                \
   }
 
-// {59648a91-5a60-4122-8ff2-54b839c84aed}
-#define NS_PARENTALCONTROLSSERVICE_CID               \
-  {                                                  \
-    0x580530e5, 0x118c, 0x4bc7, {                    \
-      0xab, 0x88, 0xbc, 0x2c, 0xd2, 0xb9, 0x72, 0x23 \
-    }                                                \
-  }
-
-// {e7f70966-9a37-48d7-8aeb-35998f31090e}
-#define NS_TYPEAHEADFIND_CID                         \
-  {                                                  \
-    0xe7f70966, 0x9a37, 0x48d7, {                    \
-      0x8a, 0xeb, 0x35, 0x99, 0x8f, 0x31, 0x09, 0x0e \
-    }                                                \
-  }
-
-// {3d8579f0-75fa-4e00-ba41-38661d5b5d17}
-#define NS_URLCLASSIFIERPREFIXSET_CID                \
-  {                                                  \
-    0x3d8579f0, 0x75fa, 0x4e00, {                    \
-      0xba, 0x41, 0x38, 0x66, 0x1d, 0x5b, 0x5d, 0x17 \
-    }                                                \
-  }
-
 // {7a258022-6765-11e5-b379-b37b1f2354be}
 #define NS_URLCLASSIFIERDBSERVICE_CID                \
   {                                                  \
     0x7a258022, 0x6765, 0x11e5, {                    \
       0xb3, 0x79, 0xb3, 0x7b, 0x1f, 0x23, 0x54, 0xbe \
     }                                                \
   }
 
-// e1797597-f4d6-4dd3-a1e1-745ad352cd80
-#define NS_URLCLASSIFIERSTREAMUPDATER_CID            \
-  {                                                  \
-    0xe1797597, 0xf4d6, 0x4dd3, {                    \
-      0xa1, 0xe1, 0x74, 0x5a, 0xd3, 0x52, 0xcd, 0x80 \
-    }                                                \
-  }
-
-// {b7b2ccec-7912-4ea6-a548-b038447004bd}
-#define NS_URLCLASSIFIERUTILS_CID                    \
-  {                                                  \
-    0xb7b2ccec, 0x7912, 0x4ea6, {                    \
-      0xa5, 0x48, 0xb0, 0x38, 0x44, 0x70, 0x04, 0xbd \
-    }                                                \
-  }
-
 #define NS_NAVHISTORYSERVICE_CID                     \
   {                                                  \
     0x88cecbb7, 0x6c63, 0x4b3b, {                    \
       0x8c, 0xd4, 0x84, 0xf3, 0xb8, 0x22, 0x8c, 0x69 \
     }                                                \
   }
 
 #define NS_NAVHISTORYRESULTTREEVIEWER_CID            \
@@ -225,62 +128,8 @@
   }
 
 #define NS_FAVICONSERVICE_CID                        \
   {                                                  \
     0x984e3259, 0x9266, 0x49cf, {                    \
       0xb6, 0x05, 0x60, 0xb0, 0x22, 0xa0, 0x07, 0x56 \
     }                                                \
   }
-
-#if defined(MOZ_UPDATER) && !defined(MOZ_WIDGET_ANDROID)
-#  define NS_UPDATEPROCESSOR_CID                       \
-    {                                                  \
-      0xf3dcf644, 0x79e8, 0x4f59, {                    \
-        0xa1, 0xbb, 0x87, 0x84, 0x54, 0x48, 0x8e, 0xf9 \
-      }                                                \
-    }
-#endif
-
-#define NS_APPLICATION_REPUTATION_SERVICE_CONTRACTID \
-  "@mozilla.org/reputationservice/application-reputation-service;1"
-
-#define NS_APPLICATION_REPUTATION_SERVICE_CID        \
-  {                                                  \
-    0xd21b4c33, 0x716f, 0x4117, {                    \
-      0x80, 0x41, 0x27, 0x70, 0xb5, 0x9f, 0xf8, 0xa6 \
-    }                                                \
-  }
-
-#define NS_LOGIN_REPUTATION_SERVICE_CONTRACTID \
-  "@mozilla.org/reputationservice/login-reputation-service;1"
-
-#define NS_LOGIN_REPUTATION_SERVICE_CID              \
-  {                                                  \
-    0x91fa9e67, 0x1427, 0x4ee9, {                    \
-      0x8e, 0xe0, 0x1a, 0x6e, 0xd5, 0x78, 0xbe, 0xe1 \
-    }                                                \
-  }
-
-#define NS_ADDONCONTENTPOLICY_CID                    \
-  {                                                  \
-    0xc26a8241, 0xecf4, 0x4aed, {                    \
-      0x9f, 0x3c, 0xf1, 0xf5, 0xc7, 0x13, 0xb9, 0xa5 \
-    }                                                \
-  }
-
-#define NS_ADDON_POLICY_SERVICE_CID                  \
-  {                                                  \
-    0x562de129, 0x8338, 0x482c, {                    \
-      0xbb, 0x96, 0xa1, 0xff, 0x09, 0xee, 0x53, 0xcc \
-    }                                                \
-  }
-
-#define NS_ADDON_POLICY_SERVICE_CONTRACTID \
-  "@mozilla.org/addons/policy-service;1"
-
-#if defined(ENABLE_TESTS)
-#  define NS_TELEMETRYGECKOVIEWTESTING_CID \
-    {0xaaa3f7f2,                           \
-     0x8ef0,                               \
-     0x41ec,                               \
-     {0x8d, 0x3, 0xae, 0xd6, 0x67, 0xcf, 0x7f, 0xa2}};
-#endif
--- a/toolkit/components/build/nsToolkitCompsModule.cpp
+++ b/toolkit/components/build/nsToolkitCompsModule.cpp
@@ -1,257 +1,37 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
-#include "mozilla/ModuleUtils.h"
-#include "nsAppStartup.h"
-#include "nsNetCID.h"
-#include "nsUserInfo.h"
-#include "nsToolkitCompsCID.h"
-#include "nsFindService.h"
-#if defined(MOZ_UPDATER) && !defined(MOZ_WIDGET_ANDROID)
-#  include "nsUpdateDriver.h"
-#endif
-
-#if !defined(MOZ_DISABLE_PARENTAL_CONTROLS)
-#  include "nsParentalControlsService.h"
-#endif
-
-#include "mozilla/AlertNotification.h"
-#include "nsAlertsService.h"
+#include "nsToolkitCompsModule.h"
 
-#include "DownloadPlatform.h"
-
-#include "nsTypeAheadFind.h"
-
-#include "ApplicationReputation.h"
-#include "LoginReputation.h"
 #include "nsUrlClassifierDBService.h"
-#include "nsUrlClassifierStreamUpdater.h"
-#include "nsUrlClassifierUtils.h"
-#include "nsUrlClassifierPrefixSet.h"
-
-#include "nsBrowserStatusFilter.h"
-#include "mozilla/FinalizationWitnessService.h"
-#include "mozilla/NativeOSFileInternals.h"
-#include "mozilla/AddonContentPolicy.h"
-#include "mozilla/AddonManagerStartup.h"
-#include "mozilla/ExtensionPolicyService.h"
+#include "nsISupports.h"
 
 #if defined(XP_WIN)
 #  include "NativeFileWatcherWin.h"
 #else
 #  include "NativeFileWatcherNotSupported.h"
+
+NS_IMPL_ISUPPORTS(mozilla::NativeFileWatcherService,
+                  nsINativeFileWatcherService);
 #endif  // (XP_WIN)
 
-#if !defined(MOZ_WIDGET_ANDROID)
-#  define MOZ_HAS_TERMINATOR
-#endif
-
-#if defined(MOZ_HAS_TERMINATOR)
-#  include "nsTerminator.h"
-#endif
-
-#if defined(ENABLE_TESTS)
-#  include "geckoview/TelemetryGeckoViewTesting.h"
-#endif
-
 using namespace mozilla;
 
 /////////////////////////////////////////////////////////////////////////////
 
-NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsAppStartup, Init)
-
-#if defined(MOZ_HAS_TERMINATOR)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsTerminator)
-#endif
-
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsUserInfo)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsFindService)
-
-#if !defined(MOZ_DISABLE_PARENTAL_CONTROLS)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsParentalControlsService)
-#endif
-
-NS_GENERIC_FACTORY_CONSTRUCTOR(AlertNotification)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsAlertsService)
-
-NS_GENERIC_FACTORY_CONSTRUCTOR(DownloadPlatform)
-
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsTypeAheadFind)
-
-NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(
-    ApplicationReputationService, ApplicationReputationService::GetSingleton)
-NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(LoginReputationService,
-                                         LoginReputationService::GetSingleton)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsUrlClassifierPrefixSet)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsUrlClassifierStreamUpdater)
-NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsUrlClassifierUtils, Init)
-
-static nsresult nsUrlClassifierDBServiceConstructor(nsISupports *aOuter,
-                                                    REFNSIID aIID,
-                                                    void **aResult) {
+nsresult nsUrlClassifierDBServiceConstructor(nsISupports *aOuter,
+                                             const nsIID &aIID,
+                                             void **aResult) {
   nsresult rv;
   NS_ENSURE_ARG_POINTER(aResult);
   NS_ENSURE_NO_AGGREGATION(aOuter);
 
-  nsUrlClassifierDBService *inst = nsUrlClassifierDBService::GetInstance(&rv);
-  if (nullptr == inst) {
+  RefPtr<nsUrlClassifierDBService> inst =
+      nsUrlClassifierDBService::GetInstance(&rv);
+  if (!inst) {
     return rv;
   }
-  /* NS_ADDREF(inst); */
-  rv = inst->QueryInterface(aIID, aResult);
-  NS_RELEASE(inst);
 
-  return rv;
+  return inst->QueryInterface(aIID, aResult);
 }
-
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsBrowserStatusFilter)
-#if defined(MOZ_UPDATER) && !defined(MOZ_WIDGET_ANDROID)
-NS_GENERIC_FACTORY_CONSTRUCTOR(nsUpdateProcessor)
-#endif
-NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(FinalizationWitnessService, Init)
-NS_GENERIC_FACTORY_CONSTRUCTOR(NativeOSFileInternalsService)
-NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(NativeFileWatcherService, Init)
-
-NS_GENERIC_FACTORY_CONSTRUCTOR(AddonContentPolicy)
-NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(AddonManagerStartup,
-                                         AddonManagerStartup::GetInstance)
-NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(ExtensionPolicyService,
-                                         ExtensionPolicyService::GetInstance)
-
-#if defined(ENABLE_TESTS)
-NS_GENERIC_FACTORY_CONSTRUCTOR(TelemetryGeckoViewTestingImpl)
-#endif
-
-NS_DEFINE_NAMED_CID(NS_TOOLKIT_APPSTARTUP_CID);
-#if defined(MOZ_HAS_TERMINATOR)
-NS_DEFINE_NAMED_CID(NS_TOOLKIT_TERMINATOR_CID);
-#endif
-NS_DEFINE_NAMED_CID(NS_USERINFO_CID);
-NS_DEFINE_NAMED_CID(ALERT_NOTIFICATION_CID);
-NS_DEFINE_NAMED_CID(NS_ALERTSSERVICE_CID);
-#if !defined(MOZ_DISABLE_PARENTAL_CONTROLS)
-NS_DEFINE_NAMED_CID(NS_PARENTALCONTROLSSERVICE_CID);
-#endif
-NS_DEFINE_NAMED_CID(NS_DOWNLOADPLATFORM_CID);
-NS_DEFINE_NAMED_CID(NS_FIND_SERVICE_CID);
-NS_DEFINE_NAMED_CID(NS_TYPEAHEADFIND_CID);
-NS_DEFINE_NAMED_CID(NS_APPLICATION_REPUTATION_SERVICE_CID);
-NS_DEFINE_NAMED_CID(NS_LOGIN_REPUTATION_SERVICE_CID);
-NS_DEFINE_NAMED_CID(NS_URLCLASSIFIERPREFIXSET_CID);
-NS_DEFINE_NAMED_CID(NS_URLCLASSIFIERDBSERVICE_CID);
-NS_DEFINE_NAMED_CID(NS_URLCLASSIFIERSTREAMUPDATER_CID);
-NS_DEFINE_NAMED_CID(NS_URLCLASSIFIERUTILS_CID);
-NS_DEFINE_NAMED_CID(NS_BROWSERSTATUSFILTER_CID);
-#if defined(MOZ_UPDATER) && !defined(MOZ_WIDGET_ANDROID)
-NS_DEFINE_NAMED_CID(NS_UPDATEPROCESSOR_CID);
-#endif
-NS_DEFINE_NAMED_CID(FINALIZATIONWITNESSSERVICE_CID);
-NS_DEFINE_NAMED_CID(NATIVE_OSFILE_INTERNALS_SERVICE_CID);
-NS_DEFINE_NAMED_CID(NS_ADDONCONTENTPOLICY_CID);
-NS_DEFINE_NAMED_CID(NS_ADDON_MANAGER_STARTUP_CID);
-NS_DEFINE_NAMED_CID(NS_ADDON_POLICY_SERVICE_CID);
-NS_DEFINE_NAMED_CID(NATIVE_FILEWATCHER_SERVICE_CID);
-#if defined(ENABLE_TESTS)
-NS_DEFINE_NAMED_CID(NS_TELEMETRYGECKOVIEWTESTING_CID);
-#endif
-
-static const Module::CIDEntry kToolkitCIDs[] = {
-    {&kNS_TOOLKIT_APPSTARTUP_CID, false, nullptr, nsAppStartupConstructor},
-#if defined(MOZ_HAS_TERMINATOR)
-    {&kNS_TOOLKIT_TERMINATOR_CID, false, nullptr, nsTerminatorConstructor},
-#endif
-    {&kNS_USERINFO_CID, false, nullptr, nsUserInfoConstructor},
-    {&kALERT_NOTIFICATION_CID, false, nullptr, AlertNotificationConstructor},
-    {&kNS_ALERTSSERVICE_CID, false, nullptr, nsAlertsServiceConstructor},
-#if !defined(MOZ_DISABLE_PARENTAL_CONTROLS)
-    {&kNS_PARENTALCONTROLSSERVICE_CID, false, nullptr,
-     nsParentalControlsServiceConstructor},
-#endif
-    {&kNS_DOWNLOADPLATFORM_CID, false, nullptr, DownloadPlatformConstructor},
-    {&kNS_FIND_SERVICE_CID, false, nullptr, nsFindServiceConstructor},
-    {&kNS_TYPEAHEADFIND_CID, false, nullptr, nsTypeAheadFindConstructor},
-    {&kNS_APPLICATION_REPUTATION_SERVICE_CID, false, nullptr,
-     ApplicationReputationServiceConstructor},
-    {&kNS_LOGIN_REPUTATION_SERVICE_CID, false, nullptr,
-     LoginReputationServiceConstructor},
-    {&kNS_URLCLASSIFIERPREFIXSET_CID, false, nullptr,
-     nsUrlClassifierPrefixSetConstructor},
-    {&kNS_URLCLASSIFIERDBSERVICE_CID, false, nullptr,
-     nsUrlClassifierDBServiceConstructor},
-    {&kNS_URLCLASSIFIERSTREAMUPDATER_CID, false, nullptr,
-     nsUrlClassifierStreamUpdaterConstructor},
-    {&kNS_URLCLASSIFIERUTILS_CID, false, nullptr,
-     nsUrlClassifierUtilsConstructor},
-    {&kNS_BROWSERSTATUSFILTER_CID, false, nullptr,
-     nsBrowserStatusFilterConstructor},
-#if defined(MOZ_UPDATER) && !defined(MOZ_WIDGET_ANDROID)
-    {&kNS_UPDATEPROCESSOR_CID, false, nullptr, nsUpdateProcessorConstructor},
-#endif
-    {&kFINALIZATIONWITNESSSERVICE_CID, false, nullptr,
-     FinalizationWitnessServiceConstructor},
-    {&kNATIVE_OSFILE_INTERNALS_SERVICE_CID, false, nullptr,
-     NativeOSFileInternalsServiceConstructor},
-    {&kNS_ADDONCONTENTPOLICY_CID, false, nullptr,
-     AddonContentPolicyConstructor},
-    {&kNS_ADDON_MANAGER_STARTUP_CID, false, nullptr,
-     AddonManagerStartupConstructor},
-    {&kNS_ADDON_POLICY_SERVICE_CID, false, nullptr,
-     ExtensionPolicyServiceConstructor},
-    {&kNATIVE_FILEWATCHER_SERVICE_CID, false, nullptr,
-     NativeFileWatcherServiceConstructor},
-#if defined(ENABLE_TESTS)
-    {&kNS_TELEMETRYGECKOVIEWTESTING_CID, false, nullptr,
-     TelemetryGeckoViewTestingImplConstructor},
-#endif
-    {nullptr}};
-
-static const Module::ContractIDEntry kToolkitContracts[] = {
-    {NS_APPSTARTUP_CONTRACTID, &kNS_TOOLKIT_APPSTARTUP_CID},
-#if defined(MOZ_HAS_TERMINATOR)
-    {NS_TOOLKIT_TERMINATOR_CONTRACTID, &kNS_TOOLKIT_TERMINATOR_CID},
-#endif
-    {NS_USERINFO_CONTRACTID, &kNS_USERINFO_CID},
-    {ALERT_NOTIFICATION_CONTRACTID, &kALERT_NOTIFICATION_CID},
-    {NS_ALERTSERVICE_CONTRACTID, &kNS_ALERTSSERVICE_CID},
-#if !defined(MOZ_DISABLE_PARENTAL_CONTROLS)
-    {NS_PARENTALCONTROLSSERVICE_CONTRACTID, &kNS_PARENTALCONTROLSSERVICE_CID},
-#endif
-    {NS_DOWNLOADPLATFORM_CONTRACTID, &kNS_DOWNLOADPLATFORM_CID},
-    {NS_FIND_SERVICE_CONTRACTID, &kNS_FIND_SERVICE_CID},
-    {NS_TYPEAHEADFIND_CONTRACTID, &kNS_TYPEAHEADFIND_CID},
-    {NS_APPLICATION_REPUTATION_SERVICE_CONTRACTID,
-     &kNS_APPLICATION_REPUTATION_SERVICE_CID},
-    {NS_LOGIN_REPUTATION_SERVICE_CONTRACTID, &kNS_LOGIN_REPUTATION_SERVICE_CID},
-    {NS_URLCLASSIFIERPREFIXSET_CONTRACTID, &kNS_URLCLASSIFIERPREFIXSET_CID},
-    {NS_URLCLASSIFIERDBSERVICE_CONTRACTID, &kNS_URLCLASSIFIERDBSERVICE_CID},
-    {NS_URICLASSIFIERSERVICE_CONTRACTID, &kNS_URLCLASSIFIERDBSERVICE_CID},
-    {NS_URLCLASSIFIERSTREAMUPDATER_CONTRACTID,
-     &kNS_URLCLASSIFIERSTREAMUPDATER_CID},
-    {NS_URLCLASSIFIERUTILS_CONTRACTID, &kNS_URLCLASSIFIERUTILS_CID},
-    {NS_BROWSERSTATUSFILTER_CONTRACTID, &kNS_BROWSERSTATUSFILTER_CID},
-#if defined(MOZ_UPDATER) && !defined(MOZ_WIDGET_ANDROID)
-    {NS_UPDATEPROCESSOR_CONTRACTID, &kNS_UPDATEPROCESSOR_CID},
-#endif
-    {FINALIZATIONWITNESSSERVICE_CONTRACTID, &kFINALIZATIONWITNESSSERVICE_CID},
-    {NATIVE_OSFILE_INTERNALS_SERVICE_CONTRACTID,
-     &kNATIVE_OSFILE_INTERNALS_SERVICE_CID},
-    {NS_ADDONCONTENTPOLICY_CONTRACTID, &kNS_ADDONCONTENTPOLICY_CID},
-    {NS_ADDONMANAGERSTARTUP_CONTRACTID, &kNS_ADDON_MANAGER_STARTUP_CID},
-    {NS_ADDON_POLICY_SERVICE_CONTRACTID, &kNS_ADDON_POLICY_SERVICE_CID},
-    {NATIVE_FILEWATCHER_SERVICE_CONTRACTID, &kNATIVE_FILEWATCHER_SERVICE_CID},
-#if defined(ENABLE_TESTS)
-    {NS_TELEMETRYGECKOVIEWTESTING_CONTRACTID,
-     &kNS_TELEMETRYGECKOVIEWTESTING_CID},
-#endif
-    {nullptr}};
-
-static const mozilla::Module::CategoryEntry kToolkitCategories[] = {
-    {"content-policy", NS_ADDONCONTENTPOLICY_CONTRACTID,
-     NS_ADDONCONTENTPOLICY_CONTRACTID},
-    {nullptr}};
-
-static const Module kToolkitModule = {Module::kVersion, kToolkitCIDs,
-                                      kToolkitContracts, kToolkitCategories};
-
-NSMODULE_DEFN(nsToolkitCompsModule) = &kToolkitModule;
new file mode 100644
--- /dev/null
+++ b/toolkit/components/build/nsToolkitCompsModule.h
@@ -0,0 +1,12 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * 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/. */
+
+#include "nscore.h"
+#include "nsID.h"
+
+class nsISupports;
+
+nsresult nsUrlClassifierDBServiceConstructor(nsISupports *aOuter,
+                                             const nsIID& aIID,
+                                             void **aResult);
--- a/toolkit/components/filewatcher/NativeFileWatcherNotSupported.h
+++ b/toolkit/components/filewatcher/NativeFileWatcherNotSupported.h
@@ -32,13 +32,11 @@ class NativeFileWatcherService final : p
   };
 
  private:
   ~NativeFileWatcherService(){};
   NativeFileWatcherService(const NativeFileWatcherService& other) = delete;
   void operator=(const NativeFileWatcherService& other) = delete;
 };
 
-NS_IMPL_ISUPPORTS(NativeFileWatcherService, nsINativeFileWatcherService);
-
 }  // namespace mozilla
 
 #endif  // mozilla_nativefilewatcher_h__
--- a/toolkit/components/places/nsAnnotationService.h
+++ b/toolkit/components/places/nsAnnotationService.h
@@ -7,17 +7,16 @@
 #define nsAnnotationService_h___
 
 #include "nsIAnnotationService.h"
 #include "nsTArray.h"
 #include "nsCOMArray.h"
 #include "nsCOMPtr.h"
 #include "nsServiceManagerUtils.h"
 #include "nsWeakReference.h"
-#include "nsToolkitCompsCID.h"
 #include "Database.h"
 #include "nsString.h"
 #include "mozilla/Attributes.h"
 
 class nsAnnotationService final : public nsIAnnotationService,
                                   public nsSupportsWeakReference {
  public:
   NS_DECL_ISUPPORTS
--- a/toolkit/components/reputationservice/ApplicationReputation.cpp
+++ b/toolkit/components/reputationservice/ApplicationReputation.cpp
@@ -24,16 +24,17 @@
 #include "nsIURL.h"
 #include "nsIUrlClassifierDBService.h"
 #include "nsIX509Cert.h"
 #include "nsIX509CertDB.h"
 #include "nsIX509CertList.h"
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/BasePrincipal.h"
+#include "mozilla/Components.h"
 #include "mozilla/ErrorNames.h"
 #include "mozilla/LoadContext.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Services.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/intl/LocaleService.h"
 
@@ -363,17 +364,17 @@ nsresult PendingDBLookup::LookupSpecInte
   if (!principal) {
     return NS_ERROR_FAILURE;
   }
 
   // Check local lists to see if the URI has already been whitelisted or
   // blacklisted.
   LOG(("Checking DB service for principal %s [this = %p]", mSpec.get(), this));
   nsCOMPtr<nsIUrlClassifierDBService> dbService =
-      do_GetService(NS_URLCLASSIFIERDBSERVICE_CONTRACTID, &rv);
+      mozilla::components::UrlClassifierDB::Service(&rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsAutoCString tables;
   nsAutoCString allowlist;
   Preferences::GetCString(PREF_DOWNLOAD_ALLOW_TABLE, allowlist);
   if ((mLookupType != LookupType::BlocklistOnly) && !allowlist.IsEmpty()) {
     tables.Append(allowlist);
   }
--- a/toolkit/components/reputationservice/LoginReputation.cpp
+++ b/toolkit/components/reputationservice/LoginReputation.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
 #include "LoginReputation.h"
 #include "nsThreadUtils.h"
+#include "mozilla/Components.h"
 #include "mozilla/ErrorNames.h"
 #include "mozilla/Logging.h"
 #include "mozilla/net/UrlClassifierFeatureFactory.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/StaticPrefs.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/dom/HTMLInputElement.h"
@@ -108,17 +109,17 @@ RefPtr<ReputationPromise> LoginWhitelist
 
   nsCOMPtr<nsIURI> uri;
   rv = aParam->GetFormURI(getter_AddRefs(uri));
   if (NS_WARN_IF(NS_FAILED(rv) || !uri)) {
     return p;
   }
 
   nsCOMPtr<nsIURIClassifier> uriClassifier =
-      do_GetService(NS_URLCLASSIFIERDBSERVICE_CONTRACTID, &rv);
+      mozilla::components::UrlClassifierDB::Service(&rv);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return p;
   }
 
   // AsyncClassifyLocalWithTables API won't trigger a gethash request on
   // a full-length match, so this API call should only include local operation.
   // We don't support prefs overwrite for this classification.
 
--- a/toolkit/components/reputationservice/LoginReputationIPC.cpp
+++ b/toolkit/components/reputationservice/LoginReputationIPC.cpp
@@ -1,16 +1,17 @@
 
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
 #include "LoginReputationIPC.h"
+#include "mozilla/Components.h"
 #include "mozilla/Unused.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 // MOZ_LOG=LoginReputation:5
 extern LazyLogModule gLoginReputationLogModule;
 #define LR_LOG(args) \
@@ -18,17 +19,17 @@ extern LazyLogModule gLoginReputationLog
 #define LR_LOG_ENABLED() \
   MOZ_LOG_TEST(gLoginReputationLogModule, mozilla::LogLevel::Debug)
 
 NS_IMPL_ISUPPORTS(LoginReputationParent, nsILoginReputationQueryCallback)
 
 mozilla::ipc::IPCResult LoginReputationParent::QueryReputation(nsIURI* aURI) {
   nsresult rv;
   nsCOMPtr<nsILoginReputationService> service =
-      do_GetService(NS_LOGIN_REPUTATION_SERVICE_CONTRACTID, &rv);
+      components::LoginReputation::Service(&rv);
   if (NS_FAILED(rv)) {
     Unused << Send__delete__(this);
     return IPC_OK();
   }
 
   nsCOMPtr<nsILoginReputationQuery> query =
       LoginReputationService::ConstructQueryParam(aURI);
   rv = service->QueryReputation(query, this);
--- a/toolkit/components/url-classifier/Classifier.cpp
+++ b/toolkit/components/url-classifier/Classifier.cpp
@@ -10,16 +10,17 @@
 #include "nsISimpleEnumerator.h"
 #include "nsIRandomGenerator.h"
 #include "nsIInputStream.h"
 #include "nsISeekableStream.h"
 #include "nsIFile.h"
 #include "nsNetCID.h"
 #include "nsPrintfCString.h"
 #include "nsThreadUtils.h"
+#include "mozilla/Components.h"
 #include "mozilla/EndianUtils.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/IntegerPrintfMacros.h"
 #include "mozilla/Logging.h"
 #include "mozilla/SyncRunnable.h"
 #include "mozilla/Base64.h"
 #include "mozilla/Unused.h"
 #include "mozilla/UniquePtr.h"
@@ -740,17 +741,17 @@ nsresult Classifier::ApplyUpdatesBackgro
   // been called then we need to interrupt the update process.
   // We only add checkpoints for non-trivial tasks.
 
   if (aUpdates.IsEmpty()) {
     return NS_OK;
   }
 
   nsCOMPtr<nsIUrlClassifierUtils> urlUtil =
-      do_GetService(NS_URLCLASSIFIERUTILS_CONTRACTID);
+      components::UrlClassifierUtils::Service();
 
   nsCString provider;
   // Assume all TableUpdate objects should have the same provider.
   urlUtil->GetTelemetryProvider(aUpdates[0]->TableName(), provider);
 
   Telemetry::AutoTimer<Telemetry::URLCLASSIFIER_CL_KEYED_UPDATE_TIME>
       keyedTimer(provider);
 
@@ -1178,17 +1179,17 @@ bool Classifier::CheckValidUpdate(TableU
     return false;
   }
 
   return true;
 }
 
 nsCString Classifier::GetProvider(const nsACString& aTableName) {
   nsCOMPtr<nsIUrlClassifierUtils> urlUtil =
-      do_GetService(NS_URLCLASSIFIERUTILS_CONTRACTID);
+      components::UrlClassifierUtils::Service();
 
   nsCString provider;
   nsresult rv = urlUtil->GetProvider(aTableName, provider);
 
   return NS_SUCCEEDED(rv) ? provider : EmptyCString();
 }
 
 /*
--- a/toolkit/components/url-classifier/ProtocolParser.cpp
+++ b/toolkit/components/url-classifier/ProtocolParser.cpp
@@ -1,16 +1,17 @@
 //* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
 #include "ProtocolParser.h"
 #include "LookupCache.h"
 #include "nsNetCID.h"
+#include "mozilla/Components.h"
 #include "mozilla/Logging.h"
 #include "prnetdb.h"
 #include "prprf.h"
 
 #include "nsUrlClassifierDBService.h"
 #include "nsUrlClassifierUtils.h"
 #include "nsPrintfCString.h"
 #include "mozilla/Base64.h"
@@ -768,17 +769,17 @@ nsresult ProtocolParserProtobuf::Process
   if (!aResponse.has_threat_type()) {
     NS_WARNING(
         "Threat type not initialized. This seems to be an invalid response.");
     return NS_ERROR_UC_PARSER_MISSING_PARAM;
   }
 
   // Convert threat type to list name.
   nsCOMPtr<nsIUrlClassifierUtils> urlUtil =
-      do_GetService(NS_URLCLASSIFIERUTILS_CONTRACTID);
+      components::UrlClassifierUtils::Service();
   nsCString possibleListNames;
   nsresult rv = urlUtil->ConvertThreatTypeToListNames(aResponse.threat_type(),
                                                       possibleListNames);
   if (NS_FAILED(rv)) {
     PARSER_LOG(("Threat type to list name conversion error: %d",
                 aResponse.threat_type()));
     return NS_ERROR_UC_PARSER_UNKNOWN_THREAT;
   }
--- a/toolkit/components/url-classifier/nsCheckSummedOutputStream.h
+++ b/toolkit/components/url-classifier/nsCheckSummedOutputStream.h
@@ -7,17 +7,16 @@
 #define nsCheckSummedOutputStream_h__
 
 #include "nsIFile.h"
 #include "nsIOutputStream.h"
 #include "nsICryptoHash.h"
 #include "nsNetCID.h"
 #include "nsNetUtil.h"
 #include "nsString.h"
-#include "nsToolkitCompsCID.h"
 #include "../../../netwerk/base/nsBufferedStreams.h"
 #include "prio.h"
 
 class nsCheckSummedOutputStream : public nsBufferedOutputStream {
  public:
   NS_DECL_ISUPPORTS_INHERITED
 
   // Size of MD5 hash in bytes
--- a/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
@@ -9,36 +9,38 @@
 #include "nsCRT.h"
 #include "nsIDirectoryService.h"
 #include "nsIKeyModule.h"
 #include "nsIObserverService.h"
 #include "nsIPermissionManager.h"
 #include "nsIPrefBranch.h"
 #include "nsIPrefService.h"
 #include "nsIProperties.h"
+#include "nsIXULRuntime.h"
 #include "nsToolkitCompsCID.h"
-#include "nsIXULRuntime.h"
 #include "nsUrlClassifierDBService.h"
 #include "nsUrlClassifierUtils.h"
 #include "nsUrlClassifierProxies.h"
 #include "nsURILoader.h"
 #include "nsString.h"
 #include "nsReadableUtils.h"
 #include "nsTArray.h"
 #include "nsNetCID.h"
 #include "nsThreadUtils.h"
 #include "nsProxyRelease.h"
 #include "nsString.h"
 #include "mozilla/Atomics.h"
+#include "mozilla/Components.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/ErrorNames.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/Telemetry.h"
+#include "mozilla/Unused.h"
 #include "mozilla/Logging.h"
 #include "prnetdb.h"
 #include "Entries.h"
 #include "Classifier.h"
 #include "ProtocolParser.h"
 #include "mozilla/Attributes.h"
 #include "nsIPrincipal.h"
 #include "Classifier.h"
@@ -786,17 +788,17 @@ nsresult nsUrlClassifierDBServiceWorker:
   //  3) succeeded in obtaining table updates but failed to build new
   //     tables.
   //  4) succeeded in building new tables but failed to take them.
   //  5) succeeded in taking new tables.
 
   mUpdateStatus = aUpdateStatus;
 
   nsCOMPtr<nsIUrlClassifierUtils> urlUtil =
-      do_GetService(NS_URLCLASSIFIERUTILS_CONTRACTID);
+      components::UrlClassifierUtils::Service();
 
   nsCString provider;
   // Assume that all the tables in update should have the same provider.
   urlUtil->GetTelemetryProvider(mUpdateTables.SafeElementAt(0, EmptyCString()),
                                 provider);
 
   nsresult updateStatus = mUpdateStatus;
   if (NS_FAILED(mUpdateStatus)) {
@@ -1556,17 +1558,17 @@ nsUrlClassifierClassifyCallback::HandleR
     return NS_ERROR_INVALID_ARG;
   }
 
   ClassifyMatchedInfo* matchedInfo = mMatchedArray.AppendElement();
   matchedInfo->table = aTable;
   matchedInfo->fullhash = aFullHash;
 
   nsCOMPtr<nsIUrlClassifierUtils> urlUtil =
-      do_GetService(NS_URLCLASSIFIERUTILS_CONTRACTID);
+      components::UrlClassifierUtils::Service();
 
   nsCString provider;
   nsresult rv = urlUtil->GetProvider(aTable, provider);
 
   matchedInfo->provider.name = NS_SUCCEEDED(rv) ? provider : EmptyCString();
   matchedInfo->provider.priority = 0;
   for (uint8_t i = 0; i < ArrayLength(kBuiltInProviders); i++) {
     if (kBuiltInProviders[i].name.Equals(matchedInfo->provider.name)) {
@@ -1588,38 +1590,32 @@ NS_INTERFACE_MAP_BEGIN(nsUrlClassifierDB
   NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIUrlClassifierDBService,
                                      XRE_IsParentProcess())
   NS_INTERFACE_MAP_ENTRY(nsIURIClassifier)
   NS_INTERFACE_MAP_ENTRY(nsIUrlClassifierInfo)
   NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIObserver, XRE_IsParentProcess())
   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIURIClassifier)
 NS_INTERFACE_MAP_END
 
-/* static */ nsUrlClassifierDBService* nsUrlClassifierDBService::GetInstance(
-    nsresult* result) {
+/* static */ already_AddRefed<nsUrlClassifierDBService>
+nsUrlClassifierDBService::GetInstance(nsresult* result) {
   *result = NS_OK;
   if (!sUrlClassifierDBService) {
     sUrlClassifierDBService = new (fallible) nsUrlClassifierDBService();
     if (!sUrlClassifierDBService) {
       *result = NS_ERROR_OUT_OF_MEMORY;
       return nullptr;
     }
 
-    NS_ADDREF(sUrlClassifierDBService);  // addref the global
-
     *result = sUrlClassifierDBService->Init();
     if (NS_FAILED(*result)) {
-      NS_RELEASE(sUrlClassifierDBService);
       return nullptr;
     }
-  } else {
-    // Already exists, just add a ref
-    NS_ADDREF(sUrlClassifierDBService);  // addref the return result
   }
-  return sUrlClassifierDBService;
+  return do_AddRef(sUrlClassifierDBService);
 }
 
 nsUrlClassifierDBService::nsUrlClassifierDBService()
     : mCheckMalware(CHECK_MALWARE_DEFAULT),
       mCheckPhishing(CHECK_PHISHING_DEFAULT),
       mCheckBlockedURIs(CHECK_BLOCKED_DEFAULT),
       mInUpdate(false) {}
 
@@ -1719,17 +1715,18 @@ nsresult nsUrlClassifierDBService::Init(
   sGethashNoise =
       Preferences::GetUint(GETHASH_NOISE_PREF, GETHASH_NOISE_DEFAULT);
   ReadTablesFromPrefs();
   nsresult rv;
 
   {
     // Force nsIUrlClassifierUtils loading on main thread.
     nsCOMPtr<nsIUrlClassifierUtils> dummy =
-        do_GetService(NS_URLCLASSIFIERUTILS_CONTRACTID, &rv);
+        components::UrlClassifierUtils::Service(&rv);
+    Unused << dummy;
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   // Directory providers must also be accessed on the main thread.
   nsCOMPtr<nsIFile> cacheDir;
   rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_LOCAL_50_DIR,
                               getter_AddRefs(cacheDir));
   if (NS_FAILED(rv)) {
@@ -1992,17 +1989,17 @@ nsUrlClassifierDBService::SendThreatHitR
 
   if (urlStr.IsEmpty() || NS_LITERAL_STRING("about:blank").Equals(urlStr)) {
     LOG(("%s is missing a ThreatHit data reporting URL.",
          PromiseFlatCString(aProvider).get()));
     return NS_OK;
   }
 
   nsCOMPtr<nsIUrlClassifierUtils> utilsService =
-      do_GetService(NS_URLCLASSIFIERUTILS_CONTRACTID);
+      components::UrlClassifierUtils::Service();
   if (!utilsService) {
     return NS_ERROR_FAILURE;
   }
 
   nsAutoCString reportBody;
   rv =
       utilsService->MakeThreatHitReport(aChannel, aList, aFullHash, reportBody);
   NS_ENSURE_SUCCESS(rv, rv);
@@ -2094,17 +2091,17 @@ nsresult nsUrlClassifierDBService::Looku
   NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE);
 
   uri = NS_GetInnermostURI(uri);
   NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE);
 
   nsAutoCString key;
   // Canonicalize the url
   nsCOMPtr<nsIUrlClassifierUtils> utilsService =
-      do_GetService(NS_URLCLASSIFIERUTILS_CONTRACTID);
+      components::UrlClassifierUtils::Service();
   rv = utilsService->GetKeyForURI(uri, key);
   if (NS_FAILED(rv)) return rv;
 
   if (forceLookup) {
     *didLookup = true;
   } else {
     nsCOMPtr<nsIPermissionManager> permissionManager =
         services::GetPermissionManager();
@@ -2477,17 +2474,17 @@ nsUrlClassifierDBService::AsyncClassifyL
   if (AsyncClassifyLocalWithFeaturesUsingPreferences(uri, aFeatures, aListType,
                                                      aCallback)) {
     return NS_OK;
   }
 
   nsAutoCString key;
   // Canonicalize the url
   nsCOMPtr<nsIUrlClassifierUtils> utilsService =
-      do_GetService(NS_URLCLASSIFIERUTILS_CONTRACTID);
+      components::UrlClassifierUtils::Service();
   nsresult rv = utilsService->GetKeyForURI(uri, key);
   NS_ENSURE_SUCCESS(rv, rv);
 
   if (XRE_IsContentProcess()) {
     using namespace mozilla::dom;
     using namespace mozilla::ipc;
 
     ContentChild* content = ContentChild::GetSingleton();
--- a/toolkit/components/url-classifier/nsUrlClassifierDBService.h
+++ b/toolkit/components/url-classifier/nsUrlClassifierDBService.h
@@ -12,17 +12,16 @@
 #include "nsInterfaceHashtable.h"
 #include "nsIObserver.h"
 #include "nsUrlClassifierPrefixSet.h"
 #include "nsIUrlClassifierHashCompleter.h"
 #include "nsIUrlListManager.h"
 #include "nsIUrlClassifierDBService.h"
 #include "nsIUrlClassifierInfo.h"
 #include "nsIURIClassifier.h"
-#include "nsToolkitCompsCID.h"
 #include "nsICryptoHMAC.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/Mutex.h"
 #include "mozilla/TimeStamp.h"
 
 #include "Entries.h"
 #include "LookupCache.h"
 #include "HashStore.h"
@@ -96,17 +95,18 @@ class nsUrlClassifierDBService final : p
   friend class mozilla::net::AsyncUrlChannelClassifier;
 
  public:
   // This is thread safe. It throws an exception if the thread is busy.
   nsUrlClassifierDBService();
 
   nsresult Init();
 
-  static nsUrlClassifierDBService* GetInstance(nsresult* result);
+  static already_AddRefed<nsUrlClassifierDBService> GetInstance(
+      nsresult* result);
 
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_URLCLASSIFIERDBSERVICE_CID)
 
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSIURLCLASSIFIERDBSERVICE
   NS_DECL_NSIURICLASSIFIER
   NS_DECL_NSIURLCLASSIFIERINFO
   NS_DECL_NSIOBSERVER
--- a/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierPrefixSet.cpp
@@ -8,17 +8,16 @@
 #include "nsIUrlClassifierPrefixSet.h"
 #include "crc32c.h"
 #include "nsCOMPtr.h"
 #include "nsDebug.h"
 #include "nsPrintfCString.h"
 #include "nsTArray.h"
 #include "nsString.h"
 #include "nsIFile.h"
-#include "nsToolkitCompsCID.h"
 #include "nsTArray.h"
 #include "nsThreadUtils.h"
 #include "nsNetUtil.h"
 #include "nsISeekableStream.h"
 #include "nsIBufferedStreams.h"
 #include "nsIFileStreams.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/Telemetry.h"
--- a/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp
@@ -1,25 +1,25 @@
 //* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
+#include "mozilla/Components.h"
 #include "nsCRT.h"
 #include "nsIHttpChannel.h"
 #include "nsIObserverService.h"
 #include "nsIStringStream.h"
 #include "nsIUploadChannel.h"
 #include "nsIURI.h"
 #include "nsIUrlClassifierDBService.h"
 #include "nsUrlClassifierUtils.h"
 #include "nsNetUtil.h"
 #include "nsStreamUtils.h"
 #include "nsStringStream.h"
-#include "nsToolkitCompsCID.h"
 #include "nsUrlClassifierStreamUpdater.h"
 #include "mozilla/BasePrincipal.h"
 #include "mozilla/ErrorNames.h"
 #include "mozilla/Logging.h"
 #include "mozilla/ResultExtensions.h"
 #include "nsIInterfaceRequestor.h"
 #include "mozilla/LoadContext.h"
 #include "mozilla/Telemetry.h"
@@ -289,17 +289,17 @@ nsUrlClassifierStreamUpdater::DownloadUp
     // downloads.  quit-application is the same event that the download
     // manager listens for and uses to cancel pending downloads.
     nsCOMPtr<nsIObserverService> observerService =
         mozilla::services::GetObserverService();
     if (!observerService) return NS_ERROR_FAILURE;
 
     observerService->AddObserver(this, gQuitApplicationMessage, false);
 
-    mDBService = do_GetService(NS_URLCLASSIFIERDBSERVICE_CONTRACTID, &rv);
+    mDBService = mozilla::components::UrlClassifierDB::Service(&rv);
     NS_ENSURE_SUCCESS(rv, rv);
 
     mInitialized = true;
   }
 
   rv = mDBService->BeginUpdate(this, aRequestTables);
   if (rv == NS_ERROR_NOT_AVAILABLE) {
     LOG(("Service busy, already updating, queuing update %s from %s",
@@ -322,17 +322,17 @@ nsUrlClassifierStreamUpdater::DownloadUp
     return NS_OK;
   }
 
   if (NS_FAILED(rv)) {
     return rv;
   }
 
   nsCOMPtr<nsIUrlClassifierUtils> urlUtil =
-      do_GetService(NS_URLCLASSIFIERUTILS_CONTRACTID);
+      mozilla::components::UrlClassifierUtils::Service();
 
   nsTArray<nsCString> tables;
   mozilla::safebrowsing::Classifier::SplitTables(aRequestTables, tables);
   urlUtil->GetTelemetryProvider(tables.SafeElementAt(0, EmptyCString()),
                                 mTelemetryProvider);
 
   mCurrentRequest = MakeUnique<UpdateRequest>();
   BuildUpdateRequest(aRequestTables, aRequestPayload, aIsPostRequest,
--- a/toolkit/components/url-classifier/tests/gtest/Common.cpp
+++ b/toolkit/components/url-classifier/tests/gtest/Common.cpp
@@ -1,16 +1,18 @@
 #include "Common.h"
 #include "HashStore.h"
 #include "Classifier.h"
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsTArray.h"
 #include "nsIThread.h"
 #include "nsThreadUtils.h"
 #include "nsUrlClassifierUtils.h"
+#include "mozilla/Components.h"
+#include "mozilla/Unused.h"
 
 using namespace mozilla;
 using namespace mozilla::safebrowsing;
 
 #define GTEST_SAFEBROWSING_DIR NS_LITERAL_CSTRING("safebrowsing")
 #define GTEST_TABLE NS_LITERAL_CSTRING("gtest-malware-proto")
 
 template <typename Function>
@@ -90,17 +92,18 @@ void ApplyUpdate(TableUpdateArray& updat
   classifier->Open(*file);
 
   {
     // Force nsIUrlClassifierUtils loading on main thread
     // because nsIUrlClassifierDBService will not run in advance
     // in gtest.
     nsresult rv;
     nsCOMPtr<nsIUrlClassifierUtils> dummy =
-        do_GetService(NS_URLCLASSIFIERUTILS_CONTRACTID, &rv);
+        mozilla::components::UrlClassifierUtils::Service(&rv);
+    Unused << dummy;
     ASSERT_TRUE(NS_SUCCEEDED(rv));
   }
 
   SyncApplyUpdates(classifier, updates);
 }
 
 void ApplyUpdate(TableUpdate* update) {
   TableUpdateArray updates = {update};
--- a/toolkit/components/url-classifier/tests/gtest/TestUrlClassifierTableUpdateV4.cpp
+++ b/toolkit/components/url-classifier/tests/gtest/TestUrlClassifierTableUpdateV4.cpp
@@ -5,16 +5,18 @@
 #include "Classifier.h"
 #include "HashStore.h"
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsIFile.h"
 #include "nsIThread.h"
 #include "string.h"
 #include "gtest/gtest.h"
 #include "nsThreadUtils.h"
+#include "mozilla/Components.h"
+#include "mozilla/Unused.h"
 
 using namespace mozilla;
 using namespace mozilla::safebrowsing;
 
 typedef nsCString _Prefix;
 typedef nsTArray<_Prefix> _PrefixArray;
 
 #define GTEST_SAFEBROWSING_DIR NS_LITERAL_CSTRING("safebrowsing")
@@ -186,17 +188,18 @@ static void testUpdate(TableUpdateArray&
   NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(file));
 
   {
     // Force nsIUrlClassifierUtils loading on main thread
     // because nsIUrlClassifierDBService will not run in advance
     // in gtest.
     nsresult rv;
     nsCOMPtr<nsIUrlClassifierUtils> dummy =
-        do_GetService(NS_URLCLASSIFIERUTILS_CONTRACTID, &rv);
+        components::UrlClassifierUtils::Service(&rv);
+    Unused << dummy;
     ASSERT_TRUE(NS_SUCCEEDED(rv));
   }
 
   RefPtr<Classifier> classifier = new Classifier();
   classifier->Open(*file);
 
   nsresult rv = SyncApplyUpdates(classifier, tableUpdates);
   ASSERT_TRUE(rv == NS_OK);
--- a/toolkit/xre/ProfileReset.cpp
+++ b/toolkit/xre/ProfileReset.cpp
@@ -11,18 +11,18 @@
 
 #include "ProfileReset.h"
 
 #include "nsDirectoryServiceDefs.h"
 #include "nsDirectoryServiceUtils.h"
 #include "nsPIDOMWindow.h"
 #include "nsPrintfCString.h"
 #include "nsString.h"
-#include "nsToolkitCompsCID.h"
 #include "nsXPCOMCIDInternal.h"
+#include "mozilla/Components.h"
 #include "mozilla/XREAppData.h"
 
 #include "mozilla/Services.h"
 #include "mozilla/Unused.h"
 #include "prtime.h"
 
 using namespace mozilla;
 
@@ -143,17 +143,17 @@ nsresult ProfileResetCleanup(nsIToolkitP
   if (NS_FAILED(rv)) return rv;
 
   // Show a progress window while the cleanup happens since the disk I/O can
   // take time.
   nsCOMPtr<nsIWindowWatcher> windowWatcher(
       do_GetService(NS_WINDOWWATCHER_CONTRACTID));
   if (!windowWatcher) return NS_ERROR_FAILURE;
 
-  nsCOMPtr<nsIAppStartup> appStartup(do_GetService(NS_APPSTARTUP_CONTRACTID));
+  nsCOMPtr<nsIAppStartup> appStartup(components::AppStartup::Service());
   if (!appStartup) return NS_ERROR_FAILURE;
 
   nsCOMPtr<mozIDOMWindowProxy> progressWindow;
   rv = windowWatcher->OpenWindow(nullptr, kResetProgressURL, "_blank",
                                  "centerscreen,chrome,titlebar", nullptr,
                                  getter_AddRefs(progressWindow));
   if (NS_FAILED(rv)) return rv;
 
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -5,16 +5,17 @@
 
 #include "mozilla/dom/ContentParent.h"
 #include "mozilla/dom/ContentChild.h"
 #include "mozilla/ipc/GeckoChildProcessHost.h"
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/Components.h"
 #include "mozilla/FilePreferences.h"
 #include "mozilla/ChaosMode.h"
 #include "mozilla/CmdLineAndEnvUtils.h"
 #include "mozilla/IOInterposer.h"
 #include "mozilla/Likely.h"
 #include "mozilla/MemoryChecking.h"
 #include "mozilla/Poison.h"
 #include "mozilla/Preferences.h"
@@ -145,17 +146,16 @@
 #include "nsXPCOMCIDInternal.h"
 #include "nsString.h"
 #include "nsPrintfCString.h"
 #include "nsVersionComparator.h"
 
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsXULAppAPI.h"
 #include "nsXREDirProvider.h"
-#include "nsToolkitCompsCID.h"
 
 #include "nsINIParser.h"
 #include "mozilla/Omnijar.h"
 #include "mozilla/StartupTimeline.h"
 #include "mozilla/LateWriteChecks.h"
 
 #include <stdlib.h>
 #include <locale.h>
@@ -1293,17 +1293,17 @@ ScopedXPCOMStartup::~ScopedXPCOMStartup(
 
   if (mServiceManager) {
 #ifdef XP_MACOSX
     // On OS X, we need a pool to catch cocoa objects that are autoreleased
     // during teardown.
     mozilla::MacAutoreleasePool pool;
 #endif
 
-    nsCOMPtr<nsIAppStartup> appStartup(do_GetService(NS_APPSTARTUP_CONTRACTID));
+    nsCOMPtr<nsIAppStartup> appStartup(components::AppStartup::Service());
     if (appStartup) appStartup->DestroyHiddenWindow();
 
     gDirServiceProvider->DoShutdown();
     PROFILER_ADD_MARKER("Shutdown early", OTHER);
 
     WriteConsoleLog();
 
     NS_ShutdownXPCOM(mServiceManager);
@@ -1417,17 +1417,17 @@ nsresult ScopedXPCOMStartup::SetWindowCr
   NS_IF_ADDREF(gNativeAppSupport = native);
 
   // Inform the chrome registry about OS accessibility
   nsCOMPtr<nsIToolkitChromeRegistry> cr =
       mozilla::services::GetToolkitChromeRegistryService();
 
   if (cr) cr->CheckForOSAccessibility();
 
-  nsCOMPtr<nsIWindowCreator> creator(do_GetService(NS_APPSTARTUP_CONTRACTID));
+  nsCOMPtr<nsIWindowCreator> creator(components::AppStartup::Service());
   if (!creator) return NS_ERROR_UNEXPECTED;
 
   nsCOMPtr<nsIWindowWatcher> wwatch(
       do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv));
   NS_ENSURE_SUCCESS(rv, rv);
 
   return wwatch->SetWindowCreator(creator);
 }
@@ -1993,18 +1993,17 @@ static ReturnAbortOnError ShowProfileMan
           do_CreateInstance(NS_DIALOGPARAMBLOCK_CONTRACTID));
       nsCOMPtr<nsIMutableArray> dlgArray(
           do_CreateInstance(NS_ARRAY_CONTRACTID));
       NS_ENSURE_TRUE(windowWatcher && ioParamBlock && dlgArray,
                      NS_ERROR_FAILURE);
 
       ioParamBlock->SetObjects(dlgArray);
 
-      nsCOMPtr<nsIAppStartup> appStartup(
-          do_GetService(NS_APPSTARTUP_CONTRACTID));
+      nsCOMPtr<nsIAppStartup> appStartup(components::AppStartup::Service());
       NS_ENSURE_TRUE(appStartup, NS_ERROR_FAILURE);
 
       nsCOMPtr<mozIDOMWindowProxy> newWindow;
       rv = windowWatcher->OpenWindow(nullptr, kProfileManagerURL, "_blank",
                                      "centerscreen,chrome,modal,titlebar",
                                      ioParamBlock, getter_AddRefs(newWindow));
 
       NS_ENSURE_SUCCESS_LOG(rv, rv);
@@ -4212,17 +4211,17 @@ nsresult XREMain::XRE_mainRun() {
 #endif
 
   // Initialize user preferences before notifying startup observers so they're
   // ready in time for early consumers, such as the component loader.
   mDirProvider.InitializeUserPrefs();
 
   nsAppStartupNotifier::NotifyObservers(APPSTARTUP_TOPIC);
 
-  nsCOMPtr<nsIAppStartup> appStartup(do_GetService(NS_APPSTARTUP_CONTRACTID));
+  nsCOMPtr<nsIAppStartup> appStartup(components::AppStartup::Service());
   NS_ENSURE_TRUE(appStartup, NS_ERROR_FAILURE);
 
   mDirProvider.DoStartup();
 
   // As FilePreferences need the profile directory, we must initialize right
   // here.
   mozilla::FilePreferences::InitDirectoriesWhitelist();
   mozilla::FilePreferences::InitPrefs();
--- a/toolkit/xre/nsXREDirProvider.cpp
+++ b/toolkit/xre/nsXREDirProvider.cpp
@@ -1,15 +1,14 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
 #include "nsAppRunner.h"
-#include "nsToolkitCompsCID.h"
 #include "nsXREDirProvider.h"
 
 #include "jsapi.h"
 #include "xpcpublic.h"
 
 #include "nsIAppStartup.h"
 #include "nsIDirectoryEnumerator.h"
 #include "nsIFile.h"
@@ -33,16 +32,17 @@
 #include "nsEnumeratorUtils.h"
 #include "nsReadableUtils.h"
 
 #include "SpecialSystemDirectory.h"
 
 #include "mozilla/dom/ScriptSettings.h"
 
 #include "mozilla/AutoRestore.h"
+#include "mozilla/Components.h"
 #include "mozilla/Services.h"
 #include "mozilla/Omnijar.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Telemetry.h"
 
 #include <stdlib.h>
 
 #ifdef XP_WIN
@@ -957,17 +957,18 @@ nsXREDirProvider::DoStartup() {
     /*
        Make sure we've setup prefs before profile-do-change to be able to use
        them to track crashes and because we want to begin crash tracking before
        other code run from this notification since they may cause crashes.
     */
     MOZ_ASSERT(mPrefsInitialized);
 
     bool safeModeNecessary = false;
-    nsCOMPtr<nsIAppStartup> appStartup(do_GetService(NS_APPSTARTUP_CONTRACTID));
+    nsCOMPtr<nsIAppStartup> appStartup(
+        mozilla::components::AppStartup::Service());
     if (appStartup) {
       rv = appStartup->TrackStartupCrashBegin(&safeModeNecessary);
       if (NS_FAILED(rv) && rv != NS_ERROR_NOT_AVAILABLE)
         NS_WARNING("Error while beginning startup crash tracking");
 
       if (!gSafeMode && safeModeNecessary) {
         appStartup->RestartInSafeMode(nsIAppStartup::eForceQuit);
         return NS_OK;
--- a/widget/android/nsAppShell.cpp
+++ b/widget/android/nsAppShell.cpp
@@ -20,20 +20,20 @@
 #include "nsCacheService.h"
 #include "nsIDOMEventListener.h"
 #include "nsIDOMWakeLockListener.h"
 #include "nsIPowerManagerService.h"
 #include "nsISpeculativeConnect.h"
 #include "nsIURIFixup.h"
 #include "nsCategoryManagerUtils.h"
 #include "nsCDefaultURIFixup.h"
-#include "nsToolkitCompsCID.h"
 #include "nsGeoPosition.h"
 
 #include "mozilla/ArrayUtils.h"
+#include "mozilla/Components.h"
 #include "mozilla/Telemetry.h"
 #include "mozilla/Services.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Hal.h"
 #include "mozilla/dom/TabChild.h"
 #include "mozilla/intl/OSPreferences.h"
 #include "mozilla/widget/ScreenManager.h"
 #include "prenv.h"
@@ -231,18 +231,17 @@ class GeckoThreadSupport final
                                   nullptr,  // aOrigin
                                   category.get(),
                                   aData ? aData->ToString().get() : nullptr);
   }
 
   static int64_t RunUiThreadCallback() { return RunAndroidUiTasks(); }
 
   static void ForceQuit() {
-    nsCOMPtr<nsIAppStartup> appStartup =
-        do_GetService(NS_APPSTARTUP_CONTRACTID);
+    nsCOMPtr<nsIAppStartup> appStartup = components::AppStartup::Service();
 
     if (appStartup) {
       appStartup->Quit(nsIAppStartup::eForceQuit);
     }
   }
 
   static void Crash() {
     printf_stderr("Intentionally crashing...\n");
@@ -563,18 +562,17 @@ nsAppShell::Observe(nsISupports* aSubjec
     if (jni::IsAvailable()) {
       java::GeckoThread::SetState(java::GeckoThread::State::PROFILE_READY());
 
       // Gecko on Android follows the Android app model where it never
       // stops until it is killed by the system or told explicitly to
       // quit. Therefore, we should *not* exit Gecko when there is no
       // window or the last window is closed. nsIAppStartup::Quit will
       // still force Gecko to exit.
-      nsCOMPtr<nsIAppStartup> appStartup =
-          do_GetService(NS_APPSTARTUP_CONTRACTID);
+      nsCOMPtr<nsIAppStartup> appStartup = components::AppStartup::Service();
       if (appStartup) {
         appStartup->EnterLastWindowClosingSurvivalArea();
       }
     }
     removeObserver = true;
 
   } else if (!strcmp(aTopic, "chrome-document-loaded")) {
     // Set the global ready state and enable the window event dispatcher
@@ -601,18 +599,17 @@ nsAppShell::Observe(nsISupports* aSubjec
     }
     removeObserver = true;
 
   } else if (!strcmp(aTopic, "quit-application-granted")) {
     if (jni::IsAvailable()) {
       // We are told explicitly to quit, perhaps due to
       // nsIAppStartup::Quit being called. We should release our hold on
       // nsIAppStartup and let it continue to quit.
-      nsCOMPtr<nsIAppStartup> appStartup =
-          do_GetService(NS_APPSTARTUP_CONTRACTID);
+      nsCOMPtr<nsIAppStartup> appStartup = components::AppStartup::Service();
       if (appStartup) {
         appStartup->ExitLastWindowClosingSurvivalArea();
       }
     }
     removeObserver = true;
 
   } else if (!strcmp(aTopic, "nsPref:changed")) {
     if (jni::IsAvailable()) {
--- a/widget/cocoa/nsMenuBarX.mm
+++ b/widget/cocoa/nsMenuBarX.mm
@@ -21,16 +21,17 @@
 
 #include "nsIContent.h"
 #include "nsIWidget.h"
 #include "mozilla/dom/Document.h"
 #include "nsIAppStartup.h"
 #include "nsIStringBundle.h"
 #include "nsToolkitCompsCID.h"
 
+#include "mozilla/Components.h"
 #include "mozilla/dom/Element.h"
 
 NativeMenuItemTarget* nsMenuBarX::sNativeEventTarget = nil;
 nsMenuBarX* nsMenuBarX::sLastGeckoMenuBarPainted = nullptr;
 NSMenu* sApplicationMenu = nil;
 BOOL sApplicationMenuIsFallback = NO;
 BOOL gSomeMenuBarPainted = NO;
 
@@ -878,17 +879,17 @@ static BOOL gMenuItemsExecuteCommands = 
     nsIContent* mostSpecificContent = sQuitItemContent;
     if (menuBar && menuBar->mQuitItemContent) mostSpecificContent = menuBar->mQuitItemContent;
     // If we have some content for quit we execute it. Otherwise we send a native app terminate
     // message. If you want to stop a quit from happening, provide quit content and return
     // the event as unhandled.
     if (mostSpecificContent) {
       nsMenuUtilsX::DispatchCommandTo(mostSpecificContent);
     } else {
-      nsCOMPtr<nsIAppStartup> appStartup = do_GetService(NS_APPSTARTUP_CONTRACTID);
+      nsCOMPtr<nsIAppStartup> appStartup = mozilla::components::AppStartup::Service();
       if (appStartup) {
         appStartup->Quit(nsIAppStartup::eAttemptQuit);
       }
     }
     return;
   }
 
   // given the commandID, look it up in our hashtable and dispatch to
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -127,17 +127,16 @@
 #include "nsISound.h"
 #include "SystemTimeConverter.h"
 #include "WinTaskbar.h"
 #include "WidgetUtils.h"
 #include "nsIWidgetListener.h"
 #include "mozilla/dom/MouseEventBinding.h"
 #include "mozilla/dom/Touch.h"
 #include "mozilla/gfx/2D.h"
-#include "nsToolkitCompsCID.h"
 #include "nsIAppStartup.h"
 #include "mozilla/WindowsVersion.h"
 #include "mozilla/TextEvents.h"  // For WidgetKeyboardEvent
 #include "mozilla/TextEventDispatcherListener.h"
 #include "mozilla/widget/nsAutoRollup.h"
 #include "mozilla/widget/WinNativeEventData.h"
 #include "mozilla/widget/PlatformWidgetTypes.h"
 #include "nsStyleConsts.h"