Exemple #1
0
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;
}
Exemple #2
0
void PointerEvent::GetPointerType(nsAString& aPointerType,
                                  CallerType aCallerType) {
  if (ShouldResistFingerprinting(aCallerType)) {
    aPointerType.AssignLiteral("mouse");
    return;
  }

  ConvertPointerTypeToString(mEvent->AsPointerEvent()->inputSource,
                             aPointerType);
}
Exemple #3
0
bool
KeyboardEvent::ShiftKey(CallerType aCallerType)
{
  bool shiftState = mEvent->AsKeyboardEvent()->IsShift();

  if (!ShouldResistFingerprinting(aCallerType)) {
    return shiftState;
  }

  return GetSpoofedModifierStates(Modifier::MODIFIER_SHIFT, shiftState);
}
Exemple #4
0
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);
}
Exemple #5
0
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);
}
Exemple #6
0
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;
}
Exemple #7
0
int32_t PointerEvent::Twist(CallerType aCallerType) {
  return ShouldResistFingerprinting(aCallerType)
             ? 0
             : mEvent->AsPointerEvent()->twist;
}
Exemple #8
0
float PointerEvent::TangentialPressure(CallerType aCallerType) {
  return ShouldResistFingerprinting(aCallerType)
             ? 0
             : mEvent->AsPointerEvent()->tangentialPressure;
}
Exemple #9
0
int32_t PointerEvent::Height(CallerType aCallerType) {
  return ShouldResistFingerprinting(aCallerType)
             ? 1
             : mEvent->AsPointerEvent()->mHeight;
}
Exemple #10
0
int32_t PointerEvent::Width(CallerType aCallerType) {
  return ShouldResistFingerprinting(aCallerType)
             ? 1
             : mEvent->AsPointerEvent()->mWidth;
}
Exemple #11
0
int32_t PointerEvent::PointerId(CallerType aCallerType) {
  return ShouldResistFingerprinting(aCallerType)
             ? PointerEventHandler::GetSpoofedPointerIdForRFP()
             : mEvent->AsPointerEvent()->pointerId;
}