Bug 1871789 - Spoof mozInputSource and mozPressure for RFP. r=tjr,webidl,smaug

Differential Revision: https://phabricator.services.mozilla.com/D209543
This commit is contained in:
Fatih 2024-05-16 19:43:12 +00:00
Родитель c0b666f2de
Коммит 727dac89a3
6 изменённых файлов: 26 добавлений и 12 удалений

Просмотреть файл

@ -3291,7 +3291,7 @@ void Element::DispatchChromeOnlyLinkClickEvent(
/* Cancelable */ true, nsGlobalWindowInner::Cast(doc->GetInnerWindow()),
0, mouseEvent->CtrlKey(), mouseEvent->AltKey(), mouseEvent->ShiftKey(),
mouseEvent->MetaKey(), mouseEvent->Button(), mouseDOMEvent,
mouseEvent->InputSource(), IgnoreErrors());
mouseEvent->InputSource(CallerType::System), IgnoreErrors());
// Note: we're always trusted, but the event we pass as the `sourceEvent`
// might not be. Frontend code will check that event's trusted property to
// make that determination; doing it this way means we don't also start

Просмотреть файл

@ -298,11 +298,22 @@ bool MouseEvent::ShiftKey() { return mEvent->AsInputEvent()->IsShift(); }
bool MouseEvent::MetaKey() { return mEvent->AsInputEvent()->IsMeta(); }
float MouseEvent::MozPressure() const {
float MouseEvent::MozPressure(CallerType aCallerType) const {
if (nsContentUtils::ShouldResistFingerprinting(aCallerType, GetParentObject(),
RFPTarget::PointerEvents)) {
// Use the spoofed value from PointerEvent::Pressure
return 0.5;
}
return mEvent->AsMouseEventBase()->mPressure;
}
uint16_t MouseEvent::InputSource() const {
uint16_t MouseEvent::InputSource(CallerType aCallerType) const {
if (nsContentUtils::ShouldResistFingerprinting(aCallerType, GetParentObject(),
RFPTarget::PointerEvents)) {
return MouseEvent_Binding::MOZ_SOURCE_MOUSE;
}
return mEvent->AsMouseEventBase()->mInputSource;
}

Просмотреть файл

@ -82,8 +82,8 @@ class MouseEvent : public UIEvent {
const MouseEventInit& aParam);
int32_t MovementX() { return GetMovementPoint().x; }
int32_t MovementY() { return GetMovementPoint().y; }
float MozPressure() const;
uint16_t InputSource() const;
float MozPressure(CallerType) const;
uint16_t InputSource(CallerType) const;
void InitNSMouseEvent(const nsAString& aType, bool aCanBubble,
bool aCancelable, nsGlobalWindowInner* aView,
int32_t aDetail, int32_t aScreenX, int32_t aScreenY,

Просмотреть файл

@ -92,7 +92,7 @@ partial interface MouseEvent
// Finger or touch pressure event value
// ranges between 0.0 and 1.0
// TODO: Remove mozPressure. (bug 1534199)
[Deprecated="MouseEvent_MozPressure"]
[NeedsCallerType, Deprecated="MouseEvent_MozPressure"]
readonly attribute float mozPressure;
const unsigned short MOZ_SOURCE_UNKNOWN = 0;
@ -103,10 +103,10 @@ partial interface MouseEvent
const unsigned short MOZ_SOURCE_TOUCH = 5;
const unsigned short MOZ_SOURCE_KEYBOARD = 6;
[ChromeOnly]
[NeedsCallerType, ChromeOnly]
readonly attribute unsigned short inputSource;
[Deprecated="MozInputSource", BinaryName="inputSource"]
[NeedsCallerType, Deprecated="MozInputSource", BinaryName="inputSource"]
readonly attribute unsigned short mozInputSource;
// TODO: Remove initNSMouseEvent. (bug 1165213)

Просмотреть файл

@ -412,7 +412,10 @@ nsresult HTMLSelectEventListener::MouseDown(dom::Event* aMouseEvent) {
}
if (mIsCombobox) {
uint16_t inputSource = mouseEvent->InputSource();
// inputSource is used to apply padding for touch events, but
// the dropdown is rendered in another process, the webpage won't
// have access to it. It is fine to use CallerType::System here.
uint16_t inputSource = mouseEvent->InputSource(CallerType::System);
if (mElement->OpenInParentProcess()) {
nsCOMPtr<nsIContent> target = do_QueryInterface(aMouseEvent->GetTarget());
if (target && target->IsHTMLElement(nsGkAtoms::option)) {

Просмотреть файл

@ -423,7 +423,7 @@ nsBaseDragService::InvokeDragSessionWithImage(
mSourceWindowContext ? mSourceWindowContext->TopWindowContext() : nullptr;
mScreenPosition = aDragEvent->ScreenPoint(CallerType::System);
mInputSource = aDragEvent->InputSource();
mInputSource = aDragEvent->InputSource(CallerType::System);
// If dragging within a XUL tree and no custom drag image was
// set, the region argument to InvokeDragSessionWithImage needs
@ -472,7 +472,7 @@ nsBaseDragService::InvokeDragSessionWithRemoteImage(
mSourceTopWindowContext = mDragStartData->GetSourceTopWindowContext();
mScreenPosition = aDragEvent->ScreenPoint(CallerType::System);
mInputSource = aDragEvent->InputSource();
mInputSource = aDragEvent->InputSource(CallerType::System);
nsresult rv = InvokeDragSession(
aDOMNode, aPrincipal, aCsp, aCookieJarSettings, aTransferableArray,
@ -504,7 +504,7 @@ nsBaseDragService::InvokeDragSessionWithSelection(
mScreenPosition.x = aDragEvent->ScreenX(CallerType::System);
mScreenPosition.y = aDragEvent->ScreenY(CallerType::System);
mInputSource = aDragEvent->InputSource();
mInputSource = aDragEvent->InputSource(CallerType::System);
// just get the focused node from the selection
// XXXndeakin this should actually be the deepest node that contains both