Pier Angelo Vendrame pushed to branch tor-browser-128.7.0esr-14.5-1 at The Tor Project / Applications / Tor Browser
Commits: e0edfde0 by Henry Wilkes at 2025-02-25T14:30:32+00:00 fixup! TB 27476: Implement about:torconnect captive portal within Tor Browser
TB 43502: Move about:torconnect methods to TorConnectParent.
- - - - - 163e2fae by Henry Wilkes at 2025-02-25T14:30:32+00:00 fixup! TB 31286: Implementation of bridge, proxy, and firewall settings in about:preferences#connection
TB 43502: Move about:torconnect methods to TorConnectParent.
- - - - - 1f7e489c by Henry Wilkes at 2025-02-25T14:30:32+00:00 fixup! TB 40597: Implement TorSettings module
TB 43502: Remove about:torconnect specific methods from TorConnect module.
- - - - -
9 changed files:
- browser/base/content/browser-init.js - browser/base/content/browser.js - browser/base/content/browser.js.globals - browser/components/torpreferences/content/connectionPane.js - browser/modules/URILoadingHelper.sys.mjs - toolkit/components/torconnect/TorConnectChild.sys.mjs - toolkit/components/torconnect/TorConnectParent.sys.mjs - toolkit/components/torconnect/content/torConnectUrlbarButton.js - toolkit/modules/TorConnect.sys.mjs
Changes:
===================================== browser/base/content/browser-init.js ===================================== @@ -980,14 +980,9 @@ var gBrowserInit = {
// if using TorConnect, convert these uris to redirects if (TorConnect.shouldShowTorConnect) { - return Promise.resolve(uri).then(aUri => { - if (aUri == null) { - aUri = []; - } - - aUri = TorConnect.getURIsToLoad(aUri); - return aUri; - }); + return Promise.resolve(uri).then(aUri => + TorConnectParent.getURIsToLoad(aUri ?? []) + ); } return uri; })());
===================================== browser/base/content/browser.js ===================================== @@ -86,6 +86,7 @@ ChromeUtils.defineESModuleGetters(this, { TorConnect: "resource://gre/modules/TorConnect.sys.mjs", TorConnectStage: "resource://gre/modules/TorConnect.sys.mjs", TorConnectTopics: "resource://gre/modules/TorConnect.sys.mjs", + TorConnectParent: "resource://gre/actors/TorConnectParent.sys.mjs", TorDomainIsolator: "resource://gre/modules/TorDomainIsolator.sys.mjs", TorUIUtils: "resource:///modules/TorUIUtils.sys.mjs", TranslationsParent: "resource://gre/actors/TranslationsParent.sys.mjs",
===================================== browser/base/content/browser.js.globals ===================================== @@ -279,6 +279,7 @@ "TorConnect", "TorConnectStage", "TorConnectTopics", + "TorConnectParent", "gTorConnectUrlbarButton", "gTorConnectTitlebarStatus", "OnionAuthPrompt",
===================================== browser/components/torpreferences/content/connectionPane.js ===================================== @@ -25,6 +25,10 @@ const { TorProviderBuilder, TorProviderTopics } = ChromeUtils.importESModule( const { InternetStatus, TorConnect, TorConnectTopics, TorConnectStage } = ChromeUtils.importESModule("resource://gre/modules/TorConnect.sys.mjs");
+const { TorConnectParent } = ChromeUtils.importESModule( + "resource://gre/actors/TorConnectParent.sys.mjs" +); + const { QRCode } = ChromeUtils.importESModule( "resource://gre/modules/QRCode.sys.mjs" ); @@ -2261,7 +2265,7 @@ const gBridgeSettings = {
// Start Bootstrapping, which should use the configured bridges. // NOTE: We do this regardless of any previous TorConnect Error. - TorConnect.openTorConnect({ beginBootstrapping: "hard" }); + TorConnectParent.open({ beginBootstrapping: "hard" }); }); }, // closedCallback should be called after gSubDialog has already @@ -2374,7 +2378,7 @@ const gNetworkStatus = { "network-status-tor-connect-button" ); this._torConnectButton.addEventListener("click", () => { - TorConnect.openTorConnect({ beginBootstrapping: "soft" }); + TorConnectParent.open({ beginBootstrapping: "soft" }); });
this._updateInternetStatus(); @@ -2513,7 +2517,10 @@ const gConnectionPane = (function () { TorStrings.settings.bridgeChooseForMe ); chooseForMe.addEventListener("command", () => { - TorConnect.openTorConnect({ + if (!location.value) { + return; + } + TorConnectParent.open({ beginBootstrapping: "hard", regionCode: location.value, });
===================================== browser/modules/URILoadingHelper.sys.mjs ===================================== @@ -12,6 +12,7 @@ ChromeUtils.defineESModuleGetters(lazy, { AboutNewTab: "resource:///modules/AboutNewTab.sys.mjs", BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.sys.mjs", TorConnect: "resource://gre/modules/TorConnect.sys.mjs", + TorConnectParent: "resource://gre/actors/TorConnectParent.sys.mjs", });
ChromeUtils.defineLazyGetter(lazy, "ReferrerInfo", () => @@ -445,7 +446,7 @@ export const URILoadingHelper = { (url === "about:newtab" && Services.prefs.getBoolPref("browser.newtabpage.enabled", false)) ) { - url = lazy.TorConnect.getRedirectURL(url); + url = lazy.TorConnectParent.getRedirectURL(url); } }
===================================== toolkit/components/torconnect/TorConnectChild.sys.mjs ===================================== @@ -55,8 +55,8 @@ export class TorConnectChild extends RemotePageChild { } else { console.error(`Scheme is not allowed "${redirect}"`); } - } catch { - console.error(`Invalid redirect URL "${redirect}"`); + } catch (e) { + console.error(`Invalid redirect URL "${redirect}"`, e); }
// Replace the destination to prevent "about:torconnect" entering the
===================================== toolkit/components/torconnect/TorConnectParent.sys.mjs ===================================== @@ -9,7 +9,8 @@ import { const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, { - HomePage: "resource:///modules/HomePage.sys.jsm", + BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.sys.mjs", + HomePage: "resource:///modules/HomePage.sys.mjs", });
/* @@ -88,7 +89,9 @@ export class TorConnectParent extends JSWindowActorParent { return Promise.resolve(TorConnect.shouldShowTorConnect); case "torconnect:home-page": // If there are multiple home pages, just load the first one. - return Promise.resolve(TorConnect.fixupURIs(lazy.HomePage.get())[0]); + return Promise.resolve( + TorConnectParent.fixupURIs(lazy.HomePage.get())[0] + ); case "torconnect:set-quickstart": TorConnect.quickstart = message.data; break; @@ -134,4 +137,111 @@ export class TorConnectParent extends JSWindowActorParent { } return undefined; } + + /** + * Open the "about:torconnect" tab. + * + * Bootstrapping can also be automatically triggered at the same time, if the + * current TorConnect stage allows for it. + * + * @param {object} [options] - extra options. + * @param {"soft"|"hard"} [options.beginBootstrapping] - Whether to try and + * begin bootstrapping. "soft" will only trigger the bootstrap if we are not + * `potentiallyBlocked`. "hard" will try begin the bootstrap regardless. + * @param {string} [options.regionCode] - A region to pass in for + * auto-bootstrapping. + */ + static open(options) { + const win = lazy.BrowserWindowTracker.getTopWindow(); + win.switchToTabHavingURI("about:torconnect", true, { + ignoreQueryString: true, + }); + + if (!options?.beginBootstrapping || !TorConnect.canBeginBootstrap) { + return; + } + + if (options.beginBootstrapping === "hard") { + if (TorConnect.canBeginAutoBootstrap && !options.regionCode) { + // Treat as an addition startAgain request to first move back to the + // "Start" stage before bootstrapping. + TorConnect.startAgain(); + } + } else if (TorConnect.potentiallyBlocked) { + // Do not trigger the bootstrap if we have ever had an error. + return; + } + + TorConnect.beginBootstrapping(options.regionCode); + } + + /** + * Convert the given url into an about:torconnect page that redirects to it. + * + * @param {string} url - The url to convert. + * + * @returns {string} - The about:torconnect url. + */ + static getRedirectURL(url) { + return `about:torconnect?redirect=${encodeURIComponent(url)}`; + } + + /** + * Convert the given object into a list of valid URIs. + * + * The object is either from the user's homepage preference (which may + * contain multiple domains separated by "|") or uris passed to the browser + * via command-line. + * + * @param {string|string[]} uriVariant - The string to extract uris from. + * + * @returns {string[]} - The array of uris found. + */ + static fixupURIs(uriVariant) { + let uriArray; + if (typeof uriVariant === "string") { + uriArray = uriVariant.split("|"); + } else if ( + Array.isArray(uriVariant) && + uriVariant.every(entry => typeof entry === "string") + ) { + uriArray = uriVariant; + } else { + // about:tor as safe fallback + console.error(`Received unknown variant '${JSON.stringify(uriVariant)}'`); + uriArray = ["about:tor"]; + } + + // Attempt to convert user-supplied string to a uri, fallback to + // about:tor if cannot convert to valid uri object + return uriArray.map(uriString => { + try { + return ( + Services.uriFixup.getFixupURIInfo( + uriString, + Ci.nsIURIFixup.FIXUP_FLAG_NONE + ).preferredURI?.spec ?? "about:tor" + ); + } catch (e) { + console.error(`Failed to parse ${uriString}`, e); + return "about:tor"; + } + }); + } + + /** + * Replace startup URIs (home pages or command line) with about:torconnect + * URIs which redirect to them after bootstrapping. + * + * @param {string|string[]} uriVariant - The string to extract uris from. + * + * @returns {string[]} - The array or uris to use instead. + */ + static getURIsToLoad(uriVariant) { + const uris = this.fixupURIs(uriVariant); + const localUriRx = /^(file:|moz-extension:)/; + return uris.map(uri => + localUriRx.test(uri) ? uri : this.getRedirectURL(uri) + ); + } }
===================================== toolkit/components/torconnect/content/torConnectUrlbarButton.js ===================================== @@ -105,7 +105,7 @@ var gTorConnectUrlbarButton = { * Begin the tor connection bootstrapping process. */ connect() { - TorConnect.openTorConnect({ beginBootstrapping: "soft" }); + TorConnectParent.open({ beginBootstrapping: "soft" }); },
/**
===================================== toolkit/modules/TorConnect.sys.mjs ===================================== @@ -7,7 +7,6 @@ import { setTimeout, clearTimeout } from "resource://gre/modules/Timer.sys.mjs"; const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, { - BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.sys.mjs", MoatRPC: "resource://gre/modules/Moat.sys.mjs", TorBootstrapRequest: "resource://gre/modules/TorBootstrapRequest.sys.mjs", TorProviderTopics: "resource://gre/modules/TorProviderBuilder.sys.mjs", @@ -1534,47 +1533,6 @@ export const TorConnect = { Further external commands and helper methods */
- /** - * Open the "about:torconnect" tab. - * - * Bootstrapping or AutoBootstrapping can also be automatically triggered at - * the same time, if the current state allows for it. - * - * Bootstrapping will not be triggered if the connection is - * potentially blocked. - * - * @param {object} [options] - extra options. - * @property {"soft"|"hard"} [options.beginBootstrapping] - Whether to try and - * begin bootstrapping. "soft" will only trigger the bootstrap if we are not - * `potentiallyBlocked`. "hard" will try begin the bootstrap regardless. - * @property {string} [options.regionCode] - A region to pass in for - * auto-bootstrapping. - */ - openTorConnect(options) { - // FIXME: Should we move this to the about:torconnect actor? - const win = lazy.BrowserWindowTracker.getTopWindow(); - win.switchToTabHavingURI("about:torconnect", true, { - ignoreQueryString: true, - }); - - if (!options?.beginBootstrapping || !this.canBeginBootstrap) { - return; - } - - if (options.beginBootstrapping === "hard") { - if (this.canBeginAutoBootstrap && !options.regionCode) { - // Treat as an addition startAgain request to first move back to the - // "Start" stage before bootstrapping. - this.startAgain(); - } - } else if (this.potentiallyBlocked) { - // Do not trigger the bootstrap if we have ever had an error. - return; - } - - this.beginBootstrapping(options.regionCode); - }, - async getCountryCodes() { // Difference with the getter: this is to be called by TorConnectParent, and // downloads the country codes if they are not already in cache. @@ -1592,64 +1550,4 @@ export const TorConnect = { } return this._countryCodes; }, - - getRedirectURL(url) { - return `about:torconnect?redirect=${encodeURIComponent(url)}`; - }, - - /** - * Convert the given object into a list of valid URIs. - * - * The object is either from the user's homepage preference (which may - * contain multiple domains separated by "|") or uris passed to the browser - * via command-line. - * - * @param {string|string[]} uriVariant - The string to extract uris from. - * - * @return {string[]} - The array of uris found. - */ - fixupURIs(uriVariant) { - let uriArray; - if (typeof uriVariant === "string") { - uriArray = uriVariant.split("|"); - } else if ( - Array.isArray(uriVariant) && - uriVariant.every(entry => typeof entry === "string") - ) { - uriArray = uriVariant; - } else { - // about:tor as safe fallback - lazy.logger.error( - `Received unknown variant '${JSON.stringify(uriVariant)}'` - ); - uriArray = ["about:tor"]; - } - - // Attempt to convert user-supplied string to a uri, fallback to - // about:tor if cannot convert to valid uri object - return uriArray.map( - uriString => - Services.uriFixup.getFixupURIInfo( - uriString, - Ci.nsIURIFixup.FIXUP_FLAG_NONE - ).preferredURI?.spec ?? "about:tor" - ); - }, - - // called from browser.js on browser startup, passed in either the user's homepage(s) - // or uris passed via command-line; we want to replace them with about:torconnect uris - // which redirect after bootstrapping - getURIsToLoad(uriVariant) { - const uris = this.fixupURIs(uriVariant); - const localUriRx = /^(file:///|moz-extension:)/; - lazy.logger.debug( - `Will load after bootstrap => [${uris - .filter(uri => !localUriRx.test(uri)) - .join(", ")}]` - ); - - return uris.map(uri => - localUriRx.test(uri) ? uri : this.getRedirectURL(uri) - ); - }, };
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/875f93e...
tbb-commits@lists.torproject.org