Bug 1429185 - Implement policy for disabling devtools draft
authorMichael Kaply <mozilla@kaply.com>
Thu, 08 Feb 2018 12:16:29 -0600
changeset 752638 bff5cd63705a0bdc6290ea2df20d3dadecf992eb
parent 750719 2638ae89f86fbb5f224ef0511b3f77aec5503a51
push id98330
push usermozilla@kaply.com
push dateThu, 08 Feb 2018 18:17:03 +0000
bugs1429185
milestone60.0a1
Bug 1429185 - Implement policy for disabling devtools MozReview-Commit-ID: GyqqnaJPbWM
browser/base/content/nsContextMenu.js
browser/components/enterprisepolicies/Policies.jsm
browser/components/enterprisepolicies/schemas/policies-schema.json
devtools/shim/devtools-startup.js
--- a/browser/base/content/nsContextMenu.js
+++ b/browser/base/content/nsContextMenu.js
@@ -437,18 +437,20 @@ nsContextMenu.prototype = {
     var showInspect = this.inTabBrowser &&
                       Services.prefs.getBoolPref("devtools.inspector.enabled", true);
 
     this.showItem("context-viewsource", shouldShow);
     this.showItem("context-viewinfo", shouldShow);
     // The page info is broken for WebExtension popups, as the browser is
     // destroyed when the popup is closed.
     this.setItemAttr("context-viewinfo", "disabled", this.webExtBrowserType === "popup");
-    this.showItem("inspect-separator", showInspect);
-    this.showItem("context-inspect", showInspect);
+    if (Services.policies.isAllowed("devtools")) {
+      this.showItem("inspect-separator", showInspect);
+      this.showItem("context-inspect", showInspect);
+    }
 
     this.showItem("context-sep-viewsource", shouldShow);
 
     // Set as Desktop background depends on whether an image was clicked on,
     // and only works if we have a shell service.
     var haveSetDesktopBackground = false;
 
     if (AppConstants.HAVE_SHELL_SERVICE &&
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -87,16 +87,26 @@ this.Policies = {
   "DisableFirefoxScreenshots": {
     onBeforeAddons(manager, param) {
       if (param == true) {
         setAndLockPref("extensions.screenshots.disabled", true);
       }
     }
   },
 
+  "DisableDeveloperTools": {
+    onBeforeAddons(manager, param) {
+      if (param == true) {
+        setAndLockPref("devtools.enabled", false);
+        manager.disallowFeature("devtools", true);
+        manager.disallowFeature("about:devtools", true);
+      }
+    }
+  },
+
   "dont_check_default_browser": {
     onBeforeUIStartup(manager, param) {
       setAndLockPref("browser.shell.checkDefaultBrowser", false);
     }
   },
 
   "flash_plugin": {
     onBeforeUIStartup(manager, param) {
--- a/browser/components/enterprisepolicies/schemas/policies-schema.json
+++ b/browser/components/enterprisepolicies/schemas/policies-schema.json
@@ -1,8 +1,9 @@
+
 {
   "$schema": "http://json-schema.org/draft-04/schema#",
   "type": "object",
   "properties": {
     "block_about_config": {
       "description": "Blocks access to the about:config page.",
       "first_available": "60.0",
 
@@ -37,16 +38,23 @@
     "DisableFirefoxScreenshots": {
       "description": "Prevents usage of the Firefox Screenshots feature.",
       "first_available": "60.0",
 
       "type": "boolean",
       "enum": [true]
     },
 
+    "DisableDeveloperTools": {
+      "description": "Prevents access to developer tools.",
+      "first_available": "60.0",
+
+      "type": "boolean"
+    },
+
     "dont_check_default_browser": {
       "description": "Don't check for the default browser on startup.",
       "first_available": "60.0",
 
       "type": "boolean",
       "enum": [true]
     },
 
--- a/devtools/shim/devtools-startup.js
+++ b/devtools/shim/devtools-startup.js
@@ -241,16 +241,21 @@ DevToolsStartup.prototype = {
     }
   },
 
   /**
    * Called when receiving the "browser-delayed-startup-finished" event for a new
    * top-level window.
    */
   onWindowReady(window) {
+    if (!Services.policies.isAllowed("devtools")) {
+      window.document.getElementById("webDeveloperMenu").setAttribute("hidden", "true");
+      window.document.getElementById("appMenu-developer-button").setAttribute("hidden", "true");
+      return;
+    }
     this.hookWindow(window);
 
     if (Services.prefs.getBoolPref(TOOLBAR_VISIBLE_PREF, false)) {
       // Loading devtools-browser will open the developer toolbar by also checking this
       // pref.
       this.initDevTools();
     }