Richard Pospesel pushed to branch tor-browser-102.10.0esr-12.5-1 at The Tor Project / Applications / Tor Browser
Commits:
-
1222e90d
by Henry Wilkes at 2023-04-13T19:07:38+00:00
-
b652316e
by Henry Wilkes at 2023-04-13T19:07:39+00:00
-
60d18fa7
by Henry Wilkes at 2023-04-13T19:07:39+00:00
-
9fe1259d
by Henry Wilkes at 2023-04-13T19:07:40+00:00
-
d6c9dd4f
by Henry Wilkes at 2023-04-13T19:07:40+00:00
-
2a8e78df
by Henry Wilkes at 2023-04-13T19:07:41+00:00
-
203f9488
by Henry Wilkes at 2023-04-13T19:07:41+00:00
-
e109bbd2
by Henry Wilkes at 2023-04-13T19:07:42+00:00
5 changed files:
- browser/components/torconnect/TorConnectParent.jsm
- browser/components/torconnect/content/aboutTorConnect.js
- browser/components/torpreferences/content/connectionPane.js
- browser/modules/TorConnect.jsm
- toolkit/components/tor-launcher/TorMonitorService.jsm
Changes:
| ... | ... | @@ -38,7 +38,7 @@ class TorConnectParent extends JSWindowActorParent { |
| 38 | 38 | InternetStatus: TorConnect.internetStatus,
|
| 39 | 39 | DetectedLocation: TorConnect.detectedLocation,
|
| 40 | 40 | ShowViewLog: TorConnect.logHasWarningOrError,
|
| 41 | - HasBootsrapEverFailed: TorConnect.hasBootstrapEverFailed,
|
|
| 41 | + HasEverFailed: TorConnect.hasEverFailed,
|
|
| 42 | 42 | QuickStartEnabled: TorSettings.quickstart.enabled,
|
| 43 | 43 | UIState: TorConnect.uiState,
|
| 44 | 44 | };
|
| ... | ... | @@ -67,8 +67,7 @@ class TorConnectParent extends JSWindowActorParent { |
| 67 | 67 | self.state.ErrorMessage = null;
|
| 68 | 68 | self.state.ErrorDetails = null;
|
| 69 | 69 | }
|
| 70 | - self.state.HasBootsrapEverFailed =
|
|
| 71 | - TorConnect.hasBootstrapEverFailed;
|
|
| 70 | + self.state.HasEverFailed = TorConnect.hasEverFailed;
|
|
| 72 | 71 | break;
|
| 73 | 72 | }
|
| 74 | 73 | case TorConnectTopics.BootstrapProgress: {
|
| ... | ... | @@ -89,10 +88,6 @@ class TorConnectParent extends JSWindowActorParent { |
| 89 | 88 | self.state.ShowViewLog = true;
|
| 90 | 89 | break;
|
| 91 | 90 | }
|
| 92 | - case TorConnectTopics.FatalError: {
|
|
| 93 | - // TODO: handle
|
|
| 94 | - break;
|
|
| 95 | - }
|
|
| 96 | 91 | case TorSettingsTopics.SettingChanged: {
|
| 97 | 92 | if (aData === TorSettingsData.QuickStartEnabled) {
|
| 98 | 93 | self.state.QuickStartEnabled = obj.value;
|
| ... | ... | @@ -142,7 +142,6 @@ class AboutTorConnect { |
| 142 | 142 | |
| 143 | 143 | uiState = {
|
| 144 | 144 | currentState: UIStates.ConnectToTor,
|
| 145 | - connectIsTryAgain: false,
|
|
| 146 | 145 | allowAutomaticLocation: true,
|
| 147 | 146 | selectedLocation: "automatic",
|
| 148 | 147 | bootstrapCause: UIStates.ConnectToTor,
|
| ... | ... | @@ -389,12 +388,6 @@ class AboutTorConnect { |
| 389 | 388 | }
|
| 390 | 389 | |
| 391 | 390 | update_Error(state) {
|
| 392 | - if (!this.uiState.connectIsTryAgain) {
|
|
| 393 | - // TorConnect.hasBootstrapEverFailed remains false in case of Internet
|
|
| 394 | - // offline
|
|
| 395 | - this.uiState.connectIsTryAgain = true;
|
|
| 396 | - this.saveUIState();
|
|
| 397 | - }
|
|
| 398 | 391 | if (!state.StateChanged) {
|
| 399 | 392 | return;
|
| 400 | 393 | }
|
| ... | ... | @@ -457,7 +450,7 @@ class AboutTorConnect { |
| 457 | 450 | if (state?.StateChanged) {
|
| 458 | 451 | this.elements.connectButton.focus();
|
| 459 | 452 | }
|
| 460 | - if (this.uiState.connectIsTryAgain) {
|
|
| 453 | + if (state.HasEverFailed) {
|
|
| 461 | 454 | this.setBreadcrumbsStatus(
|
| 462 | 455 | BreadcrumbStatus.Active,
|
| 463 | 456 | BreadcrumbStatus.Default,
|
| ... | ... | @@ -481,7 +474,7 @@ class AboutTorConnect { |
| 481 | 474 | switch (this.uiState.bootstrapCause) {
|
| 482 | 475 | case UIStates.ConnectToTor:
|
| 483 | 476 | breadcrumbs[0] = BreadcrumbStatus.Active;
|
| 484 | - title = this.uiState.connectIsTryAgain
|
|
| 477 | + title = state.HasEverFailed
|
|
| 485 | 478 | ? TorStrings.torConnect.tryAgain
|
| 486 | 479 | : TorStrings.torConnect.torConnecting;
|
| 487 | 480 | description = TorStrings.settings.torPreferencesDescription;
|
| ... | ... | @@ -505,7 +498,7 @@ class AboutTorConnect { |
| 505 | 498 | this.setTitle(title, "");
|
| 506 | 499 | this.showConfigureConnectionLink(description);
|
| 507 | 500 | this.setProgress("", showProgressbar, state.BootstrapProgress);
|
| 508 | - if (state.HasBootsrapEverFailed) {
|
|
| 501 | + if (state.HasEverFailed) {
|
|
| 509 | 502 | this.setBreadcrumbsStatus(...breadcrumbs);
|
| 510 | 503 | } else {
|
| 511 | 504 | this.hideBreadcrumbs();
|
| ... | ... | @@ -18,9 +18,6 @@ const { |
| 18 | 18 | TorBridgeSource,
|
| 19 | 19 | } = ChromeUtils.import("resource:///modules/TorSettings.jsm");
|
| 20 | 20 | |
| 21 | -const { TorMonitorService } = ChromeUtils.import(
|
|
| 22 | - "resource://gre/modules/TorMonitorService.jsm"
|
|
| 23 | -);
|
|
| 24 | 21 | const { TorProtocolService } = ChromeUtils.import(
|
| 25 | 22 | "resource://gre/modules/TorProtocolService.jsm"
|
| 26 | 23 | );
|
| ... | ... | @@ -197,17 +194,13 @@ const gConnectionPane = (function() { |
| 197 | 194 | );
|
| 198 | 195 | // wire up connect button
|
| 199 | 196 | messageBoxButton.addEventListener("click", () => {
|
| 200 | - TorConnect.beginBootstrap();
|
|
| 201 | - TorConnect.openTorConnect();
|
|
| 197 | + TorConnect.openTorConnect({ beginBootstrap: true });
|
|
| 202 | 198 | });
|
| 203 | 199 | |
| 204 | 200 | this._populateMessagebox = () => {
|
| 205 | - if (
|
|
| 206 | - TorConnect.shouldShowTorConnect &&
|
|
| 207 | - TorConnect.state === TorConnectState.Configuring
|
|
| 208 | - ) {
|
|
| 201 | + if (TorConnect.canBeginBootstrap) {
|
|
| 209 | 202 | // set messagebox style and text
|
| 210 | - if (TorMonitorService.bootstrapErrorOccurred) {
|
|
| 203 | + if (TorConnect.hasEverFailed) {
|
|
| 211 | 204 | messageBox.parentNode.style.display = null;
|
| 212 | 205 | messageBox.className = "error";
|
| 213 | 206 | messageBoxMessage.innerText = TorStrings.torConnect.tryAgainMessage;
|
| ... | ... | @@ -291,10 +284,11 @@ const gConnectionPane = (function() { |
| 291 | 284 | TorStrings.settings.statusInternetOffline;
|
| 292 | 285 | break;
|
| 293 | 286 | }
|
| 287 | + // FIXME: What about the TorConnectState.Disabled state?
|
|
| 294 | 288 | if (TorConnect.state === TorConnectState.Bootstrapped) {
|
| 295 | 289 | torIcon.className = "connected";
|
| 296 | 290 | torStatus.textContent = TorStrings.settings.statusTorConnected;
|
| 297 | - } else if (TorConnect.hasBootstrapEverFailed) {
|
|
| 291 | + } else if (TorConnect.potentiallyBlocked) {
|
|
| 298 | 292 | torIcon.className = "blocked";
|
| 299 | 293 | torStatus.textContent = TorStrings.settings.statusTorBlocked;
|
| 300 | 294 | } else {
|
| ... | ... | @@ -358,7 +352,9 @@ const gConnectionPane = (function() { |
| 358 | 352 | TorStrings.settings.bridgeChooseForMe
|
| 359 | 353 | );
|
| 360 | 354 | chooseForMe.addEventListener("command", e => {
|
| 361 | - TorConnect.beginAutoBootstrap(location.value);
|
|
| 355 | + TorConnect.openTorConnect({
|
|
| 356 | + beginAutoBootstrap: location.value,
|
|
| 357 | + });
|
|
| 362 | 358 | });
|
| 363 | 359 | this._populateLocations = () => {
|
| 364 | 360 | const currentValue = location.value;
|
| ... | ... | @@ -404,8 +400,8 @@ const gConnectionPane = (function() { |
| 404 | 400 | };
|
| 405 | 401 | this._showAutoconfiguration = () => {
|
| 406 | 402 | if (
|
| 407 | - !TorConnect.shouldShowTorConnect ||
|
|
| 408 | - !TorMonitorService.bootstrapErrorOccurred
|
|
| 403 | + !TorConnect.canBeginAutoBootstrap ||
|
|
| 404 | + !TorConnect.potentiallyBlocked
|
|
| 409 | 405 | ) {
|
| 410 | 406 | locationGroup.setAttribute("hidden", "true");
|
| 411 | 407 | return;
|
| ... | ... | @@ -969,7 +965,7 @@ const gConnectionPane = (function() { |
| 969 | 965 | |
| 970 | 966 | // whether the page should be present in about:preferences
|
| 971 | 967 | get enabled() {
|
| 972 | - return TorMonitorService.ownsTorDaemon;
|
|
| 968 | + return TorConnect.enabled;
|
|
| 973 | 969 | },
|
| 974 | 970 | |
| 975 | 971 | //
|
| ... | ... | @@ -366,6 +366,7 @@ const TorConnect = (() => { |
| 366 | 366 | _errorMessage: null,
|
| 367 | 367 | _errorDetails: null,
|
| 368 | 368 | _logHasWarningOrError: false,
|
| 369 | + _hasEverFailed: false,
|
|
| 369 | 370 | _hasBootstrapEverFailed: false,
|
| 370 | 371 | _transitionPromise: null,
|
| 371 | 372 | |
| ... | ... | @@ -458,7 +459,6 @@ const TorConnect = (() => { |
| 458 | 459 | "Error: Censorship simulation",
|
| 459 | 460 | true
|
| 460 | 461 | );
|
| 461 | - TorMonitorService.setBootstrapError();
|
|
| 462 | 462 | return;
|
| 463 | 463 | }
|
| 464 | 464 | |
| ... | ... | @@ -581,7 +581,6 @@ const TorConnect = (() => { |
| 581 | 581 | );
|
| 582 | 582 | return;
|
| 583 | 583 | }
|
| 584 | - TorMonitorService.setBootstrapError();
|
|
| 585 | 584 | }
|
| 586 | 585 | }
|
| 587 | 586 | |
| ... | ... | @@ -793,6 +792,9 @@ const TorConnect = (() => { |
| 793 | 792 | },
|
| 794 | 793 | |
| 795 | 794 | _changeState(newState, ...args) {
|
| 795 | + if (newState === TorConnectState.Error) {
|
|
| 796 | + this._hasEverFailed = true;
|
|
| 797 | + }
|
|
| 796 | 798 | const prevState = this._state;
|
| 797 | 799 | |
| 798 | 800 | // ensure this is a valid state transition
|
| ... | ... | @@ -836,7 +838,7 @@ const TorConnect = (() => { |
| 836 | 838 | console.log("TorConnect: init()");
|
| 837 | 839 | this._callback(TorConnectState.Initial).begin();
|
| 838 | 840 | |
| 839 | - if (!TorMonitorService.ownsTorDaemon) {
|
|
| 841 | + if (!this.enabled) {
|
|
| 840 | 842 | // Disabled
|
| 841 | 843 | this._changeState(TorConnectState.Disabled);
|
| 842 | 844 | } else {
|
| ... | ... | @@ -881,15 +883,50 @@ const TorConnect = (() => { |
| 881 | 883 | Various getters
|
| 882 | 884 | */
|
| 883 | 885 | |
| 886 | + /**
|
|
| 887 | + * Whether TorConnect is enabled.
|
|
| 888 | + *
|
|
| 889 | + * @type {boolean}
|
|
| 890 | + */
|
|
| 891 | + get enabled() {
|
|
| 892 | + return TorMonitorService.ownsTorDaemon;
|
|
| 893 | + },
|
|
| 894 | + |
|
| 884 | 895 | get shouldShowTorConnect() {
|
| 885 | 896 | // TorBrowser must control the daemon
|
| 886 | 897 | return (
|
| 887 | - TorMonitorService.ownsTorDaemon &&
|
|
| 898 | + this.enabled &&
|
|
| 888 | 899 | // if we have succesfully bootstraped, then no need to show TorConnect
|
| 889 | 900 | this.state !== TorConnectState.Bootstrapped
|
| 890 | 901 | );
|
| 891 | 902 | },
|
| 892 | 903 | |
| 904 | + /**
|
|
| 905 | + * Whether bootstrapping can currently begin.
|
|
| 906 | + *
|
|
| 907 | + * The value may change with TorConnectTopics.StateChanged.
|
|
| 908 | + *
|
|
| 909 | + * @param {boolean}
|
|
| 910 | + */
|
|
| 911 | + get canBeginBootstrap() {
|
|
| 912 | + return TorConnectStateTransitions.get(this.state).includes(
|
|
| 913 | + TorConnectState.Bootstrapping
|
|
| 914 | + );
|
|
| 915 | + },
|
|
| 916 | + |
|
| 917 | + /**
|
|
| 918 | + * Whether auto-bootstrapping can currently begin.
|
|
| 919 | + *
|
|
| 920 | + * The value may change with TorConnectTopics.StateChanged.
|
|
| 921 | + *
|
|
| 922 | + * @param {boolean}
|
|
| 923 | + */
|
|
| 924 | + get canBeginAutoBootstrap() {
|
|
| 925 | + return TorConnectStateTransitions.get(this.state).includes(
|
|
| 926 | + TorConnectState.AutoBootstrapping
|
|
| 927 | + );
|
|
| 928 | + },
|
|
| 929 | + |
|
| 893 | 930 | get shouldQuickStart() {
|
| 894 | 931 | // quickstart must be enabled
|
| 895 | 932 | return (
|
| ... | ... | @@ -939,7 +976,24 @@ const TorConnect = (() => { |
| 939 | 976 | return this._logHasWarningOrError;
|
| 940 | 977 | },
|
| 941 | 978 | |
| 942 | - get hasBootstrapEverFailed() {
|
|
| 979 | + /**
|
|
| 980 | + * Whether we have ever entered the Error state.
|
|
| 981 | + *
|
|
| 982 | + * @type {boolean}
|
|
| 983 | + */
|
|
| 984 | + get hasEverFailed() {
|
|
| 985 | + return this._hasEverFailed;
|
|
| 986 | + },
|
|
| 987 | + |
|
| 988 | + /**
|
|
| 989 | + * Whether the Bootstrapping process has ever failed, not including when it
|
|
| 990 | + * failed due to not being connected to the internet.
|
|
| 991 | + *
|
|
| 992 | + * This does not include a failure in AutoBootstrapping.
|
|
| 993 | + *
|
|
| 994 | + * @type {boolean}
|
|
| 995 | + */
|
|
| 996 | + get potentiallyBlocked() {
|
|
| 943 | 997 | return this._hasBootstrapEverFailed;
|
| 944 | 998 | },
|
| 945 | 999 | |
| ... | ... | @@ -982,11 +1036,40 @@ const TorConnect = (() => { |
| 982 | 1036 | win.switchToTabHavingURI("about:preferences#connection", true);
|
| 983 | 1037 | },
|
| 984 | 1038 | |
| 985 | - openTorConnect() {
|
|
| 1039 | + /**
|
|
| 1040 | + * Open the "about:torconnect" tab.
|
|
| 1041 | + *
|
|
| 1042 | + * Bootstrapping or AutoBootstrapping can also be automatically triggered at
|
|
| 1043 | + * the same time, if the current state allows for it.
|
|
| 1044 | + *
|
|
| 1045 | + * Bootstrapping will not be triggered if the connection is
|
|
| 1046 | + * potentially blocked.
|
|
| 1047 | + *
|
|
| 1048 | + * @param {object} [options] - extra options.
|
|
| 1049 | + * @property {boolean} [options.beginBootstrap=false] - Whether to try and
|
|
| 1050 | + * begin Bootstrapping.
|
|
| 1051 | + * @property {string} [options.beginAutoBootstrap] - The location to use to
|
|
| 1052 | + * begin AutoBootstrapping, if possible.
|
|
| 1053 | + */
|
|
| 1054 | + openTorConnect(options) {
|
|
| 986 | 1055 | const win = BrowserWindowTracker.getTopWindow();
|
| 987 | 1056 | win.switchToTabHavingURI("about:torconnect", true, {
|
| 988 | 1057 | ignoreQueryString: true,
|
| 989 | 1058 | });
|
| 1059 | + if (
|
|
| 1060 | + options?.beginBootstrap &&
|
|
| 1061 | + this.canBeginBootstrap &&
|
|
| 1062 | + !this.potentiallyBlocked
|
|
| 1063 | + ) {
|
|
| 1064 | + this.beginBootstrap();
|
|
| 1065 | + }
|
|
| 1066 | + // options.beginAutoBootstrap can be an empty string.
|
|
| 1067 | + if (
|
|
| 1068 | + options?.beginAutoBootstrap !== undefined &&
|
|
| 1069 | + this.canBeginAutoBootstrap
|
|
| 1070 | + ) {
|
|
| 1071 | + this.beginAutoBootstrap(options.beginAutoBootstrap);
|
|
| 1072 | + }
|
|
| 990 | 1073 | },
|
| 991 | 1074 | |
| 992 | 1075 | viewTorLogs() {
|
| ... | ... | @@ -74,7 +74,6 @@ const TorMonitorService = { |
| 74 | 74 | _startTimeout: null,
|
| 75 | 75 | |
| 76 | 76 | _isBootstrapDone: false,
|
| 77 | - _bootstrapErrorOccurred: false,
|
|
| 78 | 77 | _lastWarningPhase: null,
|
| 79 | 78 | _lastWarningReason: null,
|
| 80 | 79 | |
| ... | ... | @@ -162,21 +161,11 @@ const TorMonitorService = { |
| 162 | 161 | return this._isBootstrapDone;
|
| 163 | 162 | },
|
| 164 | 163 | |
| 165 | - get bootstrapErrorOccurred() {
|
|
| 166 | - return this._bootstrapErrorOccurred;
|
|
| 167 | - },
|
|
| 168 | - |
|
| 169 | 164 | clearBootstrapError() {
|
| 170 | - this._bootstrapErrorOccurred = false;
|
|
| 171 | 165 | this._lastWarningPhase = null;
|
| 172 | 166 | this._lastWarningReason = null;
|
| 173 | 167 | },
|
| 174 | 168 | |
| 175 | - // This should be used for debug only
|
|
| 176 | - setBootstrapError() {
|
|
| 177 | - this._bootstrapErrorOccurred = true;
|
|
| 178 | - },
|
|
| 179 | - |
|
| 180 | 169 | get isRunning() {
|
| 181 | 170 | return !!this._connection;
|
| 182 | 171 | },
|
| ... | ... | @@ -211,7 +200,6 @@ const TorMonitorService = { |
| 211 | 200 | }
|
| 212 | 201 | } catch (e) {
|
| 213 | 202 | // TorProcess already logs the error.
|
| 214 | - this._bootstrapErrorOccurred = true;
|
|
| 215 | 203 | this._lastWarningPhase = "startup";
|
| 216 | 204 | this._lastWarningReason = e.toString();
|
| 217 | 205 | }
|
| ... | ... | @@ -248,7 +236,6 @@ const TorMonitorService = { |
| 248 | 236 | ControlConnTimings.timeoutMS
|
| 249 | 237 | ) {
|
| 250 | 238 | let s = TorLauncherUtil.getLocalizedString("tor_controlconn_failed");
|
| 251 | - this._bootstrapErrorOccurred = true;
|
|
| 252 | 239 | this._lastWarningPhase = "startup";
|
| 253 | 240 | this._lastWarningReason = s;
|
| 254 | 241 | logger.info(s);
|
| ... | ... | @@ -435,7 +422,6 @@ const TorMonitorService = { |
| 435 | 422 | |
| 436 | 423 | if (statusObj.PROGRESS === 100) {
|
| 437 | 424 | this._isBootstrapDone = true;
|
| 438 | - this._bootstrapErrorOccurred = false;
|
|
| 439 | 425 | try {
|
| 440 | 426 | Services.prefs.setBoolPref(Preferences.PromptAtStartup, false);
|
| 441 | 427 | } catch (e) {
|
| ... | ... | @@ -456,7 +442,6 @@ const TorMonitorService = { |
| 456 | 442 | },
|
| 457 | 443 | |
| 458 | 444 | _notifyBootstrapError(statusObj) {
|
| 459 | - this._bootstrapErrorOccurred = true;
|
|
| 460 | 445 | try {
|
| 461 | 446 | Services.prefs.setBoolPref(Preferences.PromptAtStartup, true);
|
| 462 | 447 | } catch (e) {
|