2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2004-08-20 22:09:19 +04:00
|
|
|
|
2014-02-27 14:51:13 +04:00
|
|
|
#include "mozilla/dom/KeyboardEvent.h"
|
2013-09-25 15:21:19 +04:00
|
|
|
#include "mozilla/TextEvents.h"
|
Bug 1222285 - Part 1: Spoofing the keyboard event to mimc a certain keyboard layout according to the content-language of the document when 'privacy.resistFingerprinting' is true. r=arthuredelstein,masayuki,smaug
This patch makes Firefox to spoof keyboardEvent.code, keyboardEvent.keycode and
modifier states, for 'Shift', 'Alt', 'Control' and 'AltGraph', when 'privacy.resistFingerprinting'
is true. Firefox will spoof keyboard events as a certain keyboard layout according
to the content language of the document, for example, we use US English keyboard for
English content. Right now, it only supports English contents, we will add more
support for more languages later. The spoofing only affects content, chrome
can still see real keyboard events.
MozReview-Commit-ID: 40JPvwLmMMB
--HG--
extra : rebase_source : 870224ba4f87b3e336c5b061ac6859dd1c48c4f2
2017-08-29 06:33:27 +03:00
|
|
|
#include "nsContentUtils.h"
|
2014-02-27 14:51:13 +04:00
|
|
|
#include "prtime.h"
|
2004-08-20 22:09:19 +04:00
|
|
|
|
2014-02-27 14:51:13 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2013-10-01 11:22:58 +04:00
|
|
|
|
2014-02-27 14:51:13 +04:00
|
|
|
KeyboardEvent::KeyboardEvent(EventTarget* aOwner,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetKeyboardEvent* aEvent)
|
2014-02-28 18:58:43 +04:00
|
|
|
: UIEvent(aOwner, aPresContext,
|
2015-08-26 15:56:59 +03:00
|
|
|
aEvent ? aEvent :
|
2015-08-29 02:58:26 +03:00
|
|
|
new WidgetKeyboardEvent(false, eVoidEvent, nullptr))
|
2014-04-14 10:37:47 +04:00
|
|
|
, mInitializedByCtor(false)
|
2014-11-03 10:05:32 +03:00
|
|
|
, mInitializedWhichValue(0)
|
2004-08-20 22:09:19 +04:00
|
|
|
{
|
|
|
|
if (aEvent) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mEventIsInternal = false;
|
2004-08-20 22:09:19 +04:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 18:59:28 +04:00
|
|
|
mEventIsInternal = true;
|
2016-03-28 07:29:42 +03:00
|
|
|
mEvent->mTime = PR_Now();
|
2013-10-29 08:14:42 +04:00
|
|
|
mEvent->AsKeyboardEvent()->mKeyNameIndex = KEY_NAME_INDEX_USE_STRING;
|
2004-08-20 22:09:19 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-28 18:58:43 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(KeyboardEvent, UIEvent)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(KeyboardEvent, UIEvent)
|
2004-08-20 22:09:19 +04:00
|
|
|
|
2014-02-27 14:51:13 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN(KeyboardEvent)
|
2004-08-20 22:09:19 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMKeyEvent)
|
2014-02-28 18:58:43 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(UIEvent)
|
2004-08-20 22:09:19 +04:00
|
|
|
|
2013-10-18 10:10:26 +04:00
|
|
|
bool
|
Bug 1222285 - Part 1: Spoofing the keyboard event to mimc a certain keyboard layout according to the content-language of the document when 'privacy.resistFingerprinting' is true. r=arthuredelstein,masayuki,smaug
This patch makes Firefox to spoof keyboardEvent.code, keyboardEvent.keycode and
modifier states, for 'Shift', 'Alt', 'Control' and 'AltGraph', when 'privacy.resistFingerprinting'
is true. Firefox will spoof keyboard events as a certain keyboard layout according
to the content language of the document, for example, we use US English keyboard for
English content. Right now, it only supports English contents, we will add more
support for more languages later. The spoofing only affects content, chrome
can still see real keyboard events.
MozReview-Commit-ID: 40JPvwLmMMB
--HG--
extra : rebase_source : 870224ba4f87b3e336c5b061ac6859dd1c48c4f2
2017-08-29 06:33:27 +03:00
|
|
|
KeyboardEvent::AltKey(CallerType aCallerType)
|
2013-10-18 10:10:26 +04:00
|
|
|
{
|
Bug 1222285 - Part 1: Spoofing the keyboard event to mimc a certain keyboard layout according to the content-language of the document when 'privacy.resistFingerprinting' is true. r=arthuredelstein,masayuki,smaug
This patch makes Firefox to spoof keyboardEvent.code, keyboardEvent.keycode and
modifier states, for 'Shift', 'Alt', 'Control' and 'AltGraph', when 'privacy.resistFingerprinting'
is true. Firefox will spoof keyboard events as a certain keyboard layout according
to the content language of the document, for example, we use US English keyboard for
English content. Right now, it only supports English contents, we will add more
support for more languages later. The spoofing only affects content, chrome
can still see real keyboard events.
MozReview-Commit-ID: 40JPvwLmMMB
--HG--
extra : rebase_source : 870224ba4f87b3e336c5b061ac6859dd1c48c4f2
2017-08-29 06:33:27 +03:00
|
|
|
bool altState = mEvent->AsKeyboardEvent()->IsAlt();
|
|
|
|
|
|
|
|
if (!ShouldResistFingerprinting(aCallerType)) {
|
|
|
|
return altState;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need to give a spoofed state for Alt key since it could be used as a
|
|
|
|
// modifier key in certain keyboard layout. For example, the '@' key for
|
|
|
|
// German keyboard for MAC is Alt+L.
|
|
|
|
return GetSpoofedModifierStates(Modifier::MODIFIER_ALT, altState);
|
2013-10-18 10:10:26 +04:00
|
|
|
}
|
|
|
|
|
2004-08-20 22:09:19 +04:00
|
|
|
NS_IMETHODIMP
|
2014-02-27 14:51:13 +04:00
|
|
|
KeyboardEvent::GetAltKey(bool* aIsDown)
|
2004-08-20 22:09:19 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aIsDown);
|
2013-04-21 03:48:55 +04:00
|
|
|
*aIsDown = AltKey();
|
2004-08-20 22:09:19 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-10-18 10:10:26 +04:00
|
|
|
bool
|
Bug 1222285 - Part 1: Spoofing the keyboard event to mimc a certain keyboard layout according to the content-language of the document when 'privacy.resistFingerprinting' is true. r=arthuredelstein,masayuki,smaug
This patch makes Firefox to spoof keyboardEvent.code, keyboardEvent.keycode and
modifier states, for 'Shift', 'Alt', 'Control' and 'AltGraph', when 'privacy.resistFingerprinting'
is true. Firefox will spoof keyboard events as a certain keyboard layout according
to the content language of the document, for example, we use US English keyboard for
English content. Right now, it only supports English contents, we will add more
support for more languages later. The spoofing only affects content, chrome
can still see real keyboard events.
MozReview-Commit-ID: 40JPvwLmMMB
--HG--
extra : rebase_source : 870224ba4f87b3e336c5b061ac6859dd1c48c4f2
2017-08-29 06:33:27 +03:00
|
|
|
KeyboardEvent::CtrlKey(CallerType aCallerType)
|
2013-10-18 10:10:26 +04:00
|
|
|
{
|
Bug 1222285 - Part 1: Spoofing the keyboard event to mimc a certain keyboard layout according to the content-language of the document when 'privacy.resistFingerprinting' is true. r=arthuredelstein,masayuki,smaug
This patch makes Firefox to spoof keyboardEvent.code, keyboardEvent.keycode and
modifier states, for 'Shift', 'Alt', 'Control' and 'AltGraph', when 'privacy.resistFingerprinting'
is true. Firefox will spoof keyboard events as a certain keyboard layout according
to the content language of the document, for example, we use US English keyboard for
English content. Right now, it only supports English contents, we will add more
support for more languages later. The spoofing only affects content, chrome
can still see real keyboard events.
MozReview-Commit-ID: 40JPvwLmMMB
--HG--
extra : rebase_source : 870224ba4f87b3e336c5b061ac6859dd1c48c4f2
2017-08-29 06:33:27 +03:00
|
|
|
bool ctrlState = mEvent->AsKeyboardEvent()->IsControl();
|
|
|
|
|
|
|
|
if (!ShouldResistFingerprinting(aCallerType)) {
|
|
|
|
return ctrlState;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need to give a spoofed state for Control key since it could be used as a
|
|
|
|
// modifier key in certain asian keyboard layouts.
|
|
|
|
return GetSpoofedModifierStates(Modifier::MODIFIER_CONTROL, ctrlState);
|
2013-10-18 10:10:26 +04:00
|
|
|
}
|
|
|
|
|
2004-08-20 22:09:19 +04:00
|
|
|
NS_IMETHODIMP
|
2014-02-27 14:51:13 +04:00
|
|
|
KeyboardEvent::GetCtrlKey(bool* aIsDown)
|
2004-08-20 22:09:19 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aIsDown);
|
2013-04-21 03:48:55 +04:00
|
|
|
*aIsDown = CtrlKey();
|
2004-08-20 22:09:19 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-10-18 10:10:26 +04:00
|
|
|
bool
|
Bug 1222285 - Part 1: Spoofing the keyboard event to mimc a certain keyboard layout according to the content-language of the document when 'privacy.resistFingerprinting' is true. r=arthuredelstein,masayuki,smaug
This patch makes Firefox to spoof keyboardEvent.code, keyboardEvent.keycode and
modifier states, for 'Shift', 'Alt', 'Control' and 'AltGraph', when 'privacy.resistFingerprinting'
is true. Firefox will spoof keyboard events as a certain keyboard layout according
to the content language of the document, for example, we use US English keyboard for
English content. Right now, it only supports English contents, we will add more
support for more languages later. The spoofing only affects content, chrome
can still see real keyboard events.
MozReview-Commit-ID: 40JPvwLmMMB
--HG--
extra : rebase_source : 870224ba4f87b3e336c5b061ac6859dd1c48c4f2
2017-08-29 06:33:27 +03:00
|
|
|
KeyboardEvent::ShiftKey(CallerType aCallerType)
|
2013-10-18 10:10:26 +04:00
|
|
|
{
|
Bug 1222285 - Part 1: Spoofing the keyboard event to mimc a certain keyboard layout according to the content-language of the document when 'privacy.resistFingerprinting' is true. r=arthuredelstein,masayuki,smaug
This patch makes Firefox to spoof keyboardEvent.code, keyboardEvent.keycode and
modifier states, for 'Shift', 'Alt', 'Control' and 'AltGraph', when 'privacy.resistFingerprinting'
is true. Firefox will spoof keyboard events as a certain keyboard layout according
to the content language of the document, for example, we use US English keyboard for
English content. Right now, it only supports English contents, we will add more
support for more languages later. The spoofing only affects content, chrome
can still see real keyboard events.
MozReview-Commit-ID: 40JPvwLmMMB
--HG--
extra : rebase_source : 870224ba4f87b3e336c5b061ac6859dd1c48c4f2
2017-08-29 06:33:27 +03:00
|
|
|
bool shiftState = mEvent->AsKeyboardEvent()->IsShift();
|
|
|
|
|
|
|
|
if (!ShouldResistFingerprinting(aCallerType)) {
|
|
|
|
return shiftState;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GetSpoofedModifierStates(Modifier::MODIFIER_SHIFT, shiftState);
|
2013-10-18 10:10:26 +04:00
|
|
|
}
|
|
|
|
|
2004-08-20 22:09:19 +04:00
|
|
|
NS_IMETHODIMP
|
2014-02-27 14:51:13 +04:00
|
|
|
KeyboardEvent::GetShiftKey(bool* aIsDown)
|
2004-08-20 22:09:19 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aIsDown);
|
2013-04-21 03:48:55 +04:00
|
|
|
*aIsDown = ShiftKey();
|
2004-08-20 22:09:19 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-10-18 10:10:26 +04:00
|
|
|
bool
|
2014-02-27 14:51:13 +04:00
|
|
|
KeyboardEvent::MetaKey()
|
2013-10-18 10:10:26 +04:00
|
|
|
{
|
|
|
|
return mEvent->AsKeyboardEvent()->IsMeta();
|
|
|
|
}
|
|
|
|
|
2004-08-20 22:09:19 +04:00
|
|
|
NS_IMETHODIMP
|
2014-02-27 14:51:13 +04:00
|
|
|
KeyboardEvent::GetMetaKey(bool* aIsDown)
|
2004-08-20 22:09:19 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aIsDown);
|
2013-04-21 03:48:55 +04:00
|
|
|
*aIsDown = MetaKey();
|
2004-08-20 22:09:19 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-11-07 15:17:32 +04:00
|
|
|
bool
|
2014-02-27 14:51:13 +04:00
|
|
|
KeyboardEvent::Repeat()
|
2013-11-07 15:17:32 +04:00
|
|
|
{
|
|
|
|
return mEvent->AsKeyboardEvent()->mIsRepeat;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-27 14:51:13 +04:00
|
|
|
KeyboardEvent::GetRepeat(bool* aIsRepeat)
|
2013-11-07 15:17:32 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aIsRepeat);
|
|
|
|
*aIsRepeat = Repeat();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-04-10 11:11:36 +04:00
|
|
|
bool
|
|
|
|
KeyboardEvent::IsComposing()
|
|
|
|
{
|
|
|
|
return mEvent->AsKeyboardEvent()->mIsComposing;
|
|
|
|
}
|
|
|
|
|
2012-04-25 07:00:02 +04:00
|
|
|
NS_IMETHODIMP
|
2014-02-27 14:51:13 +04:00
|
|
|
KeyboardEvent::GetModifierState(const nsAString& aKey,
|
|
|
|
bool* aState)
|
2012-04-25 07:00:02 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aState);
|
|
|
|
|
2013-04-21 03:48:55 +04:00
|
|
|
*aState = GetModifierState(aKey);
|
2012-04-25 07:00:02 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-24 07:49:46 +04:00
|
|
|
NS_IMETHODIMP
|
2014-02-27 14:51:13 +04:00
|
|
|
KeyboardEvent::GetKey(nsAString& aKeyName)
|
2013-04-24 07:49:46 +04:00
|
|
|
{
|
2014-12-30 04:47:53 +03:00
|
|
|
mEvent->AsKeyboardEvent()->GetDOMKeyName(aKeyName);
|
2013-04-24 07:49:46 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-05-25 06:08:58 +04:00
|
|
|
void
|
Bug 1222285 - Part 1: Spoofing the keyboard event to mimc a certain keyboard layout according to the content-language of the document when 'privacy.resistFingerprinting' is true. r=arthuredelstein,masayuki,smaug
This patch makes Firefox to spoof keyboardEvent.code, keyboardEvent.keycode and
modifier states, for 'Shift', 'Alt', 'Control' and 'AltGraph', when 'privacy.resistFingerprinting'
is true. Firefox will spoof keyboard events as a certain keyboard layout according
to the content language of the document, for example, we use US English keyboard for
English content. Right now, it only supports English contents, we will add more
support for more languages later. The spoofing only affects content, chrome
can still see real keyboard events.
MozReview-Commit-ID: 40JPvwLmMMB
--HG--
extra : rebase_source : 870224ba4f87b3e336c5b061ac6859dd1c48c4f2
2017-08-29 06:33:27 +03:00
|
|
|
KeyboardEvent::GetCode(nsAString& aCodeName, CallerType aCallerType)
|
2014-05-25 06:08:58 +04:00
|
|
|
{
|
Bug 1222285 - Part 1: Spoofing the keyboard event to mimc a certain keyboard layout according to the content-language of the document when 'privacy.resistFingerprinting' is true. r=arthuredelstein,masayuki,smaug
This patch makes Firefox to spoof keyboardEvent.code, keyboardEvent.keycode and
modifier states, for 'Shift', 'Alt', 'Control' and 'AltGraph', when 'privacy.resistFingerprinting'
is true. Firefox will spoof keyboard events as a certain keyboard layout according
to the content language of the document, for example, we use US English keyboard for
English content. Right now, it only supports English contents, we will add more
support for more languages later. The spoofing only affects content, chrome
can still see real keyboard events.
MozReview-Commit-ID: 40JPvwLmMMB
--HG--
extra : rebase_source : 870224ba4f87b3e336c5b061ac6859dd1c48c4f2
2017-08-29 06:33:27 +03:00
|
|
|
if (!ShouldResistFingerprinting(aCallerType)) {
|
|
|
|
mEvent->AsKeyboardEvent()->GetDOMCodeName(aCodeName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// When fingerprinting resistance is enabled, we will give a spoofed code
|
|
|
|
// according to the content-language of the document.
|
|
|
|
nsCOMPtr<nsIDocument> doc = GetDocument();
|
|
|
|
|
|
|
|
nsRFPService::GetSpoofedCode(doc, mEvent->AsKeyboardEvent(),
|
|
|
|
aCodeName);
|
2014-05-25 06:08:58 +04:00
|
|
|
}
|
|
|
|
|
2016-03-15 08:46:29 +03:00
|
|
|
void KeyboardEvent::GetInitDict(KeyboardEventInit& aParam)
|
|
|
|
{
|
|
|
|
GetKey(aParam.mKey);
|
|
|
|
GetCode(aParam.mCode);
|
|
|
|
aParam.mLocation = Location();
|
|
|
|
aParam.mRepeat = Repeat();
|
|
|
|
aParam.mIsComposing = IsComposing();
|
|
|
|
|
|
|
|
// legacy attributes
|
|
|
|
aParam.mKeyCode = KeyCode();
|
|
|
|
aParam.mCharCode = CharCode();
|
|
|
|
aParam.mWhich = Which();
|
|
|
|
|
|
|
|
// modifiers from EventModifierInit
|
|
|
|
aParam.mCtrlKey = CtrlKey();
|
|
|
|
aParam.mShiftKey = ShiftKey();
|
|
|
|
aParam.mAltKey = AltKey();
|
|
|
|
aParam.mMetaKey = MetaKey();
|
|
|
|
|
|
|
|
WidgetKeyboardEvent* internalEvent = mEvent->AsKeyboardEvent();
|
|
|
|
aParam.mModifierAltGraph = internalEvent->IsAltGraph();
|
|
|
|
aParam.mModifierCapsLock = internalEvent->IsCapsLocked();
|
|
|
|
aParam.mModifierFn = internalEvent->IsFn();
|
|
|
|
aParam.mModifierFnLock = internalEvent->IsFnLocked();
|
|
|
|
aParam.mModifierNumLock = internalEvent->IsNumLocked();
|
|
|
|
aParam.mModifierOS = internalEvent->IsOS();
|
|
|
|
aParam.mModifierScrollLock = internalEvent->IsScrollLocked();
|
|
|
|
aParam.mModifierSymbol = internalEvent->IsSymbol();
|
|
|
|
aParam.mModifierSymbolLock = internalEvent->IsSymbolLocked();
|
|
|
|
|
|
|
|
// EventInit
|
|
|
|
aParam.mBubbles = internalEvent->mFlags.mBubbles;
|
|
|
|
aParam.mCancelable = internalEvent->mFlags.mCancelable;
|
|
|
|
}
|
|
|
|
|
2004-08-20 22:09:19 +04:00
|
|
|
NS_IMETHODIMP
|
2014-02-27 14:51:13 +04:00
|
|
|
KeyboardEvent::GetCharCode(uint32_t* aCharCode)
|
2004-08-20 22:09:19 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCharCode);
|
2013-04-21 03:48:55 +04:00
|
|
|
*aCharCode = CharCode();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2004-08-20 22:09:19 +04:00
|
|
|
|
2013-04-21 03:48:55 +04:00
|
|
|
uint32_t
|
2014-02-27 14:51:13 +04:00
|
|
|
KeyboardEvent::CharCode()
|
2013-04-21 03:48:55 +04:00
|
|
|
{
|
2014-04-14 10:37:47 +04:00
|
|
|
// If this event is initialized with ctor, we shouldn't check event type.
|
|
|
|
if (mInitializedByCtor) {
|
2016-05-13 10:06:18 +03:00
|
|
|
return mEvent->AsKeyboardEvent()->mCharCode;
|
2014-04-14 10:37:47 +04:00
|
|
|
}
|
|
|
|
|
2015-08-22 04:34:51 +03:00
|
|
|
switch (mEvent->mMessage) {
|
2015-08-29 02:58:27 +03:00
|
|
|
case eKeyDown:
|
2016-04-22 19:22:49 +03:00
|
|
|
case eKeyDownOnPlugin:
|
2015-08-29 02:58:27 +03:00
|
|
|
case eKeyUp:
|
2016-04-22 19:22:49 +03:00
|
|
|
case eKeyUpOnPlugin:
|
2013-04-21 03:48:55 +04:00
|
|
|
return 0;
|
2015-08-29 02:58:27 +03:00
|
|
|
case eKeyPress:
|
2016-05-11 15:56:42 +03:00
|
|
|
case eAccessKeyNotFound:
|
2016-05-13 10:06:18 +03:00
|
|
|
return mEvent->AsKeyboardEvent()->mCharCode;
|
2015-08-26 15:56:59 +03:00
|
|
|
default:
|
|
|
|
break;
|
2004-08-20 22:09:19 +04:00
|
|
|
}
|
2013-04-21 03:48:55 +04:00
|
|
|
return 0;
|
2004-08-20 22:09:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-27 14:51:13 +04:00
|
|
|
KeyboardEvent::GetKeyCode(uint32_t* aKeyCode)
|
2004-08-20 22:09:19 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aKeyCode);
|
2013-04-21 03:48:55 +04:00
|
|
|
*aKeyCode = KeyCode();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2004-08-20 22:09:19 +04:00
|
|
|
|
2013-04-21 03:48:55 +04:00
|
|
|
uint32_t
|
Bug 1222285 - Part 1: Spoofing the keyboard event to mimc a certain keyboard layout according to the content-language of the document when 'privacy.resistFingerprinting' is true. r=arthuredelstein,masayuki,smaug
This patch makes Firefox to spoof keyboardEvent.code, keyboardEvent.keycode and
modifier states, for 'Shift', 'Alt', 'Control' and 'AltGraph', when 'privacy.resistFingerprinting'
is true. Firefox will spoof keyboard events as a certain keyboard layout according
to the content language of the document, for example, we use US English keyboard for
English content. Right now, it only supports English contents, we will add more
support for more languages later. The spoofing only affects content, chrome
can still see real keyboard events.
MozReview-Commit-ID: 40JPvwLmMMB
--HG--
extra : rebase_source : 870224ba4f87b3e336c5b061ac6859dd1c48c4f2
2017-08-29 06:33:27 +03:00
|
|
|
KeyboardEvent::KeyCode(CallerType aCallerType)
|
2013-04-21 03:48:55 +04:00
|
|
|
{
|
2014-04-14 10:37:47 +04:00
|
|
|
// If this event is initialized with ctor, we shouldn't check event type.
|
|
|
|
if (mInitializedByCtor) {
|
2016-05-12 11:13:49 +03:00
|
|
|
return mEvent->AsKeyboardEvent()->mKeyCode;
|
2014-04-14 10:37:47 +04:00
|
|
|
}
|
|
|
|
|
Bug 1222285 - Part 1: Spoofing the keyboard event to mimc a certain keyboard layout according to the content-language of the document when 'privacy.resistFingerprinting' is true. r=arthuredelstein,masayuki,smaug
This patch makes Firefox to spoof keyboardEvent.code, keyboardEvent.keycode and
modifier states, for 'Shift', 'Alt', 'Control' and 'AltGraph', when 'privacy.resistFingerprinting'
is true. Firefox will spoof keyboard events as a certain keyboard layout according
to the content language of the document, for example, we use US English keyboard for
English content. Right now, it only supports English contents, we will add more
support for more languages later. The spoofing only affects content, chrome
can still see real keyboard events.
MozReview-Commit-ID: 40JPvwLmMMB
--HG--
extra : rebase_source : 870224ba4f87b3e336c5b061ac6859dd1c48c4f2
2017-08-29 06:33:27 +03:00
|
|
|
if (!mEvent->HasKeyEventMessage()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ShouldResistFingerprinting(aCallerType)) {
|
2016-05-12 11:13:49 +03:00
|
|
|
return mEvent->AsKeyboardEvent()->mKeyCode;
|
2004-08-20 22:09:19 +04:00
|
|
|
}
|
Bug 1222285 - Part 1: Spoofing the keyboard event to mimc a certain keyboard layout according to the content-language of the document when 'privacy.resistFingerprinting' is true. r=arthuredelstein,masayuki,smaug
This patch makes Firefox to spoof keyboardEvent.code, keyboardEvent.keycode and
modifier states, for 'Shift', 'Alt', 'Control' and 'AltGraph', when 'privacy.resistFingerprinting'
is true. Firefox will spoof keyboard events as a certain keyboard layout according
to the content language of the document, for example, we use US English keyboard for
English content. Right now, it only supports English contents, we will add more
support for more languages later. The spoofing only affects content, chrome
can still see real keyboard events.
MozReview-Commit-ID: 40JPvwLmMMB
--HG--
extra : rebase_source : 870224ba4f87b3e336c5b061ac6859dd1c48c4f2
2017-08-29 06:33:27 +03:00
|
|
|
|
|
|
|
// The keyCode should be zero if the char code is given.
|
|
|
|
if (CharCode()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// When fingerprinting resistance is enabled, we will give a spoofed keyCode
|
|
|
|
// according to the content-language of the document.
|
|
|
|
nsCOMPtr<nsIDocument> doc = GetDocument();
|
|
|
|
uint32_t spoofedKeyCode;
|
|
|
|
|
|
|
|
if (nsRFPService::GetSpoofedKeyCode(doc, mEvent->AsKeyboardEvent(),
|
|
|
|
spoofedKeyCode)) {
|
|
|
|
return spoofedKeyCode;
|
|
|
|
}
|
|
|
|
|
2013-04-21 03:48:55 +04:00
|
|
|
return 0;
|
2004-08-20 22:09:19 +04:00
|
|
|
}
|
|
|
|
|
2013-04-21 03:48:55 +04:00
|
|
|
uint32_t
|
2014-02-27 14:51:13 +04:00
|
|
|
KeyboardEvent::Which()
|
2013-04-21 03:48:55 +04:00
|
|
|
{
|
2014-04-14 10:37:47 +04:00
|
|
|
// If this event is initialized with ctor, which can have independent value.
|
|
|
|
if (mInitializedByCtor) {
|
2014-11-03 10:05:32 +03:00
|
|
|
return mInitializedWhichValue;
|
2014-04-14 10:37:47 +04:00
|
|
|
}
|
|
|
|
|
2015-08-22 04:34:51 +03:00
|
|
|
switch (mEvent->mMessage) {
|
2015-08-29 02:58:27 +03:00
|
|
|
case eKeyDown:
|
2016-04-22 19:22:49 +03:00
|
|
|
case eKeyDownOnPlugin:
|
2015-08-29 02:58:27 +03:00
|
|
|
case eKeyUp:
|
2016-04-22 19:22:49 +03:00
|
|
|
case eKeyUpOnPlugin:
|
2013-04-21 03:48:55 +04:00
|
|
|
return KeyCode();
|
2015-08-29 02:58:27 +03:00
|
|
|
case eKeyPress:
|
2004-08-20 22:09:19 +04:00
|
|
|
//Special case for 4xp bug 62878. Try to make value of which
|
|
|
|
//more closely mirror the values that 4.x gave for RETURN and BACKSPACE
|
|
|
|
{
|
2016-05-12 11:13:49 +03:00
|
|
|
uint32_t keyCode = mEvent->AsKeyboardEvent()->mKeyCode;
|
2004-08-20 22:09:19 +04:00
|
|
|
if (keyCode == NS_VK_RETURN || keyCode == NS_VK_BACK) {
|
2013-04-21 03:48:55 +04:00
|
|
|
return keyCode;
|
2004-08-20 22:09:19 +04:00
|
|
|
}
|
2013-04-21 03:48:55 +04:00
|
|
|
return CharCode();
|
2004-08-20 22:09:19 +04:00
|
|
|
}
|
2015-08-26 15:56:59 +03:00
|
|
|
default:
|
|
|
|
break;
|
2004-08-20 22:09:19 +04:00
|
|
|
}
|
|
|
|
|
2013-04-21 03:48:55 +04:00
|
|
|
return 0;
|
2004-08-20 22:09:19 +04:00
|
|
|
}
|
|
|
|
|
2012-05-03 12:35:01 +04:00
|
|
|
NS_IMETHODIMP
|
2014-02-27 14:51:13 +04:00
|
|
|
KeyboardEvent::GetLocation(uint32_t* aLocation)
|
2012-05-03 12:35:01 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aLocation);
|
|
|
|
|
2013-04-21 03:48:55 +04:00
|
|
|
*aLocation = Location();
|
2012-05-03 12:35:01 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-10-18 10:10:24 +04:00
|
|
|
uint32_t
|
2014-02-27 14:51:13 +04:00
|
|
|
KeyboardEvent::Location()
|
2013-10-18 10:10:24 +04:00
|
|
|
{
|
2016-05-12 12:17:22 +03:00
|
|
|
return mEvent->AsKeyboardEvent()->mLocation;
|
2013-10-18 10:10:24 +04:00
|
|
|
}
|
|
|
|
|
2014-04-14 10:37:47 +04:00
|
|
|
// static
|
|
|
|
already_AddRefed<KeyboardEvent>
|
|
|
|
KeyboardEvent::Constructor(const GlobalObject& aGlobal,
|
|
|
|
const nsAString& aType,
|
|
|
|
const KeyboardEventInit& aParam,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
nsCOMPtr<EventTarget> target = do_QueryInterface(aGlobal.GetAsSupports());
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<KeyboardEvent> newEvent =
|
2014-04-14 10:37:47 +04:00
|
|
|
new KeyboardEvent(target, nullptr, nullptr);
|
2014-11-03 10:05:32 +03:00
|
|
|
newEvent->InitWithKeyboardEventInit(target, aType, aParam, aRv);
|
|
|
|
|
|
|
|
return newEvent.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
KeyboardEvent::InitWithKeyboardEventInit(EventTarget* aOwner,
|
|
|
|
const nsAString& aType,
|
|
|
|
const KeyboardEventInit& aParam,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
bool trusted = Init(aOwner);
|
2016-01-30 20:05:36 +03:00
|
|
|
InitKeyEvent(aType, aParam.mBubbles, aParam.mCancelable,
|
|
|
|
aParam.mView, false, false, false, false,
|
|
|
|
aParam.mKeyCode, aParam.mCharCode);
|
2015-04-13 10:16:13 +03:00
|
|
|
InitModifiers(aParam);
|
2014-11-03 10:05:32 +03:00
|
|
|
SetTrusted(trusted);
|
|
|
|
mDetail = aParam.mDetail;
|
|
|
|
mInitializedByCtor = true;
|
|
|
|
mInitializedWhichValue = aParam.mWhich;
|
|
|
|
|
|
|
|
WidgetKeyboardEvent* internalEvent = mEvent->AsKeyboardEvent();
|
2016-05-12 12:17:22 +03:00
|
|
|
internalEvent->mLocation = aParam.mLocation;
|
2014-04-14 10:37:47 +04:00
|
|
|
internalEvent->mIsRepeat = aParam.mRepeat;
|
|
|
|
internalEvent->mIsComposing = aParam.mIsComposing;
|
2015-02-19 09:50:19 +03:00
|
|
|
internalEvent->mKeyNameIndex =
|
|
|
|
WidgetKeyboardEvent::GetKeyNameIndex(aParam.mKey);
|
|
|
|
if (internalEvent->mKeyNameIndex == KEY_NAME_INDEX_USE_STRING) {
|
|
|
|
internalEvent->mKeyValue = aParam.mKey;
|
|
|
|
}
|
|
|
|
internalEvent->mCodeNameIndex =
|
|
|
|
WidgetKeyboardEvent::GetCodeNameIndex(aParam.mCode);
|
|
|
|
if (internalEvent->mCodeNameIndex == CODE_NAME_INDEX_USE_STRING) {
|
|
|
|
internalEvent->mCodeValue = aParam.mCode;
|
|
|
|
}
|
2014-04-14 10:37:47 +04:00
|
|
|
}
|
|
|
|
|
2004-08-20 22:09:19 +04:00
|
|
|
NS_IMETHODIMP
|
2014-02-27 14:51:13 +04:00
|
|
|
KeyboardEvent::InitKeyEvent(const nsAString& aType,
|
|
|
|
bool aCanBubble,
|
|
|
|
bool aCancelable,
|
2016-01-30 20:05:36 +03:00
|
|
|
mozIDOMWindow* aView,
|
2014-02-27 14:51:13 +04:00
|
|
|
bool aCtrlKey,
|
|
|
|
bool aAltKey,
|
|
|
|
bool aShiftKey,
|
|
|
|
bool aMetaKey,
|
|
|
|
uint32_t aKeyCode,
|
|
|
|
uint32_t aCharCode)
|
2004-08-20 22:09:19 +04:00
|
|
|
{
|
2016-10-30 22:30:06 +03:00
|
|
|
NS_ENSURE_TRUE(!mEvent->mFlags.mIsBeingDispatched, NS_OK);
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, 0);
|
2004-08-20 22:09:19 +04:00
|
|
|
|
2013-10-18 10:10:24 +04:00
|
|
|
WidgetKeyboardEvent* keyEvent = mEvent->AsKeyboardEvent();
|
2012-04-25 07:00:02 +04:00
|
|
|
keyEvent->InitBasicModifiers(aCtrlKey, aAltKey, aShiftKey, aMetaKey);
|
2016-05-12 11:13:49 +03:00
|
|
|
keyEvent->mKeyCode = aKeyCode;
|
2016-05-13 10:06:18 +03:00
|
|
|
keyEvent->mCharCode = aCharCode;
|
2004-08-20 22:09:19 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-08-06 16:52:39 +03:00
|
|
|
void
|
|
|
|
KeyboardEvent::InitKeyboardEvent(const nsAString& aType,
|
|
|
|
bool aCanBubble,
|
|
|
|
bool aCancelable,
|
2017-11-07 01:52:14 +03:00
|
|
|
nsGlobalWindowInner* aView,
|
2017-08-06 16:52:39 +03:00
|
|
|
const nsAString& aKey,
|
|
|
|
uint32_t aLocation,
|
|
|
|
bool aCtrlKey,
|
|
|
|
bool aAltKey,
|
|
|
|
bool aShiftKey,
|
|
|
|
bool aMetaKey,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE_VOID(!mEvent->mFlags.mIsBeingDispatched);
|
|
|
|
|
|
|
|
UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, 0);
|
|
|
|
|
|
|
|
WidgetKeyboardEvent* keyEvent = mEvent->AsKeyboardEvent();
|
|
|
|
keyEvent->InitBasicModifiers(aCtrlKey, aAltKey, aShiftKey, aMetaKey);
|
|
|
|
keyEvent->mLocation = aLocation;
|
|
|
|
keyEvent->mKeyNameIndex = KEY_NAME_INDEX_USE_STRING;
|
|
|
|
keyEvent->mKeyValue = aKey;
|
|
|
|
}
|
|
|
|
|
Bug 1222285 - Part 1: Spoofing the keyboard event to mimc a certain keyboard layout according to the content-language of the document when 'privacy.resistFingerprinting' is true. r=arthuredelstein,masayuki,smaug
This patch makes Firefox to spoof keyboardEvent.code, keyboardEvent.keycode and
modifier states, for 'Shift', 'Alt', 'Control' and 'AltGraph', when 'privacy.resistFingerprinting'
is true. Firefox will spoof keyboard events as a certain keyboard layout according
to the content language of the document, for example, we use US English keyboard for
English content. Right now, it only supports English contents, we will add more
support for more languages later. The spoofing only affects content, chrome
can still see real keyboard events.
MozReview-Commit-ID: 40JPvwLmMMB
--HG--
extra : rebase_source : 870224ba4f87b3e336c5b061ac6859dd1c48c4f2
2017-08-29 06:33:27 +03:00
|
|
|
already_AddRefed<nsIDocument>
|
|
|
|
KeyboardEvent::GetDocument()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
nsCOMPtr<EventTarget> eventTarget = InternalDOMEvent()->GetTarget();
|
|
|
|
|
|
|
|
if (eventTarget) {
|
|
|
|
nsCOMPtr<nsPIDOMWindowInner> win =
|
|
|
|
do_QueryInterface(eventTarget->GetOwnerGlobal());
|
|
|
|
|
|
|
|
if (win) {
|
|
|
|
doc = win->GetExtantDoc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return doc.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
KeyboardEvent::ShouldResistFingerprinting(CallerType aCallerType)
|
|
|
|
{
|
|
|
|
// There are five situations we don't need to spoof this keyboard event.
|
|
|
|
// 1. This event is generated by scripts.
|
|
|
|
// 2. This event is from Numpad.
|
|
|
|
// 3. This event is in the system group.
|
|
|
|
// 4. The caller type is system.
|
|
|
|
// 5. The pref privcy.resistFingerprinting' is false, we fast return here since
|
|
|
|
// we don't need to do any QI of following codes.
|
|
|
|
if (mInitializedByCtor ||
|
|
|
|
aCallerType == CallerType::System ||
|
|
|
|
mEvent->mFlags.mInSystemGroup ||
|
|
|
|
!nsContentUtils::ShouldResistFingerprinting() ||
|
|
|
|
mEvent->AsKeyboardEvent()->mLocation ==
|
|
|
|
nsIDOMKeyEvent::DOM_KEY_LOCATION_NUMPAD) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc = GetDocument();
|
|
|
|
|
|
|
|
return doc && !nsContentUtils::IsChromeDoc(doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
KeyboardEvent::GetSpoofedModifierStates(const Modifiers aModifierKey,
|
|
|
|
const bool aRawModifierState)
|
|
|
|
{
|
|
|
|
bool spoofedState;
|
|
|
|
nsCOMPtr<nsIDocument> doc = GetDocument();
|
|
|
|
|
|
|
|
if(nsRFPService::GetSpoofedModifierStates(doc,
|
|
|
|
mEvent->AsKeyboardEvent(),
|
|
|
|
aModifierKey,
|
|
|
|
spoofedState)) {
|
|
|
|
return spoofedState;
|
|
|
|
}
|
|
|
|
|
|
|
|
return aRawModifierState;
|
|
|
|
}
|
|
|
|
|
2014-02-27 14:51:13 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2015-08-12 14:39:31 +03:00
|
|
|
already_AddRefed<KeyboardEvent>
|
|
|
|
NS_NewDOMKeyboardEvent(EventTarget* aOwner,
|
2014-02-27 14:51:13 +04:00
|
|
|
nsPresContext* aPresContext,
|
|
|
|
WidgetKeyboardEvent* aEvent)
|
2004-08-20 22:09:19 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<KeyboardEvent> it = new KeyboardEvent(aOwner, aPresContext, aEvent);
|
2015-08-12 14:39:31 +03:00
|
|
|
return it.forget();
|
2004-08-20 22:09:19 +04:00
|
|
|
}
|