From df57e6b1780b925e1190d3c572191f7e3b88f50a Mon Sep 17 00:00:00 2001 From: Victoria Ajala Date: Tue, 18 Apr 2023 21:05:49 +0000 Subject: [PATCH] Bug 1820738 - Used a custom Module base class for WebDriver BiDi. r=jdescottes Differential Revision: https://phabricator.services.mozilla.com/D175232 --- .../WindowGlobalMessageHandler.sys.mjs | 4 ---- remote/webdriver-bidi/jar.mn | 1 + .../modules/WindowGlobalBiDiModule.sys.mjs | 18 ++++++++++++++++++ .../windowglobal/browsingContext.sys.mjs | 4 ++-- .../modules/windowglobal/input.sys.mjs | 4 ++-- .../modules/windowglobal/log.sys.mjs | 6 +++--- .../modules/windowglobal/script.sys.mjs | 9 ++++----- 7 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 remote/webdriver-bidi/modules/WindowGlobalBiDiModule.sys.mjs diff --git a/remote/shared/messagehandler/WindowGlobalMessageHandler.sys.mjs b/remote/shared/messagehandler/WindowGlobalMessageHandler.sys.mjs index c1eb38523571..a881f3a16e30 100644 --- a/remote/shared/messagehandler/WindowGlobalMessageHandler.sys.mjs +++ b/remote/shared/messagehandler/WindowGlobalMessageHandler.sys.mjs @@ -59,10 +59,6 @@ export class WindowGlobalMessageHandler extends MessageHandler { return this.#innerWindowId; } - get processActor() { - return ChromeUtils.domProcessChild.getActor("WebDriverProcessData"); - } - get window() { return this.context.window; } diff --git a/remote/webdriver-bidi/jar.mn b/remote/webdriver-bidi/jar.mn index e7409d7eefb0..c9b3aea49385 100644 --- a/remote/webdriver-bidi/jar.mn +++ b/remote/webdriver-bidi/jar.mn @@ -13,6 +13,7 @@ remote.jar: # WebDriver BiDi modules content/webdriver-bidi/modules/ModuleRegistry.sys.mjs (modules/ModuleRegistry.sys.mjs) + content/webdriver-bidi/modules/WindowGlobalBiDiModule.sys.mjs (modules/WindowGlobalBiDiModule.sys.mjs) # WebDriver BiDi root modules content/webdriver-bidi/modules/root/browsingContext.sys.mjs (modules/root/browsingContext.sys.mjs) diff --git a/remote/webdriver-bidi/modules/WindowGlobalBiDiModule.sys.mjs b/remote/webdriver-bidi/modules/WindowGlobalBiDiModule.sys.mjs new file mode 100644 index 000000000000..5e5e04692eef --- /dev/null +++ b/remote/webdriver-bidi/modules/WindowGlobalBiDiModule.sys.mjs @@ -0,0 +1,18 @@ +/* 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/. */ + +import { Module } from "chrome://remote/content/shared/messagehandler/Module.sys.mjs"; + +/** + * Base class for all WindowGlobal BiDi MessageHandler modules. + */ +export class WindowGlobalBiDiModule extends Module { + get nodeCache() { + return this.processActor.getNodeCache(); + } + + get processActor() { + return ChromeUtils.domProcessChild.getActor("WebDriverProcessData"); + } +} diff --git a/remote/webdriver-bidi/modules/windowglobal/browsingContext.sys.mjs b/remote/webdriver-bidi/modules/windowglobal/browsingContext.sys.mjs index a557461d1a8b..675626353cf2 100644 --- a/remote/webdriver-bidi/modules/windowglobal/browsingContext.sys.mjs +++ b/remote/webdriver-bidi/modules/windowglobal/browsingContext.sys.mjs @@ -2,7 +2,7 @@ * 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/. */ -import { Module } from "chrome://remote/content/shared/messagehandler/Module.sys.mjs"; +import { WindowGlobalBiDiModule } from "chrome://remote/content/webdriver-bidi/modules/WindowGlobalBiDiModule.sys.mjs"; const lazy = {}; @@ -10,7 +10,7 @@ ChromeUtils.defineESModuleGetters(lazy, { LoadListener: "chrome://remote/content/shared/listeners/LoadListener.sys.mjs", }); -class BrowsingContextModule extends Module { +class BrowsingContextModule extends WindowGlobalBiDiModule { #loadListener; #subscribedEvents; diff --git a/remote/webdriver-bidi/modules/windowglobal/input.sys.mjs b/remote/webdriver-bidi/modules/windowglobal/input.sys.mjs index be72cff16e97..a0d3f181a717 100644 --- a/remote/webdriver-bidi/modules/windowglobal/input.sys.mjs +++ b/remote/webdriver-bidi/modules/windowglobal/input.sys.mjs @@ -2,7 +2,7 @@ * 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/. */ -import { Module } from "chrome://remote/content/shared/messagehandler/Module.sys.mjs"; +import { WindowGlobalBiDiModule } from "chrome://remote/content/webdriver-bidi/modules/WindowGlobalBiDiModule.sys.mjs"; const lazy = {}; @@ -10,7 +10,7 @@ ChromeUtils.defineESModuleGetters(lazy, { action: "chrome://remote/content/shared/webdriver/Actions.sys.mjs", }); -class InputModule extends Module { +class InputModule extends WindowGlobalBiDiModule { #actionState; constructor(messageHandler) { diff --git a/remote/webdriver-bidi/modules/windowglobal/log.sys.mjs b/remote/webdriver-bidi/modules/windowglobal/log.sys.mjs index 793e80f91316..061b0d7702e3 100644 --- a/remote/webdriver-bidi/modules/windowglobal/log.sys.mjs +++ b/remote/webdriver-bidi/modules/windowglobal/log.sys.mjs @@ -2,7 +2,7 @@ * 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/. */ -import { Module } from "chrome://remote/content/shared/messagehandler/Module.sys.mjs"; +import { WindowGlobalBiDiModule } from "chrome://remote/content/webdriver-bidi/modules/WindowGlobalBiDiModule.sys.mjs"; const lazy = {}; @@ -18,7 +18,7 @@ ChromeUtils.defineESModuleGetters(lazy, { "chrome://remote/content/webdriver-bidi/RemoteValue.sys.mjs", }); -class LogModule extends Module { +class LogModule extends WindowGlobalBiDiModule { #consoleAPIListener; #consoleMessageListener; #subscribedEvents; @@ -137,7 +137,7 @@ class LogModule extends Module { text += args.map(String).join(" "); // Serialize each arg as remote value. - const nodeCache = this.messageHandler.processActor.getNodeCache(); + const nodeCache = this.nodeCache; const serializedArgs = []; for (const arg of args) { // Note that we can pass a `null` realm for now since realms are only diff --git a/remote/webdriver-bidi/modules/windowglobal/script.sys.mjs b/remote/webdriver-bidi/modules/windowglobal/script.sys.mjs index 5510e63f00e4..be7998d677f2 100644 --- a/remote/webdriver-bidi/modules/windowglobal/script.sys.mjs +++ b/remote/webdriver-bidi/modules/windowglobal/script.sys.mjs @@ -2,7 +2,7 @@ * 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/. */ -import { Module } from "chrome://remote/content/shared/messagehandler/Module.sys.mjs"; +import { WindowGlobalBiDiModule } from "chrome://remote/content/webdriver-bidi/modules/WindowGlobalBiDiModule.sys.mjs"; const lazy = {}; @@ -33,7 +33,7 @@ const EvaluationStatus = { Throw: "throw", }; -class ScriptModule extends Module { +class ScriptModule extends WindowGlobalBiDiModule { #defaultRealm; #observerListening; #preloadScripts; @@ -325,7 +325,7 @@ class ScriptModule extends Module { } = options; const realm = this.#getRealm(realmId, sandboxName); - const nodeCache = this.messageHandler.processActor.getNodeCache(); + const nodeCache = this.nodeCache; const deserializedArguments = commandArguments !== null @@ -411,7 +411,6 @@ class ScriptModule extends Module { } = options; const realm = this.#getRealm(realmId, sandboxName); - const nodeCache = this.messageHandler.processActor.getNodeCache(); const rv = realm.executeInGlobal(expression); @@ -422,7 +421,7 @@ class ScriptModule extends Module { resultOwnership, serializationOptions, { - nodeCache, + nodeCache: this.nodeCache, } ); }