Skip to content

Commit 837fe0b

Browse files
committedJan 17, 2024
Bug 1837747 - Use Services.prefs instead of Preferences.sys.mjs in remote/ r=webdriver-reviewers,Sasha
Differential Revision: https://phabricator.services.mozilla.com/D198755
1 parent 3091ab9 commit 837fe0b

File tree

6 files changed

+72
-56
lines changed

6 files changed

+72
-56
lines changed
 

‎remote/cdp/domains/parent/Security.sys.mjs

+4-8
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@ import { Domain } from "chrome://remote/content/cdp/domains/Domain.sys.mjs";
88

99
const lazy = {};
1010

11-
ChromeUtils.defineESModuleGetters(lazy, {
12-
Preferences: "resource://gre/modules/Preferences.sys.mjs",
13-
});
14-
1511
XPCOMUtils.defineLazyServiceGetters(lazy, {
1612
sss: ["@mozilla.org/ssservice;1", "nsISiteSecurityService"],
1713
certOverrideService: [
@@ -41,11 +37,11 @@ export class Security extends Domain {
4137
if (ignore) {
4238
// make it possible to register certificate overrides for domains
4339
// that use HSTS or HPKP
44-
lazy.Preferences.set(HSTS_PRELOAD_LIST_PREF, false);
45-
lazy.Preferences.set(CERT_PINNING_ENFORCEMENT_PREF, 0);
40+
Services.prefs.setBoolPref(HSTS_PRELOAD_LIST_PREF, false);
41+
Services.prefs.setIntPref(CERT_PINNING_ENFORCEMENT_PREF, 0);
4642
} else {
47-
lazy.Preferences.reset(HSTS_PRELOAD_LIST_PREF);
48-
lazy.Preferences.reset(CERT_PINNING_ENFORCEMENT_PREF);
43+
Services.prefs.clearUserPref(HSTS_PRELOAD_LIST_PREF);
44+
Services.prefs.clearUserPref(CERT_PINNING_ENFORCEMENT_PREF);
4945

5046
// clear collected HSTS and HPKP state
5147
lazy.sss.clearAll();

‎remote/components/Marionette.sys.mjs

+13-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
const lazy = {};
66

77
ChromeUtils.defineESModuleGetters(lazy, {
8-
Preferences: "resource://gre/modules/Preferences.sys.mjs",
9-
108
Deferred: "chrome://remote/content/shared/Sync.sys.mjs",
119
EnvironmentPrefs: "chrome://remote/content/marionette/prefs.sys.mjs",
1210
Log: "chrome://remote/content/shared/Log.sys.mjs",
@@ -156,7 +154,19 @@ class MarionetteParentProcess {
156154
for (let [pref, value] of lazy.EnvironmentPrefs.from(
157155
ENV_PRESERVE_PREFS
158156
)) {
159-
lazy.Preferences.set(pref, value);
157+
switch (typeof value) {
158+
case "string":
159+
Services.prefs.setStringPref(pref, value);
160+
break;
161+
case "boolean":
162+
Services.prefs.setBoolPref(pref, value);
163+
break;
164+
case "number":
165+
Services.prefs.setIntPref(pref, value);
166+
break;
167+
default:
168+
throw new TypeError(`Invalid preference type: ${typeof value}`);
169+
}
160170
}
161171
}
162172
break;

‎remote/marionette/cert.sys.mjs

+4-8
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
66

77
const lazy = {};
88

9-
ChromeUtils.defineESModuleGetters(lazy, {
10-
Preferences: "resource://gre/modules/Preferences.sys.mjs",
11-
});
12-
139
XPCOMUtils.defineLazyServiceGetter(
1410
lazy,
1511
"sss",
@@ -36,8 +32,8 @@ export const allowAllCerts = {};
3632
allowAllCerts.enable = function () {
3733
// make it possible to register certificate overrides for domains
3834
// that use HSTS or HPKP
39-
lazy.Preferences.set(HSTS_PRELOAD_LIST_PREF, false);
40-
lazy.Preferences.set(CERT_PINNING_ENFORCEMENT_PREF, 0);
35+
Services.prefs.setBoolPref(HSTS_PRELOAD_LIST_PREF, false);
36+
Services.prefs.setIntPref(CERT_PINNING_ENFORCEMENT_PREF, 0);
4137

4238
lazy.certOverrideService.setDisableAllSecurityChecksAndLetAttackersInterceptMyData(
4339
true
@@ -52,8 +48,8 @@ allowAllCerts.disable = function () {
5248
false
5349
);
5450

55-
lazy.Preferences.reset(HSTS_PRELOAD_LIST_PREF);
56-
lazy.Preferences.reset(CERT_PINNING_ENFORCEMENT_PREF);
51+
Services.prefs.clearUserPref(HSTS_PRELOAD_LIST_PREF);
52+
Services.prefs.clearUserPref(CERT_PINNING_ENFORCEMENT_PREF);
5753

5854
// clear collected HSTS and HPKP state
5955
// through the site security service

‎remote/shared/RecommendedPreferences.sys.mjs

+16-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
77
const lazy = {};
88

99
ChromeUtils.defineESModuleGetters(lazy, {
10-
Preferences: "resource://gre/modules/Preferences.sys.mjs",
11-
1210
Log: "chrome://remote/content/shared/Log.sys.mjs",
1311
});
1412

@@ -383,9 +381,22 @@ export const RecommendedPreferences = {
383381
}
384382

385383
for (const [k, v] of preferences) {
386-
if (!lazy.Preferences.isSet(k)) {
384+
if (!Services.prefs.prefHasUserValue(k)) {
387385
lazy.logger.debug(`Setting recommended pref ${k} to ${v}`);
388-
lazy.Preferences.set(k, v);
386+
387+
switch (typeof v) {
388+
case "string":
389+
Services.prefs.setStringPref(k, v);
390+
break;
391+
case "boolean":
392+
Services.prefs.setBoolPref(k, v);
393+
break;
394+
case "number":
395+
Services.prefs.setIntPref(k, v);
396+
break;
397+
default:
398+
throw new TypeError(`Invalid preference type: ${typeof v}`);
399+
}
389400

390401
// Keep track all the altered preferences to restore them on
391402
// quit-application.
@@ -418,7 +429,7 @@ export const RecommendedPreferences = {
418429
restorePreferences(preferences) {
419430
for (const k of preferences.keys()) {
420431
lazy.logger.debug(`Resetting recommended pref ${k}`);
421-
lazy.Preferences.reset(k);
432+
Services.prefs.clearUserPref(k);
422433
this.alteredPrefs.delete(k);
423434
}
424435
},

‎remote/shared/webdriver/Capabilities.sys.mjs

+20-16
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
const lazy = {};
66

77
ChromeUtils.defineESModuleGetters(lazy, {
8-
Preferences: "resource://gre/modules/Preferences.sys.mjs",
9-
108
AppInfo: "chrome://remote/content/shared/AppInfo.sys.mjs",
119
assert: "chrome://remote/content/shared/webdriver/Assert.sys.mjs",
1210
error: "chrome://remote/content/shared/webdriver/Errors.sys.mjs",
@@ -146,64 +144,70 @@ export class Proxy {
146144
init() {
147145
switch (this.proxyType) {
148146
case "autodetect":
149-
lazy.Preferences.set("network.proxy.type", 4);
147+
Services.prefs.setIntPref("network.proxy.type", 4);
150148
return true;
151149

152150
case "direct":
153-
lazy.Preferences.set("network.proxy.type", 0);
151+
Services.prefs.setIntPref("network.proxy.type", 0);
154152
return true;
155153

156154
case "manual":
157-
lazy.Preferences.set("network.proxy.type", 1);
155+
Services.prefs.setIntPref("network.proxy.type", 1);
158156

159157
if (this.httpProxy) {
160-
lazy.Preferences.set("network.proxy.http", this.httpProxy);
158+
Services.prefs.setStringPref("network.proxy.http", this.httpProxy);
161159
if (Number.isInteger(this.httpProxyPort)) {
162-
lazy.Preferences.set("network.proxy.http_port", this.httpProxyPort);
160+
Services.prefs.setIntPref(
161+
"network.proxy.http_port",
162+
this.httpProxyPort
163+
);
163164
}
164165
}
165166

166167
if (this.sslProxy) {
167-
lazy.Preferences.set("network.proxy.ssl", this.sslProxy);
168+
Services.prefs.setStringPref("network.proxy.ssl", this.sslProxy);
168169
if (Number.isInteger(this.sslProxyPort)) {
169-
lazy.Preferences.set("network.proxy.ssl_port", this.sslProxyPort);
170+
Services.prefs.setIntPref(
171+
"network.proxy.ssl_port",
172+
this.sslProxyPort
173+
);
170174
}
171175
}
172176

173177
if (this.socksProxy) {
174-
lazy.Preferences.set("network.proxy.socks", this.socksProxy);
178+
Services.prefs.setStringPref("network.proxy.socks", this.socksProxy);
175179
if (Number.isInteger(this.socksProxyPort)) {
176-
lazy.Preferences.set(
180+
Services.prefs.setIntPref(
177181
"network.proxy.socks_port",
178182
this.socksProxyPort
179183
);
180184
}
181185
if (this.socksVersion) {
182-
lazy.Preferences.set(
186+
Services.prefs.setIntPref(
183187
"network.proxy.socks_version",
184188
this.socksVersion
185189
);
186190
}
187191
}
188192

189193
if (this.noProxy) {
190-
lazy.Preferences.set(
194+
Services.prefs.setStringPref(
191195
"network.proxy.no_proxies_on",
192196
this.noProxy.join(", ")
193197
);
194198
}
195199
return true;
196200

197201
case "pac":
198-
lazy.Preferences.set("network.proxy.type", 2);
199-
lazy.Preferences.set(
202+
Services.prefs.setIntPref("network.proxy.type", 2);
203+
Services.prefs.setStringPref(
200204
"network.proxy.autoconfig_url",
201205
this.proxyAutoconfigUrl
202206
);
203207
return true;
204208

205209
case "system":
206-
lazy.Preferences.set("network.proxy.type", 5);
210+
Services.prefs.setIntPref("network.proxy.type", 5);
207211
return true;
208212

209213
default:

‎remote/shared/webdriver/test/xpcshell/test_Capabilities.js

+15-16
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44

55
"use strict";
66

7-
const { Preferences } = ChromeUtils.importESModule(
8-
"resource://gre/modules/Preferences.sys.mjs"
9-
);
10-
117
const { AppInfo } = ChromeUtils.importESModule(
128
"chrome://remote/content/shared/AppInfo.sys.mjs"
139
);
@@ -112,36 +108,36 @@ add_task(function test_Proxy_init() {
112108

113109
// no changed made, and 5 (system) is default
114110
equal(p.init(), false);
115-
equal(Preferences.get("network.proxy.type"), 5);
111+
equal(Services.prefs.getIntPref("network.proxy.type"), 5);
116112

117113
// pac
118114
p.proxyType = "pac";
119115
p.proxyAutoconfigUrl = "http://localhost:1234";
120116
ok(p.init());
121117

122-
equal(Preferences.get("network.proxy.type"), 2);
118+
equal(Services.prefs.getIntPref("network.proxy.type"), 2);
123119
equal(
124-
Preferences.get("network.proxy.autoconfig_url"),
120+
Services.prefs.getStringPref("network.proxy.autoconfig_url"),
125121
"http://localhost:1234"
126122
);
127123

128124
// direct
129125
p = new Proxy();
130126
p.proxyType = "direct";
131127
ok(p.init());
132-
equal(Preferences.get("network.proxy.type"), 0);
128+
equal(Services.prefs.getIntPref("network.proxy.type"), 0);
133129

134130
// autodetect
135131
p = new Proxy();
136132
p.proxyType = "autodetect";
137133
ok(p.init());
138-
equal(Preferences.get("network.proxy.type"), 4);
134+
equal(Services.prefs.getIntPref("network.proxy.type"), 4);
139135

140136
// system
141137
p = new Proxy();
142138
p.proxyType = "system";
143139
ok(p.init());
144-
equal(Preferences.get("network.proxy.type"), 5);
140+
equal(Services.prefs.getIntPref("network.proxy.type"), 5);
145141

146142
// manual
147143
for (let proxy of ["http", "ssl", "socks"]) {
@@ -155,12 +151,15 @@ add_task(function test_Proxy_init() {
155151
}
156152

157153
ok(p.init());
158-
equal(Preferences.get("network.proxy.type"), 1);
159-
equal(Preferences.get("network.proxy.no_proxies_on"), "foo, bar");
160-
equal(Preferences.get(`network.proxy.${proxy}`), "foo");
161-
equal(Preferences.get(`network.proxy.${proxy}_port`), 42);
154+
equal(Services.prefs.getIntPref("network.proxy.type"), 1);
155+
equal(
156+
Services.prefs.getStringPref("network.proxy.no_proxies_on"),
157+
"foo, bar"
158+
);
159+
equal(Services.prefs.getStringPref(`network.proxy.${proxy}`), "foo");
160+
equal(Services.prefs.getIntPref(`network.proxy.${proxy}_port`), 42);
162161
if (proxy === "socks") {
163-
equal(Preferences.get(`network.proxy.${proxy}_version`), 4);
162+
equal(Services.prefs.getIntPref(`network.proxy.${proxy}_version`), 4);
164163
}
165164
}
166165

@@ -169,7 +168,7 @@ add_task(function test_Proxy_init() {
169168
p.proxyType = "manual";
170169
p.noProxy = [];
171170
ok(p.init());
172-
equal(Preferences.get("network.proxy.no_proxies_on"), "");
171+
equal(Services.prefs.getStringPref("network.proxy.no_proxies_on"), "");
173172
});
174173

175174
add_task(function test_Proxy_toString() {

0 commit comments

Comments
 (0)
Failed to load comments.