summaryrefslogtreecommitdiffstats
path: root/mobile/android/actors/GeckoViewAutoFillParent.sys.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'mobile/android/actors/GeckoViewAutoFillParent.sys.mjs')
-rw-r--r--mobile/android/actors/GeckoViewAutoFillParent.sys.mjs89
1 files changed, 89 insertions, 0 deletions
diff --git a/mobile/android/actors/GeckoViewAutoFillParent.sys.mjs b/mobile/android/actors/GeckoViewAutoFillParent.sys.mjs
new file mode 100644
index 0000000000..d7248d61fe
--- /dev/null
+++ b/mobile/android/actors/GeckoViewAutoFillParent.sys.mjs
@@ -0,0 +1,89 @@
+/* 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 { GeckoViewActorParent } from "resource://gre/modules/GeckoViewActorParent.sys.mjs";
+
+const lazy = {};
+
+ChromeUtils.defineESModuleGetters(lazy, {
+ gAutofillManager: "resource://gre/modules/GeckoViewAutofill.sys.mjs",
+});
+
+export 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");