Bug 1003306 - part 2 - use services::GetPermissionManager everywhere that's appropriate; r=ehsan
authorNathan Froyd <froydnj@mozilla.com>
Tue, 29 Apr 2014 13:27:26 -0400
changeset 200330 f5f4469ec95e7bfdb511924603b7ec3333a511aa
parent 200329 a1546ce38ecd0883a13f8cfd4e837253acbbd10b
child 200331 2c7328c542f5afacdd3f39163634c47bc91d53d0
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1003306
milestone32.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 1003306 - part 2 - use services::GetPermissionManager everywhere that's appropriate; r=ehsan
content/base/src/nsContentUtils.cpp
content/base/src/nsFrameLoader.cpp
content/base/src/nsObjectLoadingContent.cpp
content/base/src/nsXMLHttpRequest.cpp
content/html/content/src/HTMLMediaElement.cpp
content/html/content/src/nsGenericHTMLFrameElement.cpp
content/media/webaudio/AudioDestinationNode.cpp
dom/asmjscache/AsmJSCache.cpp
dom/base/Navigator.cpp
dom/base/nsGlobalWindow.cpp
dom/bluetooth/BluetoothManager.cpp
dom/camera/DOMCameraManager.cpp
dom/devicestorage/nsDeviceStorage.cpp
dom/indexedDB/CheckPermissionsHelper.cpp
dom/ipc/AppProcessChecker.cpp
dom/ipc/ContentChild.cpp
dom/ipc/ContentParent.cpp
dom/mobileconnection/src/MobileConnection.cpp
dom/power/PowerManager.cpp
dom/quota/CheckQuotaHelper.cpp
dom/speakermanager/SpeakerManager.cpp
dom/src/notification/Notification.cpp
dom/src/storage/DOMStorage.cpp
dom/system/gonk/AudioChannelManager.cpp
dom/system/nsDeviceSensors.cpp
extensions/cookie/nsPopupWindowManager.cpp
layout/generic/nsSubDocumentFrame.cpp
netwerk/protocol/http/nsHttpChannel.cpp
toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
uriloader/prefetch/nsOfflineCacheUpdateService.cpp
--- a/content/base/src/nsContentUtils.cpp
+++ b/content/base/src/nsContentUtils.cpp
@@ -2869,18 +2869,17 @@ static bool
 TestSitePerm(nsIPrincipal* aPrincipal, const char* aType, uint32_t aPerm, bool aExactHostMatch)
 {
   if (!aPrincipal) {
     // We always deny (i.e. don't allow) the permission if we don't have a
     // principal.
     return aPerm != nsIPermissionManager::ALLOW_ACTION;
   }
 
-  nsCOMPtr<nsIPermissionManager> permMgr =
-    do_GetService("@mozilla.org/permissionmanager;1");
+  nsCOMPtr<nsIPermissionManager> permMgr = services::GetPermissionManager();
   NS_ENSURE_TRUE(permMgr, false);
 
   uint32_t perm;
   nsresult rv;
   if (aExactHostMatch) {
     rv = permMgr->TestExactPermissionFromPrincipal(aPrincipal, aType, &perm);
   } else {
     rv = permMgr->TestPermissionFromPrincipal(aPrincipal, aType, &perm);
--- a/content/base/src/nsFrameLoader.cpp
+++ b/content/base/src/nsFrameLoader.cpp
@@ -2611,17 +2611,17 @@ nsFrameLoader::ResetPermissionManagerSta
     }
   }
 
   // Nothing changed.
   if (appId == mAppIdSentToPermissionManager) {
     return;
   }
 
-  nsCOMPtr<nsIPermissionManager> permMgr = do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+  nsCOMPtr<nsIPermissionManager> permMgr = services::GetPermissionManager();
   if (!permMgr) {
     NS_ERROR("No PermissionManager available!");
     return;
   }
 
   // If previously we registered an appId, we have to unregister it.
   if (mAppIdSentToPermissionManager != nsIScriptSecurityManager::NO_APP_ID) {
     permMgr->ReleaseAppId(mAppIdSentToPermissionManager);
--- a/content/base/src/nsObjectLoadingContent.cpp
+++ b/content/base/src/nsObjectLoadingContent.cpp
@@ -3116,18 +3116,18 @@ nsObjectLoadingContent::ShouldPlay(Fallb
   nsCOMPtr<nsIDOMWindow> topWindow;
   rv = window->GetTop(getter_AddRefs(topWindow));
   NS_ENSURE_SUCCESS(rv, false);
   nsCOMPtr<nsIDOMDocument> topDocument;
   rv = topWindow->GetDocument(getter_AddRefs(topDocument));
   NS_ENSURE_SUCCESS(rv, false);
   nsCOMPtr<nsIDocument> topDoc = do_QueryInterface(topDocument);
 
-  nsCOMPtr<nsIPermissionManager> permissionManager = do_GetService(NS_PERMISSIONMANAGER_CONTRACTID, &rv);
-  NS_ENSURE_SUCCESS(rv, false);
+  nsCOMPtr<nsIPermissionManager> permissionManager = services::GetPermissionManager();
+  NS_ENSURE_TRUE(permissionManager, false);
 
   // For now we always say that the system principal uses click-to-play since
   // that maintains current behavior and we have tests that expect this.
   // What we really should do is disable plugins entirely in pages that use
   // the system principal, i.e. in chrome pages. That way the click-to-play
   // code here wouldn't matter at all. Bug 775301 is tracking this.
   if (!nsContentUtils::IsSystemPrincipal(topDoc->NodePrincipal())) {
     nsAutoCString permissionString;
--- a/content/base/src/nsXMLHttpRequest.cpp
+++ b/content/base/src/nsXMLHttpRequest.cpp
@@ -391,17 +391,17 @@ nsXMLHttpRequest::InitParameters(bool aA
   if (!IsSystemXHR() && aSystem) {
     nsCOMPtr<nsIDocument> doc = window->GetExtantDoc();
     if (!doc) {
       return;
     }
 
     nsCOMPtr<nsIPrincipal> principal = doc->NodePrincipal();
     nsCOMPtr<nsIPermissionManager> permMgr =
-      do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+      services::GetPermissionManager();
     if (!permMgr)
       return;
 
     uint32_t permission;
     nsresult rv =
       permMgr->TestPermissionFromPrincipal(principal, "systemXHR", &permission);
     if (NS_FAILED(rv) || permission != nsIPermissionManager::ALLOW_ACTION) {
       return;
--- a/content/html/content/src/HTMLMediaElement.cpp
+++ b/content/html/content/src/HTMLMediaElement.cpp
@@ -2333,17 +2333,17 @@ bool HTMLMediaElement::CheckAudioChannel
   // Maybe this audio channel is equal to the default value from the pref.
   nsString audioChannel;
   AudioChannelService::GetDefaultAudioChannelString(audioChannel);
   if (audioChannel.Equals(aString)) {
     return true;
   }
 
   nsCOMPtr<nsIPermissionManager> permissionManager =
-    do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+    services::GetPermissionManager();
   if (!permissionManager) {
     return false;
   }
 
   uint32_t perm = nsIPermissionManager::UNKNOWN_ACTION;
   permissionManager->TestExactPermissionFromPrincipal(NodePrincipal(),
     nsCString(NS_LITERAL_CSTRING("audio-channel-") + NS_ConvertUTF16toUTF8(aString)).get(), &perm);
   if (perm != nsIPermissionManager::ALLOW_ACTION) {
--- a/content/html/content/src/nsGenericHTMLFrameElement.cpp
+++ b/content/html/content/src/nsGenericHTMLFrameElement.cpp
@@ -413,17 +413,17 @@ nsGenericHTMLFrameElement::GetReallyIsBr
   GetMozbrowser(&hasMozbrowser);
   if (!hasMozbrowser) {
     return NS_OK;
   }
 
   // Fail if the node principal isn't trusted.
   nsIPrincipal *principal = NodePrincipal();
   nsCOMPtr<nsIPermissionManager> permMgr =
-    do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+    services::GetPermissionManager();
   NS_ENSURE_TRUE(permMgr, NS_OK);
 
   uint32_t permission = nsIPermissionManager::DENY_ACTION;
   nsresult rv = permMgr->TestPermissionFromPrincipal(principal, "browser", &permission);
   NS_ENSURE_SUCCESS(rv, NS_OK);
   *aOut = permission == nsIPermissionManager::ALLOW_ACTION;
   return NS_OK;
 }
@@ -459,17 +459,17 @@ nsGenericHTMLFrameElement::GetAppManifes
   // At the moment, you can't be an app without being a browser.
   if (!nsIMozBrowserFrame::GetReallyIsBrowserOrApp()) {
     return NS_OK;
   }
 
   // Check permission.
   nsIPrincipal *principal = NodePrincipal();
   nsCOMPtr<nsIPermissionManager> permMgr =
-    do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+    services::GetPermissionManager();
   NS_ENSURE_TRUE(permMgr, NS_OK);
 
   uint32_t permission = nsIPermissionManager::DENY_ACTION;
   nsresult rv = permMgr->TestPermissionFromPrincipal(principal,
                                                      "embed-apps",
                                                      &permission);
   NS_ENSURE_SUCCESS(rv, NS_OK);
   if (permission != nsIPermissionManager::ALLOW_ACTION) {
--- a/content/media/webaudio/AudioDestinationNode.cpp
+++ b/content/media/webaudio/AudioDestinationNode.cpp
@@ -2,16 +2,17 @@
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* 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 "AudioDestinationNode.h"
 #include "mozilla/dom/AudioDestinationNodeBinding.h"
 #include "mozilla/Preferences.h"
+#include "mozilla/Services.h"
 #include "AudioChannelAgent.h"
 #include "AudioChannelService.h"
 #include "AudioNodeEngine.h"
 #include "AudioNodeStream.h"
 #include "MediaStreamGraph.h"
 #include "OfflineAudioCompletionEvent.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIDocShell.h"
@@ -477,17 +478,17 @@ AudioDestinationNode::CheckAudioChannelP
   }
 
   // Maybe this audio channel is equal to the default one.
   if (aValue == AudioChannelService::GetDefaultAudioChannel()) {
     return true;
   }
 
   nsCOMPtr<nsIPermissionManager> permissionManager =
-    do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+    services::GetPermissionManager();
   if (!permissionManager) {
     return false;
   }
 
   nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(GetOwner());
   NS_ASSERTION(sop, "Window didn't QI to nsIScriptObjectPrincipal!");
   nsCOMPtr<nsIPrincipal> principal = sop->GetPrincipal();
 
--- a/dom/asmjscache/AsmJSCache.cpp
+++ b/dom/asmjscache/AsmJSCache.cpp
@@ -31,16 +31,17 @@
 #include "nsISimpleEnumerator.h"
 #include "nsIThread.h"
 #include "nsIXULAppInfo.h"
 #include "nsJSPrincipals.h"
 #include "nsThreadUtils.h"
 #include "nsXULAppAPI.h"
 #include "prio.h"
 #include "private/pprio.h"
+#include "mozilla/Services.h"
 
 #define ASMJSCACHE_METADATA_FILE_NAME "metadata"
 #define ASMJSCACHE_ENTRY_FILE_NAME_BASE "module"
 
 using mozilla::dom::quota::AssertIsOnIOThread;
 using mozilla::dom::quota::OriginOrPatternString;
 using mozilla::dom::quota::PersistenceType;
 using mozilla::dom::quota::QuotaManager;
@@ -683,17 +684,17 @@ MainProcessRunnable::InitOnMainThread()
       // the cache entry in persistent storage so the entry is never evicted,
       // but we need to verify that the app has unlimited storage permissions
       // first. Unlimited storage permissions justify us in skipping all quota
       // checks when storing the cache entry and avoids all the issues around
       // the persistent quota prompt.
       MOZ_ASSERT(isApp);
 
       nsCOMPtr<nsIPermissionManager> pm =
-        do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+        services::GetPermissionManager();
       NS_ENSURE_TRUE(pm, NS_ERROR_UNEXPECTED);
 
       uint32_t permission;
       rv = pm->TestPermissionFromPrincipal(mPrincipal,
                                            PERMISSION_STORAGE_UNLIMITED,
                                            &permission);
       NS_ENSURE_SUCCESS(rv, NS_ERROR_UNEXPECTED);
 
--- a/dom/base/Navigator.cpp
+++ b/dom/base/Navigator.cpp
@@ -1788,17 +1788,17 @@ Navigator::CheckPermission(const char* t
 bool
 Navigator::CheckPermission(nsPIDOMWindow* aWindow, const char* aType)
 {
   if (!aWindow) {
     return false;
   }
 
   nsCOMPtr<nsIPermissionManager> permMgr =
-    do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+    services::GetPermissionManager();
   NS_ENSURE_TRUE(permMgr, false);
 
   uint32_t permission = nsIPermissionManager::DENY_ACTION;
   permMgr->TestPermissionFromWindow(aWindow, aType, &permission);
   return permission == nsIPermissionManager::ALLOW_ACTION;
 }
 
 #ifdef MOZ_AUDIO_CHANNEL_MANAGER
@@ -2184,17 +2184,17 @@ Navigator::HasWifiManagerSupport(JSConte
 {
   // On XBL scope, the global object is NOT |window|. So we have
   // to use nsContentUtils::GetObjectPrincipal to get the principal
   // and test directly with permission manager.
 
   nsIPrincipal* principal = nsContentUtils::GetObjectPrincipal(aGlobal);
 
   nsCOMPtr<nsIPermissionManager> permMgr =
-    do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+    services::GetPermissionManager();
   NS_ENSURE_TRUE(permMgr, false);
 
   uint32_t permission = nsIPermissionManager::DENY_ACTION;
   permMgr->TestPermissionFromPrincipal(principal, "wifi-manage", &permission);
   return nsIPermissionManager::ALLOW_ACTION == permission;
 }
 
 #ifdef MOZ_B2G_BT
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -13648,17 +13648,17 @@ nsGlobalWindow::WindowOnWebIDL(JSContext
 
 #ifdef MOZ_B2G
 void
 nsGlobalWindow::EnableNetworkEvent(uint32_t aType)
 {
   MOZ_ASSERT(IsInnerWindow());
 
   nsCOMPtr<nsIPermissionManager> permMgr =
-    do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+    services::GetPermissionManager();
   if (!permMgr) {
     NS_ERROR("No PermissionManager available!");
     return;
   }
 
   uint32_t permission = nsIPermissionManager::DENY_ACTION;
   permMgr->TestExactPermissionFromPrincipal(GetPrincipal(), "network-events",
                                             &permission);
--- a/dom/bluetooth/BluetoothManager.cpp
+++ b/dom/bluetooth/BluetoothManager.cpp
@@ -13,16 +13,17 @@
 
 #include "DOMRequest.h"
 #include "nsContentUtils.h"
 #include "nsDOMClassInfo.h"
 #include "nsIPermissionManager.h"
 #include "nsThreadUtils.h"
 #include "mozilla/dom/bluetooth/BluetoothTypes.h"
 #include "mozilla/dom/BluetoothManagerBinding.h"
+#include "mozilla/Services.h"
 
 using namespace mozilla;
 
 USING_BLUETOOTH_NAMESPACE
 
 // QueryInterface implementation for BluetoothManager
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(BluetoothManager)
 NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
@@ -194,18 +195,17 @@ BluetoothManager::Create(nsPIDOMWindow* 
 }
 
 // static
 bool
 BluetoothManager::CheckPermission(nsPIDOMWindow* aWindow)
 {
   NS_ASSERTION(aWindow, "Null pointer!");
 
-  nsCOMPtr<nsIPermissionManager> permMgr =
-    do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+  nsCOMPtr<nsIPermissionManager> permMgr = services::GetPermissionManager();
   NS_ENSURE_TRUE(permMgr, false);
 
   uint32_t permission;
   nsresult rv =
     permMgr->TestPermissionFromWindow(aWindow, "bluetooth",
                                       &permission);
   NS_ENSURE_SUCCESS(rv, false);
 
--- a/dom/camera/DOMCameraManager.cpp
+++ b/dom/camera/DOMCameraManager.cpp
@@ -85,17 +85,17 @@ nsDOMCameraManager::HasSupport(JSContext
   return Navigator::HasCameraSupport(aCx, aGlobal);
 }
 
 /* static */
 bool
 nsDOMCameraManager::CheckPermission(nsPIDOMWindow* aWindow)
 {
   nsCOMPtr<nsIPermissionManager> permMgr =
-    do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+    services::GetPermissionManager();
   NS_ENSURE_TRUE(permMgr, false);
 
   uint32_t permission = nsIPermissionManager::DENY_ACTION;
   permMgr->TestPermissionFromWindow(aWindow, "camera", &permission);
   if (permission != nsIPermissionManager::ALLOW_ACTION &&
       permission != nsIPermissionManager::PROMPT_ACTION) {
     return false;
   }
--- a/dom/devicestorage/nsDeviceStorage.cpp
+++ b/dom/devicestorage/nsDeviceStorage.cpp
@@ -3135,17 +3135,17 @@ nsDOMDeviceStorage::Init(nsPIDOMWindow* 
     return NS_ERROR_FAILURE;
   }
   mPrincipal = doc->NodePrincipal();
 
   // the 'apps' type is special.  We only want this exposed
   // if the caller has the "webapps-manage" permission.
   if (aType.EqualsLiteral(DEVICESTORAGE_APPS)) {
     nsCOMPtr<nsIPermissionManager> permissionManager
-      = do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+      = services::GetPermissionManager();
     NS_ENSURE_TRUE(permissionManager, NS_ERROR_FAILURE);
 
     uint32_t permission;
     nsresult rv
       = permissionManager->TestPermissionFromPrincipal(mPrincipal,
                                                        "webapps-manage",
                                                        &permission);
 
--- a/dom/indexedDB/CheckPermissionsHelper.cpp
+++ b/dom/indexedDB/CheckPermissionsHelper.cpp
@@ -58,18 +58,17 @@ GetIndexedDBPermissions(nsIDOMWindow* aW
   nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(aWindow);
   nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(webNav);
   if (loadContext && loadContext->UsePrivateBrowsing()) {
     // TODO Support private browsing indexedDB?
     NS_WARNING("IndexedDB may not be used while in private browsing mode!");
     return PERMISSION_DENIED;
   }
 
-  nsCOMPtr<nsIPermissionManager> permissionManager =
-    do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+  nsCOMPtr<nsIPermissionManager> permissionManager = GetPermissionManager();
   NS_ENSURE_TRUE(permissionManager, PERMISSION_DENIED);
 
   uint32_t permission;
   nsresult rv =
     permissionManager->TestPermissionFromPrincipal(sop->GetPrincipal(),
                                                    PERMISSION_INDEXEDDB,
                                                    &permission);
   NS_ENSURE_SUCCESS(rv, PERMISSION_DENIED);
@@ -103,18 +102,17 @@ CheckPermissionsHelper::Run()
       NS_ASSERTION(mWindow, "Null window!");
 
       nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(mWindow);
       NS_ASSERTION(sop, "Window didn't QI to nsIScriptObjectPrincipal!");
 
       nsIPrincipal* windowPrincipal = sop->GetPrincipal();
       NS_ASSERTION(windowPrincipal, "Null principal!");
 
-      nsCOMPtr<nsIPermissionManager> permissionManager =
-        do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+      nsCOMPtr<nsIPermissionManager> permissionManager = GetPermissionManager();
       NS_ENSURE_STATE(permissionManager);
 
       rv = permissionManager->AddFromPrincipal(windowPrincipal,
                                                PERMISSION_INDEXEDDB, permission,
                                                nsIPermissionManager::EXPIRE_NEVER,
                                                0);
       NS_ENSURE_SUCCESS(rv, rv);
     }
--- a/dom/ipc/AppProcessChecker.cpp
+++ b/dom/ipc/AppProcessChecker.cpp
@@ -220,17 +220,17 @@ CheckPermission(PContentParent* aActor,
                 nsIPrincipal* aPrincipal,
                 const char* aPermission)
 {
   if (!AssertAppPrincipal(aActor, aPrincipal)) {
     return nsIPermissionManager::DENY_ACTION;
   }
 
   nsCOMPtr<nsIPermissionManager> pm =
-    do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+    services::GetPermissionManager();
   NS_ENSURE_TRUE(pm, nsIPermissionManager::DENY_ACTION);
 
   // Make sure that `aPermission' is an app permission before checking the origin.
   nsCOMPtr<nsIPrincipal> appPrincipal = GetAppPrincipal(aPrincipal->GetAppId());
   uint32_t appPerm = nsIPermissionManager::UNKNOWN_ACTION;
   nsresult rv = pm->TestExactPermissionFromPrincipal(appPrincipal, aPermission, &appPerm);
   NS_ENSURE_SUCCESS(rv, nsIPermissionManager::UNKNOWN_ACTION);
   // Setting to "deny" in the settings UI should deny everywhere.
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -1401,17 +1401,17 @@ ContentChild::RecvGeolocationUpdate(cons
   return true;
 }
 
 bool
 ContentChild::RecvAddPermission(const IPC::Permission& permission)
 {
 #if MOZ_PERMISSIONS
   nsCOMPtr<nsIPermissionManager> permissionManagerIface =
-      do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+      services::GetPermissionManager();
   nsPermissionManager* permissionManager =
       static_cast<nsPermissionManager*>(permissionManagerIface.get());
   NS_ABORT_IF_FALSE(permissionManager, 
                    "We have no permissionManager in the Content process !");
 
   nsCOMPtr<nsIURI> uri;
   NS_NewURI(getter_AddRefs(uri), NS_LITERAL_CSTRING("http://") + nsCString(permission.host));
   NS_ENSURE_TRUE(uri, true);
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -1700,17 +1700,17 @@ ContentParent::RecvReadFontList(Infallib
     return true;
 }
 
 bool
 ContentParent::RecvReadPermissions(InfallibleTArray<IPC::Permission>* aPermissions)
 {
 #ifdef MOZ_PERMISSIONS
     nsCOMPtr<nsIPermissionManager> permissionManagerIface =
-        do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+        services::GetPermissionManager();
     nsPermissionManager* permissionManager =
         static_cast<nsPermissionManager*>(permissionManagerIface.get());
     NS_ABORT_IF_FALSE(permissionManager,
                  "We have no permissionManager in the Chrome process !");
 
     nsCOMPtr<nsISimpleEnumerator> enumerator;
     DebugOnly<nsresult> rv = permissionManager->GetEnumerator(getter_AddRefs(enumerator));
     NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv), "Could not get enumerator!");
--- a/dom/mobileconnection/src/MobileConnection.cpp
+++ b/dom/mobileconnection/src/MobileConnection.cpp
@@ -152,17 +152,17 @@ MobileConnection::GetLastKnownHomeNetwor
 
 bool
 MobileConnection::CheckPermission(const char* aType)
 {
   nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
   NS_ENSURE_TRUE(window, false);
 
   nsCOMPtr<nsIPermissionManager> permMgr =
-    do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+    mozilla::services::GetPermissionManager();
   NS_ENSURE_TRUE(permMgr, false);
 
   uint32_t permission = nsIPermissionManager::DENY_ACTION;
   permMgr->TestPermissionFromWindow(window, aType, &permission);
   return permission == nsIPermissionManager::ALLOW_ACTION;
 }
 
 NS_IMETHODIMP
--- a/dom/power/PowerManager.cpp
+++ b/dom/power/PowerManager.cpp
@@ -12,16 +12,17 @@
 #include "nsIDocument.h"
 #include "nsIPermissionManager.h"
 #include "nsIPowerManagerService.h"
 #include "nsIPrincipal.h"
 #include "nsPIDOMWindow.h"
 #include "nsServiceManagerUtils.h"
 #include "nsError.h"
 #include "mozilla/dom/MozPowerManagerBinding.h"
+#include "mozilla/Services.h"
 
 namespace mozilla {
 namespace dom {
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PowerManager)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsISupports)
   NS_INTERFACE_MAP_ENTRY(nsIDOMMozWakeLockListener)
@@ -180,17 +181,17 @@ PowerManager::SetCpuSleepAllowed(bool aA
 {
   hal::SetCpuSleepAllowed(aAllowed);
 }
 
 bool
 PowerManager::CheckPermission(nsPIDOMWindow* aWindow)
 {
   nsCOMPtr<nsIPermissionManager> permMgr =
-    do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+    services::GetPermissionManager();
   NS_ENSURE_TRUE(permMgr, false);
 
   uint32_t permission = nsIPermissionManager::DENY_ACTION;
   permMgr->TestPermissionFromWindow(aWindow, "power", &permission);
 
   return permission == nsIPermissionManager::ALLOW_ACTION;
 }
 
--- a/dom/quota/CheckQuotaHelper.cpp
+++ b/dom/quota/CheckQuotaHelper.cpp
@@ -117,17 +117,17 @@ CheckQuotaHelper::GetQuotaPermission(nsI
 {
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
   NS_ASSERTION(aPrincipal, "Null principal!");
 
   NS_ASSERTION(!nsContentUtils::IsSystemPrincipal(aPrincipal),
                "Chrome windows shouldn't track quota!");
 
   nsCOMPtr<nsIPermissionManager> pm =
-    do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+    services::GetPermissionManager();
   NS_ENSURE_TRUE(pm, nsIPermissionManager::DENY_ACTION);
 
   uint32_t permission;
   nsresult rv = pm->TestPermissionFromPrincipal(aPrincipal,
                                                 PERMISSION_STORAGE_UNLIMITED,
                                                 &permission);
   NS_ENSURE_SUCCESS(rv, nsIPermissionManager::DENY_ACTION);
 
@@ -156,17 +156,17 @@ CheckQuotaHelper::Run()
       // set the permission when the prompt was shown in the parent, as
       // we cannot set the permission from the child).
       if (mPromptResult != nsIPermissionManager::UNKNOWN_ACTION &&
           XRE_GetProcessType() == GeckoProcessType_Default) {
         nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(mWindow);
         NS_ENSURE_TRUE(sop, NS_ERROR_FAILURE);
 
         nsCOMPtr<nsIPermissionManager> permissionManager =
-          do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+          services::GetPermissionManager();
         NS_ENSURE_STATE(permissionManager);
 
         rv = permissionManager->AddFromPrincipal(sop->GetPrincipal(),
                                                  PERMISSION_STORAGE_UNLIMITED,
                                                  mPromptResult,
                                                  nsIPermissionManager::EXPIRE_NEVER, 0);
         NS_ENSURE_SUCCESS(rv, rv);
       }
--- a/dom/speakermanager/SpeakerManager.cpp
+++ b/dom/speakermanager/SpeakerManager.cpp
@@ -6,16 +6,17 @@
 #include "nsIDOMClassInfo.h"
 #include "nsIDOMEvent.h"
 #include "nsIDOMEventListener.h"
 #include "SpeakerManagerService.h"
 #include "nsIPermissionManager.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "nsIDocShell.h"
 #include "AudioChannelService.h"
+#include "mozilla/Services.h"
 
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_QUERY_INTERFACE_INHERITED(SpeakerManager, DOMEventTargetHelper,
                                   nsIDOMEventListener)
 NS_IMPL_ADDREF_INHERITED(SpeakerManager, DOMEventTargetHelper)
 NS_IMPL_RELEASE_INHERITED(SpeakerManager, DOMEventTargetHelper)
@@ -142,18 +143,17 @@ SpeakerManager::Constructor(const Global
   }
 
   nsCOMPtr<nsPIDOMWindow> ownerWindow = do_QueryInterface(aGlobal.GetAsSupports());
   if (!ownerWindow) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
   }
 
-  nsCOMPtr<nsIPermissionManager> permMgr =
-    do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+  nsCOMPtr<nsIPermissionManager> permMgr = services::GetPermissionManager();
   NS_ENSURE_TRUE(permMgr, nullptr);
 
   uint32_t permission = nsIPermissionManager::DENY_ACTION;
   nsresult rv =
     permMgr->TestPermissionFromWindow(ownerWindow, "speaker-control",
                                       &permission);
   NS_ENSURE_SUCCESS(rv, nullptr);
 
--- a/dom/src/notification/Notification.cpp
+++ b/dom/src/notification/Notification.cpp
@@ -18,16 +18,17 @@
 #include "nsIPermissionManager.h"
 #include "nsIUUIDGenerator.h"
 #include "nsServiceManagerUtils.h"
 #include "nsToolkitCompsCID.h"
 #include "nsGlobalWindow.h"
 #include "nsDOMJSUtils.h"
 #include "nsIScriptSecurityManager.h"
 #include "mozilla/dom/PermissionMessageUtils.h"
+#include "mozilla/Services.h"
 #include "nsContentPermissionHelper.h"
 #ifdef MOZ_B2G
 #include "nsIDOMDesktopNotification.h"
 #endif
 
 namespace mozilla {
 namespace dom {
 
@@ -669,17 +670,17 @@ Notification::GetPermissionInternal(nsIS
     } else {
       return NotificationPermission::Denied;
     }
   }
 
   uint32_t permission = nsIPermissionManager::UNKNOWN_ACTION;
 
   nsCOMPtr<nsIPermissionManager> permissionManager =
-    do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+    services::GetPermissionManager();
 
   permissionManager->TestPermissionFromPrincipal(principal,
                                                  "desktop-notification",
                                                  &permission);
 
   // Convert the result to one of the enum types.
   switch (permission) {
   case nsIPermissionManager::ALLOW_ACTION:
--- a/dom/src/storage/DOMStorage.cpp
+++ b/dom/src/storage/DOMStorage.cpp
@@ -249,17 +249,17 @@ DOMStorage::CanUseStorage(DOMStorage* aS
   nsresult rv = nsContentUtils::GetSecurityManager()->
                   GetSubjectPrincipal(getter_AddRefs(subjectPrincipal));
   NS_ENSURE_SUCCESS(rv, false);
 
   // if subjectPrincipal were null we'd have returned after
   // IsCallerChrome().
 
   nsCOMPtr<nsIPermissionManager> permissionManager =
-    do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+    services::GetPermissionManager();
   if (!permissionManager) {
     return false;
   }
 
   uint32_t perm;
   permissionManager->TestPermissionFromPrincipal(subjectPrincipal,
                                                  kPermissionType, &perm);
 
--- a/dom/system/gonk/AudioChannelManager.cpp
+++ b/dom/system/gonk/AudioChannelManager.cpp
@@ -6,16 +6,17 @@
 #include "nsIDOMEvent.h"
 #include "nsIDOMEventListener.h"
 #include "nsPIDOMWindow.h"
 #include "nsIDocShell.h"
 #include "nsIPermissionManager.h"
 #include "nsIInterfaceRequestorUtils.h"
 #include "AudioChannelManager.h"
 #include "mozilla/dom/AudioChannelManagerBinding.h"
+#include "mozilla/Services.h"
 
 using namespace mozilla::hal;
 
 namespace mozilla {
 namespace dom {
 namespace system {
 
 NS_IMPL_QUERY_INTERFACE_INHERITED(AudioChannelManager, DOMEventTargetHelper,
@@ -80,17 +81,17 @@ AudioChannelManager::SetVolumeControlCha
     return false;
   }
 
   AudioChannel newChannel = AudioChannelService::GetAudioChannel(aChannel);
 
   // Only normal channel doesn't need permission.
   if (newChannel != AudioChannel::Normal) {
     nsCOMPtr<nsIPermissionManager> permissionManager =
-      do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+      services::GetPermissionManager();
     if (!permissionManager) {
       return false;
     }
     uint32_t perm = nsIPermissionManager::UNKNOWN_ACTION;
     permissionManager->TestPermissionFromWindow(GetOwner(),
       nsCString(NS_LITERAL_CSTRING("audio-channel-") +
       NS_ConvertUTF16toUTF8(aChannel)).get(), &perm);
     if (perm != nsIPermissionManager::ALLOW_ACTION) {
--- a/dom/system/nsDeviceSensors.cpp
+++ b/dom/system/nsDeviceSensors.cpp
@@ -12,16 +12,17 @@
 #include "nsIDOMWindow.h"
 #include "nsPIDOMWindow.h"
 #include "nsIDOMDocument.h"
 #include "nsIServiceManager.h"
 #include "nsIServiceManager.h"
 #include "GeneratedEvents.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Attributes.h"
+#include "mozilla/Services.h"
 #include "nsIPermissionManager.h"
 #include "mozilla/dom/DeviceLightEvent.h"
 #include "mozilla/dom/DeviceProximityEvent.h"
 #include "mozilla/dom/UserProximityEvent.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace hal;
@@ -176,17 +177,17 @@ WindowCannotReceiveSensorEvent (nsPIDOMW
   // it is and it does not have the "background-sensors" permission,
   // don't send any device motion events to it.
   if (!aWindow || !aWindow->IsCurrentInnerWindow()) {
     return true;
   }
 
   if (aWindow->GetOuterWindow()->IsBackground()) {
     nsCOMPtr<nsIPermissionManager> permMgr =
-      do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+      services::GetPermissionManager();
     NS_ENSURE_TRUE(permMgr, false);
     uint32_t permission = nsIPermissionManager::DENY_ACTION;
     permMgr->TestPermissionFromWindow(aWindow, "background-sensors", &permission);
     return permission != nsIPermissionManager::ALLOW_ACTION;
   }
 
   return false;
 }
--- a/extensions/cookie/nsPopupWindowManager.cpp
+++ b/extensions/cookie/nsPopupWindowManager.cpp
@@ -6,16 +6,17 @@
 #include "nsPopupWindowManager.h"
 
 #include "nsCRT.h"
 #include "nsIServiceManager.h"
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
 #include "nsIPrincipal.h"
 #include "nsIURI.h"
+#include "mozilla/Services.h"
 
 /**
  * The Popup Window Manager maintains popup window permissions by website.
  */
 
 static const char kPopupDisablePref[] = "dom.disable_open_during_load";
 
 //*****************************************************************************
@@ -35,17 +36,17 @@ NS_IMPL_ISUPPORTS(nsPopupWindowManager,
                   nsIPopupWindowManager,
                   nsIObserver,
                   nsISupportsWeakReference)
 
 nsresult
 nsPopupWindowManager::Init()
 {
   nsresult rv;
-  mPermissionManager = do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+  mPermissionManager = mozilla::services::GetPermissionManager();
 
   nsCOMPtr<nsIPrefBranch> prefBranch =
     do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
   if (NS_SUCCEEDED(rv)) {
     bool permission;
     rv = prefBranch->GetBoolPref(kPopupDisablePref, &permission);
     if (NS_FAILED(rv)) {
       permission = true;
--- a/layout/generic/nsSubDocumentFrame.cpp
+++ b/layout/generic/nsSubDocumentFrame.cpp
@@ -234,17 +234,17 @@ nsSubDocumentFrame::PassPointerEventsToC
   // uses pointer-events:none on its root element, which is admittedly
   // unlikely)
   if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::mozpasspointerevents)) {
       if (PresContext()->IsChrome()) {
         return true;
       }
 
       nsCOMPtr<nsIPermissionManager> permMgr =
-        do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+        services::GetPermissionManager();
       if (permMgr) {
         uint32_t permission = nsIPermissionManager::DENY_ACTION;
         permMgr->TestPermissionFromPrincipal(GetContent()->NodePrincipal(),
                                              "embed-apps", &permission);
 
         return permission == nsIPermissionManager::ALLOW_ACTION;
       }
   }
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -613,17 +613,17 @@ nsHttpChannel::RetrieveSSLOptions()
     if (!IsHTTPS() || mPrivateBrowsing)
         return;
 
     nsIPrincipal *principal = GetPrincipal();
     if (!principal)
         return;
 
     nsCOMPtr<nsIPermissionManager> permMgr =
-        do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+        services::GetPermissionManager();
     if (!permMgr)
         return;
 
     uint32_t perm;
     nsresult rv = permMgr->TestPermissionFromPrincipal(principal,
                                                        "falsestart-rsa", &perm);
     if (NS_SUCCEEDED(rv) && perm == nsIPermissionManager::ALLOW_ACTION) {
         LOG(("nsHttpChannel::RetrieveSSLOptions [this=%p] "
@@ -1175,17 +1175,17 @@ nsHttpChannel::ProcessSSLInformation()
     nsIPrincipal *principal = GetPrincipal();
     if (!principal)
         return;
 
     // set a permission manager flag that future transactions can
     // use via RetrieveSSLOptions(()
 
     nsCOMPtr<nsIPermissionManager> permMgr =
-        do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+        services::GetPermissionManager();
     if (!permMgr)
         return;
 
     // Allow this to stand for a week
     int64_t expireTime = (PR_Now() / PR_USEC_PER_MSEC) +
         (86400 * 7 * PR_MSEC_PER_SEC);
 
     if (kea == ssl_kea_rsa) {
--- a/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierDBService.cpp
@@ -1265,17 +1265,17 @@ nsUrlClassifierDBService::LookupURI(nsIP
 
   if (forceLookup) {
     *didLookup = true;
   } else {
     bool clean = false;
 
     if (!clean) {
       nsCOMPtr<nsIPermissionManager> permissionManager =
-        do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+        services::GetPermissionManager();
 
       if (permissionManager) {
         uint32_t perm;
         rv = permissionManager->TestPermissionFromPrincipal(aPrincipal,
                                                            "safe-browsing", &perm);
         NS_ENSURE_SUCCESS(rv, rv);
 
         clean |= (perm == nsIPermissionManager::ALLOW_ACTION);
--- a/uriloader/prefetch/nsOfflineCacheUpdateService.cpp
+++ b/uriloader/prefetch/nsOfflineCacheUpdateService.cpp
@@ -690,17 +690,17 @@ OfflineAppPermForPrincipal(nsIPrincipal 
     NS_ENSURE_SUCCESS(rv, rv);
 
     if (nsOfflineCacheUpdateService::AllowedDomains()->Contains(domain)) {
         *aAllowed = true;
         return NS_OK;
     }
 
     nsCOMPtr<nsIPermissionManager> permissionManager =
-        do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+        services::GetPermissionManager();
     if (!permissionManager) {
         return NS_OK;
     }
 
     uint32_t perm;
     const char *permName = pinned ? "pin-app" : "offline-app";
     permissionManager->TestExactPermissionFromPrincipal(aPrincipal, permName, &perm);
 
@@ -762,17 +762,17 @@ nsOfflineCacheUpdateService::AllowOfflin
         nsAutoCString domain;
         rv = aPrincipal->GetBaseDomain(domain);
         NS_ENSURE_SUCCESS(rv, rv);
 
         nsOfflineCacheUpdateService::AllowedDomains()->PutEntry(domain);
     }
     else {
         nsCOMPtr<nsIPermissionManager> permissionManager =
-            do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
+            services::GetPermissionManager();
         if (!permissionManager)
             return NS_ERROR_NOT_AVAILABLE;
 
         rv = permissionManager->AddFromPrincipal(
             aPrincipal, "offline-app", nsIPermissionManager::ALLOW_ACTION,
             nsIPermissionManager::EXPIRE_NEVER, 0);
         NS_ENSURE_SUCCESS(rv, rv);
     }