morgan pushed to branch tor-browser-128.7.0esr-14.5-1 at The Tor Project / Applications / Tor Browser
Commits: d8e17646 by Henry Wilkes at 2025-02-27T12:38:32+00:00 fixup! TB 40597: Implement TorSettings module
TB 43465: Replace TorConnect.canBeginBootstrap with TorConnect.canBeginNormalBootstrap to distinguish it from TorConnect.canBeginAutoBootstrap.
- - - - - 481be29c by Henry Wilkes at 2025-02-27T12:38:32+00:00 fixup! TB 27476: Implement about:torconnect captive portal within Tor Browser
TB 43465: Show the urlbar Connect button when the user might want to return to about:torconnect.
Instead of hiding the button when canBeginNormalBootstrap is false we show it as a plain button. Instead we hide it only when we are already bootstrapped.
We also avoid initialising the button when TorConnect is not enabled.
We also update TorConnect.open:
1. Do not re-open about:torconnect if we are already connected. E.g. when the user selects "Connect" in a bridge dialog but we are already connected by the time the settings are applied. 2. Do not call TorConnect.startAgain when receiving a "hard" request. Only the bridge dialogs make this request, and they would have already triggered startAgain by changing the bridge settings.
- - - - -
3 changed files:
- toolkit/components/torconnect/TorConnectParent.sys.mjs - toolkit/components/torconnect/content/torConnectUrlbarButton.js - toolkit/modules/TorConnect.sys.mjs
Changes:
===================================== toolkit/components/torconnect/TorConnectParent.sys.mjs ===================================== @@ -152,23 +152,23 @@ export class TorConnectParent extends JSWindowActorParent { * auto-bootstrapping. */ static open(options) { + if (!TorConnect.shouldShowTorConnect) { + // Already bootstrapped, so don't reopen about:torconnect. + return; + } + 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. + if ( + !options?.beginBootstrapping || + (options.beginBootstrapping !== "hard" && + TorConnect.potentiallyBlocked) || + (options.regionCode && !TorConnect.canBeginAutoBootstrap) || + (!options.regionCode && !TorConnect.canBeginNormalBootstrap) + ) { return; }
===================================== toolkit/components/torconnect/content/torConnectUrlbarButton.js ===================================== @@ -33,13 +33,21 @@ var gTorConnectUrlbarButton = { if (this._isActive) { return; } + + this.button = document.getElementById("tor-connect-urlbar-button"); + + if (!TorConnect.enabled) { + // Don't initialise, just hide. + this._updateButtonVisibility(); + return; + } + this._isActive = true;
const { TorStrings } = ChromeUtils.importESModule( "resource://gre/modules/TorStrings.sys.mjs" );
- this.button = document.getElementById("tor-connect-urlbar-button"); document.getElementById("tor-connect-urlbar-button-label").value = TorStrings.torConnect.torConnectButton; this.button.addEventListener("click", event => { @@ -61,7 +69,7 @@ var gTorConnectUrlbarButton = { if (topic !== this._observeTopic) { return; } - this._torConnectStageChanged(); + this._updateButtonVisibility(); }, }; Services.obs.addObserver(this._stateListener, this._observeTopic); @@ -84,7 +92,7 @@ var gTorConnectUrlbarButton = { // switching selected browser. gBrowser.addProgressListener(this._locationListener);
- this._torConnectStageChanged(); + this._updateButtonVisibility(); },
/** @@ -108,20 +116,6 @@ var gTorConnectUrlbarButton = { TorConnectParent.open({ beginBootstrapping: "soft" }); },
- /** - * Callback for when the TorConnect stage changes. - */ - _torConnectStageChanged() { - if (TorConnect.stageName === TorConnectStage.Disabled) { - // NOTE: We do not uninit early when we reach the - // TorConnectStage.Bootstrapped stage because we can still leave the - // Bootstrapped stage if the tor process exists early and needs a restart. - this.uninit(); - return; - } - this._updateButtonVisibility(); - }, - /** * Callback when the TorConnect state, current browser location, or activation * state changes. @@ -130,25 +124,25 @@ var gTorConnectUrlbarButton = { if (!this.button) { return; } - // NOTE: We do not manage focus when hiding the button. We only expect to - // move from "not hidden" to "hidden" when: - // + switching tabs to "about:torconnect", or - // + starting bootstrapping. - // - // When switching tabs, the normal tab switching logic will eventually move - // focus to the new tab or url bar, so whilst the focus may be lost - // temporarily when we hide the button, it will be re-established quickly on - // tab switch. - // - // And we don't expect bootstrapping to start whilst outside of the - // "about:torconnect", and the automatic bootstrapping should only trigger - // at the initial start. - this.button.hidden = + const hadFocus = this.button.contains(document.activeElement); + const hide = !this._isActive || this._inAboutTorConnectTab || - !TorConnect.enabled || - !TorConnect.canBeginBootstrap; - const plainButton = TorConnect.potentiallyBlocked; + TorConnect.stageName === TorConnectStage.Bootstrapped; + this.button.hidden = hide; + if (hide && hadFocus) { + // Lost focus. E.g. if the "Connect" button is focused in another window + // or tab outside of about:torconnect. + // Move focus back to the URL bar. + gURLBar.focus(); + } + // We style the button as a tor purple button if clicking the button will + // also start a bootstrap. I.e. whether we meet the conditions in + // TorConnectParent.open. + const plainButton = + !this._isActive || + !TorConnect.canBeginNormalBootstrap || + TorConnect.potentiallyBlocked; this.button.classList.toggle("tor-urlbar-button-plain", plainButton); this.button.classList.toggle("tor-button", !plainButton); },
===================================== toolkit/modules/TorConnect.sys.mjs ===================================== @@ -1048,20 +1048,17 @@ export const TorConnect = { },
/** - * Whether we are in a stage that can lead into the Bootstrapping stage. I.e. - * whether we can make a "normal" or "auto" bootstrapping request. + * Whether we are in a stage that can lead into a "normal" bootstrapping + * request. * * The value may change with TorConnectTopics.StageChanged. * * @param {boolean} */ - get canBeginBootstrap() { + get canBeginNormalBootstrap() { return ( this._stageName === TorConnectStage.Start || - this._stageName === TorConnectStage.Offline || - this._stageName === TorConnectStage.ChooseRegion || - this._stageName === TorConnectStage.RegionNotFound || - this._stageName === TorConnectStage.ConfirmRegion + this._stageName === TorConnectStage.Offline ); },
@@ -1267,14 +1264,9 @@ export const TorConnect = { return true; }
- if (!this.canBeginBootstrap) { - lazy.logger.warn(`Cannot begin bootstrap in stage ${currentStage}`); - return false; - } - if (this.canBeginAutoBootstrap) { - // Only expect "auto" bootstraps to be triggered when in an error stage. + if (!this.canBeginNormalBootstrap) { lazy.logger.warn( - `Expected a regionCode to bootstrap in stage ${currentStage}` + `Cannot begin normal bootstrap in stage ${currentStage}` ); return false; }
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/10c9315...
tbb-commits@lists.torproject.org