Skip to content

Commit

Permalink
Bug 21787: Spoof en-US for date picker
Browse files Browse the repository at this point in the history
When privacy.spoof_english === 2, then en-US spoofing is enabled.
In that case, make sure the date picker does not leak the locale.
  • Loading branch information
arthuredelstein committed Aug 22, 2018
1 parent d0ccd48 commit 55f5c19
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 21 deletions.
5 changes: 5 additions & 0 deletions dom/base/IntlUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions dom/base/IntlUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class IntlUtils final : public nsISupports
mozilla::dom::LocaleInfo& aResult,
mozilla::ErrorResult& aError);

bool SpoofEnglish() const;

private:
~IntlUtils();

Expand Down
6 changes: 6 additions & 0 deletions dom/webidl/IntlUtils.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
45 changes: 25 additions & 20 deletions toolkit/content/widgets/datetimebox.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = mSpoofEnglish ? "yyyy" : ]]>"&date.year.placeholder;"<![CDATA[;
this.mMonthPlaceHolder = mSpoofEnglish ? "mm" : ]]>"&date.month.placeholder;"<![CDATA[;
this.mDayPlaceHolder = 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 = mSpoofEnglish ? "Year" : ]]>"&date.year.label;"<![CDATA[;
this.mMonthLabel = mSpoofEnglish ? "Month" : ]]>"&date.month.label;"<![CDATA[;
this.mDayLabel = mSpoofEnglish ? "Day" : ]]>"&date.day.label;"<![CDATA[;
/* eslint-enable no-multi-spaces */
this.mMinMonth = 1;
Expand Down Expand Up @@ -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 = mSpoofEnglish ? "--" : ]]>"&time.hour.placeholder;"<![CDATA[;
this.mMinutePlaceHolder = mSpoofEnglish ? "--" : ]]>"&time.minute.placeholder;"<![CDATA[;
this.mSecondPlaceHolder = mSpoofEnglish ? "--" : ]]>"&time.second.placeholder;"<![CDATA[;
this.mMillisecPlaceHolder = mSpoofEnglish ? "--" : ]]>"&time.millisecond.placeholder;"<![CDATA[;
this.mDayPeriodPlaceHolder = mSpoofEnglish ? "--" : ]]>"&time.dayperiod.placeholder;"<![CDATA[;
this.mHourLabel = mSpoofEnglish ? "Hours" : ]]>"&time.hour.label;"<![CDATA[;
this.mMinuteLabel = mSpoofEnglish ? "Minutes" :]]>"&time.minute.label;"<![CDATA[;
this.mSecondLabel = mSpoofEnglish ? "Seconds" :]]>"&time.second.label;"<![CDATA[;
this.mMillisecLabel = mSpoofEnglish ? "Milliseconds" :]]>"&time.millisecond.label;"<![CDATA[;
this.mDayPeriodLabel = mSpoofEnglish ? "AM/PM" :]]>"&time.dayperiod.label;"<![CDATA[;
/* eslint-enable no-multi-spaces */
this.mHour12 = this.is12HourTime(this.mLocales);
Expand Down Expand Up @@ -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 = mSpoofEnglish ? ["en-US"] : window.getRegionalPrefsLocales();
this.mIsRTL = false;
let intlUtils = window.intlUtils;
if (intlUtils) {
this.mIsRTL =
intlUtils.getLocaleInfo(this.mLocales).direction === "rtl";
Expand All @@ -1241,7 +1242,11 @@
this.mResetButton =
document.getAnonymousElementByAttribute(this, "anonid", "reset-button");
this.mResetButton.style.visibility = "hidden";
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);
Expand Down
3 changes: 2 additions & 1 deletion toolkit/content/widgets/datetimepopup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 55f5c19

Please sign in to comment.