Bug 1520774 - Remove TargetFactory.forRemoteTab. r=yulia
authorAlexandre Poirot <poirot.alex@gmail.com>
Wed, 06 Feb 2019 16:17:15 +0000
changeset 518506 023ecfc5cf46837719be435324942c5c1532b7a8
parent 518505 02e125fcde8ad98bfcf4e7852f7a03798a9b48d4
child 518507 a42ea7bbd5835457630ea50f4d82779163adfed0
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyulia
bugs1520774
milestone67.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 1520774 - Remove TargetFactory.forRemoteTab. r=yulia Differential Revision: https://phabricator.services.mozilla.com/D18539
devtools/client/aboutdebugging-new/src/modules/extensions-helper.js
devtools/client/framework/connect/connect.js
devtools/client/framework/devtools-browser.js
devtools/client/framework/target-from-url.js
devtools/client/framework/target.js
devtools/client/framework/test/browser_target_remote.js
devtools/client/framework/test/browser_target_server_compartment.js
devtools/client/framework/test/browser_target_support.js
devtools/client/framework/toolbox-init.js
devtools/client/framework/toolbox-process-window.js
devtools/client/scratchpad/scratchpad.js
devtools/client/webconsole/hudservice.js
devtools/client/webide/modules/app-manager.js
devtools/client/webide/modules/tab-store.js
devtools/server/tests/browser/browser_dbg_promises-chrome-allocation-stack.js
devtools/server/tests/mochitest/test_webextension-addon-debugging-connect.html
devtools/server/tests/mochitest/webextension-helpers.js
devtools/server/tests/unit/head_dbg.js
devtools/shared/webconsole/test/common.js
--- a/devtools/client/aboutdebugging-new/src/modules/extensions-helper.js
+++ b/devtools/client/aboutdebugging-new/src/modules/extensions-helper.js
@@ -4,17 +4,16 @@
 
 "use strict";
 
 const { Cc, Ci } = require("chrome");
 loader.lazyImporter(this, "BrowserToolboxProcess",
   "resource://devtools/client/framework/ToolboxProcess.jsm");
 loader.lazyImporter(this, "AddonManager", "resource://gre/modules/AddonManager.jsm");
 
-const {TargetFactory} = require("devtools/client/framework/target");
 const {Toolbox} = require("devtools/client/framework/toolbox");
 
 const {gDevTools} = require("devtools/client/framework/devtools");
 
 let browserToolboxProcess = null;
 let remoteAddonToolbox = null;
 function closeToolbox() {
   if (browserToolboxProcess) {
@@ -50,29 +49,21 @@ exports.debugLocalAddon = async function
  * @param {String} id
  *        The addon id to debug.
  * @param {DebuggerClient} client
  *        Required for remote debugging.
  */
 exports.debugRemoteAddon = async function(id, client) {
   const addonFront = await client.mainRoot.getAddon({ id });
 
-  const addonTargetFront = await addonFront.connect();
+  const target = await addonFront.connect();
 
   // Close previous addon debugging toolbox.
   closeToolbox();
 
-  const options = {
-    activeTab: addonTargetFront,
-    chrome: true,
-    client,
-  };
-
-  const target = await TargetFactory.forRemoteTab(options);
-
   const hostType = Toolbox.HostType.WINDOW;
   remoteAddonToolbox = await gDevTools.showToolbox(target, null, hostType);
   remoteAddonToolbox.once("destroy", () => {
     remoteAddonToolbox = null;
   });
 };
 
 /**
--- a/devtools/client/framework/connect/connect.js
+++ b/devtools/client/framework/connect/connect.js
@@ -4,17 +4,16 @@
  * 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";
 
 var {require} = ChromeUtils.import("resource://devtools/shared/Loader.jsm");
 var Services = require("Services");
 var {gDevTools} = require("devtools/client/framework/devtools");
-var {TargetFactory} = require("devtools/client/framework/target");
 var {Toolbox} = require("devtools/client/framework/toolbox");
 var {DebuggerClient} = require("devtools/shared/client/debugger-client");
 var {LocalizationHelper} = require("devtools/shared/l10n");
 var L10N = new LocalizationHelper("devtools/client/locales/connection-screen.properties");
 
 var gClient;
 var gConnectionTimeout;
 
@@ -199,24 +198,16 @@ function showError(type) {
 function handleConnectionTimeout() {
   showError("timeout");
 }
 
 /**
  * The user clicked on one of the buttons.
  * Opens the toolbox.
  */
-function openToolbox(activeTab, chrome = false) {
-  const options = {
-    activeTab,
-    client: gClient,
-    chrome,
-  };
-  TargetFactory.forRemoteTab(options).then((target) => {
-    const hostType = Toolbox.HostType.WINDOW;
-    gDevTools.showToolbox(target, "webconsole", hostType).then((toolbox) => {
-      toolbox.once("destroyed", function() {
-        gClient.close();
-      });
-    }, console.error);
-    window.close();
-  }, console.error);
+async function openToolbox(target, chrome = false) {
+  const hostType = Toolbox.HostType.WINDOW;
+  const toolbox = gDevTools.showToolbox(target, "webconsole", hostType);
+  toolbox.once("destroyed", function() {
+    gClient.close();
+  });
+  window.close();
 }
--- a/devtools/client/framework/devtools-browser.js
+++ b/devtools/client/framework/devtools-browser.js
@@ -323,23 +323,17 @@ var gDevToolsBrowser = exports.gDevTools
     DebuggerServer.init();
     DebuggerServer.registerAllActors();
     DebuggerServer.allowChromeProcess = true;
 
     const transport = DebuggerServer.connectPipe();
     const client = new DebuggerClient(transport);
 
     await client.connect();
-    const front = await client.mainRoot.getProcess(processId);
-    const options = {
-      activeTab: front,
-      client,
-      chrome: true,
-    };
-    const target = await TargetFactory.forRemoteTab(options);
+    const target = await client.mainRoot.getProcess(processId);
     // Ensure closing the connection in order to cleanup
     // the debugger client and also the server created in the
     // content process
     target.on("close", () => {
       client.close();
     });
     return target;
   },
--- a/devtools/client/framework/target-from-url.js
+++ b/devtools/client/framework/target-from-url.js
@@ -1,15 +1,14 @@
 /* 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 { 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:
  *
@@ -49,19 +48,16 @@ exports.targetFromURL = async function t
     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");
 
   let front;
   if (type === "tab") {
     // Fetch target for a remote tab
     id = parseInt(id, 10);
     if (isNaN(id)) {
       throw new Error(`targetFromURL, wrong tab id '${id}', should be a number`);
     }
@@ -77,17 +73,16 @@ exports.targetFromURL = async function t
     // Fetch target for a remote chrome actor
     DebuggerServer.allowChromeProcess = true;
     try {
       id = parseInt(id, 10);
       if (isNaN(id)) {
         id = 0;
       }
       front = await client.mainRoot.getProcess(id);
-      chrome = true;
     } catch (ex) {
       if (ex.error == "noProcess") {
         throw new Error(`targetFromURL, process with id '${id}' doesn't exist`);
       }
       throw ex;
     }
   } else if (type == "window") {
     // Fetch target for a remote window actor
@@ -95,28 +90,34 @@ exports.targetFromURL = async function t
     try {
       id = parseInt(id, 10);
       if (isNaN(id)) {
         throw new Error("targetFromURL, window requires id parameter");
       }
       front = await client.mainRoot.getWindow({
         outerWindowID: id,
       });
-      chrome = true;
     } catch (ex) {
       if (ex.error == "notFound") {
         throw new Error(`targetFromURL, window with id '${id}' doesn't exist`);
       }
       throw ex;
     }
   } else {
     throw new Error(`targetFromURL, unsupported type '${type}' parameter`);
   }
 
-  return TargetFactory.forRemoteTab({ client, activeTab: front, chrome });
+  // Allows to spawn a chrome enabled target for any context
+  // (handy to debug chrome stuff in a content process)
+  const chrome = params.has("chrome");
+  if (chrome) {
+    front.forceChrome();
+  }
+
+  return front;
 };
 
 /**
  * Create a DebuggerClient for a given URL object having various query parameters:
  *
  * host:
  *    {String} The hostname or IP address to connect to.
  * port:
--- a/devtools/client/framework/target.js
+++ b/devtools/client/framework/target.js
@@ -82,41 +82,16 @@ exports.TargetFactory = {
 
     // Connect the local client to the local server
     await client.connect();
 
     // Fetch the FrameTargetActor's Front
     return client.mainRoot.getTab({ tab });
   },
 
-  /**
-   * Return a promise of a Target for a remote tab.
-   * @param {Object} options
-   *        The options object has the following properties:
-   *        {
-   *          activeTab: front for this tab target,
-   *          client: a DebuggerClient instance
-   *                  (caller owns this and is responsible for closing),
-   *          chrome: true if the remote target is the whole process
-   *        }
-   *
-   * @return A promise of a target object
-   */
-  forRemoteTab: function({ activeTab, client, chrome }) {
-    const target = activeTab;
-    if (chrome) {
-      target.forceChrome();
-    }
-    const targetPromise = target.attach().then(() => target);
-    targetPromise.catch(e => {
-      console.error("Exception while attaching target", e);
-    });
-    return targetPromise;
-  },
-
   forWorker: function(workerTargetFront) {
     return workerTargetFront;
   },
 
   /**
    * Creating a target for a tab that is being closed is a problem because it
    * allows a leak as a result of coming after the close event which normally
    * clears things up. This function allows us to ask if there is a known
--- a/devtools/client/framework/test/browser_target_remote.js
+++ b/devtools/client/framework/test/browser_target_remote.js
@@ -2,24 +2,16 @@
 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 // Ensure target is closed if client is closed directly
 function test() {
   waitForExplicitFinish();
 
-  getParentProcessActors((client, front) => {
-    const options = {
-      activeTab: front,
-      client,
-      chrome: true,
-    };
-
-    TargetFactory.forRemoteTab(options).then(target => {
-      target.on("close", () => {
-        ok(true, "Target was closed");
-        finish();
-      });
-      client.close();
+  getParentProcessActors((client, target) => {
+    target.on("close", () => {
+      ok(true, "Target was closed");
+      finish();
     });
+    client.close();
   });
 }
--- a/devtools/client/framework/test/browser_target_server_compartment.js
+++ b/devtools/client/framework/test/browser_target_server_compartment.js
@@ -89,22 +89,17 @@ async function testMainProcess() {
         Services.obs.removeObserver(observe, "devtools-thread-instantiated");
         const threadActor = subject.wrappedJSObject;
         resolve(threadActor);
       }
     };
     Services.obs.addObserver(observe, "devtools-thread-instantiated");
   });
 
-  const targetFront = await client.mainRoot.getMainProcess();
-  const target = await TargetFactory.forRemoteTab({
-    client,
-    activeTab: targetFront,
-    chrome: true,
-  });
+  const target = await client.mainRoot.getMainProcess();
   await target.attach();
 
   const [, threadClient] = await target.attachThread();
   await threadClient.resume();
   const { sources } = await threadClient.getSources();
   ok(sources.find(s => s.url == "resource://devtools/client/framework/devtools.js"),
     "The thread actor is able to attach to the chrome script, like client modules");
 
--- a/devtools/client/framework/test/browser_target_support.js
+++ b/devtools/client/framework/test/browser_target_support.js
@@ -44,25 +44,17 @@ async function testTarget(client, target
 
   close(target, client);
 }
 
 // Ensure target is closed if client is closed directly
 function test() {
   waitForExplicitFinish();
 
-  getParentProcessActors((client, front) => {
-    const options = {
-      activeTab: front,
-      client,
-      chrome: true,
-    };
-
-    TargetFactory.forRemoteTab(options).then(testTarget.bind(null, client));
-  });
+  getParentProcessActors(testTarget);
 }
 
 function close(target, client) {
   target.on("close", () => {
     ok(true, "Target was closed");
     finish();
   });
   client.close();
--- a/devtools/client/framework/toolbox-init.js
+++ b/devtools/client/framework/toolbox-init.js
@@ -12,17 +12,16 @@ const href = window.location.href.replac
 const url = new window.URL(href);
 
 // Only use this method to attach the toolbox if some query parameters are given
 if (url.search.length > 1) {
   const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm");
   const { gDevTools } = require("devtools/client/framework/devtools");
   const { targetFromURL } = require("devtools/client/framework/target-from-url");
   const { Toolbox } = require("devtools/client/framework/toolbox");
-  const { TargetFactory } = require("devtools/client/framework/target");
   const { DebuggerServer } = require("devtools/server/main");
   const { DebuggerClient } = require("devtools/shared/client/debugger-client");
 
   // `host` is the frame element loading the toolbox.
   let host = window.windowUtils.containerElement;
 
   // If there's no containerElement (which happens when loading about:devtools-toolbox as
   // a top level document), use the current window.
@@ -66,18 +65,17 @@ if (url.search.length > 1) {
       const tab = { linkedBrowser: iframe };
 
       DebuggerServer.init();
       DebuggerServer.registerAllActors();
       const client = new DebuggerClient(DebuggerServer.connectPipe());
 
       await client.connect();
       // Creates a target for a given browser iframe.
-      const front = await client.mainRoot.getTab({ tab });
-      target = await TargetFactory.forRemoteTab({client, activeTab: front, chrome: false});
+      target = await client.mainRoot.getTab({ tab });
     } else {
       target = await targetFromURL(url);
     }
     const options = { customIframe: host };
     await gDevTools.showToolbox(target, tool, Toolbox.HostType.PAGE, options);
   })().catch(error => {
     console.error("Exception while loading the toolbox", error);
   });
--- a/devtools/client/framework/toolbox-process-window.js
+++ b/devtools/client/framework/toolbox-process-window.js
@@ -7,17 +7,16 @@
 "use strict";
 
 var { loader, require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm");
 
 // Require this module to setup core modules
 loader.require("devtools/client/framework/devtools-browser");
 
 var { gDevTools } = require("devtools/client/framework/devtools");
-var { TargetFactory } = require("devtools/client/framework/target");
 var { Toolbox } = require("devtools/client/framework/toolbox");
 var Services = require("Services");
 var { DebuggerClient } = require("devtools/shared/client/debugger-client");
 var { PrefsHelper } = require("devtools/client/shared/prefs");
 const KeyShortcuts = require("devtools/client/shared/key-shortcuts");
 const { LocalizationHelper } = require("devtools/shared/l10n");
 const L10N = new LocalizationHelper("devtools/client/locales/toolbox.properties");
 
@@ -86,20 +85,20 @@ var connect = async function() {
   gClient = new DebuggerClient(transport);
   appendStatusMessage("Start protocol client for connection");
   await gClient.connect();
 
   appendStatusMessage("Get root form for toolbox");
   if (addonID) {
     const addonFront = await gClient.mainRoot.getAddon({ id: addonID });
     const addonTargetFront = await addonFront.connect();
-    await openToolbox({activeTab: addonTargetFront, chrome: true});
+    await openToolbox(addonTargetFront);
   } else {
     const front = await gClient.mainRoot.getMainProcess();
-    await openToolbox({activeTab: front, chrome: true});
+    await openToolbox(front);
   }
 };
 
 // Certain options should be toggled since we can assume chrome debugging here
 function setPrefDefaults() {
   Services.prefs.setBoolPref("devtools.inspector.showUserAgentStyles", true);
   Services.prefs.setBoolPref("devtools.performance.ui.show-platform-data", true);
   Services.prefs.setBoolPref("devtools.inspector.showAllAnonymousContent", true);
@@ -136,26 +135,19 @@ window.addEventListener("load", async fu
     console.error(e);
   }
 }, { once: true });
 
 function onCloseCommand(event) {
   window.close();
 }
 
-async function openToolbox({ activeTab, chrome }) {
-  const targetOptions = {
-    activeTab,
-    client: gClient,
-    chrome,
-  };
-
-  const form = activeTab.targetForm;
-  appendStatusMessage(`Create toolbox target: ${JSON.stringify({form, chrome}, null, 2)}`);
-  const target = await TargetFactory.forRemoteTab(targetOptions);
+async function openToolbox(target) {
+  const form = target.targetForm;
+  appendStatusMessage(`Create toolbox target: ${JSON.stringify({form}, null, 2)}`);
   const frame = document.getElementById("toolbox-iframe");
 
   // Remember the last panel that was used inside of this profile.
   // But if we are testing, then it should always open the debugger panel.
   const selectedTool =
     Services.prefs.getCharPref("devtools.browsertoolbox.panel",
       Services.prefs.getCharPref("devtools.toolbox.selectedTool",
                                   "jsdebugger"));
--- a/devtools/client/scratchpad/scratchpad.js
+++ b/devtools/client/scratchpad/scratchpad.js
@@ -2012,21 +2012,18 @@ ScratchpadWindow.prototype = extend(Scra
    */
   async _attach() {
     DebuggerServer.init();
     DebuggerServer.registerAllActors();
     DebuggerServer.allowChromeProcess = true;
 
     const client = new DebuggerClient(DebuggerServer.connectPipe());
     await client.connect();
-    const front = await client.mainRoot.getMainProcess();
-    const target = await TargetFactory.forRemoteTab({
-      activeTab: front,
-      client,
-    });
+    const target = await client.mainRoot.getMainProcess();
+    await target.attach();
     return target;
   },
 });
 
 function ScratchpadTarget(aTarget) {
   this._target = aTarget;
 }
 
--- a/devtools/client/webconsole/hudservice.js
+++ b/devtools/client/webconsole/hudservice.js
@@ -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";
 
 var Services = require("Services");
-loader.lazyRequireGetter(this, "TargetFactory", "devtools/client/framework/target", true);
 loader.lazyRequireGetter(this, "Tools", "devtools/client/definitions", true);
 loader.lazyRequireGetter(this, "gDevTools", "devtools/client/framework/devtools", true);
 loader.lazyRequireGetter(this, "DebuggerServer", "devtools/server/main", true);
 loader.lazyRequireGetter(this, "DebuggerClient", "devtools/shared/client/debugger-client", true);
 loader.lazyRequireGetter(this, "l10n", "devtools/client/webconsole/webconsole-l10n");
 loader.lazyRequireGetter(this, "WebConsole", "devtools/client/webconsole/webconsole");
 loader.lazyRequireGetter(this, "BrowserConsole", "devtools/client/webconsole/browser-console");
 
@@ -131,18 +130,17 @@ HUDService.prototype = {
       // (See Bug 1416105 for rationale).
       DebuggerServer.init();
       DebuggerServer.registerActors({ root: true, target: true });
 
       DebuggerServer.allowChromeProcess = true;
 
       const client = new DebuggerClient(DebuggerServer.connectPipe());
       await client.connect();
-      const front = await client.mainRoot.getMainProcess();
-      return { activeTab: front, client, chrome: true };
+      return client.mainRoot.getMainProcess();
     }
 
     async function openWindow(t) {
       const win = Services.ww.openWindow(null, Tools.webConsole.url,
                                        "_blank", BC_WINDOW_FEATURES, null);
 
       await new Promise(resolve => {
         win.addEventListener("DOMContentLoaded", resolve, {once: true});
@@ -151,18 +149,18 @@ HUDService.prototype = {
       win.document.title = l10n.getStr("browserConsole.title");
 
       return {iframeWindow: win, chromeWindow: win};
     }
 
     // Temporarily cache the async startup sequence so that if toggleBrowserConsole
     // gets called again we can return this console instead of opening another one.
     this._browserConsoleInitializing = (async () => {
-      const connection = await connect();
-      const target = await TargetFactory.forRemoteTab(connection);
+      const target = await connect();
+      await target.attach();
       const {iframeWindow, chromeWindow} = await openWindow(target);
       const browserConsole =
         await this.openBrowserConsole(target, iframeWindow, chromeWindow);
       return browserConsole;
     })();
 
     const browserConsole = await this._browserConsoleInitializing;
     this._browserConsoleInitializing = null;
--- a/devtools/client/webide/modules/app-manager.js
+++ b/devtools/client/webide/modules/app-manager.js
@@ -1,13 +1,12 @@
 /* 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/. */
 
-const {TargetFactory} = require("devtools/client/framework/target");
 const Services = require("Services");
 const {FileUtils} = require("resource://gre/modules/FileUtils.jsm");
 const EventEmitter = require("devtools/shared/event-emitter");
 const {OS} = require("resource://gre/modules/osfile.jsm");
 const {AppProjects} = require("devtools/client/webide/modules/app-projects");
 const TabStore = require("devtools/client/webide/modules/tab-store");
 const {AppValidator} = require("devtools/client/webide/modules/app-validator");
 const {ConnectionManager, Connection} = require("devtools/shared/client/connection-manager");
@@ -247,23 +246,17 @@ var AppManager = exports.AppManager = {
     }
     return this.getTarget().then(target => {
       target.reload();
     }, console.error);
   },
 
   getTarget: function() {
     if (this.selectedProject.type == "mainProcess") {
-      return this.connection.client.mainRoot.getMainProcess().then(front => {
-        return TargetFactory.forRemoteTab({
-          activeTab: front,
-          client: this.connection.client,
-          chrome: true,
-        });
-      });
+      return this.connection.client.mainRoot.getMainProcess();
     }
 
     if (this.selectedProject.type == "tab") {
       return this.tabStore.getTargetForTab();
     }
 
     const app = this._getProjectFront(this.selectedProject);
     if (!app) {
--- a/devtools/client/webide/modules/tab-store.js
+++ b/devtools/client/webide/modules/tab-store.js
@@ -1,13 +1,12 @@
 /* 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/. */
 
-const { TargetFactory } = require("devtools/client/framework/target");
 const EventEmitter = require("devtools/shared/event-emitter");
 const { Connection } = require("devtools/shared/client/connection-manager");
 
 const _knownTabStores = new WeakMap();
 
 var TabStore;
 
 module.exports = TabStore = function(connection) {
@@ -150,22 +149,17 @@ TabStore.prototype = {
     this._selectedTabTargetPromise = (async function() {
       // If you connect to a tab, then detach from it, the root actor may have
       // de-listed the actors that belong to the tab.  This breaks the toolbox
       // if you try to connect to the same tab again.  To work around this
       // issue, we force a "listTabs" request before connecting to a tab.
       await store.listTabs();
 
       const { outerWindowID } = store._selectedTab;
-      const activeTabFront = await store._connection.client.mainRoot.getTab({ outerWindowID });
-      return TargetFactory.forRemoteTab({
-        activeTab: activeTabFront,
-        client: store._connection.client,
-        chrome: false,
-      });
+      return store._connection.client.mainRoot.getTab({ outerWindowID });
     })();
     this._selectedTabTargetPromise.then(target => {
       target.once("close", () => {
         this._selectedTabTargetPromise = null;
       });
     });
     return this._selectedTabTargetPromise;
   },
--- a/devtools/server/tests/browser/browser_dbg_promises-chrome-allocation-stack.js
+++ b/devtools/server/tests/browser/browser_dbg_promises-chrome-allocation-stack.js
@@ -33,22 +33,17 @@ add_task(async function test() {
   const { DebuggerServer } = customLoader.require("devtools/server/main");
 
   DebuggerServer.init();
   DebuggerServer.registerAllActors();
   DebuggerServer.allowChromeProcess = true;
 
   const client = new DebuggerClient(DebuggerServer.connectPipe());
   await client.connect();
-  const targetFront = await client.mainRoot.getMainProcess();
-  const target = await TargetFactory.forRemoteTab({
-    client,
-    activeTab: targetFront,
-    chrome: true,
-  });
+  const target = await client.mainRoot.getMainProcess();
   await target.attach();
 
   await testGetAllocationStack(client, target, () => {
     const p = new Promise(() => {});
     p.name = "p";
     const q = p.then();
     q.name = "q";
     const r = p.catch(() => {});
--- a/devtools/server/tests/mochitest/test_webextension-addon-debugging-connect.html
+++ b/devtools/server/tests/mochitest/test_webextension-addon-debugging-connect.html
@@ -35,25 +35,20 @@ async function test_connect_addon(oopMod
   const transport = DebuggerServer.connectPipe();
   const client = new DebuggerClient(transport);
   await client.connect();
 
   // List addons and assertions on the expected addon actor.
   const addonFront = await client.mainRoot.getAddon({ id: extension.id });
   ok(addonFront, "The expected webextension addon actor has been found");
 
-  const addonTargetFront = await addonFront.connect();
-  ok(addonTargetFront, "The expected webextension target addon actor has been found");
+  const addonTarget = await addonFront.connect();
+  ok(addonTarget, "The expected webextension target addon actor has been found");
 
   // Connect to the target addon actor and wait for the updated list of frames.
-  const addonTarget = await TargetFactory.forRemoteTab({
-    activeTab: addonTargetFront,
-    client,
-    chrome: true,
-  });
   is(addonTarget.targetForm.isOOP, oopMode,
      "Got the expected oop mode in the webextension actor form");
   const frames = await waitForFramesUpdated(addonTarget);
   const backgroundPageFrame = frames.filter((frame) => {
     return frame.url && frame.url.endsWith("/_generated_background_page.html");
   }).pop();
   is(backgroundPageFrame.addonID, extension.id, "Got an extension frame");
 
--- a/devtools/server/tests/mochitest/webextension-helpers.js
+++ b/devtools/server/tests/mochitest/webextension-helpers.js
@@ -3,17 +3,16 @@
    promiseWebExtensionStartup, promiseWebExtensionShutdown
  */
 
 "use strict";
 
 const {require, loader} = ChromeUtils.import("resource://devtools/shared/Loader.jsm");
 const {DebuggerClient} = require("devtools/shared/client/debugger-client");
 const {DebuggerServer} = require("devtools/server/main");
-const {TargetFactory} = require("devtools/client/framework/target");
 
 const {AddonTestUtils} = require("resource://testing-common/AddonTestUtils.jsm");
 const {ExtensionTestCommon} = require("resource://testing-common/ExtensionTestCommon.jsm");
 
 loader.lazyImporter(this, "ExtensionParent", "resource://gre/modules/ExtensionParent.jsm");
 
 // Initialize a minimal DebuggerServer and connect to the webextension addon actor.
 if (!DebuggerServer.initialized) {
@@ -91,29 +90,23 @@ function collectFrameUpdates({client}, m
 
 async function attachAddon(addonId) {
   const transport = DebuggerServer.connectPipe();
   const client = new DebuggerClient(transport);
 
   await client.connect();
 
   const addonFront = await client.mainRoot.getAddon({ id: addonId });
-  const addonTargetFront = await addonFront.connect();
+  const addonTarget = await addonFront.connect();
 
-  if (!addonTargetFront) {
+  if (!addonTarget) {
     client.close();
     throw new Error(`No WebExtension Actor found for ${addonId}`);
   }
 
-  const addonTarget = await TargetFactory.forRemoteTab({
-    activeTab: addonTargetFront,
-    client,
-    chrome: true,
-  });
-
   return addonTarget;
 }
 
 async function reloadAddon({client}, addonId) {
   const addonTargetFront = await client.mainRoot.getAddon({ id: addonId });
 
   if (!addonTargetFront) {
     client.close();
--- a/devtools/server/tests/unit/head_dbg.js
+++ b/devtools/server/tests/unit/head_dbg.js
@@ -59,42 +59,28 @@ function startupAddonsManager() {
 
   internalManager.observe(null, "addons-startup", null);
 }
 
 async function createTargetForFakeTab(title) {
   const client = await startTestDebuggerServer(title);
 
   const tabs = await listTabs(client);
-  const front = findTab(tabs, title);
-  const options = {
-    activeTab: front,
-    client,
-    chrome: false,
-  };
-  const target = await TargetFactory.forRemoteTab(options);
-  return target;
+  return findTab(tabs, title);
 }
 
 async function createTargetForMainProcess() {
   DebuggerServer.init();
   DebuggerServer.registerAllActors();
   DebuggerServer.allowChromeProcess = true;
 
   const client = new DebuggerClient(DebuggerServer.connectPipe());
   await client.connect();
 
-  const front = await client.mainRoot.getMainProcess();
-  const options = {
-    activeTab: front,
-    client,
-    chrome: true,
-  };
-  const target = await TargetFactory.forRemoteTab(options);
-  return target;
+  return client.mainRoot.getMainProcess();
 }
 
 /**
  * Create a MemoryFront for a fake test tab.
  */
 async function createTabMemoryFront() {
   const target = await createTargetForFakeTab("test_memory");
 
--- a/devtools/shared/webconsole/test/common.js
+++ b/devtools/shared/webconsole/test/common.js
@@ -10,17 +10,16 @@
    closeDebugger, checkConsoleAPICalls, checkRawHeaders, runTests, nextTest, Ci, Cc,
    withActiveServiceWorker, Services, consoleAPICall */
 
 const {require} = ChromeUtils.import("resource://devtools/shared/Loader.jsm");
 const {DebuggerServer} = require("devtools/server/main");
 const {DebuggerClient} = require("devtools/shared/client/debugger-client");
 const ObjectClient = require("devtools/shared/client/object-client");
 const Services = require("Services");
-const {TargetFactory} = require("devtools/client/framework/target");
 
 function initCommon() {
   // Services.prefs.setBoolPref("devtools.debugger.log", true);
 }
 
 function initDebuggerServer() {
   DebuggerServer.init();
   DebuggerServer.registerAllActors();
@@ -62,43 +61,32 @@ var _attachConsole = async function(
         target.addEventListener("message", resolve, { once: true });
       });
     }
 
     // Fetch the console actor out of the expected target
     // ParentProcessTarget / WorkerTarget / FrameTarget
     let target, worker;
     if (!attachToTab) {
-      const front = await client.mainRoot.getMainProcess();
-      target = await TargetFactory.forRemoteTab({
-        client,
-        activeTab: front,
-        chrome: true,
-      });
+      target = await client.mainRoot.getMainProcess();
     } else {
-      const targetFront = await client.mainRoot.getTab();
-      target = await TargetFactory.forRemoteTab({
-        client,
-        activeTab: targetFront,
-      });
+      target = await client.mainRoot.getTab();
       if (attachToWorker) {
         const workerName = "console-test-worker.js#" + new Date().getTime();
         worker = new Worker(workerName);
         await waitForMessage(worker);
 
+        // listWorkers only works if the browsing context target actor is attached
+        await target.attach();
         const { workers } = await target.listWorkers();
-        const workerTargetFront = workers.filter(w => w.url == workerName)[0];
-        if (!workerTargetFront) {
+        target = workers.filter(w => w.url == workerName)[0];
+        if (!target) {
           console.error("listWorkers failed. Unable to find the worker actor\n");
           return null;
         }
-        target = await TargetFactory.forRemoteTab({
-          client,
-          activeTab: workerTargetFront,
-        });
       }
     }
 
     // Attach the Target in order to instantiate the console client
     await target.attach();
     const webConsoleClient = target.activeConsole;
     // By default the console isn't listening for anything,
     // request listeners from here