[tor-commits] [tor-messenger-build/master] Set JS locale to English/C
sukhbir at torproject.org
sukhbir at torproject.org
Mon Jul 13 03:15:09 UTC 2015
commit 427ef050da6d1adc026508299d631ce6a3fc0d01
Author: Sukhbir Singh <sukhbir at torproject.org>
Date: Sun Jul 12 23:12:22 2015 -0400
Set JS locale to English/C
This patch is copied from Tor Browser Bundle; ticket #13019, patch by
Arthur Edelstein.
---
projects/instantbird/config | 1 +
projects/instantbird/js-locale.mozpatch | 204 +++++++++++++++++++++++++++++++
2 files changed, 205 insertions(+)
diff --git a/projects/instantbird/config b/projects/instantbird/config
index 95f6c46..c216ce4 100644
--- a/projects/instantbird/config
+++ b/projects/instantbird/config
@@ -116,6 +116,7 @@ input_files:
enable: '[% c("var/windows") %]'
- filename: Bug-9173-Change-the-default-Firefox-profile-director.mozpatch
- filename: block-plugins.mozpatch
+ - filename: js-locale.mozpatch
- filename: 824009fbc42f.mozpatch
enable: '[% c("var/windows") %]'
- filename: Bug-1133689-backport-Make-D3DVsyncDisplay-destructor.mozpatch
diff --git a/projects/instantbird/js-locale.mozpatch b/projects/instantbird/js-locale.mozpatch
new file mode 100644
index 0000000..b135523
--- /dev/null
+++ b/projects/instantbird/js-locale.mozpatch
@@ -0,0 +1,204 @@
+diff --git a/browser/base/content/test/general/mochitest.ini b/browser/base/content/test/general/mochitest.ini
+index a129d73..139133e 100644
+--- a/browser/base/content/test/general/mochitest.ini
++++ b/browser/base/content/test/general/mochitest.ini
+@@ -28,7 +28,6 @@ support-files =
+
+ [test_bug364677.html]
+ [test_bug395533.html]
+-[test_bug_jsdefaultlocale.html]
+ [test_contextmenu.html]
+ skip-if = toolkit == "gtk2" || toolkit == "gtk3" || (os == 'mac' && os_version != '10.6') # disabled on Linux due to bug 513558, on Mac after 10.6 due to bug 792304
+ [test_contextmenu_input.html]
+diff --git a/browser/base/content/test/general/test_bug_jsdefaultlocale.html b/browser/base/content/test/general/test_bug_jsdefaultlocale.html
+deleted file mode 100644
+index 6566ae0..0000000
+--- a/browser/base/content/test/general/test_bug_jsdefaultlocale.html
++++ /dev/null
+@@ -1,41 +0,0 @@
+-<!DOCTYPE HTML>
+-<html>
+-<!--
+-https://bugs.torproject.org/13019
+--->
+-<head>
+- <meta charset="utf-8">
+- <title>Test for Tor Bug #13019: Prevent fingerprinting of JS-exposed locale</title>
+- <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+- <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
+- <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+-</head>
+-<body>
+-<a target="_blank" href="https://bugs.torproject.org">Bug 13019</a>
+-<p id="display"></p>
+-<pre id="test"></pre>
+-<script type="application/javascript;version=1.8">
+-let prefName = "javascript.use_us_english_locale",
+- originalPrefValue = null,
+- date = new Date();
+-// Read the current pref value.
+-try {
+- originalPrefValue = SpecialPowers.getBoolPref(prefName);
+-} catch (e) { }
+-// Enable pref "javascript.use_us_english_locale".
+-SpecialPowers.setBoolPref(prefName, true);
+-// Test that we are getting en-US locale everywhere it is exposed in JavaScript
+-is(Intl.Collator().resolvedOptions().locale, "en-US", "content JS locale from Intl.Collator");
+-is(Intl.DateTimeFormat().resolvedOptions().locale, "en-US", "content JS locale Intl.DateTimeFormat");
+-is(Intl.NumberFormat().resolvedOptions().locale, "en-US", "content JS locale from Intl.NumberFormat");
+-is(date.toLocaleString(), date.toLocaleString("en-US"), "Date formatted by JS locale");
+-// Return pref to its original value, if it had one.
+-if (originalPrefValue === null) {
+- SpecialPowers.clearUserPref(prefName);
+-} else {
+- SpecialPowers.setBoolPref(prefName, originalPrefValue);
+-}
+-
+-</script>
+-</body>
+-</html>
+diff --git a/js/src/jsapi.cpp b/js/src/jsapi.cpp
+index 877056e..169981e9 100644
+--- a/js/src/jsapi.cpp
++++ b/js/src/jsapi.cpp
+@@ -5217,13 +5217,6 @@ JS_SetDefaultLocale(JSRuntime* rt, const char* locale)
+ return rt->setDefaultLocale(locale);
+ }
+
+-JS_PUBLIC_API(const char*)
+-JS_GetDefaultLocale(JSRuntime *rt)
+-{
+- AssertHeapIsIdle(rt);
+- return rt->getDefaultLocale();
+-}
+-
+ JS_PUBLIC_API(void)
+ JS_ResetDefaultLocale(JSRuntime* rt)
+ {
+diff --git a/js/src/jsapi.h b/js/src/jsapi.h
+index 2a6fe34..2b279b5 100644
+--- a/js/src/jsapi.h
++++ b/js/src/jsapi.h
+@@ -4266,15 +4266,6 @@ extern JS_PUBLIC_API(bool)
+ JS_SetDefaultLocale(JSRuntime* rt, const char* locale);
+
+ /*
+- * Returns the default locale for the ECMAScript Internationalization API
+- * (Intl.Collator, Intl.NumberFormat, Intl.DateTimeFormat).
+- * Note that the Internationalization API encourages clients to
+- * specify their own locales.
+- */
+-extern JS_PUBLIC_API(const char*)
+-JS_GetDefaultLocale(JSRuntime *rt);
+-
+-/*
+ * Reset the default locale to OS defaults.
+ */
+ extern JS_PUBLIC_API(void)
+diff --git a/xpcom/build/XPCOMInit.cpp b/xpcom/build/XPCOMInit.cpp
+index 292652d..a58d89c 100644
+--- a/xpcom/build/XPCOMInit.cpp
++++ b/xpcom/build/XPCOMInit.cpp
+@@ -8,7 +8,6 @@
+
+ #include "mozilla/Atomics.h"
+ #include "mozilla/Poison.h"
+-#include "mozilla/Preferences.h"
+ #include "mozilla/XPCOM.h"
+ #include "nsXULAppAPI.h"
+
+@@ -44,8 +43,6 @@
+ #include "nsSupportsPrimitives.h"
+ #include "nsConsoleService.h"
+
+-#include "nsIJSRuntimeService.h"
+-
+ #include "nsComponentManager.h"
+ #include "nsCategoryManagerUtils.h"
+ #include "nsIServiceManager.h"
+@@ -488,67 +485,6 @@ NS_IMPL_ISUPPORTS(NesteggReporter, nsIMemoryReporter)
+ CountingAllocatorBase<NesteggReporter>::sAmount(0);
+ #endif /* MOZ_WEBM */
+
+-// Anonymous namespace for customizing the default locale that JavaScript
+-// uses, according to the value of the "javascript.use_us_english_locale" pref.
+-// The current default locale can be detected in JavaScript by calling
+-// `Intl.DateTimeFormat().resolvedOptions().locale`
+-namespace {
+-
+-#define USE_US_ENGLISH_LOCALE_PREF "javascript.use_us_english_locale"
+-
+-static char* sSystemLocale;
+-static char* sJSLocale;
+-
+-// Returns a pointer to the current JS Runtime.
+-static
+-JSRuntime* GetRuntime() {
+- nsresult rv;
+- nsCOMPtr<nsIJSRuntimeService> rts = do_GetService("@mozilla.org/js/xpc/RuntimeService;1", &rv);
+- if (NS_FAILED(rv)) return NULL;
+- JSRuntime* rt;
+- rts->GetRuntime(&rt);
+- return rt;
+-}
+-
+-// If the USE_US_ENGLISH_LOCALE_PREF is active, set all locales to US English.
+-// Otherwise, fall back to the default system and JS locales.
+-static
+-void UseUSEnglishLocalePrefChangedCallback(const char* /* pref */, void* /* closure */) {
+- // Get a pointer to the default JS Runtime.
+- JSRuntime* rt = GetRuntime();
+- if (rt) {
+- // Read the pref to see if we will use US English locale.
+- bool useUSEnglishLocale = mozilla::Preferences::GetBool(USE_US_ENGLISH_LOCALE_PREF, false);
+- // Set the application-wide C-locale. Needed for Date.toLocaleFormat().
+- setlocale(LC_ALL, useUSEnglishLocale ? "C" : sSystemLocale);
+- // Now override the JavaScript Runtime Locale that is used by the Intl API
+- // as well as Date.toLocaleString, Number.toLocaleString, and String.localeCompare.
+- JS_SetDefaultLocale(rt, useUSEnglishLocale ? "en-US" : sJSLocale);
+- }
+-}
+-
+-static
+-void StartWatchingUseUSEnglishLocalePref() {
+- // Get the default system locale. To be used if US English locale pref is deactivated.
+- sSystemLocale = strdup(setlocale(LC_ALL,NULL));
+- // Store the default JavaScript locale.
+- JSRuntime* rt = GetRuntime();
+- if (rt) {
+- sJSLocale = strdup(JS_GetDefaultLocale(rt));
+- }
+- // Now keep the locale updated with the current pref value.
+- mozilla::Preferences::RegisterCallbackAndCall(UseUSEnglishLocalePrefChangedCallback, USE_US_ENGLISH_LOCALE_PREF);
+-}
+-
+-static
+-void StopWatchingUseUSEnglishLocalePref() {
+- mozilla::Preferences::UnregisterCallback(UseUSEnglishLocalePrefChangedCallback, USE_US_ENGLISH_LOCALE_PREF);
+- if (sSystemLocale) free(sSystemLocale);
+- if (sJSLocale) JS_free(nullptr, sJSLocale);
+-}
+-
+-} // anonymous namespace for locale hiding
+-
+ // Note that on OSX, aBinDirectory will point to .app/Contents/Resources/browser
+ EXPORT_XPCOM_API(nsresult)
+ NS_InitXPCOM2(nsIServiceManager** aResult,
+@@ -830,8 +766,6 @@ NS_InitXPCOM2(nsIServiceManager** aResult,
+ mozilla::eventtracer::Init();
+ #endif
+
+- // Start watching the "javascript.use_us_english_locale" pref.
+- StartWatchingUseUSEnglishLocalePref();
+ return NS_OK;
+ }
+
+@@ -1104,8 +1038,6 @@ ShutdownXPCOM(nsIServiceManager* aServMgr)
+ delete sExitManager;
+ sExitManager = nullptr;
+
+- StopWatchingUseUSEnglishLocalePref();
+-
+ Omnijar::CleanUp();
+
+ HangMonitor::Shutdown();
More information about the tor-commits
mailing list