Bug 1891710: part 2) Enable <Element-outerHTML.html> WPT for Trusted Types. r=smaug
[gecko.git] / mobile / android / actors / GeckoViewAutoFillParent.sys.mjs
blobd7248d61feb9c07fd39c550b0482e75150a87899
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 import { GeckoViewActorParent } from "resource://gre/modules/GeckoViewActorParent.sys.mjs";
7 const lazy = {};
9 ChromeUtils.defineESModuleGetters(lazy, {
10   gAutofillManager: "resource://gre/modules/GeckoViewAutofill.sys.mjs",
11 });
13 export class GeckoViewAutoFillParent extends GeckoViewActorParent {
14   constructor() {
15     super();
16     this.sessionId = Services.uuid.generateUUID().toString().slice(1, -1); // discard the surrounding curly braces
17   }
19   get rootActor() {
20     return this.browsingContext.top.currentWindowGlobal.getActor(
21       "GeckoViewAutoFill"
22     );
23   }
25   get autofill() {
26     return lazy.gAutofillManager.get(this.sessionId);
27   }
29   add(node) {
30     // We will start a new session if the current one does not exist.
31     const autofill = lazy.gAutofillManager.ensure(
32       this.sessionId,
33       this.eventDispatcher
34     );
35     return autofill?.add(node);
36   }
38   focus(node) {
39     this.autofill?.focus(node);
40   }
42   commit(node) {
43     this.autofill?.commit(node);
44   }
46   update(node) {
47     this.autofill?.update(node);
48   }
50   clear() {
51     lazy.gAutofillManager.delete(this.sessionId);
52   }
54   async receiveMessage(aMessage) {
55     const { name } = aMessage;
56     debug`receiveMessage ${name}`;
58     // We need to re-route all messages through the root actor to ensure that we
59     // have a consistent sessionId for the entire browsingContext tree.
60     switch (name) {
61       case "Add": {
62         return this.rootActor.add(aMessage.data.node);
63       }
64       case "Focus": {
65         this.rootActor.focus(aMessage.data.node);
66         break;
67       }
68       case "Update": {
69         this.rootActor.update(aMessage.data.node);
70         break;
71       }
72       case "Commit": {
73         this.rootActor.commit(aMessage.data.node);
74         break;
75       }
76       case "Clear": {
77         if (this.browsingContext === this.browsingContext.top) {
78           this.clear();
79         }
80         break;
81       }
82     }
84     return null;
85   }
88 const { debug, warn } =
89   GeckoViewAutoFillParent.initLogging("GeckoViewAutoFill");