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

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



commit a2581284372175491fbd55b5f44e4c681b9009dd
Author: Richard Pospesel <richard@xxxxxxxxxxxxxx>
Date:   Mon Jul 5 17:07:23 2021 +0200

    fixup! Bug 27476: Implement about:torconnect captive portal within Tor Browser
---
 browser/components/torconnect/TorConnectParent.jsm  | 11 +----------
 .../torconnect/content/aboutTorConnect.js           | 21 +++++----------------
 browser/modules/TorConnect.jsm                      | 19 +++++++++++++++++--
 dom/base/nsGlobalWindowOuter.cpp                    |  2 ++
 toolkit/modules/RemotePageAccessManager.jsm         |  4 ----
 5 files changed, 25 insertions(+), 32 deletions(-)

diff --git a/browser/components/torconnect/TorConnectParent.jsm b/browser/components/torconnect/TorConnectParent.jsm
index f775507a744f..54548891fbab 100644
--- a/browser/components/torconnect/TorConnectParent.jsm
+++ b/browser/components/torconnect/TorConnectParent.jsm
@@ -27,6 +27,7 @@ const gActiveTopics = [
   kTorBootstrapStatusTopic,
   kTorBootstrapErrorTopic,
   kTorLogHasWarnOrErrTopic,
+  "torconnect:bootstrap-complete",
 ];
 
 const gTorLauncherPrefs = {
@@ -69,9 +70,6 @@ class TorConnectParent extends JSWindowActorParent {
     }
   }
 
-  get browser() {
-    return this.browsingContext.top.embedderElement;
-  }
 
   _OpenTorAdvancedPreferences() {
     const win = this.browsingContext.top.embedderElement.ownerGlobal;
@@ -93,11 +91,6 @@ class TorConnectParent extends JSWindowActorParent {
     );
   }
 
-  _GoToBrowserHome() {
-    const window = this.browser.ownerGlobal;
-    window.BrowserHome();
-  }
-
   receiveMessage(message) {
     switch (message.name) {
       case "TorBootstrapErrorOccurred":
@@ -106,8 +99,6 @@ class TorConnectParent extends JSWindowActorParent {
         return TorProtocolService.retrieveBootstrapStatus();
       case "OpenTorAdvancedPreferences":
         return this._OpenTorAdvancedPreferences();
-      case "GoToBrowserHome":
-        return this._GoToBrowserHome();
       case "GetLocalizedBootstrapStatus":
         const { status, keyword } = message.data;
         return TorLauncherUtil.getLocalizedBootstrapStatus(status, keyword);
diff --git a/browser/components/torconnect/content/aboutTorConnect.js b/browser/components/torconnect/content/aboutTorConnect.js
index 11301fa10cab..19fd335ccd13 100644
--- a/browser/components/torconnect/content/aboutTorConnect.js
+++ b/browser/components/torconnect/content/aboutTorConnect.js
@@ -15,10 +15,6 @@ const TorLauncherPrefs = {
   prompt_at_startup: "extensions.torlauncher.prompt_at_startup",
 }
 
-const BrowserPrefs = {
-  homepage: "browser.startup.homepage",
-}
-
 class AboutTorConnect {
   log(...args) {
     console.log(...args);
@@ -133,14 +129,6 @@ class AboutTorConnect {
     this.elemTitle.classList.add("error");
   }
 
-  goToBrowserHome() {
-    this.hideElem(this.elemCancelButton);
-
-    // redirect this about:torconnect to browser homepage
-    const homepage = RPMGetStringPref(BrowserPrefs.homepage);
-    window.location.replace(homepage);
-  }
-
   set state(state) {
     const oldState = this.state;
     if (oldState === state) {
@@ -158,7 +146,7 @@ class AboutTorConnect {
         this.setBootstrapErrorUI();
         break;
       case AboutTorConnect.STATE_BOOTSTRAPPED:
-        this.goToBrowserHome();
+        window.close();
         break;
     }
   }
@@ -219,8 +207,6 @@ class AboutTorConnect {
       // if bootstrap state is greater than 0.
       this.state = AboutTorConnect.STATE_INITIAL;
       return;
-    } else if (percentComplete >= 100) {
-      this.state = AboutTorConnect.STATE_BOOTSTRAPPED;
     } else if (percentComplete > 0) {
       this.state = AboutTorConnect.STATE_BOOTSTRAPPING;
     }
@@ -306,7 +292,10 @@ class AboutTorConnect {
     RPMAddMessageListener(kTorQuickstartPrefChanged, ({ data }) => {
       // update checkbox with latest quickstart pref value
       this.elemQuickstartCheckbox.checked = data;
-    })
+    });
+    RPMAddMessageListener("torconnect:bootstrap-complete", () => {
+      this.state = AboutTorConnect.STATE_BOOTSTRAPPED;
+    });
   }
 
   initKeyboardShortcuts() {
diff --git a/browser/modules/TorConnect.jsm b/browser/modules/TorConnect.jsm
index 2b8cd15e3b62..3125c84558db 100644
--- a/browser/modules/TorConnect.jsm
+++ b/browser/modules/TorConnect.jsm
@@ -3,11 +3,15 @@
 var EXPORTED_SYMBOLS = ["TorConnect"];
 
 const { Services } = ChromeUtils.import(
-  "resource://gre/modules/Services.jsm"
+    "resource://gre/modules/Services.jsm"
+);
+
+const { BrowserWindowTracker } = ChromeUtils.import(
+    "resource:///modules/BrowserWindowTracker.jsm"
 );
 
 const { TorProtocolService } = ChromeUtils.import(
-  "resource:///modules/TorProtocolService.jsm"
+    "resource:///modules/TorProtocolService.jsm"
 );
 
 // TODO: move the bootstrap state management out of each of the individual
@@ -29,6 +33,17 @@ var TorConnect = (() => {
             case "TorBootstrapStatus":
                 const obj = subject?.wrappedJSObject;
                 if (obj?.PROGRESS === 100) {
+                    // open home page(s) in new tabs
+                    const win = BrowserWindowTracker.getTopWindow()
+                    const urls = Services.prefs.getStringPref("browser.startup.homepage").split('|');
+
+                    let location="tab";
+                    for(const url of urls) {
+                        win.openTrustedLinkIn(url, location);
+                        // open subsequent tabs behind first tab
+                        location = "tabshifted";
+                    }
+
                     Services.obs.notifyObservers(null, "torconnect:bootstrap-complete");
                 }
                 break;
diff --git a/dom/base/nsGlobalWindowOuter.cpp b/dom/base/nsGlobalWindowOuter.cpp
index abe1e56d9714..759060f131ff 100644
--- a/dom/base/nsGlobalWindowOuter.cpp
+++ b/dom/base/nsGlobalWindowOuter.cpp
@@ -6082,6 +6082,8 @@ void nsGlobalWindowOuter::CloseOuter(bool aTrustedCaller) {
     NS_ENSURE_SUCCESS_VOID(rv);
 
     if (!StringBeginsWith(url, NS_LITERAL_STRING("about:neterror")) &&
+        // we want about:torconnect pages to be able to close themselves after bootstrap
+        !StringBeginsWith(url, NS_LITERAL_STRING("about:torconnect")) &&
         !HadOriginalOpener() && !aTrustedCaller) {
       bool allowClose =
           mAllowScriptsToClose ||
diff --git a/toolkit/modules/RemotePageAccessManager.jsm b/toolkit/modules/RemotePageAccessManager.jsm
index 0c001e707096..0927391c2ba7 100644
--- a/toolkit/modules/RemotePageAccessManager.jsm
+++ b/toolkit/modules/RemotePageAccessManager.jsm
@@ -183,7 +183,6 @@ let RemotePageAccessManager = {
     "about:torconnect": {
       RPMAddMessageListener: ["*"],
       RPMSendAsyncMessage: [
-        "GoToBrowserHome",
         "OpenTorAdvancedPreferences",
         "TorRetrieveBootstrapStatus",
         "TorStopBootstrap",
@@ -205,9 +204,6 @@ let RemotePageAccessManager = {
       RPMSetBoolPref: [
         "extensions.torlauncher.quickstart",
       ],
-      RPMGetStringPref: [
-        "browser.startup.homepage",
-      ],
     },
   },
 



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