Bug 1388738 - Reuse devtools-startup initDevTools in DevToolsShim. r=ochameau, a=gchang
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 09 Aug 2017 17:17:46 +0200
changeset 423655 ba9cc5295263af54d9ef4fedb7ecbbbc1cd9fa2c
parent 423654 620514babf09ef317a17019feec534555f91b803
child 423656 e9b8e3fb359c0e8956c148e0b37081ba0ca594e6
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau, gchang
bugs1388738
milestone56.0
Bug 1388738 - Reuse devtools-startup initDevTools in DevToolsShim. r=ochameau, a=gchang MozReview-Commit-ID: 7Qr06CZBYuf
devtools/shim/DevToolsShim.jsm
--- a/devtools/shim/DevToolsShim.jsm
+++ b/devtools/shim/DevToolsShim.jsm
@@ -1,18 +1,24 @@
 /* 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 = Components.utils;
-const Ci = Components.interfaces;
+const {utils: Cu, classes: Cc, interfaces: Ci} = Components;
 const { Services } = Cu.import("resource://gre/modules/Services.jsm", {});
 
+const { XPCOMUtils } = Cu.import("resource://gre/modules/XPCOMUtils.jsm", {});
+XPCOMUtils.defineLazyGetter(this, "DevtoolsStartup", () => {
+  return Cc["@mozilla.org/devtools/startup-clh;1"]
+            .getService(Ci.nsICommandLineHandler)
+            .wrappedJSObject;
+});
+
 this.EXPORTED_SYMBOLS = [
   "DevToolsShim",
 ];
 
 function removeItem(array, callback) {
   let index = array.findIndex(callback);
   if (index >= 0) {
     array.splice(index, 1);
@@ -229,22 +235,34 @@ this.DevToolsShim = {
    * @return {Promise} a promise that resolves when the node is selected in the inspector
    *         markup view or that resolves immediately if DevTools are not installed.
    */
   inspectNode: function (tab, selectors) {
     if (!this.isInstalled()) {
       return Promise.resolve();
     }
 
+    // Initialize DevTools explicitly to pass the "ContextMenu" reason to telemetry.
+    if (!this.isInitialized()) {
+      this._initDevTools("ContextMenu");
+    }
+
     return this.gDevTools.inspectNode(tab, selectors);
   },
 
-  _initDevTools: function () {
-    let { loader } = Cu.import("resource://devtools/shared/Loader.jsm", {});
-    loader.require("devtools/client/framework/devtools-browser");
+  /**
+   * Initialize DevTools via the devtools-startup command line handler component.
+   * Overridden in tests.
+   *
+   * @param {String} reason
+   *        optional, if provided should be a valid entry point for DEVTOOLS_ENTRY_POINT
+   *        in toolkit/components/telemetry/Histograms.json
+   */
+  _initDevTools: function (reason) {
+    DevtoolsStartup.initDevTools(reason);
   },
 
   _onDevToolsRegistered: function () {
     // Register all pending event listeners on the real gDevTools object.
     for (let [event, listener] of this.listeners) {
       this._gDevTools.on(event, listener);
     }