summaryrefslogtreecommitdiffstats
path: root/mobile/android/actors/GeckoViewAutoFillParent.jsm
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /mobile/android/actors/GeckoViewAutoFillParent.jsm
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mobile/android/actors/GeckoViewAutoFillParent.jsm')
-rw-r--r--mobile/android/actors/GeckoViewAutoFillParent.jsm101
1 files changed, 101 insertions, 0 deletions
diff --git a/mobile/android/actors/GeckoViewAutoFillParent.jsm b/mobile/android/actors/GeckoViewAutoFillParent.jsm
new file mode 100644
index 0000000000..209286b14e
--- /dev/null
+++ b/mobile/android/actors/GeckoViewAutoFillParent.jsm
@@ -0,0 +1,101 @@
+/* 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 = ["GeckoViewAutoFillParent"];
+
+const { XPCOMUtils } = ChromeUtils.importESModule(
+ "resource://gre/modules/XPCOMUtils.sys.mjs"
+);
+const { GeckoViewActorParent } = ChromeUtils.importESModule(
+ "resource://gre/modules/GeckoViewActorParent.sys.mjs"
+);
+
+const lazy = {};
+
+XPCOMUtils.defineLazyModuleGetters(lazy, {
+ gAutofillManager: "resource://gre/modules/GeckoViewAutofill.jsm",
+});
+
+class GeckoViewAutoFillParent extends GeckoViewActorParent {
+ constructor() {
+ super();
+ this.sessionId = Services.uuid
+ .generateUUID()
+ .toString()
+ .slice(1, -1); // discard the surrounding curly braces
+ }
+
+ get rootActor() {
+ return this.browsingContext.top.currentWindowGlobal.getActor(
+ "GeckoViewAutoFill"
+ );
+ }
+
+ get autofill() {
+ return lazy.gAutofillManager.get(this.sessionId);
+ }
+
+ add(node) {
+ // We will start a new session if the current one does not exist.
+ const autofill = lazy.gAutofillManager.ensure(
+ this.sessionId,
+ this.eventDispatcher
+ );
+ return autofill?.add(node);
+ }
+
+ focus(node) {
+ this.autofill?.focus(node);
+ }
+
+ commit(node) {
+ this.autofill?.commit(node);
+ }
+
+ update(node) {
+ this.autofill?.update(node);
+ }
+
+ clear() {
+ lazy.gAutofillManager.delete(this.sessionId);
+ }
+
+ async receiveMessage(aMessage) {
+ const { name } = aMessage;
+ debug`receiveMessage ${name}`;
+
+ // We need to re-route all messages through the root actor to ensure that we
+ // have a consistent sessionId for the entire browsingContext tree.
+ switch (name) {
+ case "Add": {
+ return this.rootActor.add(aMessage.data.node);
+ }
+ case "Focus": {
+ this.rootActor.focus(aMessage.data.node);
+ break;
+ }
+ case "Update": {
+ this.rootActor.update(aMessage.data.node);
+ break;
+ }
+ case "Commit": {
+ this.rootActor.commit(aMessage.data.node);
+ break;
+ }
+ case "Clear": {
+ if (this.browsingContext === this.browsingContext.top) {
+ this.clear();
+ }
+ break;
+ }
+ }
+
+ return null;
+ }
+}
+
+const { debug, warn } = GeckoViewAutoFillParent.initLogging(
+ "GeckoViewAutoFill"
+);