зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1503628 - Merge TabTarget and WorkerTarget. r=yulia
MozReview-Commit-ID: 58iL6HyXjM4 Depends on D11013 Differential Revision: https://phabricator.services.mozilla.com/D11014 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
1e489b18b6
Коммит
42da350649
|
@ -126,7 +126,23 @@ const TargetFactory = exports.TargetFactory = {
|
|||
forWorker: function(workerTargetFront) {
|
||||
let target = targets.get(workerTargetFront);
|
||||
if (target == null) {
|
||||
target = new WorkerTarget(workerTargetFront);
|
||||
target = new TabTarget({
|
||||
client: workerTargetFront.client,
|
||||
// Fake a form attribute until all TabTarget is merged with the Front itself
|
||||
// and will receive form attribute natively.
|
||||
get form() {
|
||||
return {
|
||||
actor: workerTargetFront.actorID,
|
||||
traits: {},
|
||||
// /!\ This depends on WorkerTargetFront.attach being called before this.
|
||||
// It happens that WorkerTargetFront is instantiated from attachWorker,
|
||||
// which instiate this class *and* calls `attach`.
|
||||
consoleActor: workerTargetFront.consoleActor,
|
||||
};
|
||||
},
|
||||
activeTab: workerTargetFront,
|
||||
chrome: false,
|
||||
});
|
||||
targets.set(workerTargetFront, target);
|
||||
}
|
||||
return target;
|
||||
|
@ -190,15 +206,18 @@ const TargetFactory = exports.TargetFactory = {
|
|||
* @param {Boolean} chrome
|
||||
* True, if we allow to see privileged resources like JSM, xpcom,
|
||||
* frame scripts...
|
||||
* @param {Front} activeTab (optional)
|
||||
* If we already have a front for this target, pass it here.
|
||||
* @param {xul:tab} tab (optional)
|
||||
* If the target is a local Firefox tab, a reference to the firefox
|
||||
* frontend tab object.
|
||||
*/
|
||||
function TabTarget({ form, client, chrome, tab = null }) {
|
||||
function TabTarget({ form, client, chrome, activeTab = null, tab = null }) {
|
||||
EventEmitter.decorate(this);
|
||||
this.destroy = this.destroy.bind(this);
|
||||
this._onTabNavigated = this._onTabNavigated.bind(this);
|
||||
this.activeTab = this.activeConsole = null;
|
||||
this.activeConsole = null;
|
||||
this.activeTab = activeTab;
|
||||
|
||||
this._form = form;
|
||||
this._url = form.url;
|
||||
|
@ -231,7 +250,7 @@ function TabTarget({ form, client, chrome, tab = null }) {
|
|||
if (this._form.traits && ("isBrowsingContext" in this._form.traits)) {
|
||||
this._isBrowsingContext = this._form.traits.isBrowsingContext;
|
||||
} else {
|
||||
this._isBrowsingContext = !this.isLegacyAddon && !this.isContentProcess;
|
||||
this._isBrowsingContext = !this.isLegacyAddon && !this.isContentProcess && !this.isWorkerTarget;
|
||||
}
|
||||
|
||||
// Cache of already created targed-scoped fronts
|
||||
|
@ -416,6 +435,10 @@ TabTarget.prototype = {
|
|||
return this.isLegacyAddon || this.isWebExtension;
|
||||
},
|
||||
|
||||
get isWorkerTarget() {
|
||||
return this.activeTab && this.activeTab.typeName === "workerTarget";
|
||||
},
|
||||
|
||||
get isLegacyAddon() {
|
||||
return !!(this._form && this._form.actor &&
|
||||
this._form.actor.match(/conn\d+\.addon(Target)?\d+/));
|
||||
|
@ -550,6 +573,9 @@ TabTarget.prototype = {
|
|||
} else if (this.isLegacyAddon) {
|
||||
const [, addonTargetFront] = await this._client.attachAddon(this._form);
|
||||
this.activeTab = addonTargetFront;
|
||||
} else if (this.isWorkerTarget) {
|
||||
// Worker target is the first target to have its front already instantiated.
|
||||
// The plan is to have all targets to have its front passed as constructor argument.
|
||||
} else {
|
||||
throw new Error(`Unsupported type of target. Expected target of one of the` +
|
||||
` following types: BrowsingContext, ContentProcess, or Addon (legacy).`);
|
||||
|
|
|
@ -47,12 +47,21 @@ const WorkerTargetFront = protocol.FrontClassWithSpec(workerTargetSpec, {
|
|||
|
||||
this.url = response.url;
|
||||
|
||||
// Immediately call `connect` in other to fetch console and thread actors
|
||||
// that will be later used by Target.
|
||||
const connectResponse = await this.connect({});
|
||||
this.consoleActor = connectResponse.consoleActor;
|
||||
this.threadActor = connectResponse.threadActor;
|
||||
|
||||
return response;
|
||||
}, {
|
||||
impl: "_attach",
|
||||
}),
|
||||
|
||||
detach: custom(async function() {
|
||||
if (this.isClosed) {
|
||||
return {};
|
||||
}
|
||||
let response;
|
||||
try {
|
||||
response = await this._detach();
|
||||
|
@ -81,18 +90,15 @@ const WorkerTargetFront = protocol.FrontClassWithSpec(workerTargetSpec, {
|
|||
return response;
|
||||
}
|
||||
|
||||
// The connect call on server doesn't attach the thread as of version 44.
|
||||
const connectResponse = await this.connect(options);
|
||||
await this.client.request({
|
||||
to: connectResponse.threadActor,
|
||||
const attachResponse = await this.client.request({
|
||||
to: this.threadActor,
|
||||
type: "attach",
|
||||
options,
|
||||
});
|
||||
this.thread = new ThreadClient(this, connectResponse.threadActor);
|
||||
this.consoleActor = connectResponse.consoleActor;
|
||||
this.thread = new ThreadClient(this, this.threadActor);
|
||||
this.client.registerClient(this.thread);
|
||||
|
||||
return [connectResponse, this.thread];
|
||||
return [attachResponse, this.thread];
|
||||
},
|
||||
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче