[tbb-commits] [tor-browser/tor-browser-60.1.0esr-8.0-1] Bug 21787: Spoof en-US for date picker

gk at torproject.org gk at torproject.org
Mon Aug 27 22:38:26 UTC 2018


commit 7150252e7a0213aeddfe3c0aed294aae4cfcb3b8
Author: Arthur Edelstein <arthuredelstein at gmail.com>
Date:   Mon Aug 20 15:42:08 2018 -0700

    Bug 21787: Spoof en-US for date picker
    
    When privacy.spoof_english === 2, then en-US spoofing is enabled.
    In that case, make sure the date picker does not leak the locale.
---
 dom/base/IntlUtils.cpp                    |  5 ++++
 dom/base/IntlUtils.h                      |  2 ++
 dom/webidl/IntlUtils.webidl               |  6 +++++
 toolkit/content/widgets/datetimebox.xml   | 43 +++++++++++++++++--------------
 toolkit/content/widgets/datetimepopup.xml |  3 ++-
 5 files changed, 39 insertions(+), 20 deletions(-)

diff --git a/dom/base/IntlUtils.cpp b/dom/base/IntlUtils.cpp
index 9fc21414fd58..89f2ebbdc026 100644
--- a/dom/base/IntlUtils.cpp
+++ b/dom/base/IntlUtils.cpp
@@ -141,5 +141,10 @@ IntlUtils::GetLocaleInfo(const Sequence<nsString>& aLocales,
   }
 }
 
+bool
+IntlUtils::SpoofEnglish() const {
+  return Preferences::GetInt("privacy.spoof_english", 0) == 2;
+}
+
 } // dom namespace
 } // mozilla namespace
diff --git a/dom/base/IntlUtils.h b/dom/base/IntlUtils.h
index 76875497f293..55d8e823abfd 100644
--- a/dom/base/IntlUtils.h
+++ b/dom/base/IntlUtils.h
@@ -47,6 +47,8 @@ public:
                 mozilla::dom::LocaleInfo& aResult,
                 mozilla::ErrorResult& aError);
 
+  bool SpoofEnglish() const;
+
 private:
   ~IntlUtils();
 
diff --git a/dom/webidl/IntlUtils.webidl b/dom/webidl/IntlUtils.webidl
index c70e0f955c82..1fea1735997c 100644
--- a/dom/webidl/IntlUtils.webidl
+++ b/dom/webidl/IntlUtils.webidl
@@ -70,4 +70,10 @@ interface IntlUtils {
    */
   [Throws]
   LocaleInfo getLocaleInfo(sequence<DOMString> locales);
+
+  /**
+   * Attribute that indicates whether the user has chosen
+   * to spoof the locale as en-US in content.
+   */
+  readonly attribute boolean spoofEnglish;
 };
diff --git a/toolkit/content/widgets/datetimebox.xml b/toolkit/content/widgets/datetimebox.xml
index 2a7cdd50f64d..f4bb32ca35e7 100644
--- a/toolkit/content/widgets/datetimebox.xml
+++ b/toolkit/content/widgets/datetimebox.xml
@@ -27,13 +27,13 @@
       <constructor>
       <![CDATA[
         /* eslint-disable no-multi-spaces */
-        this.mYearPlaceHolder = ]]>"&date.year.placeholder;"<![CDATA[;
-        this.mMonthPlaceHolder = ]]>"&date.month.placeholder;"<![CDATA[;
-        this.mDayPlaceHolder = ]]>"&date.day.placeholder;"<![CDATA[;
+        this.mYearPlaceHolder = this.mSpoofEnglish ? "yyyy" : ]]>"&date.year.placeholder;"<![CDATA[;
+        this.mMonthPlaceHolder = this.mSpoofEnglish ? "mm" : ]]>"&date.month.placeholder;"<![CDATA[;
+        this.mDayPlaceHolder = this.mSpoofEnglish ? "dd" : ]]>"&date.day.placeholder;"<![CDATA[;
 
-        this.mYearLabel = ]]>"&date.year.label;"<![CDATA[;
-        this.mMonthLabel = ]]>"&date.month.label;"<![CDATA[;
-        this.mDayLabel = ]]>"&date.day.label;"<![CDATA[;
+        this.mYearLabel = this.mSpoofEnglish ? "Year" : ]]>"&date.year.label;"<![CDATA[;
+        this.mMonthLabel = this.mSpoofEnglish ? "Month" : ]]>"&date.month.label;"<![CDATA[;
+        this.mDayLabel = this.mSpoofEnglish ? "Day" : ]]>"&date.day.label;"<![CDATA[;
         /* eslint-enable no-multi-spaces */
 
         this.mMinMonth = 1;
@@ -451,17 +451,17 @@
         this.mPMIndicator = pmString || kDefaultPMString;
 
         /* eslint-disable no-multi-spaces */
-        this.mHourPlaceHolder = ]]>"&time.hour.placeholder;"<![CDATA[;
-        this.mMinutePlaceHolder = ]]>"&time.minute.placeholder;"<![CDATA[;
-        this.mSecondPlaceHolder = ]]>"&time.second.placeholder;"<![CDATA[;
-        this.mMillisecPlaceHolder = ]]>"&time.millisecond.placeholder;"<![CDATA[;
-        this.mDayPeriodPlaceHolder = ]]>"&time.dayperiod.placeholder;"<![CDATA[;
-
-        this.mHourLabel = ]]>"&time.hour.label;"<![CDATA[;
-        this.mMinuteLabel = ]]>"&time.minute.label;"<![CDATA[;
-        this.mSecondLabel = ]]>"&time.second.label;"<![CDATA[;
-        this.mMillisecLabel = ]]>"&time.millisecond.label;"<![CDATA[;
-        this.mDayPeriodLabel = ]]>"&time.dayperiod.label;"<![CDATA[;
+        this.mHourPlaceHolder = this.mSpoofEnglish ? "--" : ]]>"&time.hour.placeholder;"<![CDATA[;
+        this.mMinutePlaceHolder = this.mSpoofEnglish ? "--" : ]]>"&time.minute.placeholder;"<![CDATA[;
+        this.mSecondPlaceHolder = this.mSpoofEnglish ? "--" : ]]>"&time.second.placeholder;"<![CDATA[;
+        this.mMillisecPlaceHolder = this.mSpoofEnglish ? "--" : ]]>"&time.millisecond.placeholder;"<![CDATA[;
+        this.mDayPeriodPlaceHolder = this.mSpoofEnglish ? "--" : ]]>"&time.dayperiod.placeholder;"<![CDATA[;
+
+        this.mHourLabel = this.mSpoofEnglish ? "Hours" : ]]>"&time.hour.label;"<![CDATA[;
+        this.mMinuteLabel = this.mSpoofEnglish ? "Minutes" :]]>"&time.minute.label;"<![CDATA[;
+        this.mSecondLabel = this.mSpoofEnglish ? "Seconds" :]]>"&time.second.label;"<![CDATA[;
+        this.mMillisecLabel = this.mSpoofEnglish ? "Milliseconds" :]]>"&time.millisecond.label;"<![CDATA[;
+        this.mDayPeriodLabel = this.mSpoofEnglish ? "AM/PM" :]]>"&time.dayperiod.label;"<![CDATA[;
         /* eslint-enable no-multi-spaces */
 
         this.mHour12 = this.is12HourTime(this.mLocales);
@@ -1218,10 +1218,11 @@
       <![CDATA[
         this.DEBUG = false;
         this.mInputElement = this.parentNode;
-        this.mLocales = window.getRegionalPrefsLocales();
+        let intlUtils = window.intlUtils;
+        this.mSpoofEnglish = intlUtils.spoofEnglish;
+        this.mLocales = this.mSpoofEnglish ? ["en-US"] : window.getRegionalPrefsLocales();
 
         this.mIsRTL = false;
-        let intlUtils = window.intlUtils;
         if (intlUtils) {
           this.mIsRTL =
             intlUtils.getLocaleInfo(this.mLocales).direction === "rtl";
@@ -1242,6 +1243,10 @@
         this.mResetButton =
           document.getAnonymousElementByAttribute(this, "anonid", "reset-button");
         this.mResetButton.style.visibility = "hidden";
+        if (this.mSpoofEnglish) {
+          // Use the US English version of datetime.reset.label.
+          this.mResetButton.setAttribute("aria-label", "Clear");
+        }
 
         this.EVENTS.forEach((eventName) => {
           this.addEventListener(eventName, this, { mozSystemGroup: true }, false);
diff --git a/toolkit/content/widgets/datetimepopup.xml b/toolkit/content/widgets/datetimepopup.xml
index ddbdd9dd0fd3..e9fef1234929 100644
--- a/toolkit/content/widgets/datetimepopup.xml
+++ b/toolkit/content/widgets/datetimepopup.xml
@@ -110,7 +110,8 @@
         <body><![CDATA[
           // TODO: When bug 1376616 lands, replace this.setGregorian with
           //       mozIntl.Locale for setting calendar to Gregorian
-          const locale = this.setGregorian(Services.locale.getAppLocaleAsBCP47());
+          const locale = this.setGregorian(
+            window.intlUtils.spoofEnglish ? "en-US" : Services.locale.getAppLocaleAsBCP47());
           const dir = this.mozIntl.getLocaleInfo(locale).direction;
 
           switch (this.type) {



More information about the tbb-commits mailing list