diff --git a/devtools/shim/DevToolsShim.jsm b/devtools/shim/DevToolsShim.jsm index cefaa837c28a..df77e7a3de48 100644 --- a/devtools/shim/DevToolsShim.jsm +++ b/devtools/shim/DevToolsShim.jsm @@ -14,6 +14,7 @@ XPCOMUtils.defineLazyGetter(this, "DevtoolsStartup", () => { }); const DEVTOOLS_ENABLED_PREF = "devtools.enabled"; +const DEVTOOLS_POLICY_DISABLED_PREF = "devtools.policy.disabled"; this.EXPORTED_SYMBOLS = [ "DevToolsShim", @@ -61,7 +62,16 @@ this.DevToolsShim = { * 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); }, /** @@ -179,7 +189,9 @@ this.DevToolsShim = { */ inspectNode: function (tab, selectors) { if (!this.isEnabled()) { - DevtoolsStartup.openInstallPage("ContextMenu"); + if (!this.isDisabledByPolicy()) { + DevtoolsStartup.openInstallPage("ContextMenu"); + } return Promise.resolve(); } diff --git a/devtools/shim/tests/unit/test_devtools_shim.js b/devtools/shim/tests/unit/test_devtools_shim.js index df1e49e02478..263c12e76642 100644 --- a/devtools/shim/tests/unit/test_devtools_shim.js +++ b/devtools/shim/tests/unit/test_devtools_shim.js @@ -141,15 +141,28 @@ function test_restore_session_apis() { 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");