[tor-commits] [Git][tpo/applications/tor-browser][tor-browser-102.10.0esr-12.5-1] 8 commits: fixup! Bug 40597: Implement TorSettings module

Richard Pospesel (@richard) git at gitlab.torproject.org
Thu Apr 13 20:39:16 UTC 2023



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
fixup! Bug 40597: Implement TorSettings module

Bug 41608 - Tidy up the TorConnect API for broad error states that the
different UI components can share.

Rename the `hasBootstrapEverFailed` to `potentiallyBlocked` as a
specific failure state.

Add the `hasEverFailed` boolean property as a catch-all failure state.

Add an `enabled` boolean property, which just maps to whether we own the
tor process.

- - - - -
b652316e by Henry Wilkes at 2023-04-13T19:07:39+00:00
fixup! Bug 27476: Implement about:torconnect captive portal within Tor Browser

Bug 41608 - Tidy up the TorConnect API for broad error states that the
different UI components can share.

Just use the HasEverFailed state to determine whether to show "Try
Again" or to show breadcrumbs.

- - - - -
60d18fa7 by Henry Wilkes at 2023-04-13T19:07:39+00:00
fixup! Bug 31286: Implementation of bridge, proxy, and firewall settings in about:preferences#connection

Bug 41608 - Tidy up the TorConnect API for broad error states that the
different UI components can share.

No longer import TorMonitorService, and just use TorConnect instead.

+ Use TorConnect.enabled to determine whether to show the settings.
+ Use TorConnect.hasEverFailed state rather than
  TorMonitorService.bootstrapErrorOccurred to determine whether to show
  "Try Again".
+ Use TorConnect.potentiallyBlocked to determine whether to show the
  location selector. E.g. we don't want to show this if we just failed
  an internet connection test.

- - - - -
9fe1259d by Henry Wilkes at 2023-04-13T19:07:40+00:00
fixup! Bug 40933: Add tor-launcher functionality

Bug 41608 - Remove unused TorMonitorService.bootstrapErrorOccurred

- - - - -
d6c9dd4f by Henry Wilkes at 2023-04-13T19:07:40+00:00
fixup! Bug 40597: Implement TorSettings module

Bug 41608 - Remove unused TorMonitorService.bootstrapErrorOccurred

- - - - -
2a8e78df by Henry Wilkes at 2023-04-13T19:07:41+00:00
fixup! Bug 40597: Implement TorSettings module

Bug 41608 - Add the canBeginBootstrap and canBeginAutoBootstrap
properties  to determine whether it is possible to enter the
corresponding TorConnectState from the current state.

Add options to openTorConnect to begin bootstrapping or
auto-bootstrapping once opened.

- - - - -
203f9488 by Henry Wilkes at 2023-04-13T19:07:41+00:00
fixup! Bug 31286: Implementation of bridge, proxy, and firewall settings in about:preferences#connection

Bug 41608 - Use TorConnect.canBeginBootstrap and
TorConnect.canBeginAutoBootstrap and use bootstrapping options in
openAboutTor.

Selecting a location in the preferences now also opens
"about:torconnect".

- - - - -
e109bbd2 by Henry Wilkes at 2023-04-13T19:07:42+00:00
fixup! Bug 27476: Implement about:torconnect captive portal within Tor Browser

Bug 41608 - Remove the FatalError state since it is not defined in
TorConnect.

- - - - -


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:

=====================================
browser/components/torconnect/TorConnectParent.jsm
=====================================
@@ -38,7 +38,7 @@ class TorConnectParent extends JSWindowActorParent {
       InternetStatus: TorConnect.internetStatus,
       DetectedLocation: TorConnect.detectedLocation,
       ShowViewLog: TorConnect.logHasWarningOrError,
-      HasBootsrapEverFailed: TorConnect.hasBootstrapEverFailed,
+      HasEverFailed: TorConnect.hasEverFailed,
       QuickStartEnabled: TorSettings.quickstart.enabled,
       UIState: TorConnect.uiState,
     };
@@ -67,8 +67,7 @@ class TorConnectParent extends JSWindowActorParent {
               self.state.ErrorMessage = null;
               self.state.ErrorDetails = null;
             }
-            self.state.HasBootsrapEverFailed =
-              TorConnect.hasBootstrapEverFailed;
+            self.state.HasEverFailed = TorConnect.hasEverFailed;
             break;
           }
           case TorConnectTopics.BootstrapProgress: {
@@ -89,10 +88,6 @@ class TorConnectParent extends JSWindowActorParent {
             self.state.ShowViewLog = true;
             break;
           }
-          case TorConnectTopics.FatalError: {
-            // TODO: handle
-            break;
-          }
           case TorSettingsTopics.SettingChanged: {
             if (aData === TorSettingsData.QuickStartEnabled) {
               self.state.QuickStartEnabled = obj.value;


=====================================
browser/components/torconnect/content/aboutTorConnect.js
=====================================
@@ -142,7 +142,6 @@ class AboutTorConnect {
 
   uiState = {
     currentState: UIStates.ConnectToTor,
-    connectIsTryAgain: false,
     allowAutomaticLocation: true,
     selectedLocation: "automatic",
     bootstrapCause: UIStates.ConnectToTor,
@@ -389,12 +388,6 @@ class AboutTorConnect {
   }
 
   update_Error(state) {
-    if (!this.uiState.connectIsTryAgain) {
-      // TorConnect.hasBootstrapEverFailed remains false in case of Internet
-      // offline
-      this.uiState.connectIsTryAgain = true;
-      this.saveUIState();
-    }
     if (!state.StateChanged) {
       return;
     }
@@ -457,7 +450,7 @@ class AboutTorConnect {
     if (state?.StateChanged) {
       this.elements.connectButton.focus();
     }
-    if (this.uiState.connectIsTryAgain) {
+    if (state.HasEverFailed) {
       this.setBreadcrumbsStatus(
         BreadcrumbStatus.Active,
         BreadcrumbStatus.Default,
@@ -481,7 +474,7 @@ class AboutTorConnect {
     switch (this.uiState.bootstrapCause) {
       case UIStates.ConnectToTor:
         breadcrumbs[0] = BreadcrumbStatus.Active;
-        title = this.uiState.connectIsTryAgain
+        title = state.HasEverFailed
           ? TorStrings.torConnect.tryAgain
           : TorStrings.torConnect.torConnecting;
         description = TorStrings.settings.torPreferencesDescription;
@@ -505,7 +498,7 @@ class AboutTorConnect {
     this.setTitle(title, "");
     this.showConfigureConnectionLink(description);
     this.setProgress("", showProgressbar, state.BootstrapProgress);
-    if (state.HasBootsrapEverFailed) {
+    if (state.HasEverFailed) {
       this.setBreadcrumbsStatus(...breadcrumbs);
     } else {
       this.hideBreadcrumbs();


=====================================
browser/components/torpreferences/content/connectionPane.js
=====================================
@@ -18,9 +18,6 @@ const {
   TorBridgeSource,
 } = ChromeUtils.import("resource:///modules/TorSettings.jsm");
 
-const { TorMonitorService } = ChromeUtils.import(
-  "resource://gre/modules/TorMonitorService.jsm"
-);
 const { TorProtocolService } = ChromeUtils.import(
   "resource://gre/modules/TorProtocolService.jsm"
 );
@@ -197,17 +194,13 @@ const gConnectionPane = (function() {
       );
       // wire up connect button
       messageBoxButton.addEventListener("click", () => {
-        TorConnect.beginBootstrap();
-        TorConnect.openTorConnect();
+        TorConnect.openTorConnect({ beginBootstrap: true });
       });
 
       this._populateMessagebox = () => {
-        if (
-          TorConnect.shouldShowTorConnect &&
-          TorConnect.state === TorConnectState.Configuring
-        ) {
+        if (TorConnect.canBeginBootstrap) {
           // set messagebox style and text
-          if (TorMonitorService.bootstrapErrorOccurred) {
+          if (TorConnect.hasEverFailed) {
             messageBox.parentNode.style.display = null;
             messageBox.className = "error";
             messageBoxMessage.innerText = TorStrings.torConnect.tryAgainMessage;
@@ -291,10 +284,11 @@ const gConnectionPane = (function() {
               TorStrings.settings.statusInternetOffline;
             break;
         }
+        // FIXME: What about the TorConnectState.Disabled state?
         if (TorConnect.state === TorConnectState.Bootstrapped) {
           torIcon.className = "connected";
           torStatus.textContent = TorStrings.settings.statusTorConnected;
-        } else if (TorConnect.hasBootstrapEverFailed) {
+        } else if (TorConnect.potentiallyBlocked) {
           torIcon.className = "blocked";
           torStatus.textContent = TorStrings.settings.statusTorBlocked;
         } else {
@@ -358,7 +352,9 @@ const gConnectionPane = (function() {
           TorStrings.settings.bridgeChooseForMe
         );
         chooseForMe.addEventListener("command", e => {
-          TorConnect.beginAutoBootstrap(location.value);
+          TorConnect.openTorConnect({
+            beginAutoBootstrap: location.value,
+          });
         });
         this._populateLocations = () => {
           const currentValue = location.value;
@@ -404,8 +400,8 @@ const gConnectionPane = (function() {
         };
         this._showAutoconfiguration = () => {
           if (
-            !TorConnect.shouldShowTorConnect ||
-            !TorMonitorService.bootstrapErrorOccurred
+            !TorConnect.canBeginAutoBootstrap ||
+            !TorConnect.potentiallyBlocked
           ) {
             locationGroup.setAttribute("hidden", "true");
             return;
@@ -969,7 +965,7 @@ const gConnectionPane = (function() {
 
     // whether the page should be present in about:preferences
     get enabled() {
-      return TorMonitorService.ownsTorDaemon;
+      return TorConnect.enabled;
     },
 
     //


=====================================
browser/modules/TorConnect.jsm
=====================================
@@ -366,6 +366,7 @@ const TorConnect = (() => {
     _errorMessage: null,
     _errorDetails: null,
     _logHasWarningOrError: false,
+    _hasEverFailed: false,
     _hasBootstrapEverFailed: false,
     _transitionPromise: null,
 
@@ -458,7 +459,6 @@ const TorConnect = (() => {
                   "Error: Censorship simulation",
                   true
                 );
-                TorMonitorService.setBootstrapError();
                 return;
               }
 
@@ -581,7 +581,6 @@ const TorConnect = (() => {
                     );
                     return;
                   }
-                  TorMonitorService.setBootstrapError();
                 }
               }
 
@@ -793,6 +792,9 @@ const TorConnect = (() => {
     },
 
     _changeState(newState, ...args) {
+      if (newState === TorConnectState.Error) {
+        this._hasEverFailed = true;
+      }
       const prevState = this._state;
 
       // ensure this is a valid state transition
@@ -836,7 +838,7 @@ const TorConnect = (() => {
       console.log("TorConnect: init()");
       this._callback(TorConnectState.Initial).begin();
 
-      if (!TorMonitorService.ownsTorDaemon) {
+      if (!this.enabled) {
         // Disabled
         this._changeState(TorConnectState.Disabled);
       } else {
@@ -881,15 +883,50 @@ const TorConnect = (() => {
         Various getters
         */
 
+    /**
+     * Whether TorConnect is enabled.
+     *
+     * @type {boolean}
+     */
+    get enabled() {
+      return TorMonitorService.ownsTorDaemon;
+    },
+
     get shouldShowTorConnect() {
       // TorBrowser must control the daemon
       return (
-        TorMonitorService.ownsTorDaemon &&
+        this.enabled &&
         // if we have succesfully bootstraped, then no need to show TorConnect
         this.state !== TorConnectState.Bootstrapped
       );
     },
 
+    /**
+     * Whether bootstrapping can currently begin.
+     *
+     * The value may change with TorConnectTopics.StateChanged.
+     *
+     * @param {boolean}
+     */
+    get canBeginBootstrap() {
+      return TorConnectStateTransitions.get(this.state).includes(
+        TorConnectState.Bootstrapping
+      );
+    },
+
+    /**
+     * Whether auto-bootstrapping can currently begin.
+     *
+     * The value may change with TorConnectTopics.StateChanged.
+     *
+     * @param {boolean}
+     */
+    get canBeginAutoBootstrap() {
+      return TorConnectStateTransitions.get(this.state).includes(
+        TorConnectState.AutoBootstrapping
+      );
+    },
+
     get shouldQuickStart() {
       // quickstart must be enabled
       return (
@@ -939,7 +976,24 @@ const TorConnect = (() => {
       return this._logHasWarningOrError;
     },
 
-    get hasBootstrapEverFailed() {
+    /**
+     * Whether we have ever entered the Error state.
+     *
+     * @type {boolean}
+     */
+    get hasEverFailed() {
+      return this._hasEverFailed;
+    },
+
+    /**
+     * Whether the Bootstrapping process has ever failed, not including when it
+     * failed due to not being connected to the internet.
+     *
+     * This does not include a failure in AutoBootstrapping.
+     *
+     * @type {boolean}
+     */
+    get potentiallyBlocked() {
       return this._hasBootstrapEverFailed;
     },
 
@@ -982,11 +1036,40 @@ const TorConnect = (() => {
       win.switchToTabHavingURI("about:preferences#connection", true);
     },
 
-    openTorConnect() {
+    /**
+     * 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 {boolean} [options.beginBootstrap=false] - Whether to try and
+     *   begin Bootstrapping.
+     * @property {string} [options.beginAutoBootstrap] - The location to use to
+     *   begin AutoBootstrapping, if possible.
+     */
+    openTorConnect(options) {
       const win = BrowserWindowTracker.getTopWindow();
       win.switchToTabHavingURI("about:torconnect", true, {
         ignoreQueryString: true,
       });
+      if (
+        options?.beginBootstrap &&
+        this.canBeginBootstrap &&
+        !this.potentiallyBlocked
+      ) {
+        this.beginBootstrap();
+      }
+      // options.beginAutoBootstrap can be an empty string.
+      if (
+        options?.beginAutoBootstrap !== undefined &&
+        this.canBeginAutoBootstrap
+      ) {
+        this.beginAutoBootstrap(options.beginAutoBootstrap);
+      }
     },
 
     viewTorLogs() {


=====================================
toolkit/components/tor-launcher/TorMonitorService.jsm
=====================================
@@ -74,7 +74,6 @@ const TorMonitorService = {
   _startTimeout: null,
 
   _isBootstrapDone: false,
-  _bootstrapErrorOccurred: false,
   _lastWarningPhase: null,
   _lastWarningReason: null,
 
@@ -162,21 +161,11 @@ const TorMonitorService = {
     return this._isBootstrapDone;
   },
 
-  get bootstrapErrorOccurred() {
-    return this._bootstrapErrorOccurred;
-  },
-
   clearBootstrapError() {
-    this._bootstrapErrorOccurred = false;
     this._lastWarningPhase = null;
     this._lastWarningReason = null;
   },
 
-  // This should be used for debug only
-  setBootstrapError() {
-    this._bootstrapErrorOccurred = true;
-  },
-
   get isRunning() {
     return !!this._connection;
   },
@@ -211,7 +200,6 @@ const TorMonitorService = {
       }
     } catch (e) {
       // TorProcess already logs the error.
-      this._bootstrapErrorOccurred = true;
       this._lastWarningPhase = "startup";
       this._lastWarningReason = e.toString();
     }
@@ -248,7 +236,6 @@ const TorMonitorService = {
         ControlConnTimings.timeoutMS
       ) {
         let s = TorLauncherUtil.getLocalizedString("tor_controlconn_failed");
-        this._bootstrapErrorOccurred = true;
         this._lastWarningPhase = "startup";
         this._lastWarningReason = s;
         logger.info(s);
@@ -435,7 +422,6 @@ const TorMonitorService = {
 
     if (statusObj.PROGRESS === 100) {
       this._isBootstrapDone = true;
-      this._bootstrapErrorOccurred = false;
       try {
         Services.prefs.setBoolPref(Preferences.PromptAtStartup, false);
       } catch (e) {
@@ -456,7 +442,6 @@ const TorMonitorService = {
   },
 
   _notifyBootstrapError(statusObj) {
-    this._bootstrapErrorOccurred = true;
     try {
       Services.prefs.setBoolPref(Preferences.PromptAtStartup, true);
     } catch (e) {



View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/9d585beba7ab023d3eeace0567a1361c1df4fce7...e109bbd287e7df211ef506cc49130e3acc620b17

-- 
View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/9d585beba7ab023d3eeace0567a1361c1df4fce7...e109bbd287e7df211ef506cc49130e3acc620b17
You're receiving this email because of your account on gitlab.torproject.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.torproject.org/pipermail/tor-commits/attachments/20230413/f4afba81/attachment-0001.htm>


More information about the tor-commits mailing list