[tor-commits] [tor-browser/tor-browser-68.1.0esr-9.0-1] Bug 1561322 - Allow spoofing strings in HTML forms r=baku, Pike
gk at torproject.org
gk at torproject.org
Thu Aug 29 10:58:32 UTC 2019
commit 1ad6ff94d72b99a72ac66459230755502acccd8d
Author: Alex Catarineu <acat at torproject.org>
Date: Wed Jul 24 13:22:22 2019 +0000
Bug 1561322 - Allow spoofing strings in HTML forms r=baku,Pike
When privacy.spoof_english = 2, we should hide the user's
locale in content. So we use en-US default strings for HTML
form elements, such as a Submit button.
We also force GetLocalizedEllipsis() to always return the
ellipsis used by en-US.
Differential Revision: https://phabricator.services.mozilla.com/D35815
--HG--
extra : moz-landing-system : lando
---
browser/installer/package-manifest.in | 1 +
dom/base/nsContentUtils.cpp | 35 ++++++++++++++++++++------
dom/base/nsContentUtils.h | 2 ++
dom/html/HTMLInputElement.cpp | 37 +++++++++++++++-------------
dom/locales/moz.build | 4 +++
layout/base/nsCSSFrameConstructor.cpp | 8 +++---
layout/forms/nsFileControlFrame.cpp | 4 +--
layout/forms/nsGfxButtonControlFrame.cpp | 4 +--
layout/generic/DetailsFrame.cpp | 5 ++--
mobile/android/installer/package-manifest.in | 1 +
10 files changed, 67 insertions(+), 34 deletions(-)
diff --git a/browser/installer/package-manifest.in b/browser/installer/package-manifest.in
index a160f316a56d..1a2a24f9b5b9 100644
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -344,6 +344,7 @@
@RESPATH@/res/fonts/*
@RESPATH@/res/dtd/*
@RESPATH@/res/language.properties
+ at RESPATH@/res/locale/layout/HtmlForm.properties
#ifdef XP_MACOSX
@RESPATH@/res/MainMenu.nib/
#endif
diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp
index ca8ad1d26b26..d7ab544f7274 100644
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -3507,7 +3507,7 @@ void nsContentUtils::GetEventArgNames(int32_t aNameSpaceID, nsAtom* aEventName,
// Note: The list of content bundles in nsStringBundle.cpp should be updated
// whenever entries are added or removed from this list.
-static const char gPropertiesFiles[nsContentUtils::PropertiesFile_COUNT][56] = {
+static const char* gPropertiesFiles[nsContentUtils::PropertiesFile_COUNT] = {
// Must line up with the enum values in |PropertiesFile| enum.
"chrome://global/locale/css.properties",
"chrome://global/locale/xbl.properties",
@@ -3522,7 +3522,9 @@ static const char gPropertiesFiles[nsContentUtils::PropertiesFile_COUNT][56] = {
"chrome://global/locale/commonDialogs.properties",
"chrome://global/locale/mathml/mathml.properties",
"chrome://global/locale/security/security.properties",
- "chrome://necko/locale/necko.properties"};
+ "chrome://necko/locale/necko.properties",
+ "chrome://global/locale/layout/HtmlForm.properties",
+ "resource://gre/res/locale/layout/HtmlForm.properties"};
/* static */
nsresult nsContentUtils::EnsureStringBundle(PropertiesFile aFile) {
@@ -3571,10 +3573,22 @@ void nsContentUtils::AsyncPrecreateStringBundles() {
}
}
+static bool SpoofLocaleEnglish() {
+ // 0 - will prompt
+ // 1 - don't spoof
+ // 2 - spoof
+ return StaticPrefs::privacy_spoof_english() == 2;
+}
+
/* static */
nsresult nsContentUtils::GetLocalizedString(PropertiesFile aFile,
const char* aKey,
nsAString& aResult) {
+ // When we spoof English, use en-US default strings in HTML forms.
+ if (aFile == eFORMS_PROPERTIES_MAYBESPOOF && SpoofLocaleEnglish()) {
+ aFile = eFORMS_PROPERTIES_en_US;
+ }
+
nsresult rv = EnsureStringBundle(aFile);
NS_ENSURE_SUCCESS(rv, rv);
nsIStringBundle* bundle = sStringBundles[aFile];
@@ -3587,6 +3601,11 @@ nsresult nsContentUtils::FormatLocalizedString(PropertiesFile aFile,
const char16_t** aParams,
uint32_t aParamsLength,
nsAString& aResult) {
+ // When we spoof English, use en-US default strings in HTML forms.
+ if (aFile == eFORMS_PROPERTIES_MAYBESPOOF && SpoofLocaleEnglish()) {
+ aFile = eFORMS_PROPERTIES_en_US;
+ }
+
nsresult rv = EnsureStringBundle(aFile);
NS_ENSURE_SUCCESS(rv, rv);
nsIStringBundle* bundle = sStringBundles[aFile];
@@ -5120,11 +5139,13 @@ nsIWidget* nsContentUtils::GetTopLevelWidget(nsIWidget* aWidget) {
const nsDependentString nsContentUtils::GetLocalizedEllipsis() {
static char16_t sBuf[4] = {0, 0, 0, 0};
if (!sBuf[0]) {
- nsAutoString tmp;
- Preferences::GetLocalizedString("intl.ellipsis", tmp);
- uint32_t len =
- std::min(uint32_t(tmp.Length()), uint32_t(ArrayLength(sBuf) - 1));
- CopyUnicodeTo(tmp, 0, sBuf, len);
+ if (!SpoofLocaleEnglish()) {
+ nsAutoString tmp;
+ Preferences::GetLocalizedString("intl.ellipsis", tmp);
+ uint32_t len =
+ std::min(uint32_t(tmp.Length()), uint32_t(ArrayLength(sBuf) - 1));
+ CopyUnicodeTo(tmp, 0, sBuf, len);
+ }
if (!sBuf[0]) sBuf[0] = char16_t(0x2026);
}
return nsDependentString(sBuf);
diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h
index de450090e9db..67febf189c34 100644
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -1117,6 +1117,8 @@ class nsContentUtils {
eMATHML_PROPERTIES,
eSECURITY_PROPERTIES,
eNECKO_PROPERTIES,
+ eFORMS_PROPERTIES_MAYBESPOOF,
+ eFORMS_PROPERTIES_en_US,
PropertiesFile_COUNT
};
static nsresult ReportToConsole(
diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp
index b7360a9ff3e7..dd0365a7646c 100644
--- a/dom/html/HTMLInputElement.cpp
+++ b/dom/html/HTMLInputElement.cpp
@@ -725,15 +725,15 @@ nsresult HTMLInputElement::InitFilePicker(FilePickerType aType) {
nsAutoString title;
nsAutoString okButtonLabel;
if (aType == FILE_PICKER_DIRECTORY) {
- nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
- "DirectoryUpload", title);
+ nsContentUtils::GetLocalizedString(
+ nsContentUtils::eFORMS_PROPERTIES_MAYBESPOOF, "DirectoryUpload", title);
- nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
- "DirectoryPickerOkButtonLabel",
- okButtonLabel);
+ nsContentUtils::GetLocalizedString(
+ nsContentUtils::eFORMS_PROPERTIES_MAYBESPOOF,
+ "DirectoryPickerOkButtonLabel", okButtonLabel);
} else {
- nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
- "FileUpload", title);
+ nsContentUtils::GetLocalizedString(
+ nsContentUtils::eFORMS_PROPERTIES_MAYBESPOOF, "FileUpload", title);
}
nsCOMPtr<nsIFilePicker> filePicker =
@@ -2339,22 +2339,25 @@ void HTMLInputElement::GetDisplayFileName(nsAString& aValue) const {
if ((IsDirPickerEnabled() && Allowdirs()) ||
(StaticPrefs::dom_webkitBlink_dirPicker_enabled() &&
HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory))) {
- nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
- "NoDirSelected", value);
+ nsContentUtils::GetLocalizedString(
+ nsContentUtils::eFORMS_PROPERTIES_MAYBESPOOF, "NoDirSelected", value);
} else if (HasAttr(kNameSpaceID_None, nsGkAtoms::multiple)) {
- nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
- "NoFilesSelected", value);
+ nsContentUtils::GetLocalizedString(
+ nsContentUtils::eFORMS_PROPERTIES_MAYBESPOOF, "NoFilesSelected",
+ value);
} else {
- nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
- "NoFileSelected", value);
+ nsContentUtils::GetLocalizedString(
+ nsContentUtils::eFORMS_PROPERTIES_MAYBESPOOF, "NoFileSelected",
+ value);
}
} else {
nsString count;
count.AppendInt(int(mFileData->mFilesOrDirectories.Length()));
const char16_t* params[] = {count.get()};
- nsContentUtils::FormatLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
- "XFilesSelected", params, value);
+ nsContentUtils::FormatLocalizedString(
+ nsContentUtils::eFORMS_PROPERTIES_MAYBESPOOF, "XFilesSelected", params,
+ value);
}
aValue = value;
@@ -5825,8 +5828,8 @@ HTMLInputElement::SubmitNamesValues(HTMLFormSubmission* aFormSubmission) {
!HasAttr(kNameSpaceID_None, nsGkAtoms::value)) {
// Get our default value, which is the same as our default label
nsAutoString defaultValue;
- nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
- "Submit", defaultValue);
+ nsContentUtils::GetLocalizedString(
+ nsContentUtils::eFORMS_PROPERTIES_MAYBESPOOF, "Submit", defaultValue);
value = defaultValue;
}
diff --git a/dom/locales/moz.build b/dom/locales/moz.build
index 1734739c5426..b2bcd271de7c 100644
--- a/dom/locales/moz.build
+++ b/dom/locales/moz.build
@@ -59,3 +59,7 @@ with Files("en-US/chrome/plugins.properties"):
BUG_COMPONENT = ("Core", "Plug-ins")
JAR_MANIFESTS += ['jar.mn']
+
+RESOURCE_FILES.locale.layout += [
+ 'en-US/chrome/layout/HtmlForm.properties',
+]
diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp
index 4941b7f9780a..7a5a96d1769a 100644
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -1654,8 +1654,8 @@ already_AddRefed<nsIContent> nsCSSFrameConstructor::CreateGeneratedContent(
}
nsAutoString temp;
- nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
- "Submit", temp);
+ nsContentUtils::GetLocalizedString(
+ nsContentUtils::eFORMS_PROPERTIES_MAYBESPOOF, "Submit", temp);
return CreateGenConTextNode(aState, temp, nullptr, nullptr);
}
@@ -7899,8 +7899,8 @@ void nsCSSFrameConstructor::GetAlternateTextFor(Element* aElement, nsAtom* aTag,
// If there's no "value" attribute either, then use the localized string for
// "Submit" as the alternate text.
- nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
- "Submit", aAltText);
+ nsContentUtils::GetLocalizedString(
+ nsContentUtils::eFORMS_PROPERTIES_MAYBESPOOF, "Submit", aAltText);
}
}
diff --git a/layout/forms/nsFileControlFrame.cpp b/layout/forms/nsFileControlFrame.cpp
index 5774f9f9275f..9be30011aa8e 100644
--- a/layout/forms/nsFileControlFrame.cpp
+++ b/layout/forms/nsFileControlFrame.cpp
@@ -215,8 +215,8 @@ static already_AddRefed<Element> MakeAnonButton(Document* aDoc,
// Set the file picking button text depending on the current locale.
nsAutoString buttonTxt;
- nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
- labelKey, buttonTxt);
+ nsContentUtils::GetLocalizedString(
+ nsContentUtils::eFORMS_PROPERTIES_MAYBESPOOF, labelKey, buttonTxt);
// Set the browse button text. It's a bit of a pain to do because we want to
// make sure we are not notifying.
diff --git a/layout/forms/nsGfxButtonControlFrame.cpp b/layout/forms/nsGfxButtonControlFrame.cpp
index a35765a2cb5e..03186ef7bf54 100644
--- a/layout/forms/nsGfxButtonControlFrame.cpp
+++ b/layout/forms/nsGfxButtonControlFrame.cpp
@@ -88,8 +88,8 @@ nsresult nsGfxButtonControlFrame::GetDefaultLabel(nsAString& aString) const {
return NS_OK;
}
- return nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
- prop, aString);
+ return nsContentUtils::GetLocalizedString(
+ nsContentUtils::eFORMS_PROPERTIES_MAYBESPOOF, prop, aString);
}
nsresult nsGfxButtonControlFrame::GetLabel(nsString& aLabel) {
diff --git a/layout/generic/DetailsFrame.cpp b/layout/generic/DetailsFrame.cpp
index 9f4e909f3952..e1a9f0c70b2b 100644
--- a/layout/generic/DetailsFrame.cpp
+++ b/layout/generic/DetailsFrame.cpp
@@ -98,8 +98,9 @@ nsresult DetailsFrame::CreateAnonymousContent(
mDefaultSummary = new HTMLSummaryElement(nodeInfo.forget());
nsAutoString defaultSummaryText;
- nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
- "DefaultSummary", defaultSummaryText);
+ nsContentUtils::GetLocalizedString(
+ nsContentUtils::eFORMS_PROPERTIES_MAYBESPOOF, "DefaultSummary",
+ defaultSummaryText);
RefPtr<nsTextNode> description = new nsTextNode(nodeInfoManager);
description->SetText(defaultSummaryText, false);
mDefaultSummary->AppendChildTo(description, false);
diff --git a/mobile/android/installer/package-manifest.in b/mobile/android/installer/package-manifest.in
index 816589393562..3d014cbc6e67 100644
--- a/mobile/android/installer/package-manifest.in
+++ b/mobile/android/installer/package-manifest.in
@@ -201,6 +201,7 @@
@BINPATH@/res/grabber.gif
@BINPATH@/res/dtd/*
@BINPATH@/res/language.properties
+ at BINPATH@/res/locale/layout/HtmlForm.properties
#ifndef MOZ_ANDROID_EXCLUDE_FONTS
@BINPATH@/res/fonts/*
More information about the tor-commits
mailing list