Bug 1222285 - Part 2: Making the keyboard events of modifier keys been suppressed when 'privacy.resistFingerprinting' is true. r=arthuredelstein,masayuki
authorTim Huang <tihuang@mozilla.com>
Thu, 31 Aug 2017 11:14:14 +0800
changeset 453921 b2f55468b241f28678dc5e35e19eb3b5781a1c5c
parent 453920 7140b4a3c47adf5094187fbea6d321154033cbb1
child 453922 d83173f047563c621d133423ec14aed04d899316
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersarthuredelstein, masayuki
bugs1222285
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1222285 - Part 2: Making the keyboard events of modifier keys been suppressed when 'privacy.resistFingerprinting' is true. r=arthuredelstein,masayuki This patch makes 'Shift', 'Alt', 'Contorl' and 'AltGraph' been suppressed for content when fingerprinting resistance is enabled. Chrome can still get these events. The reason behind this is that websites can still observe key combinations to tell which keyboard layout is using even we spoof the keyboardEvent.code, keyboardEvent.keyCode and modifier states. For example, the AZERTY France keyboard, the digit keys of it requires the user press the Shift key. So, it is easy to differentiate AZERTY and QWERTY keyboard by observing whether a Shift key generates its own before the digit keys. There are similar issues for 'Alt' and 'AltGraph' as well. MozReview-Commit-ID: 3CwCgvey4lK
layout/base/PresShell.cpp
widget/BasicEvents.h
widget/WidgetEventImpl.cpp
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -7975,16 +7975,20 @@ PresShell::DispatchEventToDOM(WidgetEven
     } else if (mDocument) {
       eventTarget = do_QueryInterface(mDocument);
       // If we don't have any content, the callback wouldn't probably
       // do nothing.
       eventCBPtr = nullptr;
     }
   }
   if (eventTarget) {
+    if (aEvent->IsBlockedForFingerprintingResistance()) {
+      aEvent->mFlags.mOnlySystemGroupDispatchInContent = true;
+    }
+
     if (aEvent->mClass == eCompositionEventClass) {
       IMEStateManager::DispatchCompositionEvent(eventTarget, mPresContext,
                                                 aEvent->AsCompositionEvent(),
                                                 aStatus, eventCBPtr);
     } else {
       EventDispatcher::Dispatch(eventTarget, mPresContext,
                                 aEvent, nullptr, aStatus, eventCBPtr);
     }
--- a/widget/BasicEvents.h
+++ b/widget/BasicEvents.h
@@ -857,16 +857,20 @@ public:
    * Whether the event should cause a DOM event.
    */
   bool IsAllowedToDispatchDOMEvent() const;
   /**
    * Whether the event should be dispatched in system group.
    */
   bool IsAllowedToDispatchInSystemGroup() const;
   /**
+   * Whether the event should be blocked for fingerprinting resistance.
+   */
+  bool IsBlockedForFingerprintingResistance() const;
+  /**
    * Initialize mComposed
    */
   void SetDefaultComposed()
   {
     switch (mClass) {
       case eCompositionEventClass:
         mFlags.mComposed = mMessage == eCompositionStart ||
                            mMessage == eCompositionUpdate ||
--- a/widget/WidgetEventImpl.cpp
+++ b/widget/WidgetEventImpl.cpp
@@ -505,16 +505,34 @@ bool
 WidgetEvent::IsAllowedToDispatchInSystemGroup() const
 {
   // We don't expect to implement default behaviors with pointer events because
   // if we do, prevent default on mouse events can't prevent default behaviors
   // anymore.
   return mClass != ePointerEventClass;
 }
 
+bool
+WidgetEvent::IsBlockedForFingerprintingResistance() const
+{
+  if (mClass == eKeyboardEventClass &&
+      nsContentUtils::ShouldResistFingerprinting()) {
+    const WidgetKeyboardEvent* keyboardEvent = AsKeyboardEvent();
+
+    if (keyboardEvent->mKeyNameIndex == KEY_NAME_INDEX_Alt     ||
+        keyboardEvent->mKeyNameIndex == KEY_NAME_INDEX_Shift   ||
+        keyboardEvent->mKeyNameIndex == KEY_NAME_INDEX_Control ||
+        keyboardEvent->mKeyNameIndex == KEY_NAME_INDEX_AltGraph) {
+      return true;
+    }
+  }
+
+  return false;
+}
+
 /******************************************************************************
  * mozilla::WidgetEvent
  *
  * Misc methods.
  ******************************************************************************/
 
 static dom::EventTarget*
 GetTargetForDOMEvent(nsIDOMEventTarget* aTarget)