This is an automated email from the git hooks/post-receive script.
richard pushed a commit to branch tor-browser-91.13.0esr-11.5-1 in repository tor-browser.
commit 01085f53eece2cbb7ec9f38a7bc43f9a20a72fc8 Author: Pier Angelo Vendrame pierov@torproject.org AuthorDate: Thu May 5 20:15:01 2022 +0200
Bug 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. --- browser/base/content/browser-siteIdentity.js | 4 +- browser/components/about/AboutRedirector.cpp | 63 ++++++++++++++++++++++++++++ browser/components/about/components.conf | 1 + 3 files changed, 66 insertions(+), 2 deletions(-)
diff --git a/browser/base/content/browser-siteIdentity.js b/browser/base/content/browser-siteIdentity.js index 5e70d458094cf..b7d59db3dd34d 100644 --- a/browser/base/content/browser-siteIdentity.js +++ b/browser/base/content/browser-siteIdentity.js @@ -58,8 +58,8 @@ var gIdentityHandler = { * the browser UI. */ _secureInternalPages: (AppConstants.TOR_BROWSER_UPDATE ? - /^(?:accounts|addons|cache|certificate|config|crashes|downloads|license|logins|preferences|protections|rights|rulesets|sessionrestore|support|welcomeback|tor|torconnect|tbupdate)(?:[?#]|$)/i : - /^(?:accounts|addons|cache|certificate|config|crashes|downloads|license|logins|preferences|protections|rights|rulesets|sessionrestore|support|welcomeback|tor|torconnect)(?:[?#]|$)/i), + /^(?:accounts|addons|cache|certificate|config|crashes|downloads|license|logins|manual|preferences|protections|rights|rulesets|sessionrestore|support|welcomeback|tor|torconnect|tbupdate)(?:[?#]|$)/i : + /^(?:accounts|addons|cache|certificate|config|crashes|downloads|license|logins|manual|preferences|protections|rights|rulesets|sessionrestore|support|welcomeback|tor|torconnect)(?:[?#]|$)/i),
/** * Whether the established HTTPS connection is considered "broken". diff --git a/browser/components/about/AboutRedirector.cpp b/browser/components/about/AboutRedirector.cpp index 57c4d40c8ef56..0eb86297188c3 100644 --- a/browser/components/about/AboutRedirector.cpp +++ b/browser/components/about/AboutRedirector.cpp @@ -18,6 +18,11 @@ #include "mozilla/dom/ContentChild.h" #include "mozilla/dom/ContentParent.h"
+// For Tor Browser manual +#include "nsTHashSet.h" +#include "mozilla/intl/LocaleService.h" +#include "mozilla/Omnijar.h" + namespace mozilla { namespace browser {
@@ -136,6 +141,10 @@ static const RedirEntry kRedirMap[] = { nsIAboutModule::URI_SAFE_FOR_UNTRUSTED_CONTENT | nsIAboutModule::URI_CAN_LOAD_IN_CHILD | nsIAboutModule::ALLOW_SCRIPT | nsIAboutModule::HIDE_FROM_ABOUTABOUT}, + // 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}, };
static nsAutoCString GetAboutModuleName(nsIURI* aURI) { @@ -152,6 +161,52 @@ static nsAutoCString GetAboutModuleName(nsIURI* aURI) { return path; }
+static nsTHashSet<nsCStringHashKey> GetManualLocales() +{ + nsTHashSet<nsCStringHashKey> locales; + RefPtr<nsZipArchive> zip = Omnijar::GetReader(Omnijar::APP); + 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 lang has been changed. + // We do not provide multi-language builds at the moment, so this should not + // happen, at least in Tor Browser desktop, but we prepared the patch to be + // ready also in such a case. + 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) { @@ -205,6 +260,10 @@ AboutRedirector::NewChannel(nsIURI* aURI, nsILoadInfo* aLoadInfo, NS_ENSURE_SUCCESS(rv, rv); }
+ if (path.EqualsLiteral("manual")) { + url = GetManualChromeURI(); + } + // fall back to the specified url in the map if (url.IsEmpty()) { url.AssignASCII(redir.url); @@ -263,6 +322,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 index df7c05b3193d5..e8034b31d8699 100644 --- a/browser/components/about/components.conf +++ b/browser/components/about/components.conf @@ -12,6 +12,7 @@ pages = [ 'home', 'logins', 'loginsimportreport', + 'manual', 'newtab', 'pocket-home', 'pocket-saved',