Bug 1811922 - ESMified browser/components/doh files. r=kpatenio

Differential Revision: https://phabricator.services.mozilla.com/D169872
This commit is contained in:
Bilal 2023-02-15 22:29:33 +00:00
parent aaa1dbc297
commit 10ac84be22
13 changed files with 41 additions and 87 deletions

View File

@ -21,6 +21,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
DAPTelemetrySender: "resource://gre/modules/DAPTelemetrySender.sys.mjs",
DeferredTask: "resource://gre/modules/DeferredTask.sys.mjs",
DoHController: "resource:///modules/DoHController.sys.mjs",
DownloadsViewableInternally:
"resource:///modules/DownloadsViewableInternally.sys.mjs",
@ -45,6 +46,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
SessionStartup: "resource:///modules/sessionstore/SessionStartup.sys.mjs",
SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs",
ShortcutUtils: "resource://gre/modules/ShortcutUtils.sys.mjs",
TRRRacer: "resource:///modules/TRRPerformance.sys.mjs",
TelemetryUtils: "resource://gre/modules/TelemetryUtils.sys.mjs",
UIState: "resource://services-sync/UIState.sys.mjs",
UrlbarPrefs: "resource:///modules/UrlbarPrefs.sys.mjs",
@ -69,7 +71,6 @@ XPCOMUtils.defineLazyModuleGetters(lazy, {
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
Corroborate: "resource://gre/modules/Corroborate.jsm",
Discovery: "resource:///modules/Discovery.jsm",
DoHController: "resource:///modules/DoHController.jsm",
ExperimentAPI: "resource://nimbus/ExperimentAPI.jsm",
ExtensionsUI: "resource:///modules/ExtensionsUI.jsm",
FeatureGate: "resource://featuregates/FeatureGate.jsm",
@ -104,7 +105,6 @@ XPCOMUtils.defineLazyModuleGetters(lazy, {
TabCrashHandler: "resource:///modules/ContentCrashHandlers.jsm",
TabUnloader: "resource:///modules/TabUnloader.jsm",
TRRRacer: "resource:///modules/TRRPerformance.jsm",
});
if (AppConstants.MOZ_UPDATER) {

View File

@ -2,16 +2,12 @@
* 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";
/*
* This module provides an interface to access DoH configuration - e.g. whether
* DoH is enabled, whether capabilities are enabled, etc. The configuration is
* sourced from either Remote Settings or pref values, with Remote Settings
* being preferred.
*/
var EXPORTED_SYMBOLS = ["DoHConfigController"];
const { RemoteSettings } = ChromeUtils.import(
"resource://services-settings/remote-settings.js"
);
@ -159,7 +155,7 @@ function makeBaseConfigObject() {
return newConfig;
}
const DoHConfigController = {
export const DoHConfigController = {
initComplete: null,
_resolveInitComplete: null,

View File

@ -2,34 +2,25 @@
* 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";
/*
* This module runs the automated heuristics to enable/disable DoH on different
* networks. Heuristics are run at startup and upon network changes.
* Heuristics are disabled if the user sets their DoH provider or mode manually.
*/
var EXPORTED_SYMBOLS = ["DoHController"];
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
AsyncShutdown: "resource://gre/modules/AsyncShutdown.sys.mjs",
ClientID: "resource://gre/modules/ClientID.sys.mjs",
DoHConfigController: "resource:///modules/DoHConfig.sys.mjs",
Heuristics: "resource:///modules/DoHHeuristics.sys.mjs",
Preferences: "resource://gre/modules/Preferences.sys.mjs",
clearTimeout: "resource://gre/modules/Timer.sys.mjs",
setTimeout: "resource://gre/modules/Timer.sys.mjs",
});
XPCOMUtils.defineLazyModuleGetters(lazy, {
DoHConfigController: "resource:///modules/DoHConfig.jsm",
Heuristics: "resource:///modules/DoHHeuristics.jsm",
});
// When this is set we suppress automatic TRR selection beyond dry-run as well
// as sending observer notifications during heuristics throttling.
XPCOMUtils.defineLazyPreferenceGetter(
@ -146,7 +137,7 @@ function getHashedNetworkID() {
return hasher.finish(true);
}
const DoHController = {
export const DoHController = {
_heuristicsAreEnabled: false,
async init() {
@ -568,15 +559,15 @@ const DoHController = {
if (lazy.kIsInAutomation) {
// For mochitests, just record telemetry with a dummy result.
// TRRPerformance.jsm is tested in xpcshell.
// TRRPerformance.sys.mjs is tested in xpcshell.
setDryRunResultAndRecordTelemetry("https://example.com/dns-query");
return;
}
// Importing the module here saves us from having to do it at startup, and
// ensures tests have time to set prefs before the module initializes.
let { TRRRacer } = ChromeUtils.import(
"resource:///modules/TRRPerformance.jsm"
let { TRRRacer } = ChromeUtils.importESModule(
"resource:///modules/TRRPerformance.sys.mjs"
);
await new Promise(resolve => {
let trrList = lazy.DoHConfigController.currentConfig.trrSelection.providerList.map(

View File

@ -2,18 +2,12 @@
* 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";
/*
* This module implements the heuristics used to determine whether to enable
* or disable DoH on different networks. DoHController is responsible for running
* these at startup and upon network changes.
*/
var EXPORTED_SYMBOLS = ["Heuristics", "parentalControls"];
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
const lazy = {};
@ -31,13 +25,8 @@ XPCOMUtils.defineLazyServiceGetter(
"nsIParentalControlsService"
);
ChromeUtils.defineModuleGetter(
lazy,
"DoHConfigController",
"resource:///modules/DoHConfig.jsm"
);
ChromeUtils.defineESModuleGetters(lazy, {
DoHConfigController: "resource:///modules/DoHConfig.sys.mjs",
Preferences: "resource://gre/modules/Preferences.sys.mjs",
});
@ -45,7 +34,7 @@ const GLOBAL_CANARY = "use-application-dns.net.";
const NXDOMAIN_ERR = "NS_ERROR_UNKNOWN_HOST";
const Heuristics = {
export const Heuristics = {
// String constants used to indicate outcome of heuristics.
ENABLE_DOH: "enable_doh",
DISABLE_DOH: "disable_doh",
@ -229,7 +218,7 @@ async function modifiedRoots() {
return "enable_doh";
}
async function parentalControls() {
export async function parentalControls() {
if (lazy.gParentalControlsService.parentalControlsEnabled) {
return "disable_doh";
}

View File

@ -2,10 +2,6 @@
* 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 = ["DoHTestUtils"];
const lazy = {};
ChromeUtils.defineModuleGetter(
@ -33,7 +29,7 @@ const kControllerReloadedTopic = "doh:controller-reloaded";
* Some tests need to load/reset config while DoH actors are
* uninitialized. Pass waitForConfigFlushes = false in these cases.
*/
const DoHTestUtils = {
export const DoHTestUtils = {
providers: [
{
uri: "https://example.com/1",

View File

@ -2,8 +2,6 @@
* 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";
/*
* This module tests TRR performance by issuing DNS requests to TRRs and
* recording telemetry for the network time for each request.
@ -17,16 +15,12 @@
* usable network until a full set of results has been captured. We stop retrying
* after 5 attempts.
*/
var EXPORTED_SYMBOLS = ["TRRRacer", "DNSLookup", "LookupAggregator"];
Services.telemetry.setEventRecordingEnabled(
"security.doh.trrPerformance",
true
);
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
const lazy = {};
@ -91,7 +85,7 @@ function getRandomSubdomain() {
// callback. The wrapper attempts the lookup 3 times before passing on a failure.
// If a false-y `domain` is supplied, a random subdomain will be used. Each retry
// will use a different random subdomain to ensure we bypass chached responses.
class DNSLookup {
export class DNSLookup {
constructor(domain, trrServer, callback) {
this._domain = domain;
this.trrServer = trrServer;
@ -134,7 +128,7 @@ DNSLookup.prototype.QueryInterface = ChromeUtils.generateQI(["nsIDNSListener"]);
// A wrapper around a single set of measurements. The required lookups are
// triggered and the results aggregated before telemetry is sent. If aborted,
// any aggregated results are discarded.
class LookupAggregator {
export class LookupAggregator {
constructor(onCompleteCallback, trrList) {
this.onCompleteCallback = onCompleteCallback;
this.trrList = trrList;
@ -240,7 +234,7 @@ class LookupAggregator {
// When the network goes down, an ongoing aggregator is aborted and a new one
// spawned next time we get a link, up to 5 times. On the fifth time, we just
// let the aggegator complete and mark it as tainted.
class TRRRacer {
export class TRRRacer {
constructor(onCompleteCallback, trrList) {
this._aggregator = null;
this._retryCount = 0;

View File

@ -8,14 +8,14 @@ with Files("**"):
BUG_COMPONENT = ("Firefox", "Security")
EXTRA_JS_MODULES += [
"DoHConfig.jsm",
"DoHController.jsm",
"DoHHeuristics.jsm",
"TRRPerformance.jsm",
"DoHConfig.sys.mjs",
"DoHController.sys.mjs",
"DoHHeuristics.sys.mjs",
"TRRPerformance.sys.mjs",
]
TESTING_JS_MODULES += [
"DoHTestUtils.jsm",
"DoHTestUtils.sys.mjs",
]
XPCSHELL_TESTS_MANIFESTS += ["test/unit/xpcshell.ini"]

View File

@ -4,8 +4,8 @@
"use strict";
XPCOMUtils.defineLazyModuleGetters(this, {
Heuristics: "resource:///modules/DoHHeuristics.jsm",
ChromeUtils.defineESModuleGetters(this, {
Heuristics: "resource:///modules/DoHHeuristics.sys.mjs",
});
add_task(setup);

View File

@ -1,6 +1,9 @@
"use strict";
ChromeUtils.defineESModuleGetters(this, {
DoHConfigController: "resource:///modules/DoHConfig.sys.mjs",
DoHController: "resource:///modules/DoHController.sys.mjs",
DoHTestUtils: "resource://testing-common/DoHTestUtils.sys.mjs",
Preferences: "resource://gre/modules/Preferences.sys.mjs",
Region: "resource://gre/modules/Region.sys.mjs",
RegionTestUtils: "resource://testing-common/RegionTestUtils.sys.mjs",
@ -8,9 +11,6 @@ ChromeUtils.defineESModuleGetters(this, {
XPCOMUtils.defineLazyModuleGetters(this, {
ASRouter: "resource://activity-stream/lib/ASRouter.jsm",
DoHController: "resource:///modules/DoHController.jsm",
DoHConfigController: "resource:///modules/DoHConfig.jsm",
DoHTestUtils: "resource://testing-common/DoHTestUtils.jsm",
RemoteSettings: "resource://services-settings/remote-settings.js",
});

View File

@ -81,8 +81,8 @@ function setup() {
"firefox-dns-perf-test.net."
);
let TRRPerformance = ChromeUtils.import(
"resource:///modules/TRRPerformance.jsm"
let TRRPerformance = ChromeUtils.importESModule(
"resource:///modules/TRRPerformance.sys.mjs"
);
DNSLookup = TRRPerformance.DNSLookup;

View File

@ -34,8 +34,8 @@ registerCleanupFunction(() => {
add_task(setup);
add_task(async function test_parentalControls() {
let DoHHeuristics = ChromeUtils.import(
"resource:///modules/DoHHeuristics.jsm"
let DoHHeuristics = ChromeUtils.importESModule(
"resource:///modules/DoHHeuristics.sys.mjs"
);
let parentalControls = DoHHeuristics.parentalControls;

View File

@ -7,11 +7,9 @@
/* import-globals-from /toolkit/content/preferencesBindings.js */
/* import-globals-from ../extensionControlled.js */
ChromeUtils.defineModuleGetter(
this,
"DoHConfigController",
"resource:///modules/DoHConfig.jsm"
);
ChromeUtils.defineESModuleGetters(this, {
DoHConfigController: "resource:///modules/DoHConfig.sys.mjs",
});
document
.getElementById("ConnectionsDialog")

View File

@ -12,21 +12,11 @@ const {
"resource://testing-common/EnterprisePolicyTesting.sys.mjs"
);
ChromeUtils.defineModuleGetter(
this,
"DoHController",
"resource:///modules/DoHController.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"DoHConfigController",
"resource:///modules/DoHConfig.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"DoHTestUtils",
"resource://testing-common/DoHTestUtils.jsm"
);
ChromeUtils.defineESModuleGetters(this, {
DoHConfigController: "resource:///modules/DoHConfig.sys.mjs",
DoHController: "resource:///modules/DoHController.sys.mjs",
DoHTestUtils: "resource://testing-common/DoHTestUtils.sys.mjs",
});
const SUBDIALOG_URL =
"chrome://browser/content/preferences/dialogs/connection.xhtml";