[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor-browser/tor-browser-91.2.0esr-11.0-1] fixup! Bug 27476: Implement about:torconnect captive portal within Tor Browser



commit c962f24a8a8c7825ec18ce513d354f4093e78363
Author: Richard Pospesel <richard@xxxxxxxxxxxxxx>
Date:   Fri Sep 10 11:42:55 2021 -0500

    fixup! Bug 27476: Implement about:torconnect captive portal within Tor Browser
---
 .../torconnect/content/torBootstrapUrlbar.js       |  2 +-
 .../components/torpreferences/content/torPane.js   | 51 ++++++++++++++--------
 .../torpreferences/content/torPreferences.css      |  9 ++--
 browser/modules/TorConnect.jsm                     | 13 ++++--
 4 files changed, 48 insertions(+), 27 deletions(-)

diff --git a/browser/components/torconnect/content/torBootstrapUrlbar.js b/browser/components/torconnect/content/torBootstrapUrlbar.js
index 7843b80be8b9..e6a88490f33d 100644
--- a/browser/components/torconnect/content/torBootstrapUrlbar.js
+++ b/browser/components/torconnect/content/torBootstrapUrlbar.js
@@ -76,7 +76,7 @@ var TorBootstrapUrlbar = {
         inputContainer: gURLBar._inputContainer,
       })
       this.elements.torConnectBox.addEventListener("click", () => {
-        window.openTrustedLinkIn("about:torconnect", "tab");
+        TorConnect.openTorConnect();
       });
       Services.obs.addObserver(this, TorConnectTopics.StateChange);
       this.observing = true;
diff --git a/browser/components/torpreferences/content/torPane.js b/browser/components/torpreferences/content/torPane.js
index afdb27351831..a975c93cb8ed 100644
--- a/browser/components/torpreferences/content/torPane.js
+++ b/browser/components/torpreferences/content/torPane.js
@@ -10,7 +10,7 @@ const { TorProtocolService } = ChromeUtils.import(
   "resource:///modules/TorProtocolService.jsm"
 );
 
-const { TorConnect } = ChromeUtils.import(
+const { TorConnect, TorConnectTopics, TorConnectState } = ChromeUtils.import(
   "resource:///modules/TorConnect.jsm"
 );
 
@@ -159,35 +159,42 @@ const gTorPane = (function() {
       this._messageBoxButton = prefpane.querySelector(selectors.messageBox.button);
       // wire up connect button
       this._messageBoxButton.addEventListener("click", () => {
-        TorConnect.beginBootstrap().then((result) => {
-          let win = Services.wm.getMostRecentWindow("navigator:browser");
-          // switch to existing about:torconnect tab or create a new one
-          win.switchToTabHavingURI("about:torconnect", true);
-        });
+        TorConnect.beginBootstrap();
+        TorConnect.openTorConnect();
       });
 
-      let populateMessagebox = () => {
-        if (TorConnect.shouldShowTorConnect) {
+      this._populateMessagebox = () => {
+        if (TorConnect.shouldShowTorConnect &&
+            TorConnect.state === TorConnectState.Configuring) {
           // set messagebox style and text
           if (TorProtocolService.torBootstrapErrorOccurred()) {
+            this._messageBox.parentNode.style.display = null;
             this._messageBox.className = "error";
             this._messageBoxMessage.innerText = TorStrings.torConnect.tryAgainMessage;
             this._messageBoxButton.innerText = TorStrings.torConnect.tryAgain;
           } else {
+            this._messageBox.parentNode.style.display = null;
             this._messageBox.className = "warning";
             this._messageBoxMessage.innerText = TorStrings.torConnect.connectMessage;
             this._messageBoxButton.innerText = TorStrings.torConnect.torConnectButton;
           }
         } else {
+          // we need to explicitly hide the groupbox, as switching between
+          // the tor pane and other panes will 'unhide' (via the 'hidden'
+          // attribute) the groupbox, offsetting all of the content down
+          // by the groupbox's margin (even if content is 0 height)
+          this._messageBox.parentNode.style.display = "none";
           this._messageBox.className = "hidden";
           this._messageBoxMessage.innerText = "";
           this._messageBoxButton.innerText = "";
         }
       }
-      populateMessagebox();
+      this._populateMessagebox();
+      Services.obs.addObserver(this, TorConnectTopics.StateChange);
+
       // update the messagebox whenever we come back to the page
       window.addEventListener("focus", val => {
-        populateMessagebox();
+        this._populateMessagebox();
       });
 
       // Heading
@@ -571,6 +578,7 @@ const gTorPane = (function() {
     uninit() {
       // unregister our observer topics
       Services.obs.removeObserver(TorSettingsTopics.SettingChanged, this);
+      Services.obs.removeObserver(TorConnectTopics.StateChange, this);
     },
 
     // whether the page should be present in about:preferences
@@ -582,15 +590,24 @@ const gTorPane = (function() {
     // Callbacks
     //
 
-    // callback for when the quickstart pref changes
     observe(subject, topic, data) {
-      if (topic === TorSettingsTopics.SettingChanged) {
-        let obj = subject?.wrappedJSObject;
-        switch(data) {
-          case TorSettingsData.QuickStartEnabled: {
-            this._enableQuickstartCheckbox.checked = obj.value;
-            break;
+      switch (topic) {
+       // triggered when a TorSettings param has changed
+        case TorSettingsTopics.SettingChanged: {
+          let obj = subject?.wrappedJSObject;
+          switch(data) {
+            case TorSettingsData.QuickStartEnabled: {
+              this._enableQuickstartCheckbox.checked = obj.value;
+              break;
+            }
           }
+          break;
+        }
+        // triggered when tor connect state changes and we may
+        // need to update the messagebox
+        case TorConnectTopics.StateChange: {
+          this._populateMessagebox();
+          break;
         }
       }
     },
diff --git a/browser/components/torpreferences/content/torPreferences.css b/browser/components/torpreferences/content/torPreferences.css
index 47b8ff18e0af..e3cc429f5982 100644
--- a/browser/components/torpreferences/content/torPreferences.css
+++ b/browser/components/torpreferences/content/torPreferences.css
@@ -87,14 +87,15 @@
 
   border-radius: 2px;
   border: 0;
-  padding-left: 8px;
-  padding-right: 8px;
+  padding: 0px 8px;
   margin-left: auto;
   margin-right: 0px;
 
   font-size: 11px;
-  font-weight: 400;
+  font-weight: 600;
   white-space: nowrap;
+
+  color: white;
 }
 
 #torPreferences-connectMessageBox.error #torPreferences-connectMessageBox-button {
@@ -115,12 +116,10 @@
 
 #torPreferences-connectMessageBox.warning #torPreferences-connectMessageBox-button:hover {
   background-color: var(--purple-80);
-  color: white!important;
 }
 
 #torPreferences-connectMessageBox.warning #torPreferences-connectMessageBox-button:active {
   background-color: var(--purple-90);
-  color: white!important;
 }
 
 /* Advanced Settings */
diff --git a/browser/modules/TorConnect.jsm b/browser/modules/TorConnect.jsm
index f2c92dcb8f21..ddc14148eb88 100644
--- a/browser/modules/TorConnect.jsm
+++ b/browser/modules/TorConnect.jsm
@@ -329,8 +329,8 @@ const TorConnect = (() => {
             return (TorProtocolService.ownsTorDaemon &&
                    // and we're not using the legacy launcher
                    !TorLauncherUtil.useLegacyLauncher &&
-                   // legacy checks, TODO: maybe this should be in terms of our own state?
-                   (TorProtocolService.isNetworkDisabled() || !TorProtocolService.isBootstrapDone()));
+                   // if we have succesfully bootstraped, then no need to show TorConnect
+                   this.state != TorConnectState.Bootstrapped);
         },
 
         get shouldQuickStart() {
@@ -420,8 +420,13 @@ const TorConnect = (() => {
         Further external commands and helper methods
         */
         openTorPreferences: function() {
-            const win = BrowserWindowTracker.getTopWindow()
-            win.openTrustedLinkIn("about:preferences#tor", "tab");
+            const win = BrowserWindowTracker.getTopWindow();
+            win.switchToTabHavingURI("about:preferences#tor", true);
+        },
+
+        openTorConnect: function() {
+            const win = BrowserWindowTracker.getTopWindow();
+            win.switchToTabHavingURI("about:torconnect", true, {ignoreQueryString: true});
         },
 
         copyTorLogs: function() {



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits