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
 - 
481be29c
by Henry Wilkes at 2025-02-27T12:38:32+00:00
 
3 changed files:
- toolkit/components/torconnect/TorConnectParent.sys.mjs
 - toolkit/components/torconnect/content/torConnectUrlbarButton.js
 - toolkit/modules/TorConnect.sys.mjs
 
Changes:
| ... | ... | @@ -152,23 +152,23 @@ export class TorConnectParent extends JSWindowActorParent { | 
| 152 | 152 |     *   auto-bootstrapping.
 | 
| 153 | 153 |     */
 | 
| 154 | 154 |    static open(options) {
 | 
| 155 | +    if (!TorConnect.shouldShowTorConnect) {
 | 
|
| 156 | +      // Already bootstrapped, so don't reopen about:torconnect.
 | 
|
| 157 | +      return;
 | 
|
| 158 | +    }
 | 
|
| 159 | +  | 
|
| 155 | 160 |      const win = lazy.BrowserWindowTracker.getTopWindow();
 | 
| 156 | 161 |      win.switchToTabHavingURI("about:torconnect", true, {
 | 
| 157 | 162 |        ignoreQueryString: true,
 | 
| 158 | 163 |      });
 | 
| 159 | 164 | |
| 160 | -    if (!options?.beginBootstrapping || !TorConnect.canBeginBootstrap) {
 | 
|
| 161 | -      return;
 | 
|
| 162 | -    }
 | 
|
| 163 | -  | 
|
| 164 | -    if (options.beginBootstrapping === "hard") {
 | 
|
| 165 | -      if (TorConnect.canBeginAutoBootstrap && !options.regionCode) {
 | 
|
| 166 | -        // Treat as an addition startAgain request to first move back to the
 | 
|
| 167 | -        // "Start" stage before bootstrapping.
 | 
|
| 168 | -        TorConnect.startAgain();
 | 
|
| 169 | -      }
 | 
|
| 170 | -    } else if (TorConnect.potentiallyBlocked) {
 | 
|
| 171 | -      // Do not trigger the bootstrap if we have ever had an error.
 | 
|
| 165 | +    if (
 | 
|
| 166 | +      !options?.beginBootstrapping ||
 | 
|
| 167 | +      (options.beginBootstrapping !== "hard" &&
 | 
|
| 168 | +        TorConnect.potentiallyBlocked) ||
 | 
|
| 169 | +      (options.regionCode && !TorConnect.canBeginAutoBootstrap) ||
 | 
|
| 170 | +      (!options.regionCode && !TorConnect.canBeginNormalBootstrap)
 | 
|
| 171 | +    ) {
 | 
|
| 172 | 172 |        return;
 | 
| 173 | 173 |      }
 | 
| 174 | 174 | 
| ... | ... | @@ -33,13 +33,21 @@ var gTorConnectUrlbarButton = { | 
| 33 | 33 |      if (this._isActive) {
 | 
| 34 | 34 |        return;
 | 
| 35 | 35 |      }
 | 
| 36 | +  | 
|
| 37 | +    this.button = document.getElementById("tor-connect-urlbar-button");
 | 
|
| 38 | +  | 
|
| 39 | +    if (!TorConnect.enabled) {
 | 
|
| 40 | +      // Don't initialise, just hide.
 | 
|
| 41 | +      this._updateButtonVisibility();
 | 
|
| 42 | +      return;
 | 
|
| 43 | +    }
 | 
|
| 44 | +  | 
|
| 36 | 45 |      this._isActive = true;
 | 
| 37 | 46 | |
| 38 | 47 |      const { TorStrings } = ChromeUtils.importESModule(
 | 
| 39 | 48 |        "resource://gre/modules/TorStrings.sys.mjs"
 | 
| 40 | 49 |      );
 | 
| 41 | 50 | |
| 42 | -    this.button = document.getElementById("tor-connect-urlbar-button");
 | 
|
| 43 | 51 |      document.getElementById("tor-connect-urlbar-button-label").value =
 | 
| 44 | 52 |        TorStrings.torConnect.torConnectButton;
 | 
| 45 | 53 |      this.button.addEventListener("click", event => {
 | 
| ... | ... | @@ -61,7 +69,7 @@ var gTorConnectUrlbarButton = { | 
| 61 | 69 |          if (topic !== this._observeTopic) {
 | 
| 62 | 70 |            return;
 | 
| 63 | 71 |          }
 | 
| 64 | -        this._torConnectStageChanged();
 | 
|
| 72 | +        this._updateButtonVisibility();
 | 
|
| 65 | 73 |        },
 | 
| 66 | 74 |      };
 | 
| 67 | 75 |      Services.obs.addObserver(this._stateListener, this._observeTopic);
 | 
| ... | ... | @@ -84,7 +92,7 @@ var gTorConnectUrlbarButton = { | 
| 84 | 92 |      // switching selected browser.
 | 
| 85 | 93 |      gBrowser.addProgressListener(this._locationListener);
 | 
| 86 | 94 | |
| 87 | -    this._torConnectStageChanged();
 | 
|
| 95 | +    this._updateButtonVisibility();
 | 
|
| 88 | 96 |    },
 | 
| 89 | 97 | |
| 90 | 98 |    /**
 | 
| ... | ... | @@ -108,20 +116,6 @@ var gTorConnectUrlbarButton = { | 
| 108 | 116 |      TorConnectParent.open({ beginBootstrapping: "soft" });
 | 
| 109 | 117 |    },
 | 
| 110 | 118 | |
| 111 | -  /**
 | 
|
| 112 | -   * Callback for when the TorConnect stage changes.
 | 
|
| 113 | -   */
 | 
|
| 114 | -  _torConnectStageChanged() {
 | 
|
| 115 | -    if (TorConnect.stageName === TorConnectStage.Disabled) {
 | 
|
| 116 | -      // NOTE: We do not uninit early when we reach the
 | 
|
| 117 | -      // TorConnectStage.Bootstrapped stage because we can still leave the
 | 
|
| 118 | -      // Bootstrapped stage if the tor process exists early and needs a restart.
 | 
|
| 119 | -      this.uninit();
 | 
|
| 120 | -      return;
 | 
|
| 121 | -    }
 | 
|
| 122 | -    this._updateButtonVisibility();
 | 
|
| 123 | -  },
 | 
|
| 124 | -  | 
|
| 125 | 119 |    /**
 | 
| 126 | 120 |     * Callback when the TorConnect state, current browser location, or activation
 | 
| 127 | 121 |     * state changes.
 | 
| ... | ... | @@ -130,25 +124,25 @@ var gTorConnectUrlbarButton = { | 
| 130 | 124 |      if (!this.button) {
 | 
| 131 | 125 |        return;
 | 
| 132 | 126 |      }
 | 
| 133 | -    // NOTE: We do not manage focus when hiding the button. We only expect to
 | 
|
| 134 | -    // move from "not hidden" to "hidden" when:
 | 
|
| 135 | -    // + switching tabs to "about:torconnect", or
 | 
|
| 136 | -    // + starting bootstrapping.
 | 
|
| 137 | -    //
 | 
|
| 138 | -    // When switching tabs, the normal tab switching logic will eventually move
 | 
|
| 139 | -    // focus to the new tab or url bar, so whilst the focus may be lost
 | 
|
| 140 | -    // temporarily when we hide the button, it will be re-established quickly on
 | 
|
| 141 | -    // tab switch.
 | 
|
| 142 | -    //
 | 
|
| 143 | -    // And we don't expect bootstrapping to start whilst outside of the
 | 
|
| 144 | -    // "about:torconnect", and the automatic bootstrapping should only trigger
 | 
|
| 145 | -    // at the initial start.
 | 
|
| 146 | -    this.button.hidden =
 | 
|
| 127 | +    const hadFocus = this.button.contains(document.activeElement);
 | 
|
| 128 | +    const hide =
 | 
|
| 147 | 129 |        !this._isActive ||
 | 
| 148 | 130 |        this._inAboutTorConnectTab ||
 | 
| 149 | -      !TorConnect.enabled ||
 | 
|
| 150 | -      !TorConnect.canBeginBootstrap;
 | 
|
| 151 | -    const plainButton = TorConnect.potentiallyBlocked;
 | 
|
| 131 | +      TorConnect.stageName === TorConnectStage.Bootstrapped;
 | 
|
| 132 | +    this.button.hidden = hide;
 | 
|
| 133 | +    if (hide && hadFocus) {
 | 
|
| 134 | +      // Lost focus. E.g. if the "Connect" button is focused in another window
 | 
|
| 135 | +      // or tab outside of about:torconnect.
 | 
|
| 136 | +      // Move focus back to the URL bar.
 | 
|
| 137 | +      gURLBar.focus();
 | 
|
| 138 | +    }
 | 
|
| 139 | +    // We style the button as a tor purple button if clicking the button will
 | 
|
| 140 | +    // also start a bootstrap. I.e. whether we meet the conditions in
 | 
|
| 141 | +    // TorConnectParent.open.
 | 
|
| 142 | +    const plainButton =
 | 
|
| 143 | +      !this._isActive ||
 | 
|
| 144 | +      !TorConnect.canBeginNormalBootstrap ||
 | 
|
| 145 | +      TorConnect.potentiallyBlocked;
 | 
|
| 152 | 146 |      this.button.classList.toggle("tor-urlbar-button-plain", plainButton);
 | 
| 153 | 147 |      this.button.classList.toggle("tor-button", !plainButton);
 | 
| 154 | 148 |    },
 | 
| ... | ... | @@ -1048,20 +1048,17 @@ export const TorConnect = { | 
| 1048 | 1048 |    },
 | 
| 1049 | 1049 | |
| 1050 | 1050 |    /**
 | 
| 1051 | -   * Whether we are in a stage that can lead into the Bootstrapping stage. I.e.
 | 
|
| 1052 | -   * whether we can make a "normal" or "auto" bootstrapping request.
 | 
|
| 1051 | +   * Whether we are in a stage that can lead into a "normal" bootstrapping
 | 
|
| 1052 | +   * request.
 | 
|
| 1053 | 1053 |     *
 | 
| 1054 | 1054 |     * The value may change with TorConnectTopics.StageChanged.
 | 
| 1055 | 1055 |     *
 | 
| 1056 | 1056 |     * @param {boolean}
 | 
| 1057 | 1057 |     */
 | 
| 1058 | -  get canBeginBootstrap() {
 | 
|
| 1058 | +  get canBeginNormalBootstrap() {
 | 
|
| 1059 | 1059 |      return (
 | 
| 1060 | 1060 |        this._stageName === TorConnectStage.Start ||
 | 
| 1061 | -      this._stageName === TorConnectStage.Offline ||
 | 
|
| 1062 | -      this._stageName === TorConnectStage.ChooseRegion ||
 | 
|
| 1063 | -      this._stageName === TorConnectStage.RegionNotFound ||
 | 
|
| 1064 | -      this._stageName === TorConnectStage.ConfirmRegion
 | 
|
| 1061 | +      this._stageName === TorConnectStage.Offline
 | 
|
| 1065 | 1062 |      );
 | 
| 1066 | 1063 |    },
 | 
| 1067 | 1064 | |
| ... | ... | @@ -1267,14 +1264,9 @@ export const TorConnect = { | 
| 1267 | 1264 |        return true;
 | 
| 1268 | 1265 |      }
 | 
| 1269 | 1266 | |
| 1270 | -    if (!this.canBeginBootstrap) {
 | 
|
| 1271 | -      lazy.logger.warn(`Cannot begin bootstrap in stage ${currentStage}`);
 | 
|
| 1272 | -      return false;
 | 
|
| 1273 | -    }
 | 
|
| 1274 | -    if (this.canBeginAutoBootstrap) {
 | 
|
| 1275 | -      // Only expect "auto" bootstraps to be triggered when in an error stage.
 | 
|
| 1267 | +    if (!this.canBeginNormalBootstrap) {
 | 
|
| 1276 | 1268 |        lazy.logger.warn(
 | 
| 1277 | -        `Expected a regionCode to bootstrap in stage ${currentStage}`
 | 
|
| 1269 | +        `Cannot begin normal bootstrap in stage ${currentStage}`
 | 
|
| 1278 | 1270 |        );
 | 
| 1279 | 1271 |        return false;
 | 
| 1280 | 1272 |      }
 |