2020-09-12 05:39:32 +03:00
|
|
|
/* 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/. */
|
|
|
|
|
2022-10-20 14:37:01 +03:00
|
|
|
const { GeckoViewUtils } = ChromeUtils.importESModule(
|
|
|
|
"resource://gre/modules/GeckoViewUtils.sys.mjs"
|
2020-09-12 05:39:32 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
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() {
|
2022-05-17 04:34:40 +03:00
|
|
|
const { browsingContext } = this;
|
|
|
|
// If this is a chrome actor, the chrome window will be at
|
|
|
|
// browsingContext.window.
|
|
|
|
if (!browsingContext.isContent && browsingContext.window) {
|
|
|
|
return browsingContext.window;
|
|
|
|
}
|
|
|
|
return this.browser?.ownerGlobal;
|
2020-09-12 05:39:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
get eventDispatcher() {
|
2022-05-17 04:34:40 +03:00
|
|
|
return this.window?.moduleManager.eventDispatcher;
|
2020-09-12 05:39:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
receiveMessage(aMessage) {
|
2022-05-17 04:34:40 +03:00
|
|
|
if (!this.window) {
|
|
|
|
// If we have no window, it means that this browsingContext has been
|
|
|
|
// destroyed already and there's nothing to do here for us.
|
|
|
|
debug`receiveMessage window destroyed ${aMessage.name} ${aMessage.data?.type}`;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (aMessage.name) {
|
|
|
|
case "DispatcherMessage":
|
|
|
|
return this.eventDispatcher.sendRequest(aMessage.data);
|
|
|
|
case "DispatcherQuery":
|
|
|
|
return this.eventDispatcher.sendRequestForResult(aMessage.data);
|
|
|
|
}
|
|
|
|
|
2020-09-12 05:39:32 +03:00
|
|
|
// By default messages are forwarded to the module.
|
2022-05-17 04:34:40 +03:00
|
|
|
return this.window.moduleManager.onMessageFromActor(this.name, aMessage);
|
2020-09-12 05:39:32 +03:00
|
|
|
}
|
|
|
|
}
|
2022-05-17 04:34:40 +03:00
|
|
|
|
|
|
|
const { debug, warn } = GeckoViewUtils.initLogging("GeckoViewActorParent");
|