commit f3087859831ba28cf7cf5c652e05649045024af7
parent d8e2cbbf20dd4f5ecb755de50cc740892b6c23b4
Author: Pier Angelo Vendrame <pierov@torproject.org>
Date: Thu, 5 May 2022 20:15:01 +0200
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.
Diffstat:
5 files changed, 84 insertions(+), 0 deletions(-)
diff --git a/browser/base/content/browser-menubar.inc b/browser/base/content/browser-menubar.inc
@@ -450,6 +450,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"
diff --git a/browser/base/content/browser-menubar.js b/browser/base/content/browser-menubar.js
@@ -105,6 +105,12 @@ document.addEventListener(
case "helpPolicySupport":
openTrustedLinkIn(Services.policies.getSupportMenu().URL.href, "tab");
break;
+ case "torBrowserUserManual":
+ gBrowser.selectedTab = gBrowser.addTab("about:manual", {
+ triggeringPrincipal:
+ Services.scriptSecurityManager.getSystemPrincipal(),
+ });
+ break;
}
});
diff --git a/browser/components/about/AboutRedirector.cpp b/browser/components/about/AboutRedirector.cpp
@@ -17,6 +17,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"
@@ -179,6 +184,12 @@ static const RedirEntry kRedirMap[] = {
nsIAboutModule::URI_CAN_LOAD_IN_PRIVILEGEDABOUT_PROCESS},
{"tor", "chrome://browser/content/abouttor/aboutTor.html",
BASE_BROWSER_HOME_PAGE_FLAGS},
+ // 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) {
@@ -195,6 +206,54 @@ static nsAutoCString GetAboutModuleName(nsIURI* aURI) {
return path;
}
+static nsTHashSet<nsCStringHashKey> GetManualLocales() {
+ nsTHashSet<nsCStringHashKey> locales;
+ RefPtr<nsZipArchive> zip = Omnijar::GetReader(Omnijar::APP);
+ if (!zip) {
+ // Probably a local build started with ./mach run
+ return locales;
+ }
+ UniquePtr<nsZipFind> find;
+ const nsAutoCString prefix("chrome/browser/content/browser/manual/");
+ nsAutoCString needle = prefix;
+ needle.Append("*.html");
+ if (NS_SUCCEEDED(zip->FindInit(needle.get(), getter_Transfers(find)))) {
+ const char* entryName;
+ uint16_t entryNameLen;
+ while (NS_SUCCEEDED(find->FindNext(&entryName, &entryNameLen))) {
+ // 5 is to remove the final `.html`
+ const size_t length = entryNameLen - prefix.Length() - 5;
+ locales.Insert(nsAutoCString(entryName + prefix.Length(), length));
+ }
+ }
+ return locales;
+}
+
+static nsAutoCString GetManualChromeURI() {
+ static nsTHashSet<nsCStringHashKey> locales = GetManualLocales();
+
+ nsAutoCString reqLocale;
+ intl::LocaleService::GetInstance()->GetAppLocaleAsBCP47(reqLocale);
+ // Check every time the URL is needed in case the locale has changed.
+ // It might help also if we start allowing to change language, e.g., with a
+ // get parameter (see tor-browser#42675).
+ if (!locales.Contains(reqLocale) && reqLocale.Length() > 2 &&
+ reqLocale[2] == '-') {
+ // At the moment, codes in our manual output are either 2 letters (en) or
+ // 5 letters (pt-BR)
+ reqLocale.SetLength(2);
+ }
+ if (!locales.Contains(reqLocale)) {
+ reqLocale = "en";
+ }
+
+ // %s is the language
+ constexpr char model[] = "chrome://browser/content/manual/%s.html";
+ nsAutoCString url;
+ url.AppendPrintf(model, reqLocale.get());
+ return url;
+}
+
NS_IMETHODIMP
AboutRedirector::NewChannel(nsIURI* aURI, nsILoadInfo* aLoadInfo,
nsIChannel** result) {
@@ -232,6 +291,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);
@@ -290,6 +353,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);
diff --git a/browser/components/about/components.conf b/browser/components/about/components.conf
@@ -15,6 +15,7 @@ pages = [
'keyboard',
'logins',
'loginsimportreport',
+ 'manual',
'messagepreview',
'newtab',
'opentabs',
diff --git a/browser/components/customizableui/content/panelUI.js b/browser/components/customizableui/content/panelUI.js
@@ -784,6 +784,12 @@ const PanelUI = {
case "appMenu_helpPolicySupport":
openTrustedLinkIn(Services.policies.getSupportMenu().URL.href, "tab");
break;
+ case "appMenu_torBrowserUserManual":
+ gBrowser.selectedTab = gBrowser.addTab("about:manual", {
+ triggeringPrincipal:
+ Services.scriptSecurityManager.getSystemPrincipal(),
+ });
+ break;
}
},