Bug 1694140 - [devtools] Stop using TargetFactory.forTab in devtools code r=perftest-reviewers,ochameau

Depends on D105998

Differential Revision: https://phabricator.services.mozilla.com/D105999
This commit is contained in:
Julian Descottes 2021-02-25 12:58:14 +00:00
Родитель a49f853e14
Коммит 5b183d1d77
7 изменённых файлов: 58 добавлений и 96 удалений

Просмотреть файл

@ -16,13 +16,7 @@ const { Cc, Ci } = require("chrome");
const Services = require("Services");
const { gDevTools } = require("devtools/client/framework/devtools");
// Load target and toolbox lazily as they need gDevTools to be fully initialized
loader.lazyRequireGetter(
this,
"TargetFactory",
"devtools/client/framework/target",
true
);
// Load toolbox lazily as it needs gDevTools to be fully initialized
loader.lazyRequireGetter(
this,
"Toolbox",
@ -104,17 +98,16 @@ var gDevToolsBrowser = (exports.gDevToolsBrowser = {
*/
// used by browser-sets.inc, command
async toggleToolboxCommand(gBrowser, startTime) {
const target = await TargetFactory.forTab(gBrowser.selectedTab);
const toolbox = gDevTools.getToolbox(target);
const toolbox = await gDevTools.getToolboxForTab(gBrowser.selectedTab);
// If a toolbox exists, using toggle from the Main window :
// - should close a docked toolbox
// - should focus a windowed toolbox
const isDocked = toolbox && toolbox.hostType != Toolbox.HostType.WINDOW;
if (isDocked) {
gDevTools.closeToolbox(target);
gDevTools.closeToolboxForTab(gBrowser.selectedTab);
} else {
gDevTools.showToolbox(target, null, null, null, startTime);
gDevTools.showToolboxForTab(gBrowser.selectedTab, { startTime });
}
},
@ -235,8 +228,8 @@ var gDevToolsBrowser = (exports.gDevToolsBrowser = {
return;
}
const target = await TargetFactory.forTab(win.gBrowser.selectedTab);
const toolbox = gDevTools.getToolbox(target);
const tab = win.gBrowser.selectedTab;
const toolbox = await gDevTools.getToolboxForTab(tab);
const toolDefinition = gDevTools.getToolDefinition(toolId);
if (
@ -259,15 +252,11 @@ var gDevToolsBrowser = (exports.gDevToolsBrowser = {
gDevTools.emit("select-tool-command", toolId);
} else {
gDevTools
.showToolbox(
target,
toolId,
null,
null,
.showToolboxForTab(tab, {
raise: !toolDefinition.preventRaisingOnKey,
startTime,
undefined,
!toolDefinition.preventRaisingOnKey
)
toolId,
})
.then(newToolbox => {
newToolbox.fireCustomKey(toolId);
gDevTools.emit("select-tool-command", toolId);
@ -468,42 +457,42 @@ var gDevToolsBrowser = (exports.gDevToolsBrowser = {
);
async function slowScriptDebugHandler(tab, callback) {
const target = await TargetFactory.forTab(tab);
gDevTools
.showToolboxForTab(tab, { toolId: "jsdebugger" })
.then(toolbox => {
const threadFront = toolbox.threadFront;
gDevTools.showToolbox(target, "jsdebugger").then(toolbox => {
const threadFront = toolbox.threadFront;
// Break in place, which means resuming the debuggee thread and pausing
// right before the next step happens.
switch (threadFront.state) {
case "paused":
// When the debugger is already paused.
threadFront.resumeThenPause();
callback();
break;
case "attached":
// When the debugger is already open.
threadFront.interrupt().then(() => {
// Break in place, which means resuming the debuggee thread and pausing
// right before the next step happens.
switch (threadFront.state) {
case "paused":
// When the debugger is already paused.
threadFront.resumeThenPause();
callback();
});
break;
case "resuming":
// The debugger is newly opened.
threadFront.once("resumed", () => {
break;
case "attached":
// When the debugger is already open.
threadFront.interrupt().then(() => {
threadFront.resumeThenPause();
callback();
});
});
break;
default:
throw Error(
"invalid thread front state in slow script debug handler: " +
threadFront.state
);
}
});
break;
case "resuming":
// The debugger is newly opened.
threadFront.once("resumed", () => {
threadFront.interrupt().then(() => {
threadFront.resumeThenPause();
callback();
});
});
break;
default:
throw Error(
"invalid thread front state in slow script debug handler: " +
threadFront.state
);
}
});
}
debugService.activationHandler = function(window) {

Просмотреть файл

@ -765,16 +765,11 @@ DevTools.prototype = {
* markup view.
*/
async inspectNode(tab, domReference, startTime) {
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(
target,
"inspector",
null,
null,
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "inspector",
startTime,
"inspect_dom"
);
reason: "inspect_dom",
});
const inspector = toolbox.getCurrentPanel();
const nodeFront = await inspector.inspectorFront.getNodeActorFromContentDomReference(
@ -813,15 +808,10 @@ DevTools.prototype = {
* selected in the accessibility inspector.
*/
async inspectA11Y(tab, domReference, startTime) {
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(
target,
"accessibility",
null,
null,
startTime
);
const toolbox = await gDevTools.showToolboxForTab(tab, {
toolId: "accessibility",
startTime,
});
const inspectorFront = await toolbox.target.getFront("inspector");
const nodeFront = await inspectorFront.getNodeActorFromContentDomReference(
domReference

Просмотреть файл

@ -144,8 +144,7 @@ class ResponsiveUIManager {
const isKnownTab = TargetFactory.isKnownTab(tab);
let toolbox;
if (isKnownTab) {
const target = await TargetFactory.forTab(tab);
toolbox = gDevTools.getToolbox(target);
toolbox = await gDevTools.getToolboxForTab(tab);
}
const hostType = toolbox ? toolbox.hostType : "none";
const hasToolbox = !!toolbox;
@ -215,8 +214,7 @@ class ResponsiveUIManager {
const isKnownTab = TargetFactory.isKnownTab(tab);
let toolbox;
if (isKnownTab) {
const target = await TargetFactory.forTab(tab);
toolbox = gDevTools.getToolbox(target);
toolbox = await gDevTools.getToolboxForTab(tab);
}
const hostType = toolbox ? toolbox.hostType : "none";

Просмотреть файл

@ -4,12 +4,6 @@
"use strict";
loader.lazyRequireGetter(
this,
"TargetFactory",
"devtools/client/framework/target",
true
);
loader.lazyRequireGetter(
this,
"gDevTools",
@ -44,8 +38,7 @@ async function showNotification(
// toolbox for the tab. If one exists, use the toolbox's notification box so that the
// message is placed closer to the action taken by the user.
if (toolboxButton) {
const target = await TargetFactory.forTab(tab);
const toolbox = gDevTools.getToolbox(target);
const toolbox = gDevTools.getToolboxForTab(tab);
if (toolbox) {
nbox = toolbox.notificationBox;
}

Просмотреть файл

@ -380,8 +380,7 @@ add_task(async function() {
async function openAndCloseToolbox(toolId, host) {
const tab = await addTab(URL);
const target = await TargetFactory.forTab(tab);
const toolbox = await gDevTools.showToolbox(target, toolId);
const toolbox = await gDevTools.showToolboxForTab(tab, { toolId });
await toolbox.switchHost(host);
await toolbox.destroy();

Просмотреть файл

@ -1033,9 +1033,7 @@ DevToolsStartup.prototype = {
handleDevToolsFlag: async function(window) {
const require = this.initDevTools("CommandLine");
const { gDevTools } = require("devtools/client/framework/devtools");
const { TargetFactory } = require("devtools/client/framework/target");
const target = await TargetFactory.forTab(window.gBrowser.selectedTab);
gDevTools.showToolbox(target);
await gDevTools.showToolboxForTab(window.gBrowser.selectedTab);
},
_isRemoteDebuggingEnabled() {

Просмотреть файл

@ -10,7 +10,6 @@
const Services = require("Services");
const { gDevTools } = require("devtools/client/framework/devtools");
const { TargetFactory } = require("devtools/client/framework/target");
// With Bug 1588203, the talos server supports a dynamic proxy that will
// redirect any http:// call to the talos server. This means we can use
@ -79,8 +78,7 @@ exports.getActiveTab = getActiveTab;
exports.getToolbox = async function() {
let tab = getActiveTab();
let target = await TargetFactory.forTab(tab);
return gDevTools.getToolbox(target);
return gDevTools.getToolboxForTab(tab);
};
/**
@ -100,12 +98,9 @@ const openToolbox = async function(tool = "webconsole", onLoad) {
dump(`Open toolbox on '${tool}'\n`);
let tab = getActiveTab();
dump(`Open toolbox - Wait for tab target\n`);
let target = await TargetFactory.forTab(tab);
dump(`Open toolbox - Call showToolbox\n`);
dump(`Open toolbox - Call showToolboxForTab\n`);
let onToolboxCreated = gDevTools.once("toolbox-created");
let showPromise = gDevTools.showToolbox(target, tool);
let showPromise = gDevTools.showToolboxForTab(tab, { toolId: tool });
dump(`Open toolbox - Wait for "toolbox-created"\n`);
let toolbox = await onToolboxCreated;
@ -125,9 +120,9 @@ exports.openToolbox = openToolbox;
exports.closeToolbox = async function() {
let tab = getActiveTab();
let target = await TargetFactory.forTab(tab);
await target.client.waitForRequestsToSettle();
await gDevTools.closeToolbox(target);
let toolbox = await gDevTools.getToolboxForTab(tab);
await toolbox.target.client.waitForRequestsToSettle();
await gDevTools.closeToolboxForTab(tab);
};
// Settle test isn't recorded, it only prints the pending duration