Bug 1694140 - [devtools] Stop using TargetFactory.forTab outside of devtools r=rpl,ochameau

Depends on D106000

Differential Revision: https://phabricator.services.mozilla.com/D106001
This commit is contained in:
Julian Descottes 2021-02-25 18:02:52 +00:00
parent d9b1d58f33
commit 6e37958c88
4 changed files with 19 additions and 56 deletions

View File

@ -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,

View File

@ -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);
});

View File

@ -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));
},

View File

@ -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));