commit 0396e4f834a31ec0cc7b9c4b853417891a09c43c
Author: Arthur Edelstein <arthuredelstein(a)gmail.com>
Date: Mon Jul 27 17:17:15 2015 -0700
fixup! Bug 15646: Prevent keyboard layout fingerprinting in KeyboardEvent
---
dom/events/KeyCodeConsensus.h | 9 +++++++--
dom/events/KeyboardEvent.cpp | 10 +++++++++-
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/dom/events/KeyCodeConsensus.h b/dom/events/KeyCodeConsensus.h
index 5493c36..53ec7f6 100644
--- a/dom/events/KeyCodeConsensus.h
+++ b/dom/events/KeyCodeConsensus.h
@@ -5,14 +5,15 @@
#include "nsString.h"
#include "nsDataHashtable.h"
+#include "mozilla/StaticMutex.h"
// KEY_INTERNAL is called by KEY or SHIFT.
-#define KEY_INTERNAL(key, code, keyCode, shift) \
+#define KEY_INTERNAL(key, code, keyCode, shift) \
gCodes->Put(NS_LITERAL_STRING(key), NS_LITERAL_STRING(#code)); \
gKeyCodes->Put(NS_LITERAL_STRING(key), keyCode); \
gShiftStates->Put(NS_LITERAL_STRING(key), shift);
-// KEY and SHIFT Assign a consensus codeName and keyCode for the given keyName.
+// KEY and SHIFT assign a consensus codeName and keyCode for the given keyName.
// KEY indicates that shift is off.
#define KEY(key, code, keyCode) KEY_INTERNAL(key, code, keyCode, false)
// SHIFT indicates that shift is on.
@@ -26,12 +27,16 @@ static nsDataHashtable<nsStringHashKey, uint32_t>* gKeyCodes;
// gShiftStates provides a shift value for each keyName.
static nsDataHashtable<nsStringHashKey, bool>* gShiftStates;
+static StaticMutex createKeyCodesMutex;
+
// Populate the global static maps gCodes, gKeCodes, gShiftStates
// with their constant values.
static void createKeyCodes()
{
if (gCodes) return;
+ StaticMutexAutoLock lock(createKeyCodesMutex);
+
gCodes = new nsDataHashtable<nsStringHashKey, nsString>();
gKeyCodes = new nsDataHashtable<nsStringHashKey, uint32_t>();
gShiftStates = new nsDataHashtable<nsStringHashKey, bool>();
diff --git a/dom/events/KeyboardEvent.cpp b/dom/events/KeyboardEvent.cpp
index 8829b8f..76e6e39 100644
--- a/dom/events/KeyboardEvent.cpp
+++ b/dom/events/KeyboardEvent.cpp
@@ -46,7 +46,15 @@ NS_INTERFACE_MAP_END_INHERITING(UIEvent)
bool
KeyboardEvent::AltKey()
{
- return mEvent->AsKeyboardEvent()->IsAlt();
+ bool altState = mEvent->AsKeyboardEvent()->IsAlt();
+ if (ResistFingerprinting()) {
+ nsString keyName;
+ GetKey(keyName);
+ bool exists = gCodes->Get(keyName, nullptr);
+ return exists ? false : altState;
+ } else {
+ return altState;
+ }
}
NS_IMETHODIMP