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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
/* 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";
ChromeUtils.defineESModuleGetters(this, {
UrlbarPrefs: "resource:///modules/UrlbarPrefs.sys.mjs",
UrlbarProviderExtension:
"resource:///modules/UrlbarProviderExtension.sys.mjs",
});
var { ExtensionPreferencesManager } = ChromeUtils.import(
"resource://gre/modules/ExtensionPreferencesManager.jsm"
);
var { getSettingsAPI } = ExtensionPreferencesManager;
ExtensionPreferencesManager.addSetting("engagementTelemetry", {
prefNames: ["browser.urlbar.eventTelemetry.enabled"],
setCallback(value) {
return { [this.prefNames[0]]: value };
},
});
this.urlbar = class extends ExtensionAPI {
getAPI(context) {
return {
urlbar: {
closeView() {
let window = windowTracker.getTopNormalWindow(context);
window.gURLBar.view.close();
},
focus(select = false) {
let window = windowTracker.getTopNormalWindow(context);
if (select) {
window.gURLBar.select();
} else {
window.gURLBar.focus();
}
},
search(searchString, options = {}) {
let window = windowTracker.getTopNormalWindow(context);
window.gURLBar.search(searchString, options);
},
onBehaviorRequested: new EventManager({
context,
name: "urlbar.onBehaviorRequested",
register: (fire, providerName) => {
let provider = UrlbarProviderExtension.getOrCreate(providerName);
provider.setEventListener(
"behaviorRequested",
async queryContext => {
if (queryContext.isPrivate && !context.privateBrowsingAllowed) {
return "inactive";
}
return fire.async(queryContext).catch(error => {
throw context.normalizeError(error);
});
}
);
return () => provider.setEventListener("behaviorRequested", null);
},
}).api(),
onEngagement: new EventManager({
context,
name: "urlbar.onEngagement",
register: (fire, providerName) => {
let provider = UrlbarProviderExtension.getOrCreate(providerName);
provider.setEventListener(
"engagement",
async (isPrivate, state) => {
if (isPrivate && !context.privateBrowsingAllowed) {
return;
}
return fire.async(state).catch(error => {
throw context.normalizeError(error);
});
}
);
return () => provider.setEventListener("engagement", null);
},
}).api(),
onQueryCanceled: new EventManager({
context,
name: "urlbar.onQueryCanceled",
register: (fire, providerName) => {
let provider = UrlbarProviderExtension.getOrCreate(providerName);
provider.setEventListener("queryCanceled", async queryContext => {
if (queryContext.isPrivate && !context.privateBrowsingAllowed) {
return;
}
await fire.async(queryContext).catch(error => {
throw context.normalizeError(error);
});
});
return () => provider.setEventListener("queryCanceled", null);
},
}).api(),
onResultsRequested: new EventManager({
context,
name: "urlbar.onResultsRequested",
register: (fire, providerName) => {
let provider = UrlbarProviderExtension.getOrCreate(providerName);
provider.setEventListener(
"resultsRequested",
async queryContext => {
if (queryContext.isPrivate && !context.privateBrowsingAllowed) {
return [];
}
return fire.async(queryContext).catch(error => {
throw context.normalizeError(error);
});
}
);
return () => provider.setEventListener("resultsRequested", null);
},
}).api(),
onResultPicked: new EventManager({
context,
name: "urlbar.onResultPicked",
inputHandling: true,
register: (fire, providerName) => {
let provider = UrlbarProviderExtension.getOrCreate(providerName);
provider.setEventListener(
"resultPicked",
async (resultPayload, dynamicElementName) => {
return fire
.async(resultPayload, dynamicElementName)
.catch(error => {
throw context.normalizeError(error);
});
}
);
return () => provider.setEventListener("resultPicked", null);
},
}).api(),
engagementTelemetry: getSettingsAPI({
context,
name: "engagementTelemetry",
callback: () => UrlbarPrefs.get("eventTelemetry.enabled"),
}),
},
};
}
};
|