Merge mozilla-central to inbound. a=merge CLOSED TREE
authorGurzau Raul <rgurzau@mozilla.com>
Sat, 03 Mar 2018 23:50:10 +0200
changeset 461508 f2968c766ed43deb324d3ee3f5bc09d14fed655b
parent 461507 b0eb708c533b05df8c2cfc1b97fc0199e3e84394 (current diff)
parent 461495 8cced2a46f73238da13e41bcae8f6f801419bb7a (diff)
child 461509 0df0223d1c9f81b07d4c7ac7744cb333281e0a80
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmerge
milestone60.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
Merge mozilla-central to inbound. a=merge CLOSED TREE
--- a/devtools/shim/DevToolsShim.jsm
+++ b/devtools/shim/DevToolsShim.jsm
@@ -9,16 +9,17 @@ const { Services } = ChromeUtils.import(
 const { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm", {});
 XPCOMUtils.defineLazyGetter(this, "DevtoolsStartup", () => {
   return Cc["@mozilla.org/devtools/startup-clh;1"]
             .getService(Ci.nsICommandLineHandler)
             .wrappedJSObject;
 });
 
 const DEVTOOLS_ENABLED_PREF = "devtools.enabled";
+const DEVTOOLS_POLICY_DISABLED_PREF = "devtools.policy.disabled";
 
 this.EXPORTED_SYMBOLS = [
   "DevToolsShim",
 ];
 
 function removeItem(array, callback) {
   let index = array.findIndex(callback);
   if (index >= 0) {
@@ -56,17 +57,26 @@ this.DevToolsShim = {
   },
 
   /**
    * Returns true if DevTools are enabled for the current profile. If devtools are not
    * enabled, initializing DevTools will open the onboarding page. Some entry points
    * should no-op in this case.
    */
   isEnabled: function () {
-    return Services.prefs.getBoolPref(DEVTOOLS_ENABLED_PREF);
+    let enabled = Services.prefs.getBoolPref(DEVTOOLS_ENABLED_PREF);
+    return enabled && !this.isDisabledByPolicy();
+  },
+
+  /**
+   * Returns true if the devtools are completely disabled and can not be enabled. All
+   * entry points should return without throwing, initDevTools should never be called.
+   */
+  isDisabledByPolicy: function () {
+    return Services.prefs.getBoolPref(DEVTOOLS_POLICY_DISABLED_PREF, false);
   },
 
   /**
    * Check if DevTools have already been initialized.
    *
    * @return {Boolean} true if DevTools are initialized.
    */
   isInitialized: function () {
@@ -174,17 +184,19 @@ this.DevToolsShim = {
    *        An array of CSS selectors to find the target node. Several selectors can be
    *        needed if the element is nested in frames and not directly in the root
    *        document.
    * @return {Promise} a promise that resolves when the node is selected in the inspector
    *         markup view or that resolves immediately if DevTools are not installed.
    */
   inspectNode: function (tab, selectors) {
     if (!this.isEnabled()) {
-      DevtoolsStartup.openInstallPage("ContextMenu");
+      if (!this.isDisabledByPolicy()) {
+        DevtoolsStartup.openInstallPage("ContextMenu");
+      }
       return Promise.resolve();
     }
 
     // Record the timing at which this event started in order to compute later in
     // gDevTools.showToolbox, the complete time it takes to open the toolbox.
     // i.e. especially take `DevtoolsStartup.initDevTools` into account.
     let { performance } = Services.appShell.hiddenDOMWindow;
     let startTime = performance.now();
--- a/devtools/shim/tests/unit/test_devtools_shim.js
+++ b/devtools/shim/tests/unit/test_devtools_shim.js
@@ -136,25 +136,38 @@ function test_restore_session_apis() {
 
   // Create fake session objects to restore.
   let sessionWithoutDevTools = {};
   let sessionWithDevTools = {
     scratchpads: [{}],
     browserConsole: true,
   };
 
-  Services.prefs.setBoolPref("devtools.enabled", false);
-  ok(!DevToolsShim.isInitialized(), "DevTools are not initialized");
-  ok(!DevToolsShim.isEnabled(), "DevTools are not enabled");
+  function checkRestoreSessionNotApplied(policyDisabled, enabled) {
+    Services.prefs.setBoolPref("devtools.enabled", enabled);
+    Services.prefs.setBoolPref("devtools.policy.disabled", policyDisabled);
+    ok(!DevToolsShim.isInitialized(), "DevTools are not initialized");
+    ok(!DevToolsShim.isEnabled(), "DevTools are not enabled");
 
-  // Check that save & restore DevToolsSession don't initialize the tools and don't crash.
-  DevToolsShim.saveDevToolsSession({});
-  DevToolsShim.restoreDevToolsSession(sessionWithDevTools);
+    // Check that save & restore DevToolsSession don't initialize the tools and don't
+    // crash.
+    DevToolsShim.saveDevToolsSession({});
+    DevToolsShim.restoreDevToolsSession(sessionWithDevTools);
+    ok(!DevToolsShim.isInitialized(), "DevTools are still not initialized");
+  }
+
+  // Tools are disabled by policy and not enabled
+  checkRestoreSessionNotApplied(true, false);
+  // Tools are not disabled by policy, but not enabled
+  checkRestoreSessionNotApplied(false, false);
+  // Tools are disabled by policy and "considered" as enabled (see Bug 1440675)
+  checkRestoreSessionNotApplied(true, true);
 
   Services.prefs.setBoolPref("devtools.enabled", true);
+  Services.prefs.setBoolPref("devtools.policy.disabled", false);
   ok(DevToolsShim.isEnabled(), "DevTools are enabled");
   ok(!DevToolsShim.isInitialized(), "DevTools are not initialized");
 
   // Check that DevTools are not initialized when calling restoreDevToolsSession without
   // DevTools related data.
   DevToolsShim.restoreDevToolsSession(sessionWithoutDevTools);
   ok(!DevToolsShim.isInitialized(), "DevTools are still not initialized");