mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
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
This commit is contained in:
parent
3209c82acb
commit
536fd2e65f
@ -336,6 +336,7 @@
|
||||
@RESPATH@/res/fonts/*
|
||||
@RESPATH@/res/dtd/*
|
||||
@RESPATH@/res/language.properties
|
||||
@RESPATH@/res/locale/layout/HtmlForm.properties
|
||||
#ifdef XP_MACOSX
|
||||
@RESPATH@/res/MainMenu.nib/
|
||||
#endif
|
||||
|
@ -3560,7 +3560,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",
|
||||
@ -3575,7 +3575,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) {
|
||||
@ -3624,10 +3626,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];
|
||||
@ -3638,6 +3652,11 @@ nsresult nsContentUtils::GetLocalizedString(PropertiesFile aFile,
|
||||
nsresult nsContentUtils::FormatLocalizedString(
|
||||
PropertiesFile aFile, const char* aKey, const nsTArray<nsString>& aParams,
|
||||
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];
|
||||
@ -5124,11 +5143,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);
|
||||
|
@ -1101,6 +1101,8 @@ class nsContentUtils {
|
||||
eMATHML_PROPERTIES,
|
||||
eSECURITY_PROPERTIES,
|
||||
eNECKO_PROPERTIES,
|
||||
eFORMS_PROPERTIES_MAYBESPOOF,
|
||||
eFORMS_PROPERTIES_en_US,
|
||||
PropertiesFile_COUNT
|
||||
};
|
||||
static nsresult ReportToConsole(
|
||||
|
@ -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 =
|
||||
@ -2333,21 +2333,24 @@ void HTMLInputElement::GetDisplayFileName(nsAString& aValue) const {
|
||||
if ((StaticPrefs::dom_input_dirpicker() && 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()));
|
||||
|
||||
nsContentUtils::FormatLocalizedString(
|
||||
value, nsContentUtils::eFORMS_PROPERTIES, "XFilesSelected", count);
|
||||
value, nsContentUtils::eFORMS_PROPERTIES_MAYBESPOOF, "XFilesSelected",
|
||||
count);
|
||||
}
|
||||
|
||||
aValue = value;
|
||||
@ -5776,8 +5779,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;
|
||||
}
|
||||
|
||||
|
@ -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',
|
||||
]
|
||||
|
@ -1649,8 +1649,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);
|
||||
}
|
||||
|
||||
@ -7956,8 +7956,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
|
@ -204,6 +204,7 @@
|
||||
@BINPATH@/res/grabber.gif
|
||||
@BINPATH@/res/dtd/*
|
||||
@BINPATH@/res/language.properties
|
||||
@BINPATH@/res/locale/layout/HtmlForm.properties
|
||||
|
||||
#ifndef MOZ_ANDROID_EXCLUDE_FONTS
|
||||
@BINPATH@/res/fonts/*
|
||||
|
Loading…
Reference in New Issue
Block a user