Commit 4983f698 authored by henry's avatar henry Committed by morgan
Browse files

fixup! TB 31286: Implementation of bridge, proxy, and firewall settings in...

fixup! TB 31286: Implementation of bridge, proxy, and firewall settings in about:preferences#connection

TB 43939: Add a connection assist banner.
parent e97309cd
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@
  <script type="module" src="chrome://browser/content/preferences/widgets/update-state.mjs"></script>
  <script type="module" src="chrome://browser/content/ipprotection/bandwidth-usage.mjs"></script>
  <script type="module" src="chrome://browser/content/torpreferences/widgets/tor-bridges-display.mjs"></script>
  <script type="module" src="chrome://browser/content/torpreferences/widgets/tor-connection-assist-banner.mjs"></script>
  <script type="module" src="chrome://browser/content/torpreferences/widgets/tor-connection-status.mjs"></script>
  <script src="chrome://browser/content/torpreferences/bridgemoji/BridgeEmoji.js"/>
</head>
+35 −0
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@ import { Preferences } from "chrome://global/content/preferences/Preferences.mjs
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
  InternetStatus: "moz-src:///toolkit/modules/TorConnect.sys.mjs",
  moveFocusToBridgeHeading:
    "chrome://browser/content/torpreferences/config/helpers.mjs",
  openBridgeDialog:
    "chrome://browser/content/torpreferences/config/helpers.mjs",
  openUserProvideBridgeDialog:
@@ -68,6 +70,18 @@ SettingGroupManager.registerGroups({
    headingLevel: 2,
    controlAttrs: { "focusable-heading": true },
    items: [
      {
        id: "connectionAssistBanner",
        // NOTE: Instead of using a custom widget for this one banner, we could
        // use moz-message-bar and populate it's children. However, we want to
        // intercept the "click" event for the "Connection Assist" link within
        // the banner text. As of ESR 153, onUserClick would not allow us to
        // intercept the event because the `<a>` would need to be wrapped in a
        // `<setting-control>`. But Fluent would not allow wrapping the
        // `<setting-control>` element as part of a wider string (unlike
        // `<a data-l10n-name="link">`, which is allowed). tor-browser#43939.
        control: "tor-connection-assist-banner",
      },
      {
        id: "bridgesEnabled",
        l10nId: "tor-bridges-use-bridges",
@@ -253,6 +267,27 @@ Preferences.addSetting({
  },
});

Preferences.addSetting({
  id: "connectionAssistBanner",
  deps: ["torStatus"],
  _wasVisible: false,
  visible({ torStatus }) {
    const visible = torStatus.value === "potentially-blocked";
    if (
      !visible &&
      this._wasVisible &&
      document
        .getElementById("connectionAssistBanner")
        ?.contains(document.activeElement)
    ) {
      // About to loose focus, move focus to the bridge heading.
      lazy.moveFocusToBridgeHeading(window, true);
    }
    this._wasVisible = visible;
    return visible;
  },
});

Preferences.addSetting({
  id: "torSettingsReady",
  _ready: false,
+1 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ browser.jar:
    content/browser/torpreferences/config/connection.mjs             (config/connection.mjs)
    content/browser/torpreferences/config/helpers.mjs                (config/helpers.mjs)
    content/browser/torpreferences/widgets/tor-bridges-display.mjs   (widgets/tor-bridges-display.mjs)
    content/browser/torpreferences/widgets/tor-connection-assist-banner.mjs (widgets/tor-connection-assist-banner.mjs)
    content/browser/torpreferences/widgets/tor-connection-status.mjs (widgets/tor-connection-status.mjs)
    content/browser/torpreferences/widgets/tor-connection-status.css (widgets/tor-connection-status.css)
    content/browser/torpreferences/connectionPane.js                 (content/connectionPane.js)
+56 −0
Original line number Diff line number Diff line
import { MozLitElement } from "chrome://global/content/lit-utils.mjs";
import { html } from "chrome://global/content/vendor/lit.all.mjs";

const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
  TorConnect: "moz-src:///toolkit/modules/TorConnect.sys.mjs",
  TorConnectParent:
    "moz-src:///browser/components/torconnect/TorConnectParent.sys.mjs",
});

const TOR_CONNECT_HREF = "about:torconnect";

/**
 * Widget for displaying a Connection Assist banner.
 *
 * @tagname tor-connection-status
 */
class TorConnectionAssistBanner extends MozLitElement {
  render() {
    return html`
      <moz-message-bar
        role="complementary"
        type="warning"
        @click=${this.#handleClick}
      >
        <span
          slot="message"
          data-l10n-id="tor-bridges-connection-assist-message"
        >
          <a
            id="link"
            data-l10n-name="link"
            href=${TOR_CONNECT_HREF}
            target="_blank"
          ></a>
        </span>
      </moz-message-bar>
    `;
  }

  #handleClick(event) {
    if (!this.shadowRoot.getElementById("link")?.contains(event.target)) {
      return;
    }
    event.preventDefault();
    if (!lazy.TorConnect.inConnectionAssistStage) {
      // Switch to the "ChooseRegion" stage to reflect "Connection Assist".
      lazy.TorConnect.chooseRegion();
    }
    lazy.TorConnectParent.open();
  }
}
customElements.define(
  "tor-connection-assist-banner",
  TorConnectionAssistBanner
);