Commit a1386766 authored by Richard Pospesel's avatar Richard Pospesel Committed by Pier Angelo Vendrame
Browse files

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 b60e986b
Loading
Loading
Loading
Loading
+58 −22
Original line number Diff line number Diff line
@@ -67,6 +67,9 @@ ChromeUtils.defineESModuleGetters(this, {
    "resource:///modules/firefox-view-tabs-setup-manager.sys.mjs",
  TelemetryEnvironment: "resource://gre/modules/TelemetryEnvironment.sys.mjs",
  TorDomainIsolator: "resource://gre/modules/TorDomainIsolator.sys.mjs",
  TorConnect: "resource://gre/modules/TorConnect.sys.mjs",
  TorConnectState: "resource://gre/modules/TorConnect.sys.mjs",
  TorConnectTopics: "resource://gre/modules/TorConnect.sys.mjs",
  TranslationsParent: "resource://gre/actors/TranslationsParent.sys.mjs",
  UITour: "resource:///modules/UITour.sys.mjs",
  UpdateUtils: "resource://gre/modules/UpdateUtils.sys.mjs",
@@ -282,6 +285,16 @@ XPCOMUtils.defineLazyScriptGetter(
  "gPageStyleMenu",
  "chrome://browser/content/browser-pagestyle.js"
);
XPCOMUtils.defineLazyScriptGetter(
  this,
  ["gTorConnectUrlbarButton"],
  "chrome://global/content/torconnect/torConnectUrlbarButton.js"
);
XPCOMUtils.defineLazyScriptGetter(
  this,
  ["gTorConnectTitlebarStatus"],
  "chrome://global/content/torconnect/torConnectTitlebarStatus.js"
);
XPCOMUtils.defineLazyScriptGetter(
  this,
  ["gTorCircuitPanel"],
@@ -712,6 +725,7 @@ var gPageIcons = {
};

var gInitialPages = [
  "about:torconnect",
  "about:blank",
  "about:home",
  "about:firefoxview",
@@ -1727,6 +1741,9 @@ var gBrowserInit = {
    // Init the NewIdentityButton
    NewIdentityButton.init();

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

    gTorCircuitPanel.init();

    // Certain kinds of automigration rely on this notification to complete
@@ -2409,21 +2426,23 @@ var gBrowserInit = {

      let defaultArgs = BrowserHandler.defaultArgs;

      // figure out which URI to actually load (or a Promise to get the uri)
      uri = (aUri => {
        // If the given URI is different from the homepage, we want to load it.
      if (uri != defaultArgs) {
        if (aUri != defaultArgs) {
          AboutNewTab.noteNonDefaultStartup();

        if (uri instanceof Ci.nsIArray) {
          if (aUri instanceof Ci.nsIArray) {
            // Transform the nsIArray of nsISupportsString's into a JS Array of
            // JS strings.
            return Array.from(
            uri.enumerate(Ci.nsISupportsString),
              aUri.enumerate(Ci.nsISupportsString),
              supportStr => supportStr.data
            );
        } else if (uri instanceof Ci.nsISupportsString) {
          return uri.data;
          } else if (aUri instanceof Ci.nsISupportsString) {
            return aUri.data;
          }
        return uri;
          return aUri;
        }

        // The URI appears to be the the homepage. We want to load it only if
@@ -2435,6 +2454,20 @@ var gBrowserInit = {
        return willOverride.then(willOverrideHomepage =>
          willOverrideHomepage ? null : uri
        );
      })(uri);

      // if using TorConnect, convert these uris to redirects
      if (TorConnect.shouldShowTorConnect) {
        return Promise.resolve(uri).then(aUri => {
          if (aUri == null) {
            aUri = [];
          }

          aUri = TorConnect.getURIsToLoad(aUri);
          return aUri;
        });
      }
      return uri;
    })());
  },

@@ -2502,6 +2535,9 @@ var gBrowserInit = {

    NewIdentityButton.uninit();

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

    gTorCircuitPanel.uninit();

    if (gToolbarKeyNavEnabled) {
+1 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@
<?xml-stylesheet href="chrome://browser/skin/places/tree-icons.css" type="text/css"?>
<?xml-stylesheet href="chrome://browser/skin/places/editBookmark.css" type="text/css"?>
<?xml-stylesheet href="chrome://browser/content/torCircuitPanel.css" type="text/css"?>
<?xml-stylesheet href="chrome://global/content/torconnect/torConnectTitlebarStatus.css" type="text/css"?>

<!DOCTYPE window [
  <!ENTITY % torbuttonDTD SYSTEM "chrome://torbutton/locale/torbutton.dtd">
+13 −0
Original line number Diff line number Diff line
@@ -108,6 +108,12 @@
        <label data-l10n-id="private-browsing-indicator-label"></label>
      </hbox>

      <html:div id="tor-connect-titlebar-status" role="status">
        <html:img alt=""
                  src="chrome://global/content/torconnect/tor-not-connected-to-connected-animated.svg" />
        <html:span id="tor-connect-titlebar-status-label"></html:span>
      </html:div>

#include titlebar-items.inc.xhtml

    </toolbar>
@@ -415,6 +421,13 @@
                       class="urlbar-icon"/>
              </hbox>
            </hbox>

            <hbox id="tor-connect-urlbar-button"
                  role="button"
                  class="tor-urlbar-button"
                  hidden="true">
              <label id="tor-connect-urlbar-button-label"/>
            </hbox>
          </hbox>
        </hbox>
        <toolbartabstop/>
+36 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
  ReaderMode: "resource://gre/modules/ReaderMode.sys.mjs",
  SearchUIUtils: "resource:///modules/SearchUIUtils.sys.mjs",
  SearchUtils: "resource://gre/modules/SearchUtils.sys.mjs",
  TorConnect: "resource://gre/modules/TorConnect.sys.mjs",
  UrlbarController: "resource:///modules/UrlbarController.sys.mjs",
  UrlbarEventBufferer: "resource:///modules/UrlbarEventBufferer.sys.mjs",
  UrlbarPrefs: "resource:///modules/UrlbarPrefs.sys.mjs",
@@ -63,6 +64,36 @@ const SEARCH_BUTTON_ID = "urlbar-search-button";
// The scalar category of TopSites click for Contextual Services
const SCALAR_CATEGORY_TOPSITES = "contextual.services.topsites.click";

// in certain scenarios we want user input uris to open in a new tab if they do so from the
// about:torconnect tab
function maybeUpdateOpenLocationForTorConnect(
  openUILinkWhere,
  currentURI,
  destinationURI
) {
  try {
    // only open in new tab if:
    if (
      // user is navigating away from about:torconnect
      currentURI === "about:torconnect" &&
      // we are trying to open in same tab
      openUILinkWhere === "current" &&
      // only if user still has not bootstrapped
      lazy.TorConnect.shouldShowTorConnect &&
      // and user is not just navigating to about:torconnect
      destinationURI !== "about:torconnect"
    ) {
      return "tab";
    }
  } catch (e) {
    // swallow exception and fall through returning original so we don't accidentally break
    // anything if an exception is thrown
    console.log(e?.message ? e.message : e);
  }

  return openUILinkWhere;
}

let getBoundsWithoutFlushing = element =>
  element.ownerGlobal.windowUtils.getBoundsWithoutFlushing(element);
let px = number => number.toFixed(2) + "px";
@@ -2805,6 +2836,11 @@ export class UrlbarInput {
      this.inputField.setSelectionRange(0, 0);
    }

    openUILinkWhere = maybeUpdateOpenLocationForTorConnect(
      openUILinkWhere,
      this.window.gBrowser.currentURI.asciiSpec,
      url
    );
    if (openUILinkWhere != "current") {
      this.handleRevert();
    }
+26 −0
Original line number Diff line number Diff line
@@ -9,6 +9,10 @@ import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";

const lazy = {};

ChromeUtils.defineESModuleGetters(lazy, {
  TorConnect: "resource://gre/modules/TorConnect.sys.mjs",
});

XPCOMUtils.defineLazyModuleGetters(lazy, {
  AboutNewTab: "resource:///modules/AboutNewTab.jsm",
  BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
@@ -417,6 +421,28 @@ export const URILoadingHelper = {
      return;
    }

    // make sure users are not faced with the scary red 'tor isn't working' screen
    // if they navigate to about:tor before bootstrapped
    //
    // fixes tor-browser#40752
    // new tabs also redirect to about:tor if browser.newtabpage.enabled is true
    // otherwise they go to about:blank
    if (lazy.TorConnect.shouldShowTorConnect) {
      const homeURLs = [
        "about:home",
        "about:privatebrowsing",
        "about:tor",
        "about:welcome",
      ];
      if (
        homeURLs.includes(url) ||
        (url === "about:newtab" &&
          Services.prefs.getBoolPref("browser.newtabpage.enabled", false))
      ) {
        url = lazy.TorConnect.getRedirectURL(url);
      }
    }

    let {
      allowThirdPartyFixup,
      postData,
Loading