From ba1afc2fcfc466fecb93ac77f91d46b72785d6bb Mon Sep 17 00:00:00 2001 From: Arthur Edelstein Date: Wed, 23 Sep 2015 10:20:44 -0700 Subject: [PATCH] Bug 17009: Pref to suppress some modifier key events --- layout/base/nsIPresShell.h | 3 +++ layout/base/nsPresShell.cpp | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/layout/base/nsIPresShell.h b/layout/base/nsIPresShell.h index cbbae0e8fd22e..dc0bb0ab40503 100644 --- a/layout/base/nsIPresShell.h +++ b/layout/base/nsIPresShell.h @@ -1861,6 +1861,9 @@ protected: // to true, so we can avoid any paint calls for widget related to this // presshell. bool mIsNeverPainting; + + // If true, don't report Alt, Shift, and AltGr KeyboardEvents to content. + static bool sSuppressModifierKeyEvents; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsIPresShell, NS_IPRESSHELL_IID) diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 56ac370b96d1f..1db07f8e54c4a 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -242,6 +242,8 @@ static nsClassHashtable* sActivePointersIds; +bool nsIPresShell::sSuppressModifierKeyEvents = false; + // RangePaintInfo is used to paint ranges to offscreen buffers struct RangePaintInfo { RefPtr mRange; @@ -7174,6 +7176,16 @@ PresShell::HandleKeyboardEvent(nsINode* aTarget, nsEventStatus* aStatus, EventDispatchingCallback* aEventCB) { + if (nsContentUtils::ResistFingerprinting() && sSuppressModifierKeyEvents) { + nsString keyName; + aEvent.GetDOMKeyName(keyName); + if (keyName.Equals(NS_LITERAL_STRING("Shift")) || + keyName.Equals(NS_LITERAL_STRING("Alt")) || + keyName.Equals(NS_LITERAL_STRING("AltGraph"))) { + aEvent.mFlags.mOnlyChromeDispatch = true; + } + } + MOZ_ASSERT(aTarget); // return true if the event target is in its child process @@ -10913,6 +10925,9 @@ void nsIPresShell::InitializeStatics() sPointerCaptureList = new nsClassHashtable; sActivePointersIds = new nsClassHashtable; + Preferences::AddBoolVarCache(&sSuppressModifierKeyEvents, + "privacy.suppressModifierKeyEvents", false); + } void nsIPresShell::ReleaseStatics() -- GitLab