зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1648154 - Forward child actor messages to the relevant module. r=esawin
This patch tightens the coupling between the parent module and the child actors. Each parent module will receive messages from the corresponding child actors whenever the parent actor does not define a message handler. The parent actor also has the option to handle some messages and delegate the rest by calling `super.receiveMessage`. The idea is that every message that can be handled within the browsingContext should be handled in the parent actor, while everything that needs context across browsing contexts (e.g. page navigation listeners) should be handled in the parent module. Differential Revision: https://phabricator.services.mozilla.com/D89506
This commit is contained in:
Родитель
652cebf086
Коммит
f98d1aa2d2
|
@ -90,9 +90,13 @@ var ModuleManager = {
|
|||
this
|
||||
);
|
||||
|
||||
this._moduleByActorName = new Map();
|
||||
this.forEach(module => {
|
||||
module.onInit();
|
||||
module.loadInitFrameScript();
|
||||
for (const actorName of module.actorNames) {
|
||||
this._moduleByActorName[actorName] = module;
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener("unload", () => {
|
||||
|
@ -260,6 +264,10 @@ var ModuleManager = {
|
|||
);
|
||||
},
|
||||
|
||||
onMessageFromActor(aActorName, aMessage) {
|
||||
this._moduleByActorName[aActorName].receiveMessage(aMessage);
|
||||
},
|
||||
|
||||
onEvent(aEvent, aData, aCallback) {
|
||||
debug`onEvent ${aEvent} ${aData}`;
|
||||
switch (aEvent) {
|
||||
|
@ -357,6 +365,19 @@ class ModuleInfo {
|
|||
|
||||
this._onInitPhase = onInit;
|
||||
this._onEnablePhase = onEnable;
|
||||
|
||||
const actorNames = [];
|
||||
if (this._onInitPhase?.actors) {
|
||||
actorNames.push(Object.keys(this._onInitPhase.actors));
|
||||
}
|
||||
if (this._onEnablePhase?.actors) {
|
||||
actorNames.push(Object.keys(this._onEnablePhase.actors));
|
||||
}
|
||||
this._actorNames = Object.freeze(actorNames);
|
||||
}
|
||||
|
||||
get actorNames() {
|
||||
return this._actorNames;
|
||||
}
|
||||
|
||||
onInit() {
|
||||
|
@ -471,6 +492,14 @@ class ModuleInfo {
|
|||
this._updateContentModuleState(/* includeSettings */ aEnabled);
|
||||
}
|
||||
|
||||
receiveMessage(aMessage) {
|
||||
if (!this._impl) {
|
||||
throw new Error(`No impl for message: ${aMessage.name}.`);
|
||||
}
|
||||
|
||||
this._impl.receiveMessage(aMessage);
|
||||
}
|
||||
|
||||
onContentModuleLoaded() {
|
||||
this._updateContentModuleState(/* includeSettings */ true);
|
||||
|
||||
|
@ -655,8 +684,7 @@ function startup() {
|
|||
},
|
||||
]);
|
||||
|
||||
// TODO: Bug 1569360 Allows actors to temporarely access ModuleManager until
|
||||
// we migrate everything over to actors.
|
||||
// Allows actors to access ModuleManager.
|
||||
window.moduleManager = ModuleManager;
|
||||
|
||||
Services.tm.dispatchToMainThread(() => {
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const { GeckoViewUtils } = ChromeUtils.import(
|
||||
"resource://gre/modules/GeckoViewUtils.jsm"
|
||||
);
|
||||
|
||||
const EXPORTED_SYMBOLS = ["GeckoViewActorParent"];
|
||||
|
||||
class GeckoViewActorParent extends JSWindowActorParent {
|
||||
static initLogging(aModuleName) {
|
||||
const tag = aModuleName.replace("GeckoView", "");
|
||||
return GeckoViewUtils.initLogging(tag);
|
||||
}
|
||||
|
||||
get browser() {
|
||||
return this.browsingContext.top.embedderElement;
|
||||
}
|
||||
|
||||
get window() {
|
||||
return this.browser.ownerGlobal;
|
||||
}
|
||||
|
||||
get eventDispatcher() {
|
||||
return this.window.moduleManager.eventDispatcher;
|
||||
}
|
||||
|
||||
receiveMessage(aMessage) {
|
||||
// By default messages are forwarded to the module.
|
||||
this.window.moduleManager.onMessageFromActor(this.name, aMessage);
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ EXTRA_JS_MODULES += [
|
|||
'DelayedInit.jsm',
|
||||
'GeckoViewActorChild.jsm',
|
||||
'GeckoViewActorManager.jsm',
|
||||
'GeckoViewActorParent.jsm',
|
||||
'GeckoViewAutocomplete.jsm',
|
||||
'GeckoViewAutofill.jsm',
|
||||
'GeckoViewChildModule.jsm',
|
||||
|
|
Загрузка…
Ссылка в новой задаче