Bug 1359837 - Block mozAddonsManager if xpinstall.enabled is false/locked. r=mossop, a=jcristau
authorMichael Kaply <mozilla@kaply.com>
Fri, 28 Apr 2017 10:42:05 -0500
changeset 394125 d5e1be51863d66c5fa4c860883ece938972c4f39
parent 394124 63e5df87225066221139c162917afcc5758d88d5
child 394126 b6b58f56432af99bc6b8356da3ea96170a04190e
push id7370
push userryanvm@gmail.com
push dateTue, 30 May 2017 18:45:25 +0000
treeherdermozilla-beta@b6b58f56432a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop, jcristau
bugs1359837
milestone54.0
Bug 1359837 - Block mozAddonsManager if xpinstall.enabled is false/locked. r=mossop, a=jcristau MozReview-Commit-ID: 3BUxRLMjYkF
toolkit/mozapps/extensions/AddonManagerWebAPI.cpp
--- a/toolkit/mozapps/extensions/AddonManagerWebAPI.cpp
+++ b/toolkit/mozapps/extensions/AddonManagerWebAPI.cpp
@@ -15,16 +15,32 @@
 #include "nsIDocShell.h"
 #include "nsIScriptObjectPrincipal.h"
 
 namespace mozilla {
 using namespace mozilla::dom;
 
 static bool
 IsValidHost(const nsACString& host) {
+  // This is ugly, but Preferences.h doesn't have support
+  // for default prefs or locked prefs
+  nsCOMPtr<nsIPrefService> prefService (do_GetService(NS_PREFSERVICE_CONTRACTID));
+  nsCOMPtr<nsIPrefBranch> prefs;
+  if (prefService) {
+    prefService->GetDefaultBranch(nullptr, getter_AddRefs(prefs));
+    bool isEnabled;
+    if (NS_SUCCEEDED(prefs->GetBoolPref("xpinstall.enabled", &isEnabled)) && !isEnabled) {
+      bool isLocked;
+      prefs->PrefIsLocked("xpinstall.enabled", &isLocked);
+      if (isLocked) {
+        return false;
+      }
+    }
+  }
+
   if (host.Equals("addons.mozilla.org") ||
       host.Equals("discovery.addons.mozilla.org") ||
       host.Equals("testpilot.firefox.com")) {
     return true;
   }
 
   // When testing allow access to the developer sites.
   if (Preferences::GetBool("extensions.webapi.testing", false)) {