Bug 1485676 - Rename TabTarget.makeRemote to TabTarget.attach. r=jdescottes

Summary:
Now that all the "remoting" of this method has been moved to TargetFactory.createTargetForTab,
we should rename this method to what it does now. It mostly call attach requests
of the target actor and its child console actor.
It also "connect" the webextension target actor, but I would like to eventually move that
outside of TabTarget.attach, like makeRemote.

Depends On D4078

Reviewers: yulia!

Tags: #secure-revision

Bug #: 1485676

Differential Revision: https://phabricator.services.mozilla.com/D6161

MozReview-Commit-ID: KmFi1LIUBga
This commit is contained in:
Alexandre Poirot 2018-09-18 02:10:24 -07:00
Родитель 082e20e693
Коммит fc8714580a
39 изменённых файлов: 110 добавлений и 112 удалений

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

@ -35,7 +35,7 @@ function getDevToolsPrefBranchName(extensionId) {
*/
global.getDevToolsTargetForContext = async (context) => {
if (context.devToolsTarget) {
await context.devToolsTarget.makeRemote();
await context.devToolsTarget.attach();
return context.devToolsTarget;
}
@ -49,7 +49,7 @@ global.getDevToolsTargetForContext = async (context) => {
const tab = context.devToolsToolbox.target.tab;
context.devToolsTarget = await DevToolsShim.createTargetForTab(tab);
await context.devToolsTarget.makeRemote();
await context.devToolsTarget.attach();
return context.devToolsTarget;
};

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

@ -61,7 +61,7 @@ AccessibilityPanel.prototype = {
// Local monitoring needs to make the target remote.
if (!this.target.isRemote) {
await this.target.makeRemote();
await this.target.attach();
}
this._telemetry = new Telemetry();

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

@ -24,7 +24,7 @@ class ApplicationPanel {
async open() {
if (!this.toolbox.target.isRemote) {
await this.toolbox.target.makeRemote();
await this.toolbox.target.attach();
}
await this.panelWin.Application.bootstrap({

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

@ -48,7 +48,7 @@ function navigate(target, url, waitForTargetEvent = "navigate") {
async function openNewTabAndApplicationPanel(url) {
const tab = await addTab(url);
const target = await TargetFactory.forTab(tab);
await target.makeRemote();
await target.attach();
const toolbox = await gDevTools.showToolbox(target, "application");
const panel = toolbox.getCurrentPanel();

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

@ -32,7 +32,7 @@ CanvasDebuggerPanel.prototype = {
// Local debugging needs to make the target remote.
if (!this.target.isRemote) {
targetPromise = this.target.makeRemote();
targetPromise = this.target.attach();
} else {
targetPromise = Promise.resolve(this.target);
}

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

@ -135,7 +135,8 @@ function initCallWatcherBackend(aUrl) {
});
const target = await TargetFactory.forTab(tab);
await target.makeRemote();
await target.attach();
const front = new CallWatcherFront(target.client, target.form);
return { target, front };
})();
@ -149,7 +150,7 @@ function initCanvasDebuggerBackend(aUrl) {
const tab = await addTab(aUrl);
const target = await TargetFactory.forTab(tab);
await target.makeRemote();
await target.attach();
const front = new CanvasFront(target.client, target.form);
return { target, front };
@ -163,7 +164,7 @@ function initCanvasDebuggerFrontend(aUrl) {
const tab = await addTab(aUrl);
const target = await TargetFactory.forTab(tab);
await target.makeRemote();
await target.attach();
Services.prefs.setBoolPref("devtools.canvasdebugger.enabled", true);
const toolbox = await gDevTools.showToolbox(target, "canvasdebugger");

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

@ -22,7 +22,7 @@ function DebuggerPanel(iframeWindow, toolbox) {
DebuggerPanel.prototype = {
open: async function() {
if (!this.toolbox.target.isRemote) {
await this.toolbox.target.makeRemote();
await this.toolbox.target.attach();
}
const {

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

@ -39,7 +39,7 @@ DebuggerPanel.prototype = {
// Local debugging needs to make the target remote.
if (!this.target.isRemote) {
targetPromise = this.target.makeRemote();
targetPromise = this.target.attach();
// Listen for tab switching events to manage focus when the content window
// is paused and events suppressed.
this.target.tab.addEventListener("TabSelect", this);

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

@ -46,7 +46,7 @@ DomPanel.prototype = {
// Local monitoring needs to make the target remote.
if (!this.target.isRemote) {
await this.target.makeRemote();
await this.target.attach();
}
this.initialize();

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

@ -45,7 +45,13 @@ const TargetFactory = exports.TargetFactory = {
},
/**
* Constructor a target for the given tab.
* Instantiate a target for the given tab.
*
* This will automatically:
* - spawn a DebuggerServer in the parent process,
* - create a DebuggerClient and connect it to this local DebuggerServer,
* - call RootActor's `getTab` request to retrieve the FrameTargetActor's form,
* - instantiate a TabTarget instance.
*
* @param {XULTab} tab
* The tab to use in creating a new target.
@ -109,7 +115,7 @@ const TargetFactory = exports.TargetFactory = {
let targetPromise = promiseTargets.get(options);
if (targetPromise == null) {
const target = new TabTarget(options);
targetPromise = target.makeRemote().then(() => target);
targetPromise = target.attach().then(() => target);
promiseTargets.set(options, targetPromise);
}
return targetPromise;
@ -456,77 +462,68 @@ TabTarget.prototype = {
},
/**
* Adds remote protocol capabilities to the target, so that it can be used
* for tools that support the Remote Debugging Protocol even for local
* connections.
* Attach the target and its console actor.
*
* This method will mainly call `attach` request on the target actor as well
* as the console actor.
* For webextension, it also preliminary converts addonTargetActor to a
* WebExtensionTargetActor.
*/
makeRemote: async function() {
if (this._remote) {
return this._remote;
attach() {
if (this._attach) {
return this._attach;
}
if (this._form.isWebExtension &&
this.client.mainRoot.traits.webExtensionAddonConnect) {
// The addonTargetActor form is related to a WebExtensionActor instance,
// which isn't a target actor on its own, it is an actor living in the parent
// process with access to the addon metadata, it can control the addon (e.g.
// reloading it) and listen to the AddonManager events related to the lifecycle of
// the addon (e.g. when the addon is disabled or uninstalled).
// To retrieve the target actor instance, we call its "connect" method, (which
// fetches the target actor form from a WebExtensionTargetActor instance).
const {form} = await this._client.request({
to: this._form.actor, type: "connect",
});
// Attach the target actor
const attachTarget = async () => {
const [response, tabClient] = await this._client.attachTab(this._form.actor);
this.activeTab = tabClient;
this.threadActor = response.threadActor;
};
this._form = form;
this._url = form.url;
this._title = form.title;
}
// Attach the console actor
const attachConsole = async () => {
const [, consoleClient] = await this._client.attachConsole(
this._form.consoleActor, []);
this.activeConsole = consoleClient;
this._setupRemoteListeners();
this._onInspectObject = packet => this.emit("inspect-object", packet);
this.activeConsole.on("inspectObject", this._onInspectObject);
};
this._remote = new Promise((resolve, reject) => {
const attachTab = async () => {
try {
const [response, tabClient] = await this._client.attachTab(this._form.actor);
this.activeTab = tabClient;
this.threadActor = response.threadActor;
} catch (e) {
reject("Unable to attach to the tab: " + e);
return;
}
attachConsole();
};
this._attach = (async () => {
if (this._form.isWebExtension &&
this.client.mainRoot.traits.webExtensionAddonConnect) {
// The addonTargetActor form is related to a WebExtensionActor instance,
// which isn't a target actor on its own, it is an actor living in the parent
// process with access to the addon metadata, it can control the addon (e.g.
// reloading it) and listen to the AddonManager events related to the lifecycle of
// the addon (e.g. when the addon is disabled or uninstalled).
// To retrieve the target actor instance, we call its "connect" method, (which
// fetches the target actor form from a WebExtensionTargetActor instance).
const {form} = await this._client.request({
to: this._form.actor, type: "connect",
});
const onConsoleAttached = ([response, consoleClient]) => {
this.activeConsole = consoleClient;
this._onInspectObject = packet => this.emit("inspect-object", packet);
this.activeConsole.on("inspectObject", this._onInspectObject);
resolve(null);
};
const attachConsole = () => {
this._client.attachConsole(this._form.consoleActor, [])
.then(onConsoleAttached, response => {
reject(
`Unable to attach to the console [${response.error}]: ${response.message}`);
});
};
if (this.isBrowsingContext) {
// In the remote debugging case, the protocol connection will have been
// already initialized in the connection screen code.
attachTab();
} else {
// AddonActor and chrome debugging on RootActor doesn't inherit from
// BrowsingContextTargetActor and doesn't need to be attached.
attachConsole();
this._form = form;
this._url = form.url;
this._title = form.title;
}
});
return this._remote;
this._setupRemoteListeners();
// AddonActor and chrome debugging on RootActor don't inherit from
// BrowsingContextTargetActor (i.e. this.isBrowsingContext=false) and don't need
// to be attached.
if (this.isBrowsingContext) {
await attachTarget();
}
// But all target actor have a console actor to attach
return attachConsole();
})();
return this._attach;
},
/**
@ -731,7 +728,7 @@ TabTarget.prototype = {
this._client = null;
this._tab = null;
this._form = null;
this._remote = null;
this._attach = null;
this._root = null;
this._title = null;
this._url = null;
@ -845,7 +842,7 @@ WorkerTarget.prototype = {
return undefined;
},
makeRemote: function() {
attach: function() {
return Promise.resolve();
},

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

@ -6,7 +6,7 @@ add_task(async function() {
await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser);
const target = await TargetFactory.forTab(gBrowser.selectedTab);
await target.makeRemote();
await target.attach();
is(target.tab, gBrowser.selectedTab, "Target linked to the right tab.");
const willNavigate = once(target, "will-navigate");

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

@ -10,7 +10,7 @@ var { WebAudioFront } =
require("devtools/shared/fronts/webaudio");
async function testTarget(client, target) {
await target.makeRemote();
await target.attach();
is(target.hasActor("timeline"), true, "target.hasActor() true when actor exists.");
is(target.hasActor("webaudio"), true, "target.hasActor() true when actor exists.");

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

@ -15,7 +15,7 @@ const L10N = new LocalizationHelper("devtools/client/locales/toolbox.properties"
add_task(async function() {
const tab = await addTab("about:blank");
const target = await TargetFactory.forTab(tab);
await target.makeRemote();
await target.attach();
const toolIDs = gDevTools.getToolDefinitionArray()
.filter(

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

@ -35,7 +35,7 @@ function test() {
toggleAllTools(true);
const tab = await addTab("about:blank");
const target = await TargetFactory.forTab(tab);
await target.makeRemote();
await target.attach();
await performChecks(target);
gBrowser.removeCurrentTab();
toggleAllTools(false);

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

@ -20,7 +20,7 @@ function test() {
addTab(TEST_URL).then(async () => {
target = await TargetFactory.forTab(gBrowser.selectedTab);
target.makeRemote().then(() => {
target.attach().then(() => {
toolIDs = gDevTools.getToolDefinitionArray()
.filter(def => def.isTargetSupported(target))
.map(def => def.id);

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

@ -84,7 +84,7 @@ OptionsPanel.prototype = {
async open() {
// For local debugging we need to make the target remote.
if (!this.target.isRemote) {
await this.target.makeRemote();
await this.target.attach();
}
this.setupToolsList();

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

@ -447,7 +447,7 @@ Toolbox.prototype = {
// the iframe being ready (makes startup faster)
// Load the toolbox-level actor fronts and utilities now
await this._target.makeRemote();
await this._target.attach();
// Start tracking network activity on toolbox open for targets such as tabs.
// (Workers and potentially others don't manage the console client in the target.)

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

@ -172,7 +172,7 @@ Inspector.prototype = {
localizeMarkup(this.panelDoc);
this._cssProperties = await initCssProperties(this.toolbox);
await this.target.makeRemote();
await this.target.attach();
await this._getPageStyle();
// This may throw if the document is still loading and we are

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

@ -102,7 +102,7 @@ exports.menuitems = [
async oncommand(event) {
const window = event.target.ownerDocument.defaultView;
const target = await TargetFactory.forTab(window.gBrowser.selectedTab);
await target.makeRemote();
await target.attach();
const inspectorFront = await target.getFront("inspector");
inspectorFront.pickColorFromPage({copyOnSelect: true, fromMenu: true});
},

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

@ -12,7 +12,7 @@ function NetMonitorPanel(iframeWindow, toolbox) {
NetMonitorPanel.prototype = {
async open() {
if (!this.toolbox.target.isRemote) {
await this.toolbox.target.makeRemote();
await this.toolbox.target.attach();
}
// Reuse an existing Network monitor API object if available.

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

@ -95,7 +95,7 @@ NetMonitorAPI.prototype = {
async connectBackend(connector, connection, actions, getState) {
// The connection might happen during Toolbox initialization
// so make sure the target is ready.
await connection.tabConnection.tabTarget.makeRemote();
await connection.tabConnection.tabTarget.attach();
return connector.connectFirefox(connection, actions, getState);
},

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

@ -45,7 +45,7 @@ HarAutomation.prototype = {
this.toolbox = toolbox;
const target = toolbox.target;
target.makeRemote().then(() => {
target.attach().then(() => {
this.startMonitoring(target.client, target.form);
});
},

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

@ -291,7 +291,7 @@ function initNetMonitor(url, enableCache) {
const target = await TargetFactory.forTab(tab);
await target.makeRemote();
await target.attach();
info("Target remoted.");
const toolbox = await gDevTools.showToolbox(target, "netmonitor");

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

@ -24,7 +24,7 @@ exports.initPanelInTab = async function({ tool, tab }) {
dump(`Initializing a ${tool} panel.\n`);
const target = await TargetFactory.forTab(tab);
await target.makeRemote();
await target.attach();
// Open a toolbox and wait for the connection to the performance actors
// to be opened. This is necessary because of the WebConsole's

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

@ -599,7 +599,7 @@ var Scratchpad = {
target.once("navigate", () => {
this.run().then(results => deferred.resolve(results));
});
target.makeRemote().then(() => target.activeTab.reload());
target.attach().then(() => target.activeTab.reload());
return deferred.promise;
},
@ -2099,7 +2099,7 @@ ScratchpadTab.prototype = {
scratchpadTargets.delete(aSubject);
}
});
return target.makeRemote().then(() => target);
return target.attach().then(() => target);
},
};
@ -2143,7 +2143,7 @@ ScratchpadTarget.prototype = extend(ScratchpadTab.prototype, {
if (this._target.isRemote) {
return promise.resolve(this._target);
}
return this._target.makeRemote().then(() => this._target);
return this._target.attach().then(() => this._target);
}
});

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

@ -36,7 +36,7 @@ ShaderEditorPanel.prototype = {
async open() {
// Local debugging needs to make the target remote.
if (!this.target.isRemote) {
await this.target.makeRemote();
await this.target.attach();
}
this.front = new WebGLFront(this.target.client, this.target.form);

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

@ -151,7 +151,7 @@ function initBackend(aUrl) {
const tab = await addTab(aUrl);
const target = await TargetFactory.forTab(tab);
await target.makeRemote();
await target.attach();
const front = new WebGLFront(target.client, target.form);
return { target, front };
@ -165,7 +165,7 @@ function initShaderEditor(aUrl) {
const tab = await addTab(aUrl);
const target = await TargetFactory.forTab(tab);
await target.makeRemote();
await target.attach();
Services.prefs.setBoolPref("devtools.shadereditor.enabled", true);
const toolbox = await gDevTools.showToolbox(target, "shadereditor");

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

@ -409,7 +409,7 @@ var openToolboxForTab = async function(tab, toolId, hostType) {
let toolbox;
const target = await TargetFactory.forTab(tab);
await target.makeRemote();
await target.attach();
// Check if the toolbox is already loaded.
toolbox = gDevTools.getToolbox(target);

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

@ -85,7 +85,7 @@ add_task(async function test() {
async function runTests() {
const target = await TargetFactory.forTab(gBrowser.selectedTab);
await target.makeRemote();
await target.attach();
inspector = InspectorFront(target.client, target.form);
const walker = await inspector.getWalker();
completer = new CSSCompleter({walker: walker,

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

@ -15,7 +15,7 @@ add_task(async function() {
async function runTests() {
const target = await TargetFactory.forTab(gBrowser.selectedTab);
await target.makeRemote();
await target.attach();
const inspector = InspectorFront(target.client, target.form);
const walker = await inspector.getWalker();
const {ed, win, edWin} = await setup(null, {

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

@ -39,7 +39,7 @@ class StoragePanel {
let targetPromise;
// We always interact with the target as if it were remote
if (!this.target.isRemote) {
targetPromise = this.target.makeRemote();
targetPromise = this.target.attach();
} else {
targetPromise = Promise.resolve(this.target);
}

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

@ -42,7 +42,7 @@ StyleEditorPanel.prototype = {
async open() {
// We always interact with the target as if it were remote
if (!this.target.isRemote) {
await this.target.makeRemote();
await this.target.attach();
}
this.target.on("close", this.destroy);

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

@ -25,7 +25,7 @@ WebAudioEditorPanel.prototype = {
// Local debugging needs to make the target remote.
if (!this.target.isRemote) {
targetPromise = this.target.makeRemote();
targetPromise = this.target.attach();
} else {
targetPromise = Promise.resolve(this.target);
}

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

@ -66,7 +66,7 @@ function initBackend(aUrl) {
const tab = await addTab(aUrl);
const target = await TargetFactory.forTab(tab);
await target.makeRemote();
await target.attach();
const front = new WebAudioFront(target.client, target.form);
return { target, front };
@ -85,7 +85,7 @@ function initWebAudioEditor(aUrl) {
const tab = await addTab(aUrl);
const target = await TargetFactory.forTab(tab);
await target.makeRemote();
await target.attach();
Services.prefs.setBoolPref("devtools.webaudioeditor.enabled", true);
const toolbox = await gDevTools.showToolbox(target, "webaudioeditor");

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

@ -54,7 +54,7 @@ WebConsolePanel.prototype = {
// Local debugging needs to make the target remote.
if (!this.target.isRemote) {
await this.target.makeRemote();
await this.target.attach();
}
const webConsoleUIWindow = iframe.contentWindow.wrappedJSObject;

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

@ -29,7 +29,7 @@ window.onload = function() {
const selectedTab = chromeWin.gBrowser.selectedTab;
const target = await TargetFactory.forTab(selectedTab);
await target.makeRemote();
await target.attach();
const front = FramerateFront(client, form);
front.startRecording().then(() => {

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

@ -110,11 +110,11 @@ const knownFronts = new WeakMap();
/**
* Create a CSSUsageFront only when needed (returns a promise)
* For notes on target.makeRemote(), see
* For notes on target.attach(), see
* https://bugzilla.mozilla.org/show_bug.cgi?id=1016330#c7
*/
exports.getUsage = function(trgt) {
return trgt.makeRemote().then(() => {
return trgt.attach().then(() => {
let front = knownFronts.get(trgt.client);
if (front == null && trgt.form.cssUsageActor != null) {
front = new CSSUsageFront(trgt.client, trgt.form);

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

@ -24,7 +24,7 @@ var openToolboxForTab = async function(tab, toolId, hostType) {
let toolbox;
let target = await TargetFactory.forTab(tab);
await target.makeRemote();
await target.attach();
// Check if the toolbox is already loaded.
toolbox = gDevTools.getToolbox(target);

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

@ -26,7 +26,7 @@ var openToolboxForTab = async function(tab, toolId, hostType) {
let toolbox;
let target = await TargetFactory.forTab(tab);
await target.makeRemote();
await target.attach();
// Check if the toolbox is already loaded.
toolbox = gDevTools.getToolbox(target);