Skip to content
Snippets Groups Projects
Verified Commit 4098cfce authored by ma1's avatar ma1
Browse files

Bug 42288: Allow language spoofing in status messages.

parent 2673b6cc
No related branches found
No related tags found
No related merge requests found
......@@ -318,6 +318,7 @@
@RESPATH@/res/locale/layout/HtmlForm.properties
@RESPATH@/res/locale/layout/MediaDocument.properties
@RESPATH@/res/locale/layout/xmlparser.properties
@RESPATH@/res/locale/xslt/xslt.properties
@RESPATH@/res/locale/dom/dom.properties
#ifdef XP_MACOSX
@RESPATH@/res/MainMenu.nib/
......
......@@ -57,6 +57,10 @@ RESOURCE_FILES.locale.layout += [
"en-US/chrome/layout/xmlparser.properties",
]
RESOURCE_FILES.locale.xslt += [
"en-US/chrome/xslt/xslt.properties",
]
RESOURCE_FILES.locale.dom += [
"en-US/chrome/dom/dom.properties",
]
......@@ -942,11 +942,17 @@ void txMozillaXSLTProcessor::reportError(nsresult aResult,
mozilla::components::StringBundle::Service();
if (sbs) {
nsString errorText;
sbs->FormatStatusMessage(aResult, u"", errorText);
bool spoofLocale = nsContentUtils::SpoofLocaleEnglish();
if (spoofLocale && mSource) {
Document* sourceDoc = mSource->OwnerDoc();
spoofLocale = !(sourceDoc && sourceDoc->AllowsL10n());
}
sbs->FormatStatusMessage(aResult, u"", spoofLocale, errorText);
nsAutoString errorMessage;
nsCOMPtr<nsIStringBundle> bundle;
sbs->CreateBundle(XSLT_MSGS_URL, getter_AddRefs(bundle));
sbs->CreateBundle(spoofLocale ? XSLT_MSGS_URL_en_US : XSLT_MSGS_URL,
getter_AddRefs(bundle));
if (bundle) {
AutoTArray<nsString, 1> error = {errorText};
......
......@@ -7,5 +7,6 @@
#define DOM_XSLT_XSLT_TXXSLTMSGSURL_H_
#define XSLT_MSGS_URL "chrome://global/locale/xslt/xslt.properties"
#define XSLT_MSGS_URL_en_US "resource://gre/res/locale/xslt/xslt.properties"
#endif // DOM_XSLT_XSLT_TXXSLTMSGSURL_H_
......@@ -86,9 +86,13 @@ interface nsIStringBundleService : nsISupports
* used in the string lookup process.
* @param aStatusArg - The status message argument(s). Multiple arguments
* can be separated by newline ('\n') characters.
* @param aSpoofLocale - If true (default is false), forces the en-US
locale on content-accessible messages (XSLT errors so far).
* @return the formatted message
*/
AString formatStatusMessage(in nsresult aStatus, in wstring aStatusArg);
AString formatStatusMessage(in nsresult aStatus,
in wstring aStatusArg,
[optional] in boolean aSpoofLocale);
/**
* flushes the string bundle cache - useful when the locale changes or
......
......@@ -977,6 +977,7 @@ nsresult nsStringBundleService::FormatWithBundle(
NS_IMETHODIMP
nsStringBundleService::FormatStatusMessage(nsresult aStatus,
const char16_t* aStatusArg,
bool aSpoofLocale,
nsAString& result) {
uint32_t i, argCount = 0;
nsCOMPtr<nsIStringBundle> bundle;
......@@ -1012,7 +1013,8 @@ nsStringBundleService::FormatStatusMessage(nsresult aStatus,
switch (NS_ERROR_GET_MODULE(aStatus)) {
case NS_ERROR_MODULE_XSLT:
getStringBundle(XSLT_MSGS_URL, getter_AddRefs(bundle));
getStringBundle(aSpoofLocale ? XSLT_MSGS_URL_en_US : XSLT_MSGS_URL,
getter_AddRefs(bundle));
break;
case NS_ERROR_MODULE_NETWORK:
getStringBundle(NECKO_MSGS_URL, getter_AddRefs(bundle));
......
......@@ -181,6 +181,7 @@
@BINPATH@/res/locale/layout/HtmlForm.properties
@BINPATH@/res/locale/layout/MediaDocument.properties
@BINPATH@/res/locale/layout/xmlparser.properties
@BINPATH@/res/locale/xslt/xslt.properties
@BINPATH@/res/locale/dom/dom.properties
#ifndef MOZ_ANDROID_EXCLUDE_FONTS
......
......@@ -1230,7 +1230,7 @@ NS_IMETHODIMP nsDocLoader::OnStatus(nsIRequest* aRequest, nsresult aStatus,
mozilla::components::StringBundle::Service();
if (!sbs) return NS_ERROR_FAILURE;
nsAutoString msg;
nsresult rv = sbs->FormatStatusMessage(aStatus, aStatusArg, msg);
nsresult rv = sbs->FormatStatusMessage(aStatus, aStatusArg, false, msg);
if (NS_FAILED(rv)) return rv;
// Keep around the message. In case a request finishes, we need to make sure
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment