Bug 1630228 - Basic implementation to disable F12 until toolbox opens r=nchevobbe
☠☠ backed out by bc7658646927 ☠ ☠
authorJulian Descottes <jdescottes@mozilla.com>
Tue, 28 Apr 2020 20:09:15 +0000
changeset 526571 ae64b5ffc3b5908449007132500fb0bc56b838a2
parent 526570 3dcd50f429d93356a9b0b1a01d55dee689c597fe
child 526572 f9e6d07f3a9056e6600e789df49bdc56791efddd
push id37358
push useropoprus@mozilla.com
push dateWed, 29 Apr 2020 03:05:14 +0000
treeherdermozilla-central@6bb8423186c1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnchevobbe
bugs1630228
milestone77.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
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
devtools/client/framework/devtools-browser.js
devtools/client/framework/toolbox.js
modules/libpref/init/all.js
--- a/devtools/client/framework/devtools-browser.js
+++ b/devtools/client/framework/devtools-browser.js
@@ -65,16 +65,20 @@ loader.lazyImporter(
 
 const { LocalizationHelper } = require("devtools/shared/l10n");
 const L10N = new LocalizationHelper(
   "devtools/client/locales/toolbox.properties"
 );
 
 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.
  */
 var gDevToolsBrowser = (exports.gDevToolsBrowser = {
   /**
    * A record of the windows whose menus we altered, so we can undo the changes
    * as the window is closed
@@ -294,18 +298,33 @@ var gDevToolsBrowser = (exports.gDevTool
     // If this is a toolbox's panel key shortcut, delegate to selectToolCommand
     if (key.toolId) {
       await gDevToolsBrowser.selectToolCommand(window, key.toolId, startTime);
       return;
     }
     // Otherwise implement all other key shortcuts individually here
     switch (key.id) {
       case "toggleToolbox":
+        await gDevToolsBrowser.toggleToolboxCommand(window.gBrowser, startTime);
+        break;
       case "toggleToolboxF12":
-        await gDevToolsBrowser.toggleToolboxCommand(window.gBrowser, startTime);
+        // 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;
       case "browserConsole":
         const {
           BrowserConsoleManager,
         } = require("devtools/client/webconsole/browser-console-manager");
--- a/devtools/client/framework/toolbox.js
+++ b/devtools/client/framework/toolbox.js
@@ -207,16 +207,18 @@ loader.lazyRequireGetter(
 );
 
 loader.lazyRequireGetter(
   this,
   "PICKER_TYPES",
   "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
  * the iframes where the tool panels will be living in.
  *
  * @param {object} target
  *        The object the toolbox is debugging.
  * @param {string} selectedTool
@@ -248,16 +250,22 @@ function Toolbox(
   this.targetList = new TargetList(target.client.mainRoot, target);
   this.resourceWatcher = new ResourceWatcher(this.targetList);
 
   // The session ID is used to determine which telemetry events belong to which
   // toolbox session. Because we use Amplitude to analyse the telemetry data we
   // 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();
 
   this._toolPanels = new Map();
   // Map of tool startup components for given tool id.
   this._toolStartups = new Map();
   this._inspectorExtensionSidebars = new Map();
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -4906,16 +4906,19 @@ pref("devtools.remote.adb.extensionID", 
 pref("devtools.remote.adb.extensionURL", "https://ftp.mozilla.org/pub/mozilla.org/labs/devtools/adb-extension/#OS#/adb-extension-latest-#OS#.xpi");
 
 // URL of the remote JSON catalog used for device simulation.
 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
 pref("dom.postMessage.sharedArrayBuffer.bypassCOOP_COEP.insecure.enabled", false);
 #else
 pref("dom.postMessage.sharedArrayBuffer.bypassCOOP_COEP.insecure.enabled", false, locked);
 #endif