Bug 1388738 - reuse devtools-startup initDevTools in DevToolsShim;r=ochameau draft
authorJulian Descottes <jdescottes@mozilla.com>
Wed, 09 Aug 2017 17:17:46 +0200
changeset 643960 e1ebc3429a182f0eea2990fb550bf7d7d9136aba
parent 643173 4c5fbf49376351679dcc49f4cff26c3c2e055ccc
child 643961 77f54e2fca1e2b518377845ba9abb8b331efcd71
child 643962 556d0795f94f0042ed4ea1dd00f3d3bfee3b456f
push id73278
push userjdescottes@mozilla.com
push dateThu, 10 Aug 2017 09:59:13 +0000
reviewersochameau
bugs1388738
milestone57.0a1
Bug 1388738 - reuse devtools-startup initDevTools in DevToolsShim;r=ochameau MozReview-Commit-ID: 7Qr06CZBYuf
devtools/shim/DevToolsShim.jsm
--- a/devtools/shim/DevToolsShim.jsm
+++ b/devtools/shim/DevToolsShim.jsm
@@ -1,16 +1,15 @@
 /* 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", {});
 
 this.EXPORTED_SYMBOLS = [
   "DevToolsShim",
 ];
 
 function removeItem(array, callback) {
   let index = array.findIndex(callback);
@@ -225,22 +224,37 @@ 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.
+   *
+   * @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) {
+    const devtoolsStartup = Cc["@mozilla.org/devtools/startup-clh;1"]
+                              .getService(Ci.nsICommandLineHandler)
+                              .wrappedJSObject;
+
+    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);
     }