Bug 1442451 - do not restore DevTools session when disabled by policy;r=jryans

MozReview-Commit-ID: oORq9CltE3

--HG--
extra : rebase_source : f4344a5ec10ef1ea68494fcdb6b1f9400b4f82be
This commit is contained in:
Julian Descottes 2018-03-02 08:55:24 +01:00
parent 6cf5ac594a
commit 470ac856ce
2 changed files with 33 additions and 8 deletions

View File

@ -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();
}

View File

@ -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");