blob: 209286b14e09f2ba9f3ec8e4a4c56164adb6320f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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"
);
|