From 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:47:29 +0200 Subject: Adding upstream version 115.8.0esr. Signed-off-by: Daniel Baumann --- .../modules/geckoview/GeckoViewChildModule.jsm | 87 ++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 mobile/android/modules/geckoview/GeckoViewChildModule.jsm (limited to 'mobile/android/modules/geckoview/GeckoViewChildModule.jsm') diff --git a/mobile/android/modules/geckoview/GeckoViewChildModule.jsm b/mobile/android/modules/geckoview/GeckoViewChildModule.jsm new file mode 100644 index 0000000000..6a81247b36 --- /dev/null +++ b/mobile/android/modules/geckoview/GeckoViewChildModule.jsm @@ -0,0 +1,87 @@ +/* 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/. */ + +"use strict"; + +var EXPORTED_SYMBOLS = ["GeckoViewChildModule"]; + +const { GeckoViewUtils } = ChromeUtils.importESModule( + "resource://gre/modules/GeckoViewUtils.sys.mjs" +); + +const { debug, warn } = GeckoViewUtils.initLogging("Module[C]"); + +class GeckoViewChildModule { + static initLogging(aModuleName) { + this._moduleName = aModuleName; + const tag = aModuleName.replace("GeckoView", "") + "[C]"; + return GeckoViewUtils.initLogging(tag); + } + + static create(aGlobal, aModuleName) { + return new this(aModuleName || this._moduleName, aGlobal); + } + + constructor(aModuleName, aGlobal) { + this.moduleName = aModuleName; + this.messageManager = aGlobal; + this.enabled = false; + + if (!aGlobal._gvEventDispatcher) { + aGlobal._gvEventDispatcher = GeckoViewUtils.getDispatcherForWindow( + aGlobal.content + ); + aGlobal.addEventListener( + "unload", + event => { + if (event.target === this.messageManager) { + aGlobal._gvEventDispatcher.finalize(); + } + }, + { + mozSystemGroup: true, + } + ); + } + this.eventDispatcher = aGlobal._gvEventDispatcher; + + this.messageManager.addMessageListener( + "GeckoView:UpdateModuleState", + aMsg => { + if (aMsg.data.module !== this.moduleName) { + return; + } + + const { enabled } = aMsg.data; + + if (enabled !== this.enabled) { + if (!enabled) { + this.onDisable(); + } + + this.enabled = enabled; + + if (enabled) { + this.onEnable(); + } + } + } + ); + + this.onInit(); + + this.messageManager.sendAsyncMessage("GeckoView:ContentModuleLoaded", { + module: this.moduleName, + }); + } + + // Override to initialize module. + onInit() {} + + // Override to enable module after setting a Java delegate. + onEnable() {} + + // Override to disable module after clearing the Java delegate. + onDisable() {} +} -- cgit v1.2.3