Bug 1359837 - Block mozAddonsManager if xpinstall.enabled is false/locked. r=mossop
authorMichael Kaply <mozilla@kaply.com>
Fri, 28 Apr 2017 10:42:05 -0500
changeset 360724 4639f041d809fa12ac774c68f4a3e08be74268af
parent 360723 5bb9806150d8b45b8e0ad0ab9e4f478b8808924c
child 360725 9b65b087ee20e21993889a9c3329a1cf6a7e6f40
push id90721
push userryanvm@gmail.com
push dateFri, 26 May 2017 01:33:12 +0000
treeherdermozilla-inbound@862e534ade6d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs1359837
milestone55.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 1359837 - Block mozAddonsManager if xpinstall.enabled is false/locked. r=mossop 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)) {