Bug 1783821 - [devtools] Manual rewrites r=bomsy
authorAlexandre Poirot <poirot.alex@gmail.com>
Mon, 05 Sep 2022 12:29:57 +0000
changeset 634590 1be11ab96e3f285137f3a8f7c280f7497f84e0d9
parent 634589 7c6d06d2adaa26766cd815576a63aea69bb57c4a
child 634591 75dd64071e8b9da8e411abe337120eb2cd7aa2d4
push id169153
push userapoirot@mozilla.com
push dateMon, 05 Sep 2022 12:32:33 +0000
treeherderautoland@1be11ab96e3f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbomsy
bugs1783821
milestone106.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 1783821 - [devtools] Manual rewrites r=bomsy In md files and code comments and mostly from common js files. I'm moving away from require to load sys.mjs files so that we are closer to what we do in mozilla-central. Differential Revision: https://phabricator.services.mozilla.com/D154073
devtools/client/framework/browser-toolbox/README.md
devtools/client/framework/browser-toolbox/window.js
devtools/client/framework/devtools-browser.js
devtools/client/framework/devtools.js
devtools/client/menus.js
devtools/shared/loader/Loader.jsm
layout/tools/layout-debug/ui/content/layoutdebug.js
toolkit/xre/nsAppRunner.cpp
--- a/devtools/client/framework/browser-toolbox/README.md
+++ b/devtools/client/framework/browser-toolbox/README.md
@@ -13,25 +13,25 @@ You can either start it via a keyboard s
 When describing the setup used by the Browser Toolbox, we will refer to those two distinct Firefox instances as:
 - the target Firefox: this is the current instance, that we want to debug
 - the client Firefox: this is the new instance that will only run the Browser Toolbox window
 
 ## Browser Toolbox Architecture
 
 The startup sequence of the browser toolbox begins in the target Firefox.
 
-`browser-toolbox/Launcher.jsm` will be first reponsible for creating a remote DevToolsServer. This new DevToolsServer runs in the parent process but is separated from any existing DevTools DevToolsServer that spawned earlier for regular DevTools usage. Thanks to this, we will be able to debug files loaded in those regular DevToolsServers used for content toolboxes, about:debugging, ...
+`browser-toolbox/Launcher.sys.mjs` will be first reponsible for creating a remote DevToolsServer. This new DevToolsServer runs in the parent process but is separated from any existing DevTools DevToolsServer that spawned earlier for regular DevTools usage. Thanks to this, we will be able to debug files loaded in those regular DevToolsServers used for content toolboxes, about:debugging, ...
 
-Then we need to start the client Firefox. To do that, `browser-toolbox/Launcher.jsm` creates a profile that will be a copy of the current profile loaded in the target Firefox, so that all user preferences can be automatically ported over. As a reminder both client and target Firefox will run simultaneously, so they can't use the same profile.
+Then we need to start the client Firefox. To do that, `browser-toolbox/Launcher.sys.mjs` creates a profile that will be a copy of the current profile loaded in the target Firefox, so that all user preferences can be automatically ported over. As a reminder both client and target Firefox will run simultaneously, so they can't use the same profile.
 
 This new profile is stored inside the folder of the target profile, in a `chrome_debugger_profile` folder. So the next time the Browser Toolbox opens this for profile, it will be reused.
 
-Once the profile is ready (or if it was already there), `browser-toolbox/Launcher.jsm` spawns a new Firefox instance with a few additional parameters, most importantly `-chrome chrome://devtools/content/framework/browser-toolbox/window.html`.
+Once the profile is ready (or if it was already there), `browser-toolbox/Launcher.sys.mjs` spawns a new Firefox instance with a few additional parameters, most importantly `-chrome chrome://devtools/content/framework/browser-toolbox/window.html`.
 
 This way Firefox will load `browser-toolbox/window.html` instead of the regular browser window. Most of the logic is then handled by `browser-toolbox/window.js` which will connect to the remote server opened on the target Firefox and will then load a toolbox connected to this server.
 
 ## Debugging the Browser Toolbox
 
 Note that you can open a Browser Toolbox from the Browser Toolbox. Simply reuse the same shortcut as the one you used to open the first Browser Toolbox, but this time while the Browser Toolbox window is focused.
 
-Another Browser Toolbox will spawn, this time debugging the first Browser Toolbox Firefox instance. If you are curious about how this is done, `browser-toolbox/window.js` simply loads `browser-toolbox/Launcher.jsm` and requests to open a new Browser Toolbox.
+Another Browser Toolbox will spawn, this time debugging the first Browser Toolbox Firefox instance. If you are curious about how this is done, `browser-toolbox/window.js` simply loads `browser-toolbox/Launcher.sys.mjs` and requests to open a new Browser Toolbox.
 
 This will open yet another Firefox instance, running in another process. And a new `chrome_debugger_profile` folder will be created inside the existing Browser Toolbox profile (which as explained in the previous section, is already in a `chrome_debugger_profile` folder under the target Firefox profile).
--- a/devtools/client/framework/browser-toolbox/window.js
+++ b/devtools/client/framework/browser-toolbox/window.js
@@ -19,21 +19,22 @@ var { PrefsHelper } = require("devtools/
 const KeyShortcuts = require("devtools/client/shared/key-shortcuts");
 const { LocalizationHelper } = require("devtools/shared/l10n");
 const L10N = new LocalizationHelper(
   "devtools/client/locales/toolbox.properties"
 );
 const env = Cc["@mozilla.org/process/environment;1"].getService(
   Ci.nsIEnvironment
 );
-loader.lazyImporter(
-  this,
-  "BrowserToolboxLauncher",
-  "resource://devtools/client/framework/browser-toolbox/Launcher.jsm"
-);
+
+const lazy = {};
+ChromeUtils.defineESModuleGetters(lazy, {
+  BrowserToolboxLauncher:
+    "resource://devtools/client/framework/browser-toolbox/Launcher.sys.mjs",
+});
 
 // Timeout to wait before we assume that a connect() timed out without an error.
 // In milliseconds. (With the Debugger pane open, this has been reported to last
 // more than 10 seconds!)
 const STATUS_REVEAL_TIME = 15000;
 
 /**
  * Shortcuts for accessing various debugger preferences.
@@ -182,17 +183,17 @@ function onCloseCommand(event) {
 
 /**
  * Open a Browser toolbox debugging the current browser toolbox
  *
  * This helps debugging the browser toolbox code, especially the code
  * running in the parent process. i.e. frontend code.
  */
 function onDebugBrowserToolbox() {
-  BrowserToolboxLauncher.init();
+  lazy.BrowserToolboxLauncher.init();
 }
 
 /**
  * Replicate the local-build-only key shortcut to reload the browser
  */
 function onReloadBrowser() {
   gToolbox.commands.targetCommand.reloadTopLevelTarget();
 }
--- a/devtools/client/framework/devtools-browser.js
+++ b/devtools/client/framework/devtools-browser.js
@@ -8,16 +8,24 @@
  * This is the main module loaded in Firefox desktop that handles browser
  * windows and coordinates devtools around each window.
  *
  * This module is loaded lazily by devtools-clhandler.js, once the first
  * browser window is ready (i.e. fired browser-delayed-startup-finished event)
  **/
 
 const Services = require("Services");
+const ChromeUtils = require("ChromeUtils");
+
+const lazy = {};
+ChromeUtils.defineESModuleGetters(lazy, {
+  BrowserToolboxLauncher:
+    "resource://devtools/client/framework/browser-toolbox/Launcher.sys.mjs",
+});
+
 const { gDevTools } = require("devtools/client/framework/devtools");
 const {
   getTheme,
   addThemeObserver,
   removeThemeObserver,
 } = require("devtools/client/shared/theme");
 
 // Load toolbox lazily as it needs gDevTools to be fully initialized
@@ -56,21 +64,16 @@ loader.lazyRequireGetter(
   "devtools/client/responsive/manager"
 );
 loader.lazyRequireGetter(
   this,
   "toggleEnableDevToolsPopup",
   "devtools/client/framework/enable-devtools-popup",
   true
 );
-loader.lazyImporter(
-  this,
-  "BrowserToolboxLauncher",
-  "resource://devtools/client/framework/browser-toolbox/Launcher.jsm"
-);
 
 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";
 
@@ -316,17 +319,17 @@ var gDevToolsBrowser = (exports.gDevTool
         } else {
           await gDevToolsBrowser.toggleToolboxCommand(
             window.gBrowser,
             startTime
           );
         }
         break;
       case "browserToolbox":
-        BrowserToolboxLauncher.init();
+        lazy.BrowserToolboxLauncher.init();
         break;
       case "browserConsole":
         const {
           BrowserConsoleManager,
         } = require("devtools/client/webconsole/browser-console-manager");
         BrowserConsoleManager.openBrowserConsoleOrFocus();
         break;
       case "responsiveDesignMode":
--- a/devtools/client/framework/devtools.js
+++ b/devtools/client/framework/devtools.js
@@ -1,21 +1,28 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 const { Cu } = require("chrome");
 const Services = require("Services");
+const ChromeUtils = require("ChromeUtils");
 
 const {
   DevToolsShim,
 } = require("chrome://devtools-startup/content/DevToolsShim.jsm");
 
+const lazy = {};
+ChromeUtils.defineESModuleGetters(lazy, {
+  BrowserToolboxLauncher:
+    "resource://devtools/client/framework/browser-toolbox/Launcher.sys.mjs",
+});
+
 loader.lazyRequireGetter(
   this,
   "TabDescriptorFactory",
   "devtools/client/framework/tab-descriptor-factory",
   true
 );
 loader.lazyRequireGetter(
   this,
@@ -38,21 +45,16 @@ loader.lazyRequireGetter(
 loader.lazyRequireGetter(
   this,
   "Toolbox",
   "devtools/client/framework/toolbox",
   true
 );
 
 loader.lazyRequireGetter(this, "Telemetry", "devtools/client/shared/telemetry");
-loader.lazyImporter(
-  this,
-  "BrowserToolboxLauncher",
-  "resource://devtools/client/framework/browser-toolbox/Launcher.jsm"
-);
 
 const {
   defaultTools: DefaultTools,
   defaultThemes: DefaultThemes,
 } = require("devtools/client/definitions");
 const EventEmitter = require("devtools/shared/event-emitter");
 const {
   getTheme,
@@ -446,25 +448,25 @@ DevTools.prototype = {
   /**
    * Called from SessionStore.jsm in mozilla-central when saving the current state.
    *
    * @param {Object} state
    *                 A SessionStore state object that gets modified by reference
    */
   saveDevToolsSession(state) {
     state.browserConsole = BrowserConsoleManager.getBrowserConsoleSessionState();
-    state.browserToolbox = BrowserToolboxLauncher.getBrowserToolboxSessionState();
+    state.browserToolbox = lazy.BrowserToolboxLauncher.getBrowserToolboxSessionState();
   },
 
   /**
    * Restore the devtools session state as provided by SessionStore.
    */
   async restoreDevToolsSession({ browserConsole, browserToolbox }) {
     if (browserToolbox) {
-      BrowserToolboxLauncher.init();
+      lazy.BrowserToolboxLauncher.init();
     }
 
     if (browserConsole && !BrowserConsoleManager.getBrowserConsole()) {
       await BrowserConsoleManager.toggleBrowserConsole();
     }
   },
 
   /**
--- a/devtools/client/menus.js
+++ b/devtools/client/menus.js
@@ -21,16 +21,23 @@
  *   Helps figuring out the DOM id for the related <xul:key>
  *   in order to have the key text displayed in menus.
  * - checkbox:
  *   If true, the menuitem is prefixed by a checkbox and runtime code can
  *   toggle it.
  */
 
 const { Cu } = require("chrome");
+const ChromeUtils = require("ChromeUtils");
+
+const lazy = {};
+ChromeUtils.defineESModuleGetters(lazy, {
+  BrowserToolboxLauncher:
+    "resource://devtools/client/framework/browser-toolbox/Launcher.sys.mjs",
+});
 
 loader.lazyRequireGetter(this, "Services", "Services");
 loader.lazyRequireGetter(this, "flags", "devtools/shared/flags");
 
 loader.lazyRequireGetter(
   this,
   "gDevToolsBrowser",
   "devtools/client/framework/devtools-browser",
@@ -49,21 +56,16 @@ loader.lazyRequireGetter(
 );
 loader.lazyRequireGetter(
   this,
   "CommandsFactory",
   "devtools/shared/commands/commands-factory",
   true
 );
 
-loader.lazyImporter(
-  this,
-  "BrowserToolboxLauncher",
-  "resource://devtools/client/framework/browser-toolbox/Launcher.jsm"
-);
 loader.lazyRequireGetter(
   this,
   "PICKER_TYPES",
   "devtools/shared/picker-constants"
 );
 
 exports.menuitems = [
   {
@@ -87,17 +89,17 @@ exports.menuitems = [
       const window = event.target.ownerDocument.defaultView;
       gDevToolsBrowser.openAboutDebugging(window.gBrowser);
     },
   },
   {
     id: "menu_browserToolbox",
     l10nKey: "browserToolboxMenu",
     oncommand() {
-      BrowserToolboxLauncher.init();
+      lazy.BrowserToolboxLauncher.init();
     },
     keyId: "browserToolbox",
   },
   {
     id: "menu_browserContentToolbox",
     l10nKey: "browserContentToolboxMenu",
     oncommand(event) {
       const window = event.target.ownerDocument.defaultView;
--- a/devtools/shared/loader/Loader.jsm
+++ b/devtools/shared/loader/Loader.jsm
@@ -210,14 +210,14 @@ DevToolsLoader.prototype = {
 var loader = new DevToolsLoader({
   /**
    * Sets whether the compartments loaded by this instance should be invisible
    * to the debugger.  Invisibility is needed for loaders that support debugging
    * of chrome code.  This is true of remote target environments, like Fennec or
    * B2G.  It is not the default case for desktop Firefox because we offer the
    * Browser Toolbox for chrome debugging there, which uses its own, separate
    * loader instance.
-   * @see devtools/client/framework/browser-toolbox/Launcher.jsm
+   * @see devtools/client/framework/browser-toolbox/Launcher.sys.mjs
    */
   invisibleToDebugger: Services.appinfo.name !== "Firefox",
 });
 
 var require = loader.require;
--- a/layout/tools/layout-debug/ui/content/layoutdebug.js
+++ b/layout/tools/layout-debug/ui/content/layoutdebug.js
@@ -14,26 +14,21 @@ var gWritingProfile = false;
 var gWrittenProfile = false;
 
 const { E10SUtils } = ChromeUtils.import(
   "resource://gre/modules/E10SUtils.jsm"
 );
 const { Preferences } = ChromeUtils.import(
   "resource://gre/modules/Preferences.jsm"
 );
-
-var { loader } = ChromeUtils.import(
-  "resource://devtools/shared/loader/Loader.jsm"
-);
-
-loader.lazyImporter(
-  this,
-  "BrowserToolboxLauncher",
-  "resource://devtools/client/framework/browser-toolbox/Launcher.jsm"
-);
+const lazy = {};
+ChromeUtils.defineESModuleGetters(lazy, {
+  BrowserToolboxLauncher:
+    "resource://devtools/client/framework/browser-toolbox/Launcher.sys.mjs",
+});
 
 const FEATURES = {
   paintDumping: "nglayout.debug.paint_dumping",
   invalidateDumping: "nglayout.debug.invalidate_dumping",
   eventDumping: "nglayout.debug.event_dumping",
   motionEventDumping: "nglayout.debug.motion_event_dumping",
   crossingEventDumping: "nglayout.debug.crossing_event_dumping",
   reflowCounts: "layout.reflow.showframecounts",
@@ -107,17 +102,17 @@ class Debugger {
     this.setPagedMode(this._pagedMode);
   }
 
   setPagedMode(v) {
     this._sendMessage("setPagedMode", v);
   }
 
   openDevTools() {
-    BrowserToolboxLauncher.init();
+    lazy.BrowserToolboxLauncher.init();
   }
 
   async _sendMessage(name, arg) {
     await this._sendMessageTo(gBrowser.browsingContext, name, arg);
   }
 
   async _sendMessageTo(context, name, arg) {
     let global = context.currentWindowGlobal;
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -4559,17 +4559,17 @@ const char* ShouldNotProcessUpdatesReaso
 }
 
 Maybe<ShouldNotProcessUpdatesReason> ShouldNotProcessUpdates(
     nsXREDirProvider& aDirProvider) {
   // Do not process updates if we're launching devtools, as evidenced by
   // "--chrome ..." with the browser toolbox chrome document URL.
 
   // Keep this synchronized with the value of the same name in
-  // devtools/client/framework/browser-toolbox/Launcher.jsm.  Or, for bonus
+  // devtools/client/framework/browser-toolbox/Launcher.sys.mjs.  Or, for bonus
   // points, lift this value to nsIXulRuntime or similar, so that it can be
   // accessed in both locations.  (The prefs service isn't available at this
   // point so the simplest manner of sharing the value is not available to us.)
   const char* BROWSER_TOOLBOX_WINDOW_URL =
       "chrome://devtools/content/framework/browser-toolbox/window.html";
 
   const char* chromeParam = nullptr;
   if (ARG_FOUND == CheckArg("chrome", &chromeParam, CheckArgFlag::None)) {