uint32_t KeyboardEvent::KeyCode(CallerType aCallerType) { // If this event is initialized with ctor, we shouldn't check event type. if (mInitializedByCtor) { return mEvent->AsKeyboardEvent()->mKeyCode; } if (!mEvent->HasKeyEventMessage()) { return 0; } if (!ShouldResistFingerprinting(aCallerType)) { return mEvent->AsKeyboardEvent()->mKeyCode; } // 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; } return 0; }
void PointerEvent::GetPointerType(nsAString& aPointerType, CallerType aCallerType) { if (ShouldResistFingerprinting(aCallerType)) { aPointerType.AssignLiteral("mouse"); return; } ConvertPointerTypeToString(mEvent->AsPointerEvent()->inputSource, aPointerType); }
bool KeyboardEvent::ShiftKey(CallerType aCallerType) { bool shiftState = mEvent->AsKeyboardEvent()->IsShift(); if (!ShouldResistFingerprinting(aCallerType)) { return shiftState; } return GetSpoofedModifierStates(Modifier::MODIFIER_SHIFT, shiftState); }
bool KeyboardEvent::AltKey(CallerType aCallerType) { 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); }
void KeyboardEvent::GetCode(nsAString& aCodeName, CallerType aCallerType) { 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); }
float PointerEvent::Pressure(CallerType aCallerType) { if (mEvent->mMessage == ePointerUp || !ShouldResistFingerprinting(aCallerType)) { return mEvent->AsPointerEvent()->pressure; } // According to [1], we should use 0.5 when it is in active buttons state and // 0 otherwise for devices that don't support pressure. And a pointerup event // always reports 0, so we don't need to spoof that. // // [1] https://www.w3.org/TR/pointerevents/#dom-pointerevent-pressure float spoofedPressure = 0.0; if (mEvent->AsPointerEvent()->buttons) { spoofedPressure = 0.5; } return spoofedPressure; }
int32_t PointerEvent::Twist(CallerType aCallerType) { return ShouldResistFingerprinting(aCallerType) ? 0 : mEvent->AsPointerEvent()->twist; }
float PointerEvent::TangentialPressure(CallerType aCallerType) { return ShouldResistFingerprinting(aCallerType) ? 0 : mEvent->AsPointerEvent()->tangentialPressure; }
int32_t PointerEvent::Height(CallerType aCallerType) { return ShouldResistFingerprinting(aCallerType) ? 1 : mEvent->AsPointerEvent()->mHeight; }
int32_t PointerEvent::Width(CallerType aCallerType) { return ShouldResistFingerprinting(aCallerType) ? 1 : mEvent->AsPointerEvent()->mWidth; }
int32_t PointerEvent::PointerId(CallerType aCallerType) { return ShouldResistFingerprinting(aCallerType) ? PointerEventHandler::GetSpoofedPointerIdForRFP() : mEvent->AsPointerEvent()->pointerId; }