Bug 1630228 - Basic implementation to disable F12 until toolbox opens r=nchevobbe

In this changeset, we add a preference that will simply disable F12 when it is set.
UI and tests are in followup patches

Differential Revision: https://phabricator.services.mozilla.com/D71035
This commit is contained in:
Julian Descottes 2020-04-28 20:09:15 +00:00
Родитель 9bc5c5b884
Коммит 7642daff2c
3 изменённых файлов: 31 добавлений и 1 удалений

Просмотреть файл

@ -70,6 +70,10 @@ const L10N = new LocalizationHelper(
const BROWSER_STYLESHEET_URL = "chrome://devtools/skin/devtools-browser.css";
// XXX: This could also be moved to DevToolsStartup, which is the first
// "entry point" for DevTools shortcuts and forwards the events
// devtools-browser.
const DEVTOOLS_F12_DISABLED_PREF = "devtools.experiment.f12.shortcut_disabled";
/**
* gDevToolsBrowser exposes functions to connect the gDevTools instance with a
* Firefox instance.
@ -299,9 +303,24 @@ var gDevToolsBrowser = (exports.gDevToolsBrowser = {
// Otherwise implement all other key shortcuts individually here
switch (key.id) {
case "toggleToolbox":
case "toggleToolboxF12":
await gDevToolsBrowser.toggleToolboxCommand(window.gBrowser, startTime);
break;
case "toggleToolboxF12":
// See Bug 1630228. F12 is responsible for most of the accidental usage
// of DevTools. The preference here is used as part of an experiment to
// disable the F12 shortcut by default.
const isF12Disabled = Services.prefs.getBoolPref(
DEVTOOLS_F12_DISABLED_PREF,
false
);
if (!isF12Disabled) {
await gDevToolsBrowser.toggleToolboxCommand(
window.gBrowser,
startTime
);
}
break;
case "browserToolbox":
BrowserToolboxLauncher.init();
break;

Просмотреть файл

@ -212,6 +212,8 @@ loader.lazyRequireGetter(
"devtools/shared/picker-constants"
);
const DEVTOOLS_F12_DISABLED_PREF = "devtools.experiment.f12.shortcut_disabled";
/**
* A "Toolbox" is the component that holds all the tools for one specific
* target. Visually, it's a document that includes the tools tabs and all
@ -253,6 +255,12 @@ function Toolbox(
// must use the time since the system wide epoch as the session ID.
this.sessionId = msSinceProcessStart;
// If the user opened the toolbox, we can now enable the F12 shortcut.
if (Services.prefs.getBoolPref(DEVTOOLS_F12_DISABLED_PREF, false)) {
// Flip the preference.
Services.prefs.setBoolPref(DEVTOOLS_F12_DISABLED_PREF, false);
}
// Map of the available DevTools WebExtensions:
// Map<extensionUUID, extensionName>
this._webExtensions = new Map();

Просмотреть файл

@ -4911,6 +4911,9 @@ pref("devtools.devices.url", "https://code.cdn.mozilla.net/devices/devices.json"
// Enable Inactive CSS detection; used both by the client and the server.
pref("devtools.inspector.inactive.css.enabled", true);
// The F12 experiment aims at disabling f12 on selected profiles.
pref("devtools.experiment.f12.shortcut_disabled", false);
#if defined(NIGHTLY_BUILD) || defined(MOZ_DEV_EDITION)
// Define in StaticPrefList.yaml and override here since StaticPrefList.yaml
// doesn't provide a way to lock the pref