Commit b30f24a6 authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame 🎃
Browse files

TB 11698: Incorporate Tor Browser Manual pages into Tor Browser

This patch associates the about:manual page to a translated page that
must be injected to browser/omni.ja after the build.
The content must be placed in chrome/browser/content/browser/manual/, so
that is then available at chrome://browser/content/manual/.
We preferred giving absolute freedom to the web team, rather than having
to change the patch in case of changes on the documentation.
parent 20cee7c6
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -458,6 +458,10 @@
              <menupopup id="menu_HelpPopup">
<!-- Note: Items under here are cloned to the AppMenu Help submenu. The cloned items
     have their strings defined by appmenu-data-l10n-id. -->
                <!-- Add Tor Browser manual link -->
                <menuitem id="torBrowserUserManual"
                          data-l10n-id="menu-open-tor-manual"
                          appmenu-data-l10n-id="appmenu-open-tor-manual"/>
                <menuitem id="menu_openHelp"
                          hidden="true"
                          data-l10n-id="menu-get-help"
+7 −0
Original line number Diff line number Diff line
@@ -116,6 +116,13 @@ document.addEventListener(
            });
          }
          break;

        case "torBrowserUserManual":
          gBrowser.selectedTab = gBrowser.addTab("about:manual", {
            triggeringPrincipal:
              Services.scriptSecurityManager.getSystemPrincipal(),
          });
          break;
      }
    });

+17 −0
Original line number Diff line number Diff line
@@ -126,6 +126,23 @@ let JSWINDOWACTORS = {
    remoteTypes: ["privilegedabout"],
  },

  AboutManual: {
    parent: {
      esModuleURI:
        "moz-src:///browser/components/aboutmanual/AboutManualParent.sys.mjs",
    },
    child: {
      esModuleURI:
        "moz-src:///browser/components/aboutmanual/AboutManualChild.sys.mjs",

      events: {
        ManualLocaleSelected: { wantUntrusted: true },
      },
    },

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

  AboutMessagePreview: {
    parent: {
      esModuleURI: "resource:///actors/AboutMessagePreviewParent.sys.mjs",
+60 −0
Original line number Diff line number Diff line
@@ -16,6 +16,11 @@
#include "mozilla/dom/ContentChild.h"
#include "mozilla/browser/NimbusFeatures.h"

// For Tor Browser manual
#include "nsTHashSet.h"
#include "mozilla/intl/LocaleService.h"
#include "mozilla/Omnijar.h"

#define PROFILES_ENABLED_PREF "browser.profiles.enabled"
#define ABOUT_WELCOME_CHROME_URL \
  "chrome://browser/content/aboutwelcome/aboutwelcome.html"
@@ -192,6 +197,12 @@ static const RedirEntry kRedirMap[] = {
         nsIAboutModule::URI_CAN_LOAD_IN_CHILD | nsIAboutModule::ALLOW_SCRIPT |
         nsIAboutModule::HIDE_FROM_ABOUTABOUT |
         nsIAboutModule::IS_SECURE_CHROME_UI},
    // The correct URI must be obtained by GetManualChromeURI
    {"manual", "about:blank",
     nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT |
         nsIAboutModule::ALLOW_SCRIPT | nsIAboutModule::URI_MUST_LOAD_IN_CHILD |
         nsIAboutModule::URI_CAN_LOAD_IN_PRIVILEGEDABOUT_PROCESS |
         nsIAboutModule::IS_SECURE_CHROME_UI},
};

static nsAutoCString GetAboutModuleName(nsIURI* aURI) {
@@ -208,6 +219,47 @@ static nsAutoCString GetAboutModuleName(nsIURI* aURI) {
  return path;
}

static nsAutoCString GetManualChromeURI() {
  nsTArray<nsCString> availableLocales;
  nsCString availableLocalesStr;
  if (NS_SUCCEEDED(mozilla::Preferences::GetCString(
          "torbrowser.manual.available-locales", availableLocalesStr)) &&
      availableLocalesStr.Length() > 0) {
    for (const nsACString& locale : availableLocalesStr.Split(',')) {
      availableLocales.AppendElement(locale);
    }
  }
  nsCString tryLocale;
  if (!NS_SUCCEEDED(mozilla::Preferences::GetCString("torbrowser.manual.locale",
                                                     tryLocale)) ||
      !availableLocales.Contains(tryLocale)) {
    nsTArray<nsCString> appLocales;
    intl::LocaleService::GetInstance()->GetAppLocalesAsBCP47(appLocales);
    bool found = false;
    for (size_t i = 0; i < appLocales.Length(); i++) {
      tryLocale = appLocales[i];
      if (availableLocales.Contains(tryLocale)) {
        found = true;
        break;
      } else if (tryLocale.Length() > 3 && tryLocale[2] == '-') {
        // Strip the region code and see if the lang matches.
        tryLocale.SetLength(2);
        if (availableLocales.Contains(tryLocale)) {
          found = true;
          break;
        }
      }
    }
    if (!found) {
      tryLocale.AssignLiteral("en");
    }
  }
  nsAutoCString uri;
  uri.AppendPrintf("chrome://browser/content/aboutmanual/aboutManual-%s.html",
                   tryLocale.get());
  return uri;
}

NS_IMETHODIMP
AboutRedirector::NewChannel(nsIURI* aURI, nsILoadInfo* aLoadInfo,
                            nsIChannel** result) {
@@ -245,6 +297,10 @@ AboutRedirector::NewChannel(nsIURI* aURI, nsILoadInfo* aLoadInfo,
        url.AssignASCII(BASE_BROWSER_HOME_PAGE_URL);
      }

      if (path.EqualsLiteral("manual")) {
        url = GetManualChromeURI();
      }

      // fall back to the specified url in the map
      if (url.IsEmpty()) {
        url.AssignASCII(redir.url);
@@ -303,6 +359,10 @@ AboutRedirector::GetChromeURI(nsIURI* aURI, nsIURI** chromeURI) {

  nsAutoCString name = GetAboutModuleName(aURI);

  if (name.EqualsLiteral("manual")) {
    return NS_NewURI(chromeURI, GetManualChromeURI());
  }

  for (const auto& redir : kRedirMap) {
    if (name.Equals(redir.id)) {
      return NS_NewURI(chromeURI, redir.url);
+1 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ pages = [
    'keyboard',
    'logins',
    'loginsimportreport',
    'manual',
    'messagepreview',
    'newtab',
    'opentabs',
Loading