Skip to content
Snippets Groups Projects
Verified Commit 5004c86f authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame :jack_o_lantern:
Browse files

fixup! Bug 40597: Implement TorSettings module

Changes needed for the new control port implementation.

Also, moved to ES modules and done some refactors on Moat.
parent 2d1b115d
Branches
Tags
1 merge request!734Bug 42030: Rebased 13.0 alpha onto Firefox 115.2.0esr
"use strict";
/* 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/. */
var EXPORTED_SYMBOLS = ["BridgeDB"];
const lazy = {};
const { MoatRPC } = ChromeUtils.import("resource:///modules/Moat.jsm");
ChromeUtils.defineESModuleGetters(lazy, {
MoatRPC: "resource:///modules/Moat.sys.mjs",
});
var BridgeDB = {
export var BridgeDB = {
_moatRPC: null,
_challenge: null,
_image: null,
......@@ -20,7 +24,7 @@ var BridgeDB = {
async submitCaptchaGuess(solution) {
if (!this._moatRPC) {
this._moatRPC = new MoatRPC();
this._moatRPC = new lazy.MoatRPC();
await this._moatRPC.init();
}
......@@ -37,7 +41,7 @@ var BridgeDB = {
async requestNewCaptchaImage() {
try {
if (!this._moatRPC) {
this._moatRPC = new MoatRPC();
this._moatRPC = new lazy.MoatRPC();
await this._moatRPC.init();
}
......
This diff is collapsed.
"use strict";
/* 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/. */
var EXPORTED_SYMBOLS = [
"InternetStatus",
"TorConnect",
"TorConnectTopics",
"TorConnectState",
];
import { setTimeout, clearTimeout } from "resource://gre/modules/Timer.sys.mjs";
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const lazy = {};
const { setTimeout, clearTimeout } = ChromeUtils.import(
"resource://gre/modules/Timer.jsm"
);
ChromeUtils.defineESModuleGetters(lazy, {
MoatRPC: "resource:///modules/Moat.sys.mjs",
TorBootstrapRequest: "resource://gre/modules/TorBootstrapRequest.sys.mjs",
TorProviderBuilder: "resource://gre/modules/TorProviderBuilder.sys.mjs",
});
const { BrowserWindowTracker } = ChromeUtils.import(
// TODO: Should we move this to the about:torconnect actor?
ChromeUtils.defineModuleGetter(
lazy,
"BrowserWindowTracker",
"resource:///modules/BrowserWindowTracker.jsm"
);
const { TorMonitorService } = ChromeUtils.import(
"resource://gre/modules/TorMonitorService.jsm"
);
const { TorBootstrapRequest } = ChromeUtils.import(
"resource://gre/modules/TorBootstrapRequest.jsm"
);
const { TorSettings, TorSettingsTopics, TorBuiltinBridgeTypes } =
ChromeUtils.import("resource:///modules/TorSettings.jsm");
import {
TorSettings,
TorSettingsTopics,
TorBuiltinBridgeTypes,
} from "resource:///modules/TorSettings.sys.mjs";
const { TorStrings } = ChromeUtils.import("resource:///modules/TorStrings.jsm");
const { MoatRPC } = ChromeUtils.import("resource:///modules/Moat.jsm");
const TorTopics = Object.freeze({
LogHasWarnOrErr: "TorLogHasWarnOrErr",
ProcessExited: "TorProcessExited",
......@@ -46,7 +42,7 @@ const TorConnectPrefs = Object.freeze({
allow_internet_test: "torbrowser.bootstrap.allow_internet_test",
});
const TorConnectState = Object.freeze({
export const TorConnectState = Object.freeze({
/* Our initial state */
Initial: "Initial",
/* In-between initial boot and bootstrapping, users can change tor network settings during this state */
......@@ -156,7 +152,7 @@ const TorConnectStateTransitions = Object.freeze(
);
/* Topics Notified by the TorConnect module */
const TorConnectTopics = Object.freeze({
export const TorConnectTopics = Object.freeze({
StateChange: "torconnect:state-change",
BootstrapProgress: "torconnect:bootstrap-progress",
BootstrapComplete: "torconnect:bootstrap-complete",
......@@ -238,7 +234,7 @@ const debug_sleep = async ms => {
});
};
const InternetStatus = Object.freeze({
export const InternetStatus = Object.freeze({
Unknown: -1,
Offline: 0,
Online: 1,
......@@ -302,7 +298,7 @@ class InternetTest {
// waiting both for the bootstrap, and for the Internet test.
// However, managing Moat with async/await is much easier as it avoids a
// callback hell, and it makes extra explicit that we are uniniting it.
const mrpc = new MoatRPC();
const mrpc = new lazy.MoatRPC();
let status = null;
let error = null;
try {
......@@ -340,7 +336,7 @@ class InternetTest {
}
}
const TorConnect = (() => {
export const TorConnect = (() => {
let retval = {
_state: TorConnectState.Initial,
_bootstrapProgress: 0,
......@@ -459,7 +455,7 @@ const TorConnect = (() => {
return;
}
const tbr = new TorBootstrapRequest();
const tbr = new lazy.TorBootstrapRequest();
const internetTest = new InternetTest();
let cancelled = false;
......@@ -604,7 +600,7 @@ const TorConnect = (() => {
// lookup user's potential censorship circumvention settings from Moat service
try {
this.mrpc = new MoatRPC();
this.mrpc = new lazy.MoatRPC();
await this.mrpc.init();
if (this.transitioning) {
......@@ -678,7 +674,7 @@ const TorConnect = (() => {
await TorSettings.applySettings();
// build out our bootstrap request
const tbr = new TorBootstrapRequest();
const tbr = new lazy.TorBootstrapRequest();
tbr.onbootstrapstatus = (progress, status) => {
TorConnect._updateBootstrapStatus(progress, status);
};
......@@ -915,7 +911,7 @@ const TorConnect = (() => {
* @type {boolean}
*/
get enabled() {
return TorMonitorService.ownsTorDaemon;
return lazy.TorProviderBuilder.build().ownsTorDaemon;
},
get shouldShowTorConnect() {
......@@ -1053,7 +1049,7 @@ const TorConnect = (() => {
Further external commands and helper methods
*/
openTorPreferences() {
const win = BrowserWindowTracker.getTopWindow();
const win = lazy.BrowserWindowTracker.getTopWindow();
win.switchToTabHavingURI("about:preferences#connection", true);
},
......@@ -1073,7 +1069,7 @@ const TorConnect = (() => {
* begin AutoBootstrapping, if possible.
*/
openTorConnect(options) {
const win = BrowserWindowTracker.getTopWindow();
const win = lazy.BrowserWindowTracker.getTopWindow();
win.switchToTabHavingURI("about:torconnect", true, {
ignoreQueryString: true,
});
......@@ -1094,7 +1090,7 @@ const TorConnect = (() => {
},
viewTorLogs() {
const win = BrowserWindowTracker.getTopWindow();
const win = lazy.BrowserWindowTracker.getTopWindow();
win.switchToTabHavingURI("about:preferences#connection-viewlogs", true);
},
......@@ -1104,7 +1100,7 @@ const TorConnect = (() => {
if (this._countryCodes.length) {
return this._countryCodes;
}
const mrpc = new MoatRPC();
const mrpc = new lazy.MoatRPC();
try {
await mrpc.init();
this._countryCodes = await mrpc.circumvention_countries();
......
"use strict";
/* 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/. */
var EXPORTED_SYMBOLS = [
"TorSettings",
"TorSettingsTopics",
"TorSettingsData",
"TorBridgeSource",
"TorBuiltinBridgeTypes",
"TorProxyType",
];
const lazy = {};
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { TorMonitorService } = ChromeUtils.import(
"resource://gre/modules/TorMonitorService.jsm"
);
const { TorProtocolService } = ChromeUtils.import(
"resource://gre/modules/TorProtocolService.jsm"
);
/* tor-launcher observer topics */
const TorTopics = Object.freeze({
ProcessIsReady: "TorProcessIsReady",
ChromeUtils.defineESModuleGetters(lazy, {
TorProviderBuilder: "resource://gre/modules/TorProviderBuilder.sys.mjs",
TorProviderTopics: "resource://gre/modules/TorProviderBuilder.sys.mjs",
});
/* TorSettings observer topics */
const TorSettingsTopics = Object.freeze({
export const TorSettingsTopics = Object.freeze({
Ready: "torsettings:ready",
SettingChanged: "torsettings:setting-changed",
});
/* TorSettings observer data (for SettingChanged topic) */
const TorSettingsData = Object.freeze({
export const TorSettingsData = Object.freeze({
QuickStartEnabled: "torsettings:quickstart_enabled",
});
......@@ -98,21 +84,21 @@ const TorConfigKeys = Object.freeze({
clientTransportPlugin: "ClientTransportPlugin",
});
const TorBridgeSource = Object.freeze({
export const TorBridgeSource = Object.freeze({
Invalid: -1,
BuiltIn: 0,
BridgeDB: 1,
UserProvided: 2,
});
const TorProxyType = Object.freeze({
export const TorProxyType = Object.freeze({
Invalid: -1,
Socks4: 0,
Socks5: 1,
HTTPS: 2,
});
const TorBuiltinBridgeTypes = Object.freeze(
export const TorBuiltinBridgeTypes = Object.freeze(
(() => {
const bridgeListBranch = Services.prefs.getBranch(
TorLauncherPrefs.default_bridge
......@@ -254,7 +240,7 @@ const arrayCopy = function (array) {
/* TorSettings module */
const TorSettings = (() => {
export const TorSettings = (() => {
const self = {
_settings: null,
......@@ -288,7 +274,8 @@ const TorSettings = (() => {
/* load or init our settings, and register observers */
init() {
if (TorMonitorService.ownsTorDaemon) {
const provider = lazy.TorProviderBuilder.build();
if (provider.ownsTorDaemon) {
// if the settings branch exists, load settings from prefs
if (Services.prefs.getBoolPref(TorSettingsPrefs.enabled, false)) {
this.loadFromPrefs();
......@@ -296,9 +283,9 @@ const TorSettings = (() => {
// otherwise load defaults
this._settings = this.defaultSettings();
}
Services.obs.addObserver(this, TorTopics.ProcessIsReady);
Services.obs.addObserver(this, lazy.TorProviderTopics.ProcessIsReady);
if (TorMonitorService.isRunning) {
if (provider.isRunning) {
this.handleProcessReady();
}
}
......@@ -309,8 +296,11 @@ const TorSettings = (() => {
console.log(`TorSettings: Observed ${topic}`);
switch (topic) {
case TorTopics.ProcessIsReady:
Services.obs.removeObserver(this, TorTopics.ProcessIsReady);
case lazy.TorProviderTopics.ProcessIsReady:
Services.obs.removeObserver(
this,
lazy.TorProviderTopics.ProcessIsReady
);
await this.handleProcessReady();
break;
}
......@@ -569,7 +559,7 @@ const TorSettings = (() => {
}
/* Push to Tor */
await TorProtocolService.writeSettings(settingsMap);
await lazy.TorProviderBuilder.build().writeSettings(settingsMap);
return this;
},
......
......@@ -123,7 +123,7 @@ XPCSHELL_TESTS_MANIFESTS += ["test/unit/xpcshell.ini"]
EXTRA_JS_MODULES += [
"AboutNewTab.jsm",
"AsyncTabSwitcher.jsm",
"BridgeDB.jsm",
"BridgeDB.sys.mjs",
"BrowserUIUtils.jsm",
"BrowserUsageTelemetry.jsm",
"BrowserWindowTracker.jsm",
......@@ -135,7 +135,7 @@ EXTRA_JS_MODULES += [
"FeatureCallout.sys.mjs",
"HomePage.jsm",
"LaterRun.jsm",
'Moat.jsm',
"Moat.sys.mjs",
"NewTabPagePreloading.jsm",
"OpenInTabsUtils.jsm",
"PageActions.jsm",
......@@ -149,8 +149,8 @@ EXTRA_JS_MODULES += [
"SitePermissions.sys.mjs",
"TabsList.jsm",
"TabUnloader.jsm",
"TorConnect.jsm",
"TorSettings.jsm",
"TorConnect.sys.mjs",
"TorSettings.sys.mjs",
"TorStrings.jsm",
"TransientPrefs.jsm",
"URILoadingHelper.sys.mjs",
......
......@@ -3,21 +3,12 @@ const lazy = {};
// We will use the modules only when the profile is loaded, so prefer lazy
// loading
ChromeUtils.defineESModuleGetters(lazy, {
TorConnect: "resource:///modules/TorConnect.sys.mjs",
TorLauncherUtil: "resource://gre/modules/TorLauncherUtil.sys.mjs",
TorProviderBuilder: "resource://gre/modules/TorProviderBuilder.sys.mjs",
TorSettings: "resource:///modules/TorSettings.sys.mjs",
});
ChromeUtils.defineModuleGetter(
lazy,
"TorConnect",
"resource:///modules/TorConnect.jsm"
);
ChromeUtils.defineModuleGetter(
lazy,
"TorSettings",
"resource:///modules/TorSettings.jsm"
);
/* Browser observer topis */
const BrowserTopics = Object.freeze({
ProfileAfterChange: "profile-after-change",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment