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

BB 42583: Modify moz-support-link for Base Browser.

parent 44f50cee
Loading
Loading
Loading
Loading
+39 −17
Original line number Diff line number Diff line
@@ -102,6 +102,42 @@ export default class MozSupportLink extends HTMLAnchorElement {

  #setHref() {
    let supportPage = this.getAttribute("support-page") ?? "";
    // Support pages that start with "tor-manual:" are meant to point to the
    // Tor Project's support pages. See tor-browser#44903.
    const torManualPrefix = "tor-manual:";
    if (supportPage.startsWith(torManualPrefix)) {
      const torManualPage = supportPage.substring(torManualPrefix.length);
      const [page, anchor] = torManualPage.split("_", 2);

      let locale = Services.locale.appLocaleAsBCP47;
      if (locale === "ja-JP-macos") {
        // Convert quirk-locale to the locale used for tor project.
        locale = "ja";
      }

      let href = `https://tb-manual.torproject.org/${locale}/${page}/`;
      if (anchor) {
        href = `${href}#${anchor}`;
      }
      this.href = href;
      return;
    }
    // For base-browser we sometimes want to override firefox support links with
    // our own.
    // See tor-browser#40899.
    switch (supportPage) {
      case "preferences":
        // Shown twice in preferences, both as `{ -brand-short-name } Support`.
        // Instead of directing to support for preferences, we link to general
        // tor browser support.
        // See tor-browser#32092.
        this.href = Services.prefs.getStringPref(
          "browser.base-browser-support-url",
          ""
        );
        return;
      // Fall through to support.mozilla.org
    }
    let base = MozSupportLink.SUPPORT_URL + supportPage;
    this.href = this.hasAttribute("utm-content")
      ? formatUTMParams(this.getAttribute("utm-content"), base)
@@ -121,21 +157,7 @@ customElements.define("moz-support-link", MozSupportLink, { extends: "a" });
 *          Otherwise the url in unmodified form.
 */
export function formatUTMParams(contentAttribute, url) {
  if (!contentAttribute) {
  // Do not add utm parameters. See tor-browser#42583.
  // NOTE: This method is also present in about:addons.
  return url;
}
  let parsedUrl = new URL(url);
  let domain = `.${parsedUrl.hostname}`;
  if (
    !domain.endsWith(".mozilla.org") &&
    // For testing: addons-dev.allizom.org and addons.allizom.org
    !domain.endsWith(".allizom.org")
  ) {
    return url;
  }

  parsedUrl.searchParams.set("utm_source", "firefox-browser");
  parsedUrl.searchParams.set("utm_medium", "firefox-browser");
  parsedUrl.searchParams.set("utm_content", contentAttribute);
  return parsedUrl.href;
}