Commit ba98c304 authored by henry's avatar henry Committed by richard
Browse files

amend! Bug 27476: Implement about:torconnect captive portal within Tor Browser

Bug 27476: Implement about:torconnect captive portal within Tor Browser

- implements new about:torconnect page as tor-launcher replacement
- adds new torconnect component to browser
- tor process management functionality remains implemented in tor-launcher through the TorProtocolService module
- adds warning/error box to about:preferences#tor when not connected to tor

Bug 40773: Update the about:torconnect frontend page to match additional UI flows.

Bug 41608: Add a toolbar status button and a urlbar "Connect" button.
parent a71b5035
Loading
Loading
Loading
Loading
+18 −4
Original line number Diff line number Diff line
@@ -80,6 +80,8 @@ XPCOMUtils.defineLazyModuleGetters(this, {
  TabCrashHandler: "resource:///modules/ContentCrashHandlers.jsm",
  TelemetryEnvironment: "resource://gre/modules/TelemetryEnvironment.jsm",
  TorConnect: "resource:///modules/TorConnect.jsm",
  TorConnectState: "resource:///modules/TorConnect.jsm",
  TorConnectTopics: "resource:///modules/TorConnect.jsm",
  Translation: "resource:///modules/translation/TranslationParent.jsm",
  UITour: "resource:///modules/UITour.jsm",
  UpdateUtils: "resource://gre/modules/UpdateUtils.jsm",
@@ -269,6 +271,16 @@ XPCOMUtils.defineLazyScriptGetter(
  "gSharedTabWarning",
  "chrome://browser/content/browser-webrtc.js"
);
XPCOMUtils.defineLazyScriptGetter(
  this,
  ["gTorConnectUrlbarButton"],
  "chrome://browser/content/torconnect/torConnectUrlbarButton.js"
);
XPCOMUtils.defineLazyScriptGetter(
  this,
  ["gTorConnectTitlebarStatus"],
  "chrome://browser/content/torconnect/torConnectTitlebarStatus.js"
);
XPCOMUtils.defineLazyScriptGetter(
  this,
  ["gTorCircuitPanel"],
@@ -1808,6 +1820,9 @@ var gBrowserInit = {
    // Init the OnionAuthPrompt
    OnionAuthPrompt.init();

    gTorConnectUrlbarButton.init();
    gTorConnectTitlebarStatus.init();

    gTorCircuitPanel.init();

    // Certain kinds of automigration rely on this notification to complete
@@ -1895,8 +1910,6 @@ var gBrowserInit = {
    }

    this._loadHandled = true;

    TorBootstrapUrlbar.init();
  },

  _cancelDelayedStartup() {
@@ -2554,9 +2567,10 @@ var gBrowserInit = {

    OnionAuthPrompt.uninit();

    gTorCircuitPanel.uninit();
    gTorConnectUrlbarButton.uninit();
    gTorConnectTitlebarStatus.uninit();

    TorBootstrapUrlbar.uninit();
    gTorCircuitPanel.uninit();

    gAccessibilityServiceIndicator.uninit();

+1 −1
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@
<?xml-stylesheet href="chrome://browser/skin/places/editBookmark.css" type="text/css"?>
<?xml-stylesheet href="chrome://browser/content/onionservices/onionservices.css" type="text/css"?>
<?xml-stylesheet href="chrome://browser/content/torCircuitPanel.css" type="text/css"?>
<?xml-stylesheet href="chrome://browser/content/torconnect/torConnectTitlebarStatus.css" type="text/css"?>

<!DOCTYPE window [
#include browser-doctype.inc
@@ -123,7 +124,6 @@
  Services.scriptloader.loadSubScript("chrome://browser/content/search/searchbar.js", this);
  Services.scriptloader.loadSubScript("chrome://browser/content/languageNotification.js", this);
  Services.scriptloader.loadSubScript("chrome://torbutton/content/torbutton.js", this);
  Services.scriptloader.loadSubScript("chrome://browser/content/torconnect/torBootstrapUrlbar.js", this);

  window.onload = gBrowserInit.onLoad.bind(gBrowserInit);
  window.onunload = gBrowserInit.onUnload.bind(gBrowserInit);
+12 −1
Original line number Diff line number Diff line
@@ -93,6 +93,11 @@
              aria-live="polite"/>
      <hbox class="private-browsing-indicator"/>

      <html:div id="tor-connect-titlebar-status" role="status">
        <html:img alt="" id="tor-connect-titlebar-status-icon" />
        <html:span id="tor-connect-titlebar-status-label"></html:span>
      </html:div>

#include titlebar-items.inc.xhtml

    </toolbar>
@@ -335,7 +340,6 @@
                   data-l10n-id="urlbar-go-button"/>
            <hbox id="page-action-buttons" context="pageActionContextMenu">
              <toolbartabstop/>
#include ../../components/torconnect/content/torconnect-urlbar.inc.xhtml
              <hbox id="contextual-feature-recommendation" role="button" hidden="true">
                <hbox id="cfr-label-container">
                  <label id="cfr-label"/>
@@ -381,6 +385,13 @@
              </hbox>
            </hbox>

            <hbox id="tor-connect-urlbar-button"
                  role="button"
                  class="tor-urlbar-button"
                  hidden="true">
              <label id="tor-connect-urlbar-button-label"/>
            </hbox>

#include ../../components/onionservices/content/onionlocation-urlbar.inc.xhtml
          </hbox>
        </hbox>
+0 −5
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg viewBox="0 0 16 16" width="16" height="16" xmlns="http://www.w3.org/2000/svg">
  <path d="m14.1161 15.6245c-.0821.0001-.1634-.016-.2393-.0474-.0758-.0314-.1447-.0775-.2027-.1356l-12.749984-12.749c-.109266-.11882-.168406-.27526-.165071-.43666.003335-.16139.068886-.31525.182967-.42946.114078-.11421.267868-.17994.429258-.18345.16139-.00352.3179.05544.43685.16457l12.74998 12.75c.1168.1176.1824.2767.1824.4425s-.0656.3249-.1824.4425c-.058.058-.1269.1039-.2028.1352-.0759.0312-.1571.0471-.2392.0468z" fill-opacity="context-fill-opacity" fill="#ff0039" />
  <path d="m 8,0.5000002 c -1.61963,0 -3.1197431,0.5137987 -4.3457031,1.3867188 l 0.84375,0.8417968 0.7792969,0.78125 0.8613281,0.8613282 0.8164062,0.8164062 0.9863281,0.984375 h 0.058594 c 1.00965,0 1.828125,0.818485 1.828125,1.828125 0,0.01968 6.2e-4,0.039074 0,0.058594 L 10.8125,9.0449221 C 10.9334,8.7195921 11,8.3674002 11,8.0000002 c 0,-1.65685 -1.34314,-3 -3,-3 v -1.078125 c 2.25231,0 4.078125,1.825845 4.078125,4.078125 0,0.67051 -0.162519,1.3033281 -0.449219,1.8613281 l 0.861328,0.8613277 C 12.972434,9.9290067 13.25,8.9965102 13.25,8.0000002 c 0,-2.89949 -2.35049,-5.25 -5.25,-5.25 v -1.078125 c 3.4949,0 6.328125,2.833195 6.328125,6.328125 0,1.29533 -0.388841,2.4990528 -1.056641,3.5019528 l 0.841797,0.84375 C 14.986181,11.119703 15.5,9.6196302 15.5,8.0000002 c 0,-4.14214 -3.3579,-7.5 -7.5,-7.5 z m -6.1113281,3.15625 C 1.0154872,4.8821451 0.5,6.3803304 0.5,8.0000002 0.5,12.1421 3.85786,15.5 8,15.5 c 1.6198027,0 3.117896,-0.515441 4.34375,-1.388672 L 11.501953,13.269531 C 10.498787,13.937828 9.295838,14.328125 8,14.328125 V 13.25 c 0.9967306,0 1.9287093,-0.277621 2.722656,-0.759766 L 9.859375,11.626953 C 9.3016226,11.913918 8.6705338,12.078125 8,12.078125 V 11 C 8.3664751,11 8.716425,10.93088 9.0410156,10.810547 6.6639891,8.4300416 4.2743195,6.0418993 1.8886719,3.6562502 Z" fill-opacity="context-fill-opacity" fill="context-fill"/>
</svg>
+0 −95
Original line number Diff line number Diff line
// Copyright (c) 2021, The Tor Project, Inc.

"use strict";

const { TorConnect, TorConnectTopics, TorConnectState } = ChromeUtils.import(
  "resource:///modules/TorConnect.jsm"
);
const { TorStrings } = ChromeUtils.import("resource:///modules/TorStrings.jsm");

/* globals browser, gURLBar, Services */

var TorBootstrapUrlbar = {
  selectors: Object.freeze({
    torConnect: {
      box: "hbox#torconnect-box",
      label: "label#torconnect-label",
    },
  }),

  elements: null,

  updateTorConnectBox(state) {
    switch (state) {
      case TorConnectState.Initial:
      case TorConnectState.Configuring:
      case TorConnectState.AutoConfiguring:
      case TorConnectState.Error:
      case TorConnectState.FatalError: {
        this.elements.torConnectBox.removeAttribute("hidden");
        this.elements.torConnectLabel.textContent =
          TorStrings.torConnect.torNotConnectedConcise;
        this.elements.inputContainer.setAttribute("torconnect", "offline");
        break;
      }
      case TorConnectState.Bootstrapping: {
        this.elements.torConnectBox.removeAttribute("hidden");
        this.elements.torConnectLabel.textContent =
          TorStrings.torConnect.torConnectingConcise;
        this.elements.inputContainer.setAttribute("torconnect", "connecting");
        break;
      }
      case TorConnectState.Bootstrapped: {
        this.elements.torConnectBox.removeAttribute("hidden");
        this.elements.torConnectLabel.textContent =
          TorStrings.torConnect.torConnectedConcise;
        this.elements.inputContainer.setAttribute("torconnect", "connected");
        // hide torconnect box after 5 seconds
        setTimeout(() => {
          this.elements.torConnectBox.setAttribute("hidden", "true");
        }, 5000);
        break;
      }
      case TorConnectState.Disabled: {
        this.elements.torConnectBox.setAttribute("hidden", "true");
        break;
      }
      default:
        break;
    }
  },

  observe(aSubject, aTopic, aData) {
    if (aTopic === TorConnectTopics.StateChange) {
      const obj = aSubject?.wrappedJSObject;
      this.updateTorConnectBox(obj?.state);
    }
  },

  init() {
    if (TorConnect.shouldShowTorConnect) {
      // browser isn't populated until init
      this.elements = Object.freeze({
        torConnectBox: browser.ownerGlobal.document.querySelector(
          this.selectors.torConnect.box
        ),
        torConnectLabel: browser.ownerGlobal.document.querySelector(
          this.selectors.torConnect.label
        ),
        inputContainer: gURLBar._inputContainer,
      });
      this.elements.torConnectBox.addEventListener("click", () => {
        TorConnect.openTorConnect();
      });
      Services.obs.addObserver(this, TorConnectTopics.StateChange);
      this.observing = true;
      this.updateTorConnectBox(TorConnect.state);
    }
  },

  uninit() {
    if (this.observing) {
      Services.obs.removeObserver(this, TorConnectTopics.StateChange);
    }
  },
};
Loading