From 6e37958c88d4f8b65324a940693a0e4c494333e8 Mon Sep 17 00:00:00 2001 From: Julian Descottes Date: Thu, 25 Feb 2021 18:02:52 +0000 Subject: [PATCH] Bug 1694140 - [devtools] Stop using TargetFactory.forTab outside of devtools r=rpl,ochameau Depends on D106000 Differential Revision: https://phabricator.services.mozilla.com/D106001 --- .../extensions/test/browser/head_devtools.js | 24 ++++++--------- .../devtools/browser_devtools.js | 4 +-- .../extension/configurations/DevTools.jsm | 29 +++++-------------- dom/security/test/cors/head.js | 18 +----------- 4 files changed, 19 insertions(+), 56 deletions(-) diff --git a/browser/components/extensions/test/browser/head_devtools.js b/browser/components/extensions/test/browser/head_devtools.js index 7b4d602d4cfb..cb966be055e3 100644 --- a/browser/components/extensions/test/browser/head_devtools.js +++ b/browser/components/extensions/test/browser/head_devtools.js @@ -2,7 +2,7 @@ /* vim: set sts=2 sw=2 et tw=80: */ "use strict"; -/* exported openToolboxForTab, closeToolboxForTab, getToolboxTargetForTab, +/* exported openToolboxForTab, closeToolboxForTab, registerBlankToolboxPanel, TOOLBOX_BLANK_PANEL_ID, assertDevToolsExtensionEnabled */ ChromeUtils.defineModuleGetter( @@ -14,10 +14,6 @@ XPCOMUtils.defineLazyGetter(this, "gDevTools", () => { const { gDevTools } = loader.require("devtools/client/framework/devtools"); return gDevTools; }); -XPCOMUtils.defineLazyGetter(this, "TargetFactory", () => { - const { TargetFactory } = loader.require("devtools/client/framework/target"); - return TargetFactory; -}); ChromeUtils.defineModuleGetter( this, @@ -56,10 +52,6 @@ async function registerBlankToolboxPanel() { gDevTools.registerTool(testBlankPanel); } -function getToolboxTargetForTab(tab) { - return TargetFactory.forTab(tab); -} - async function openToolboxForTab(tab, panelId = TOOLBOX_BLANK_PANEL_ID) { if ( panelId == TOOLBOX_BLANK_PANEL_ID && @@ -69,22 +61,24 @@ async function openToolboxForTab(tab, panelId = TOOLBOX_BLANK_PANEL_ID) { registerBlankToolboxPanel(); } - const target = await getToolboxTargetForTab(tab); - const toolbox = await gDevTools.showToolbox(target, panelId); - const { url, outerWindowID } = target.form; + const toolbox = await gDevTools.showToolboxForTab(tab, { toolId: panelId }); + const { url, outerWindowID } = toolbox.target.form; info( `Developer toolbox opened on panel "${panelId}" for target ${JSON.stringify( { url, outerWindowID } )}` ); - return { toolbox, target }; + return { toolbox, target: toolbox.target }; } async function closeToolboxForTab(tab) { - const target = await getToolboxTargetForTab(tab); + const toolbox = await gDevTools.getToolboxForTab(tab); + const target = toolbox.target; const { url, outerWindowID } = target.form; - await gDevTools.closeToolbox(target); + + await gDevTools.closeToolboxForTab(tab); await target.destroy(); + info( `Developer toolbox closed for target ${JSON.stringify({ url, diff --git a/browser/tools/mozscreenshots/devtools/browser_devtools.js b/browser/tools/mozscreenshots/devtools/browser_devtools.js index 367bda2617c7..5f2504bc7233 100644 --- a/browser/tools/mozscreenshots/devtools/browser_devtools.js +++ b/browser/tools/mozscreenshots/devtools/browser_devtools.js @@ -7,7 +7,6 @@ "use strict"; const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm"); -const { TargetFactory } = require("devtools/client/framework/target"); const { gDevTools } = require("devtools/client/framework/devtools"); add_task(async function capture() { @@ -18,6 +17,5 @@ add_task(async function capture() { await TestRunner.start(sets, "devtools"); - let target = await TargetFactory.forTab(gBrowser.selectedTab); - await gDevTools.closeToolbox(target); + await gDevTools.closeToolboxForTab(gBrowser.selectedTab); }); diff --git a/browser/tools/mozscreenshots/mozscreenshots/extension/configurations/DevTools.jsm b/browser/tools/mozscreenshots/mozscreenshots/extension/configurations/DevTools.jsm index a15e1ea77a55..937c60a80cac 100644 --- a/browser/tools/mozscreenshots/mozscreenshots/extension/configurations/DevTools.jsm +++ b/browser/tools/mozscreenshots/mozscreenshots/extension/configurations/DevTools.jsm @@ -7,15 +7,14 @@ var EXPORTED_SYMBOLS = ["DevTools"]; const { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm"); -const { TargetFactory } = require("devtools/client/framework/target"); const { gDevTools } = require("devtools/client/framework/devtools"); const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); const { setTimeout } = ChromeUtils.import("resource://gre/modules/Timer.jsm"); -async function getTargetForSelectedTab() { - let browserWindow = Services.wm.getMostRecentWindow("navigator:browser"); - let target = await TargetFactory.forTab(browserWindow.gBrowser.selectedTab); - return target; +async function showToolboxForSelectedTab(toolId, hostType) { + const browserWindow = Services.wm.getMostRecentWindow("navigator:browser"); + const tab = browserWindow.gBrowser.selectedTab; + return gDevTools.showToolboxForTab(tab, { toolId, hostType }); } function selectToolbox(toolbox) { @@ -37,8 +36,7 @@ var DevTools = { this.configurations[panel] = {}; this.configurations[panel].applyConfig = async function() { Services.prefs.setIntPref("devtools.toolbox.footer.height", 800); - let target = await getTargetForSelectedTab(); - let toolbox = await gDevTools.showToolbox(target, panel, "bottom"); + let toolbox = await showToolboxForSelectedTab(panel, "bottom"); this.selectors = [selectToolbox.bind(null, toolbox)]; await new Promise(resolve => setTimeout(resolve, 500)); }; @@ -49,20 +47,14 @@ var DevTools = { bottomToolbox: { async applyConfig() { Services.prefs.clearUserPref("devtools.toolbox.footer.height"); - let target = await getTargetForSelectedTab(); - let toolbox = await gDevTools.showToolbox( - target, - "inspector", - "bottom" - ); + let toolbox = await showToolboxForSelectedTab("inspector", "bottom"); this.selectors = [selectToolbox.bind(null, toolbox)]; await new Promise(resolve => setTimeout(resolve, 1000)); }, }, sideToolbox: { async applyConfig() { - let target = await getTargetForSelectedTab(); - let toolbox = await gDevTools.showToolbox(target, "inspector", "right"); + let toolbox = await showToolboxForSelectedTab("inspector", "right"); this.selectors = [selectToolbox.bind(null, toolbox)]; await new Promise(resolve => setTimeout(resolve, 1000)); }, @@ -73,12 +65,7 @@ var DevTools = { undockedToolbox: { windowType: "devtools:toolbox", async applyConfig() { - let target = await getTargetForSelectedTab(); - let toolbox = await gDevTools.showToolbox( - target, - "inspector", - "window" - ); + let toolbox = await showToolboxForSelectedTab("inspector", "window"); this.selectors = [selectToolbox.bind(null, toolbox)]; await new Promise(resolve => setTimeout(resolve, 1000)); }, diff --git a/dom/security/test/cors/head.js b/dom/security/test/cors/head.js index c4356ec4658a..8e052989cd0c 100644 --- a/dom/security/test/cors/head.js +++ b/dom/security/test/cors/head.js @@ -8,7 +8,6 @@ function scopedCuImport(path) { const { loader, require } = scopedCuImport( "resource://devtools/shared/Loader.jsm" ); -const { TargetFactory } = require("devtools/client/framework/target"); const { Utils: WebConsoleUtils } = require("devtools/client/webconsole/utils"); let { gDevTools } = require("devtools/client/framework/devtools"); let promise = require("promise"); @@ -22,22 +21,7 @@ let promise = require("promise"); */ var openToolboxForTab = async function(tab, toolId, hostType) { info("Opening the toolbox"); - - let toolbox; - let target = await TargetFactory.forTab(tab); - await target.attach(); - - // Check if the toolbox is already loaded. - toolbox = gDevTools.getToolbox(target); - if (toolbox) { - if (!toolId || (toolId && toolbox.getPanel(toolId))) { - info("Toolbox is already opened"); - return toolbox; - } - } - - // If not, load it now. - toolbox = await gDevTools.showToolbox(target, toolId, hostType); + const toolbox = await gDevTools.showToolboxForTab(tab, { toolId, hostType }); // Make sure that the toolbox frame is focused. await new Promise(resolve => waitForFocus(resolve, toolbox.win));