Commit 1aeaceb8 authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame 🎃 Committed by richard
Browse files

fixup! Bug 7494: Create local home page for TBB.

First step toward IPC modernizartion (WIP).
parent 448ac064
Loading
Loading
Loading
Loading
+15 −0
Changes for browser/components/BrowserGlue.sys.mjs: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -328,6 +328,21 @@ let JSWINDOWACTORS = {
    matches: ["about:tabcrashed*"],
  },

  AboutTor: {
    parent: {
      esModuleURI: "resource:///actors/AboutTorParent.sys.mjs",
    },
    child: {
      esModuleURI: "resource:///actors/AboutTorChild.sys.mjs",

      events: {
        DOMContentLoaded: {},
      },
    },

    matches: ["about:tor"],
  },

  AboutWelcome: {
    parent: {
      moduleURI: "resource:///actors/AboutWelcomeParent.jsm",
+24 −0
Changes for browser/components/abouttor/AboutTorChild.sys.mjs: 24 added lines, 0 removed lines.
Original line number Diff line number Diff line
export class AboutTorChild extends JSWindowActorChild {
  handleEvent(e) {
    switch (e.type) {
      case "DOMContentLoaded":
        this.sendAsyncMessage("AboutTor:ContentLoaded");
    }
  }

  receiveMessage(message) {
    switch (message.name) {
      case "AboutTor:ChromeData":
        this.#sendToContent("ChromeData", message.data);
        break;
      case "AboutTor:LocaleData":
        this.#sendToContent("LocaleData", message.data);
        break;
    }
  }

  #sendToContent(eventName, detail) {
    let event = new this.contentWindow.CustomEvent(eventName, {
      detail: Cu.cloneInto(detail, this.contentWindow),
    });
    this.contentWindow.dispatchEvent(event);
  }
}
+29 −0
Changes for browser/components/abouttor/AboutTorParent.sys.mjs: 29 added lines, 0 removed lines.
Original line number Diff line number Diff line
export class AboutTorParent extends JSWindowActorParent {
  async receiveMessage(message) {
    if (message.name === "AboutTor:ContentLoaded") {
      this.#sendChromeData();
      this.#sendLocale();
    }
  }

  #sendChromeData() {
    const tbbVersion = Services.prefs.getCharPref("torbrowser.version");
    this.sendAsyncMessage("AboutTor:ChromeData", {
      tbbVersion,
      torOn: true,
      updateChannel: "alpha",
      hasBeenUpdated: true,
    });
  }

  #sendLocale() {
    try {
      const kBrandBundle = "chrome://branding/locale/brand.properties";
      const brandBundle = Services.strings.createBundle(kBrandBundle);
      const productName = brandBundle.GetStringFromName("brandFullName");
      let locale = Services.locale.appLocaleAsBCP47;
      if (locale === "ja-JP-macos") {
        locale = "ja";
      }
      this.sendAsyncMessage("AboutTor:LocaleData", { locale, productName });
    } catch (e) {}
  }
}
+56 −5
Changes for browser/components/abouttor/content/aboutTor.js: 56 added lines, 5 removed lines.
Original line number Diff line number Diff line
/*************************************************************************
 * Copyright (c) 2020, The Tor Project, Inc.
 * Copyright (c) 2023, The Tor Project, Inc.
 * See LICENSE for licensing information.
 *
 * vim: set sw=2 sts=2 ts=8 et syntax=javascript:
 *************************************************************************/

window.addEventListener("pageshow", function () {
  let evt = new CustomEvent("AboutTorLoad", { bubbles: true });
  document.dispatchEvent(evt);
});
const AboutTorListener = {
  tbbVersion: "",

  init() {
    window.addEventListener("ChromeData", this.onChromeData.bind(this));
    window.addEventListener("LocaleData", this.onLocaleData.bind(this));
  },

  onChromeData(e) {
    const body = document.body;
    const data = e.detail;

    if (data.tbbVersion) {
      this.tbbVersion = data.tbbVersion;
    }

    // Update status: tor on/off, Tor Browser manual shown.
    if (data.torOn) {
      body.setAttribute("toron", "yes");
    } else {
      body.removeAttribute("toron");
    }

    if (data.updateChannel) {
      body.setAttribute("updatechannel", data.updateChannel);
    } else {
      body.removeAttribute("updatechannel");
    }

    if (data.hasBeenUpdated) {
      body.setAttribute("hasbeenupdated", "yes");
      document
        .getElementById("update-infolink")
        .setAttribute("href", data.updateMoreInfoURL);
    }

    // Setting body.initialized="yes" displays the body.
    body.setAttribute("initialized", "yes");
  },

  onLocaleData(e) {
    const { locale, productName } = e.detail;
    // Set localized "Get Involved" link.
    document.getElementById(
      "getInvolvedLink"
    ).href = `https://community.torproject.org/${locale}`;

    // Display the Tor Browser product name and version.
    document.getElementById(
      "torbrowser-version"
    ).textContent = `${productName} ${this.tbbVersion}`;
  },
};

AboutTorListener.init();