Bug 1317759. Remove LegacyIsCallerChromeOrNativeCode use in Event::GetScreenCoords in favor or caller type checks at the entrypoints where we really care about pretending that our screen is client-area sized. r=smaug

This commit is contained in:
Boris Zbarsky 2016-11-16 14:10:22 -05:00
parent 3815c83ef1
commit 04caf50b43
7 changed files with 52 additions and 14 deletions

View File

@ -893,12 +893,6 @@ Event::GetScreenCoords(nsPresContext* aPresContext,
WidgetEvent* aEvent,
LayoutDeviceIntPoint aPoint)
{
if (!nsContentUtils::LegacyIsCallerChromeOrNativeCode() &&
nsContentUtils::ResistFingerprinting()) {
// When resisting fingerprinting, return client coordinates instead.
return GetClientCoords(aPresContext, aEvent, aPoint, CSSIntPoint(0, 0));
}
if (EventStateManager::sIsPointerLocked) {
return EventStateManager::sLastScreenPoint;
}

View File

@ -357,13 +357,21 @@ NS_IMETHODIMP
MouseEvent::GetScreenX(int32_t* aScreenX)
{
NS_ENSURE_ARG_POINTER(aScreenX);
*aScreenX = ScreenX();
*aScreenX = ScreenX(CallerType::System);
return NS_OK;
}
int32_t
MouseEvent::ScreenX()
MouseEvent::ScreenX(CallerType aCallerType)
{
if (aCallerType != CallerType::System &&
nsContentUtils::ResistFingerprinting()) {
// Sanitize to something sort of like client cooords, but not quite
// (defaulting to (0,0) instead of our pre-specified client coords).
return Event::GetClientCoords(mPresContext, mEvent, mEvent->mRefPoint,
CSSIntPoint(0, 0)).x;
}
return Event::GetScreenCoords(mPresContext, mEvent, mEvent->mRefPoint).x;
}
@ -371,13 +379,21 @@ NS_IMETHODIMP
MouseEvent::GetScreenY(int32_t* aScreenY)
{
NS_ENSURE_ARG_POINTER(aScreenY);
*aScreenY = ScreenY();
*aScreenY = ScreenY(CallerType::System);
return NS_OK;
}
int32_t
MouseEvent::ScreenY()
MouseEvent::ScreenY(CallerType aCallerType)
{
if (aCallerType != CallerType::System &&
nsContentUtils::ResistFingerprinting()) {
// Sanitize to something sort of like client cooords, but not quite
// (defaulting to (0,0) instead of our pre-specified client coords).
return Event::GetClientCoords(mPresContext, mEvent, mEvent->mRefPoint,
CSSIntPoint(0, 0)).y;
}
return Event::GetScreenCoords(mPresContext, mEvent, mEvent->mRefPoint).y;
}

View File

@ -7,6 +7,7 @@
#ifndef mozilla_dom_MouseEvent_h_
#define mozilla_dom_MouseEvent_h_
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/UIEvent.h"
#include "mozilla/dom/MouseEventBinding.h"
#include "mozilla/EventForwards.h"
@ -42,8 +43,8 @@ public:
return Button() + 1;
}
int32_t ScreenX();
int32_t ScreenY();
int32_t ScreenX(CallerType aCallerType);
int32_t ScreenY(CallerType aCallerType);
int32_t ClientX();
int32_t ClientY();
int32_t OffsetX();

View File

@ -140,6 +140,28 @@ Touch::GetTarget() const
return mTarget;
}
int32_t
Touch::ScreenX(CallerType aCallerType) const
{
if (aCallerType != CallerType::System &&
nsContentUtils::ResistFingerprinting()) {
return ClientX();
}
return mScreenPoint.x;
}
int32_t
Touch::ScreenY(CallerType aCallerType) const
{
if (aCallerType != CallerType::System &&
nsContentUtils::ResistFingerprinting()) {
return ClientY();
}
return mScreenPoint.y;
}
void
Touch::InitializePoints(nsPresContext* aPresContext, WidgetEvent* aEvent)
{

View File

@ -10,6 +10,7 @@
#include "mozilla/Attributes.h"
#include "mozilla/EventForwards.h"
#include "mozilla/MouseEvents.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/TouchBinding.h"
#include "nsWrapperCache.h"
#include "Units.h"
@ -67,8 +68,8 @@ public:
// WebIDL
int32_t Identifier() const { return mIdentifier; }
EventTarget* GetTarget() const;
int32_t ScreenX() const { return mScreenPoint.x; }
int32_t ScreenY() const { return mScreenPoint.y; }
int32_t ScreenX(CallerType aCallerType) const;
int32_t ScreenY(CallerType aCallerType) const;
int32_t ClientX() const { return mClientPoint.x; }
int32_t ClientY() const { return mClientPoint.y; }
int32_t PageX() const { return mPagePoint.x; }

View File

@ -12,7 +12,9 @@
[Constructor(DOMString typeArg, optional MouseEventInit mouseEventInitDict)]
interface MouseEvent : UIEvent {
[NeedsCallerType]
readonly attribute long screenX;
[NeedsCallerType]
readonly attribute long screenY;
readonly attribute long clientX;
readonly attribute long clientY;

View File

@ -30,7 +30,9 @@ dictionary TouchInit {
interface Touch {
readonly attribute long identifier;
readonly attribute EventTarget? target;
[NeedsCallerType]
readonly attribute long screenX;
[NeedsCallerType]
readonly attribute long screenY;
readonly attribute long clientX;
readonly attribute long clientY;