Commit e49c0a7b authored by henry's avatar henry Committed by Pier Angelo Vendrame
Browse files

fixup! TB 27476: Implement about:torconnect captive portal within Tor Browser

TB 44781: Use a static title for `about:torconnect`.

We now use Fluent to set the page `<title>`, this causes some delay
between the page being loaded and the title being set. Which cause the
`about:torconnect` URL to flash in the browser tab selector. Moreover,
even the prior non-Fluent approach would have "New Tab" flash in the
title just before "Connect to Tor" was set.

As such, we adjust `tabbrowser.js` and `tabs.js` to:

1. Set the `about:torconnect`'s tab label to the expected page title
   before the page has loaded and set it's title.
2. Set the very first tab's label to the `about:torconnect` page title
   at startup, rather than "New Tab".
parent a6704d82
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
@@ -223,6 +223,11 @@
          true
        );
      });
      // Add a synchronous localisation to get the about:torconnect title.
      // See tor-browser#44781.
      ChromeUtils.defineLazyGetter(this, "torconnectLocalization", () => {
        return new Localization(["toolkit/global/tor-browser.ftl"], true);
      });
      XPCOMUtils.defineLazyPreferenceGetter(
        this,
        "_shouldExposeContentTitle",
@@ -2334,6 +2339,39 @@
        return false;
      }

      // We want to set the title for an about:torconnect tab prior to the page
      // being loaded. In particular, we need to wait for:
      //
      // 1. The first `<browser>` element to switch `currentURI` from
      //    `about:blank` to `about:torconnect`.
      // 2. The page's `<title>` to be set, which is delayed by the page load
      //    and the async FluentDOM.
      //
      // This avoids flashes of "New Tab" and the URL appearing in the tab
      // label. See tor-browser#44781.
      if (aTab._isFirstTabLoading) {
        if (!isURL && !isContentTitle) {
          // Wait until we have a proper title or URL.
          // NOTES:
          // 1. This is only expected for the first call to `onLocationChange`
          //    for the very first tab opened in a new window. In this scenario,
          //    we expect the page's `currentURI` to be `about:blank` (and not
          //    the actual `chrome:` path to `blanktab.html`). We use the
          //    `_isFirstTabLoading` condition as an extra protection.
          // 2. We have already set the title for this tab in
          //    `MozTabbrowserTabs.init`, depending on whether we expect this to
          //    turn into `about:torconnect` or a "New Tab" (`about:tor` or
          //    `blanktab.html`). So we don't need to make any changes here.
          return false;
        }
        delete aTab._isFirstTabLoading;
      }
      if (isURL && aLabel.startsWith("about:torconnect")) {
        aLabel = this.tabContainer.torconnectTitle;
        isContentTitle = true;
        isURL = false;
      }

      // If it's a long data: URI that uses base64 encoding, truncate to a
      // reasonable length rather than trying to display the entire thing,
      // which can hang or crash the browser.
+22 −1
Original line number Diff line number Diff line
@@ -134,7 +134,16 @@
      this._hiddenSoundPlayingTabs = new Set();
      this.previewPanel = null;

      this.allTabs[0].label = this.emptyTabTitle;
      // When a new application window is spawned, this will set the initial
      // tab's displayed title. If `shouldShowTorConnect` is true, we expect
      // this first page to be `about:torconnect`, so we show the corresponding
      // title that will be used once the page is shown. See tor-browser#44781.
      this.allTabs[0].label = TorConnect.shouldShowTorConnect
        ? this.torconnectTitle
        : this.emptyTabTitle;
      // Mark this as the first tab that is still loading. This can be cleared
      // once we have a definite title or URI.
      this.allTabs[0]._isFirstTabLoading = true;

      this.newTabButton.setAttribute(
        "aria-label",
@@ -817,6 +826,18 @@
      return gBrowser.tabLocalization.formatValueSync(l10nId);
    }

    /**
     * The about:torconnect page <title>, to be fetched when about:torconnect
     * has not yet been loaded.
     *
     * @type {string}
     */
    get torconnectTitle() {
      return gBrowser.torconnectLocalization.formatValueSync(
        "tor-connect-page-title"
      );
    }

    get tabbox() {
      return document.getElementById("tabbrowser-tabbox");
    }
+4 −0
Original line number Diff line number Diff line
@@ -6,6 +6,8 @@
      http-equiv="Content-Security-Policy"
      content="default-src chrome:; object-src 'none'"
    />
    <title data-l10n-id="tor-connect-page-title"></title>

    <link rel="stylesheet" href="chrome://global/skin/tor-common.css" />
    <link
      rel="stylesheet"
@@ -14,6 +16,8 @@
      media="all"
    />

    <link rel="localization" href="toolkit/global/tor-browser.ftl" />

    <script
      type="module"
      src="chrome://global/content/elements/moz-toggle.mjs"
+0 −1
Original line number Diff line number Diff line
@@ -229,7 +229,6 @@ class AboutTorConnect {
    if (className) {
      this.elements.title.classList.add(className);
    }
    document.title = title;
  }

  setLongText(...args) {