Bug 1497457 - Reuse clients from remote client manager in about:devtools-toolbox;r=daisuke,ladybenko
☠☠ backed out by a6eccac5baa2 ☠ ☠
authorJulian Descottes <jdescottes@mozilla.com>
Mon, 26 Nov 2018 19:55:33 +0000
changeset 507324 9923755ee205175171873f87bacae7140fc5c35d
parent 507323 f2a39a18f2f602b230062c3e6735f80cf9d84272
child 507325 b2830500918c4bcef6bbbc794d1d70c0626b784b
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdaisuke, ladybenko
bugs1497457
milestone65.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 1497457 - Reuse clients from remote client manager in about:devtools-toolbox;r=daisuke,ladybenko Depends on D12039 Differential Revision: https://phabricator.services.mozilla.com/D12040
devtools/client/aboutdebugging-new/src/actions/debug-targets.js
devtools/client/framework/target-from-url.js
devtools/client/shared/remote-debugging/remote-client-manager.js
--- a/devtools/client/aboutdebugging-new/src/actions/debug-targets.js
+++ b/devtools/client/aboutdebugging-new/src/actions/debug-targets.js
@@ -1,16 +1,18 @@
 /* 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 { AddonManager } = require("resource://gre/modules/AddonManager.jsm");
 const { gDevToolsBrowser } = require("devtools/client/framework/devtools-browser");
+const { remoteClientManager } =
+  require("devtools/client/shared/remote-debugging/remote-client-manager");
 
 const { l10n } = require("../modules/l10n");
 
 const {
   debugLocalAddon,
   debugRemoteAddon,
   openTemporaryExtension,
   uninstallAddon,
@@ -39,19 +41,20 @@ function inspectDebugTarget(type, id) {
   return async (_, getState) => {
     const runtime = getCurrentRuntime(getState().runtimes);
     const { runtimeDetails, type: runtimeType } = runtime;
 
     switch (type) {
       case DEBUG_TARGETS.TAB: {
         // Open tab debugger in new window.
         if (runtimeType === RUNTIMES.NETWORK || runtimeType === RUNTIMES.USB) {
-          const { host, port } = runtimeDetails.transportDetails;
-          window.open(`about:devtools-toolbox?type=tab&id=${id}` +
-                      `&host=${host}&port=${port}`);
+          // Pass the remote id from the client manager so that about:devtools-toolbox can
+          // retrieve the connected client directly.
+          const remoteId = remoteClientManager.getRemoteId(runtime.id, runtime.type);
+          window.open(`about:devtools-toolbox?type=tab&id=${id}&remoteId=${remoteId}`);
         } else if (runtimeType === RUNTIMES.THIS_FIREFOX) {
           window.open(`about:devtools-toolbox?type=tab&id=${id}`);
         }
         break;
       }
       case DEBUG_TARGETS.EXTENSION: {
         if (runtimeType === RUNTIMES.NETWORK || runtimeType === RUNTIMES.USB) {
           const devtoolsClient = runtimeDetails.clientWrapper.client;
--- a/devtools/client/framework/target-from-url.js
+++ b/devtools/client/framework/target-from-url.js
@@ -2,16 +2,18 @@
  * 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 { TargetFactory } = require("devtools/client/framework/target");
 const { DebuggerServer } = require("devtools/server/main");
 const { DebuggerClient } = require("devtools/shared/client/debugger-client");
+const { remoteClientManager } =
+  require("devtools/client/shared/remote-debugging/remote-client-manager");
 
 /**
  * Construct a Target for a given URL object having various query parameters:
  *
  * - host, port & ws: See the documentation for clientFromURL
  *
  * - type: tab, process, window
  *      {String} The type of target to connect to.
@@ -34,19 +36,24 @@ const { DebuggerClient } = require("devt
  *
  * @param {URL} url
  *        The url to fetch query params from.
  *
  * @return A target object
  */
 exports.targetFromURL = async function targetFromURL(url) {
   const client = await clientFromURL(url);
-  await client.connect();
+  const params = url.searchParams;
 
-  const params = url.searchParams;
+  // Clients retrieved from the remote-client-manager are already connected.
+  if (!params.get("remoteId")) {
+    // Connect any other client.
+    await client.connect();
+  }
+
   const type = params.get("type");
   if (!type) {
     throw new Error("targetFromURL, missing type parameter");
   }
   let id = params.get("id");
   // Allows to spawn a chrome enabled target for any context
   // (handy to debug chrome stuff in a content process)
   let chrome = params.has("chrome");
@@ -111,25 +118,34 @@ exports.targetFromURL = async function t
 
 /**
  * Create a DebuggerClient for a given URL object having various query parameters:
  *
  * host:
  *    {String} The hostname or IP address to connect to.
  * port:
  *    {Number} The TCP port to connect to, to use with `host` argument.
+ * remoteId:
+ *    {String} Remote client id, for runtimes from the remote-client-manager
  * ws:
  *    {Boolean} If true, connect via websocket instead of regular TCP connection.
  *
  * @param {URL} url
  *        The url to fetch query params from.
  * @return a promise that resolves a DebuggerClient object
  */
 async function clientFromURL(url) {
   const params = url.searchParams;
+
+  // If a remote id was provided we should already have a connected client available.
+  const remoteId = params.get("remoteId");
+  if (remoteId) {
+    return remoteClientManager.getClientByRemoteId(remoteId).client;
+  }
+
   const host = params.get("host");
   const port = params.get("port");
   const webSocket = !!params.get("ws");
 
   let transport;
   if (port) {
     transport = await DebuggerClient.socketConnect({ host, port, webSocket });
   } else {
--- a/devtools/client/shared/remote-debugging/remote-client-manager.js
+++ b/devtools/client/shared/remote-debugging/remote-client-manager.js
@@ -44,16 +44,25 @@ class RemoteClientManager {
   }
 
   // See JSDoc for id, type from setClient.
   removeClient(id, type) {
     const key = this._getKey(id, type);
     this._removeClientByKey(key);
   }
 
+  getRemoteId(id, type) {
+    return encodeURIComponent(this._getKey(id, type));
+  }
+
+  getClientByRemoteId(remoteId) {
+    const key = decodeURIComponent(remoteId);
+    return this._clients.get(key);
+  }
+
   _getKey(id, type) {
     return id + "-" + type;
   }
 
   _removeClientByKey(key) {
     if (this.hasClient(key)) {
       this.getClient(key).client.removeListener("closed", this._onClientClosed);
       this._clients.delete(key);