Commit 99f998aa authored by Alex Catarineu's avatar Alex Catarineu Committed by Matthew Finkel
Browse files

Bug 30683: Prevent detection of locale via some *.properties

Spoofing dom/dom.properties, layout/xmlparser.properties,
layout/MediaDocument.properties to en-US if needed.
parent 86ef6918
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -345,6 +345,9 @@
@RESPATH@/res/dtd/*
@RESPATH@/res/language.properties
@RESPATH@/res/locale/layout/HtmlForm.properties
@RESPATH@/res/locale/layout/MediaDocument.properties
@RESPATH@/res/locale/layout/xmlparser.properties
@RESPATH@/res/locale/dom/dom.properties
#ifdef XP_MACOSX
@RESPATH@/res/MainMenu.nib/
#endif
+13 −4
Original line number Diff line number Diff line
@@ -3531,7 +3531,9 @@ static const char* gPropertiesFiles[nsContentUtils::PropertiesFile_COUNT] = {
    "chrome://global/locale/security/security.properties",
    "chrome://necko/locale/necko.properties",
    "chrome://global/locale/layout/HtmlForm.properties",
    "resource://gre/res/locale/layout/HtmlForm.properties"};
    "resource://gre/res/locale/layout/HtmlForm.properties",
    "chrome://global/locale/dom/dom.properties",
    "resource://gre/res/locale/dom/dom.properties"};

/* static */
nsresult nsContentUtils::EnsureStringBundle(PropertiesFile aFile) {
@@ -3580,7 +3582,8 @@ void nsContentUtils::AsyncPrecreateStringBundles() {
  }
}

static bool SpoofLocaleEnglish() {
/* static */
bool nsContentUtils::SpoofLocaleEnglish() {
  // 0 - will prompt
  // 1 - don't spoof
  // 2 - spoof
@@ -3591,9 +3594,12 @@ static bool SpoofLocaleEnglish() {
nsresult nsContentUtils::GetLocalizedString(PropertiesFile aFile,
                                            const char* aKey,
                                            nsAString& aResult) {
  // When we spoof English, use en-US default strings in HTML forms.
  // When we spoof English, use en-US properties in strings that are accessible
  // by content.
  if (aFile == eFORMS_PROPERTIES_MAYBESPOOF && SpoofLocaleEnglish()) {
    aFile = eFORMS_PROPERTIES_en_US;
  } else if (aFile == eDOM_PROPERTIES_MAYBESPOOF && SpoofLocaleEnglish()) {
    aFile = eDOM_PROPERTIES_en_US;
  }

  nsresult rv = EnsureStringBundle(aFile);
@@ -3608,9 +3614,12 @@ 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.
  // When we spoof English, use en-US properties in strings that are accessible
  // by content.
  if (aFile == eFORMS_PROPERTIES_MAYBESPOOF && SpoofLocaleEnglish()) {
    aFile = eFORMS_PROPERTIES_en_US;
  } else if (aFile == eDOM_PROPERTIES_MAYBESPOOF && SpoofLocaleEnglish()) {
    aFile = eDOM_PROPERTIES_en_US;
  }

  nsresult rv = EnsureStringBundle(aFile);
+4 −0
Original line number Diff line number Diff line
@@ -1119,6 +1119,8 @@ class nsContentUtils {
    eNECKO_PROPERTIES,
    eFORMS_PROPERTIES_MAYBESPOOF,
    eFORMS_PROPERTIES_en_US,
    eDOM_PROPERTIES_MAYBESPOOF,
    eDOM_PROPERTIES_en_US,
    PropertiesFile_COUNT
  };
  static nsresult ReportToConsole(
@@ -1132,6 +1134,8 @@ class nsContentUtils {

  static void LogMessageToConsole(const char* aMsg);

  static bool SpoofLocaleEnglish();

  /**
   * Get the localized string named |aKey| in properties file |aFile|.
   */
+1 −1
Original line number Diff line number Diff line
@@ -1539,7 +1539,7 @@ nsresult HTMLSelectElement::GetValidationMessage(nsAString& aValidationMessage,
    case VALIDITY_STATE_VALUE_MISSING: {
      nsAutoString message;
      nsresult rv = nsContentUtils::GetLocalizedString(
          nsContentUtils::eDOM_PROPERTIES, "FormValidationSelectMissing",
          nsContentUtils::eDOM_PROPERTIES_MAYBESPOOF, "FormValidationSelectMissing",
          message);
      aValidationMessage = message;
      return rv;
+3 −3
Original line number Diff line number Diff line
@@ -1001,7 +1001,7 @@ nsresult HTMLTextAreaElement::GetValidationMessage(

      const char16_t* params[] = {strMaxLength.get(), strTextLength.get()};
      rv = nsContentUtils::FormatLocalizedString(
          nsContentUtils::eDOM_PROPERTIES, "FormValidationTextTooLong", params,
          nsContentUtils::eDOM_PROPERTIES_MAYBESPOOF, "FormValidationTextTooLong", params,
          message);
      aValidationMessage = message;
    } break;
@@ -1017,13 +1017,13 @@ nsresult HTMLTextAreaElement::GetValidationMessage(

      const char16_t* params[] = {strMinLength.get(), strTextLength.get()};
      rv = nsContentUtils::FormatLocalizedString(
          nsContentUtils::eDOM_PROPERTIES, "FormValidationTextTooShort", params,
          nsContentUtils::eDOM_PROPERTIES_MAYBESPOOF, "FormValidationTextTooShort", params,
          message);
      aValidationMessage = message;
    } break;
    case VALIDITY_STATE_VALUE_MISSING: {
      nsAutoString message;
      rv = nsContentUtils::GetLocalizedString(nsContentUtils::eDOM_PROPERTIES,
      rv = nsContentUtils::GetLocalizedString(nsContentUtils::eDOM_PROPERTIES_MAYBESPOOF,
                                              "FormValidationValueMissing",
                                              message);
      aValidationMessage = message;
Loading