Bug 1506548 - Return WorkerTargetFront from listWorkers instead of form. r=yulia

MozReview-Commit-ID: 4CBQNwC8tKq

Depends on D11762

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alexandre Poirot 2018-11-15 10:23:50 +00:00
Родитель 3d2b60f108
Коммит 49ef5b5792
24 изменённых файлов: 83 добавлений и 116 удалений

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

@ -35,7 +35,7 @@ const {
RUNTIMES,
} = require("../constants");
function inspectDebugTarget(type, id) {
function inspectDebugTarget({ type, id, front }) {
return async (_, getState) => {
const runtime = getCurrentRuntime(getState().runtimes);
const { runtimeDetails, type: runtimeType } = runtime;
@ -65,7 +65,7 @@ function inspectDebugTarget(type, id) {
}
case DEBUG_TARGETS.WORKER: {
// Open worker toolbox in new window.
gDevToolsBrowser.openWorkerToolbox(runtimeDetails.client, id);
gDevToolsBrowser.openWorkerToolbox(front);
break;
}

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

@ -26,7 +26,7 @@ class InspectAction extends PureComponent {
inspect() {
const { dispatch, target } = this.props;
dispatch(Actions.inspectDebugTarget(target.type, target.id));
dispatch(Actions.inspectDebugTarget(target));
}
render() {

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

@ -42,8 +42,9 @@ function getServiceWorkerStatus(isActive, isRunning) {
function toComponentData(workers, isServiceWorker) {
return workers.map(worker => {
// Here `worker` is the worker object created by RootFront.listAllWorkers
const type = DEBUG_TARGETS.WORKER;
const id = worker.workerTargetActor;
const front = worker.workerTargetFront;
const icon = "chrome://devtools/skin/images/debugging-workers.svg";
let { fetch, name, registrationActor, scope } = worker;
let isActive = false;
@ -54,14 +55,14 @@ function toComponentData(workers, isServiceWorker) {
fetch = fetch ? SERVICE_WORKER_FETCH_STATES.LISTENING
: SERVICE_WORKER_FETCH_STATES.NOT_LISTENING;
isActive = worker.active;
isRunning = !!worker.workerTargetActor;
isRunning = !!worker.workerTargetFront;
status = getServiceWorkerStatus(isActive, isRunning);
}
return {
name,
icon,
id,
front,
type,
details: {
fetch,

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

@ -33,7 +33,7 @@ class ServiceWorkerTarget extends Component {
scope: PropTypes.string.isRequired,
// registrationActor can be missing in e10s.
registrationActor: PropTypes.string,
workerTargetActor: PropTypes.string,
workerTargetFront: PropTypes.object,
}).isRequired,
};
}
@ -85,8 +85,8 @@ class ServiceWorkerTarget extends Component {
return;
}
const { client, target } = this.props;
gDevToolsBrowser.openWorkerToolbox(client, target.workerTargetActor);
const { workerTargetFront } = this.props.target;
gDevToolsBrowser.openWorkerToolbox(workerTargetFront);
}
push() {
@ -97,11 +97,8 @@ class ServiceWorkerTarget extends Component {
return;
}
const { client, target } = this.props;
client.request({
to: target.workerTargetActor,
type: "push",
});
const { workerTargetFront } = this.props.target;
workerTargetFront.push();
}
start() {
@ -149,7 +146,7 @@ class ServiceWorkerTarget extends Component {
isRunning() {
// We know the target is running if it has a worker actor.
return !!this.props.target.workerTargetActor;
return !!this.props.target.workerTargetFront;
}
isActive() {

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

@ -27,7 +27,7 @@ class WorkerTarget extends Component {
target: PropTypes.shape({
icon: PropTypes.string,
name: PropTypes.string.isRequired,
workerTargetActor: PropTypes.string,
workerTargetFront: PropTypes.object,
}).isRequired,
};
}
@ -38,8 +38,8 @@ class WorkerTarget extends Component {
}
debug() {
const { client, target } = this.props;
gDevToolsBrowser.openWorkerToolbox(client, target.workerTargetActor);
const { workerTargetFront } = this.props.target;
gDevToolsBrowser.openWorkerToolbox(workerTargetFront);
}
render() {

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

@ -35,7 +35,7 @@ class Worker extends Component {
scope: PropTypes.string.isRequired,
// registrationActor can be missing in e10s.
registrationActor: PropTypes.string,
workerTargetActor: PropTypes.string,
workerTargetFront: PropTypes.object,
}).isRequired,
};
}
@ -54,8 +54,8 @@ class Worker extends Component {
return;
}
const { client, worker } = this.props;
gDevToolsBrowser.openWorkerToolbox(client, worker.workerTargetActor);
const { workerTargetFront } = this.props.worker;
gDevToolsBrowser.openWorkerToolbox(workerTargetFront);
}
start() {
@ -81,7 +81,7 @@ class Worker extends Component {
isRunning() {
// We know the worker is running if it has a worker actor.
return !!this.props.worker.workerTargetActor;
return !!this.props.worker.workerTargetFront;
}
isActive() {

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

@ -6,6 +6,7 @@
const { Task } = require("devtools/shared/task");
const { LocalizationHelper } = require("devtools/shared/l10n");
const { gDevTools } = require("devtools/client/framework/devtools");
const { gDevToolsBrowser } = require("devtools/client/framework/devtools-browser");
const { TargetFactory } = require("devtools/client/framework/target");
const { Toolbox } = require("devtools/client/framework/toolbox");
loader.lazyRequireGetter(this, "openContentLink", "devtools/client/shared/link", true);
@ -67,12 +68,8 @@ DebuggerPanel.prototype = {
openContentLink(url);
},
openWorkerToolbox: async function(worker) {
const [response, workerTargetFront] =
await this.toolbox.target.client.attachWorker(worker.actor);
const workerTarget = TargetFactory.forWorker(workerTargetFront);
const toolbox = await gDevTools.showToolbox(workerTarget, "jsdebugger", Toolbox.HostType.WINDOW);
toolbox.once("destroy", () => workerTargetFront.detach());
openWorkerToolbox: function(workerTargetFront) {
return gDevToolsBrowser.openWorkerToolbox(workerTargetFront, "jsdebugger");
},
getFrames: function() {

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

@ -16,7 +16,7 @@ import type { Worker } from "../../types";
export class Workers extends PureComponent {
props: {
workers: List<Worker>,
openWorkerToolbox: string => void
openWorkerToolbox: object => void
};
renderWorkers(workers) {

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

@ -951,11 +951,6 @@ function findWorker(workers, url) {
return null;
}
function attachWorker(targetFront, worker) {
info("Attaching to worker with url '" + worker.url + "'.");
return targetFront.attachWorker(worker.actor);
}
function waitForWorkerListChanged(targetFront) {
info("Waiting for worker list to change.");
return targetFront.once("workerListChanged");
@ -1135,8 +1130,7 @@ async function initWorkerDebugger(TAB_URL, WORKER_URL) {
await createWorkerInTab(tab, WORKER_URL);
let { workers } = await listWorkers(targetFront);
let [, workerTargetFront] = await attachWorker(targetFront,
findWorker(workers, WORKER_URL));
let workerTargetFront = findWorker(workers, WORKER_URL);
let toolbox = await gDevTools.showToolbox(TargetFactory.forWorker(workerTargetFront),
"jsdebugger",

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

@ -374,14 +374,14 @@ var gDevToolsBrowser = exports.gDevToolsBrowser = {
* Open a window-hosted toolbox to debug the worker associated to the provided
* worker actor.
*
* @param {DebuggerClient} client
* @param {Object} workerTargetActor
* worker actor form to debug
* @param {WorkerTargetFront} workerTargetFront
* worker actor front to debug
* @param {String} toolId (optional)
* The id of the default tool to show
*/
async openWorkerToolbox(client, workerTargetActor) {
const [, workerTargetFront] = await client.attachWorker(workerTargetActor);
async openWorkerToolbox(workerTargetFront, toolId) {
const workerTarget = TargetFactory.forWorker(workerTargetFront);
const toolbox = await gDevTools.showToolbox(workerTarget, null, Toolbox.HostType.WINDOW);
const toolbox = await gDevTools.showToolbox(workerTarget, toolId, Toolbox.HostType.WINDOW);
toolbox.once("destroy", () => workerTargetFront.detach());
},

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

@ -579,10 +579,16 @@ Target.prototype = {
} else if (this.isLegacyAddon) {
const [, addonTargetFront] = await this._client.attachAddon(this.form);
this.activeTab = addonTargetFront;
} else if (this.isWorkerTarget || this.isContentProcess) {
// Worker and Content process targets are the first target to have their front already
// instantiated. The plan is to have all targets to have their front passed as
// constructor argument.
// Worker and Content process targets are the first target to have their front already
// instantiated. The plan is to have all targets to have their front passed as
// constructor argument.
} else if (this.isWorkerTarget) {
// Worker is the first front to be completely migrated to have only its attach
// method being called from Target.attach. Other fronts should be refactored.
await this.activeTab.attach();
} else if (this.isContentProcess) {
// ContentProcessTarget is the only one target without any attach request.
} else {
throw new Error(`Unsupported type of target. Expected target of one of the` +
` following types: BrowsingContext, ContentProcess, Worker or ` +

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

@ -44,8 +44,8 @@ function test() {
// createWorker in the tab to be resolved.
yield createWorkerInTab(tab, WORKER1_URL);
let { workers } = yield listWorkers(targetFront);
let [, workerTargetFront1] = yield attachWorker(targetFront,
findWorker(workers, WORKER1_URL));
let workerTargetFront1 = findWorker(workers, WORKER1_URL);
yield workerTargetFront1.attach();
is(workerTargetFront1.isClosed, false, "worker in tab 1 should not be closed");
executeSoon(() => {
@ -56,8 +56,8 @@ function test() {
yield createWorkerInTab(tab, WORKER2_URL);
({ workers } = yield listWorkers(targetFront));
const [, workerTargetFront2] = yield attachWorker(targetFront,
findWorker(workers, WORKER2_URL));
const workerTargetFront2 = findWorker(workers, WORKER2_URL);
yield workerTargetFront2.attach();
is(workerTargetFront2.isClosed, false, "worker in tab 2 should not be closed");
executeSoon(() => {
@ -67,8 +67,8 @@ function test() {
is(workerTargetFront2.isClosed, true, "worker in tab 2 should be closed");
({ workers } = yield listWorkers(targetFront));
[, workerTargetFront1] = yield attachWorker(targetFront,
findWorker(workers, WORKER1_URL));
workerTargetFront1 = findWorker(workers, WORKER1_URL);
yield workerTargetFront1.attach();
is(workerTargetFront1.isClosed, false, "worker in tab 1 should not be closed");
yield close(client);

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

@ -9,11 +9,6 @@ Services.scriptloader.loadSubScript(
"chrome://mochitests/content/browser/devtools/client/shared/test/helper_workers.js",
this);
// The following "connectionClosed" rejection should not be left uncaught. This
// test has been whitelisted until the issue is fixed.
ChromeUtils.import("resource://testing-common/PromiseTestUtils.jsm", this);
PromiseTestUtils.expectUncaughtRejection(/[object Object]/);
const TAB_URL = EXAMPLE_URL + "doc_WorkerTargetActor.attachThread-tab.html";
const WORKER_URL = "code_WorkerTargetActor.attachThread-worker.js";
@ -34,8 +29,7 @@ add_task(async function() {
await createWorkerInTab(tab, WORKER_URL);
const { workers } = await listWorkers(targetFront);
const [, workerTargetFront] = await attachWorker(targetFront,
findWorker(workers, WORKER_URL));
const workerTargetFront = findWorker(workers, WORKER_URL);
const toolbox = await gDevTools.showToolbox(TargetFactory.forWorker(workerTargetFront),
"jsdebugger",

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

@ -134,11 +134,6 @@ function findWorker(workers, url) {
return null;
}
function attachWorker(targetFront, worker) {
info("Attaching to worker with url '" + worker.url + "'.");
return targetFront.attachWorker(worker.actor);
}
function waitForWorkerListChanged(targetFront) {
info("Waiting for worker list to change.");
return targetFront.once("workerListChanged");
@ -190,8 +185,7 @@ async function initWorkerDebugger(TAB_URL, WORKER_URL) {
await createWorkerInTab(tab, WORKER_URL);
const { workers } = await listWorkers(targetFront);
const [, workerTargetFront] = await attachWorker(targetFront,
findWorker(workers, WORKER_URL));
const workerTargetFront = findWorker(workers, WORKER_URL);
const toolbox = await gDevTools.showToolbox(TargetFactory.forWorker(workerTargetFront),
"jsdebugger",

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

@ -655,8 +655,7 @@ const browsingContextTargetPrototype = {
this._workerTargetActorList.onListChanged = this._onWorkerTargetActorListChanged;
return {
"from": this.actorID,
"workers": actors.map((actor) => actor.form()),
workers: actors,
};
});
},

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

@ -25,7 +25,6 @@ loader.lazyRequireGetter(this, "WebConsoleClient", "devtools/shared/webconsole/c
loader.lazyRequireGetter(this, "AddonTargetFront", "devtools/shared/fronts/targets/addon", true);
loader.lazyRequireGetter(this, "RootFront", "devtools/shared/fronts/root", true);
loader.lazyRequireGetter(this, "BrowsingContextTargetFront", "devtools/shared/fronts/targets/browsing-context", true);
loader.lazyRequireGetter(this, "WorkerTargetFront", "devtools/shared/fronts/targets/worker", true);
loader.lazyRequireGetter(this, "ThreadClient", "devtools/shared/client/thread-client");
loader.lazyRequireGetter(this, "ObjectClient", "devtools/shared/client/object-client");
loader.lazyRequireGetter(this, "Pool", "devtools/shared/protocol", true);
@ -60,7 +59,7 @@ function DebuggerClient(transport) {
// Once RootClient becomes a protocol.js actor, these actors can be attached to it
// instead of this pool.
// This Pool will automatically be added to this._pools via addActorPool once the first
// Front will be added to it (in attachTarget, attachWorker,...).
// Front will be added to it (in attachTarget, ...).
// And it does not need to destroyed explicitly as all Pools are destroyed on client
// closing.
this._frontPool = new Pool(this);
@ -381,17 +380,6 @@ DebuggerClient.prototype = {
return [response, front];
},
attachWorker: async function(workerTargetActor) {
let front = this._frontPool.actor(workerTargetActor);
if (!front) {
front = new WorkerTargetFront(this, { actor: workerTargetActor });
this._frontPool.manage(front);
}
const response = await front.attach();
return [response, front];
},
/**
* Attach to an addon target actor.
*

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

@ -95,30 +95,30 @@ const RootFront = protocol.FrontClassWithSpec(rootSpec, {
});
});
workers.forEach(form => {
workers.forEach(front => {
const worker = {
name: form.url,
url: form.url,
workerTargetActor: form.actor,
name: front.url,
url: front.url,
workerTargetFront: front,
};
switch (form.type) {
switch (front.type) {
case Ci.nsIWorkerDebugger.TYPE_SERVICE:
const registration = result.service.find(r => r.scope === form.scope);
const registration = result.service.find(r => r.scope === front.scope);
if (registration) {
// XXX: Race, sometimes a ServiceWorkerRegistrationInfo doesn't
// have a scriptSpec, but its associated WorkerDebugger does.
if (!registration.url) {
registration.name = registration.url = form.url;
registration.name = registration.url = front.url;
}
registration.workerTargetActor = form.actor;
registration.workerTargetFront = front;
} else {
worker.fetch = form.fetch;
worker.fetch = front.fetch;
// If a service worker registration could not be found, this means we are in
// e10s, and registrations are not forwarded to other processes until they
// reach the activated state. Augment the worker as a registration worker to
// display it in aboutdebugging.
worker.scope = form.scope;
worker.scope = front.scope;
worker.active = false;
result.service.push(worker);
}

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

@ -101,10 +101,6 @@ protocol.FrontClassWithSpec(browsingContextTargetSpec, {
}, {
impl: "_detach",
}),
attachWorker: function(workerTargetActor) {
return this.client.attachWorker(workerTargetActor);
},
});
exports.BrowsingContextTargetFront = BrowsingContextTargetFront;

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

@ -10,16 +10,12 @@ const {custom} = protocol;
loader.lazyRequireGetter(this, "ThreadClient", "devtools/shared/client/thread-client");
const WorkerTargetFront = protocol.FrontClassWithSpec(workerTargetSpec, {
initialize: function(client, form) {
protocol.Front.prototype.initialize.call(this, client, form);
initialize: function(client) {
protocol.Front.prototype.initialize.call(this, client);
this.thread = null;
this.traits = {};
// Save the full form for Target class usage
// Do not use `form` name to avoid colliding with protocol.js's `form` method
this.targetForm = form;
// TODO: remove once ThreadClient becomes a front
this.client = client;
@ -29,6 +25,18 @@ const WorkerTargetFront = protocol.FrontClassWithSpec(workerTargetSpec, {
this.on("close", this.destroy);
},
form(json) {
this.actorID = json.actor;
// Save the full form for Target class usage.
// Do not use `form` name to avoid colliding with protocol.js's `form` method
this.targetForm = json;
this.url = json.url;
this.type = json.type;
this.scope = json.scope;
this.fetch = json.fetch;
},
get isClosed() {
return this._isClosed;
},

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

@ -272,7 +272,7 @@ const Types = exports.__TypesForTests = [
{
types: ["workerTarget"],
spec: "devtools/shared/specs/targets/worker",
front: null,
front: "devtools/shared/fronts/targets/worker",
},
{
types: ["audionode", "webaudio"],

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

@ -15,7 +15,7 @@ types.addDictType("root.listAddons", {
addons: "array:json",
});
types.addDictType("root.listWorkers", {
workers: "array:json",
workers: "array:workerTarget",
});
types.addDictType("root.listServiceWorkerRegistrations", {
registrations: "array:json",

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

@ -37,7 +37,7 @@ types.addDictType("browsingContextTarget.window", {
types.addDictType("browsingContextTarget.workers", {
error: "nullable:string",
workers: "nullable:array:json",
workers: "nullable:array:workerTarget",
});
types.addDictType("browsingContextTarget.reload", {

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

@ -7,7 +7,7 @@ const {types, Option, RetVal, generateActorSpec} = require("devtools/shared/prot
types.addDictType("contentProcessTarget.workers", {
error: "nullable:string",
workers: "nullable:array:json",
workers: "nullable:array:workerTarget",
});
const contentProcessTargetSpec = generateActorSpec({

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

@ -105,19 +105,12 @@ var _attachConsole = async function(
await waitForMessage(worker);
const { workers } = await targetFront.listWorkers();
const workerTargetActor = workers.filter(w => w.url == workerName)[0].actor;
if (!workerTargetActor) {
console.error("listWorkers failed. Unable to find the " +
"worker actor\n");
return;
}
const [workerResponse, workerTargetFront] =
await targetFront.attachWorker(workerTargetActor);
if (!workerTargetFront || workerResponse.error) {
console.error("attachWorker failed. No worker target front or " +
" error: " + workerResponse.error);
const workerTargetFront = workers.filter(w => w.url == workerName)[0];
if (!workerTargetFront) {
console.error("listWorkers failed. Unable to find the worker actor\n");
return;
}
await workerTargetFront.attach();
await workerTargetFront.attachThread({});
state.actor = workerTargetFront.targetForm.consoleActor;
state.dbgClient.attachConsole(workerTargetFront.targetForm.consoleActor, listeners)