Bug 1382499 - Enhance fingerprinting resistance for Touch API draft
authorChung-Sheng Fu <cfu@mozilla.com>
Mon, 31 Jul 2017 17:30:38 +0800
changeset 618328 eb22ca3c28dc5c2b9da55eb03cfb21835ed4232b
parent 618186 6d1b50a370b4adffbb1ee73b9f51707c90d6a2b1
child 640044 b8d8310a1c8e30f23ff71e77dde7c97343235310
push id71306
push userbmo:cfu@mozilla.com
push dateMon, 31 Jul 2017 09:32:42 +0000
bugs1382499
milestone56.0a1
Bug 1382499 - Enhance fingerprinting resistance for Touch API MozReview-Commit-ID: 8nzOkvIvwrD
dom/events/Touch.cpp
dom/events/Touch.h
dom/webidl/Touch.webidl
layout/base/PresShell.cpp
widget/InputData.cpp
--- a/dom/events/Touch.cpp
+++ b/dom/events/Touch.cpp
@@ -155,16 +155,56 @@ Touch::ScreenY(CallerType aCallerType) c
 {
   if (nsContentUtils::ResistFingerprinting(aCallerType)) {
     return ClientY();
   }
 
   return mScreenPoint.y;
 }
 
+int32_t
+Touch::RadiusX(CallerType aCallerType) const
+{
+  if (nsContentUtils::ResistFingerprinting(aCallerType)) {
+    return 1;
+  }
+
+  return mRadius.x;
+}
+
+int32_t
+Touch::RadiusY(CallerType aCallerType) const
+{
+  if (nsContentUtils::ResistFingerprinting(aCallerType)) {
+    return 1;
+  }
+
+  return mRadius.y;
+}
+
+float
+Touch::RotationAngle(CallerType aCallerType) const
+{
+  if (nsContentUtils::ResistFingerprinting(aCallerType)) {
+    return 0.0f;
+  }
+
+  return mRotationAngle;
+}
+
+float
+Touch::Force(CallerType aCallerType) const
+{
+  if (nsContentUtils::ResistFingerprinting(aCallerType)) {
+    return 0.0f;
+  }
+
+  return mForce;
+}
+
 void
 Touch::InitializePoints(nsPresContext* aPresContext, WidgetEvent* aEvent)
 {
   if (mPointsInitialized) {
     return;
   }
   mClientPoint = Event::GetClientCoords(
     aPresContext, aEvent, mRefPoint, mClientPoint);
@@ -179,20 +219,20 @@ Touch::SetTarget(EventTarget* aTarget)
 {
   mTarget = aTarget;
 }
 
 bool
 Touch::Equals(Touch* aTouch)
 {
   return mRefPoint == aTouch->mRefPoint &&
-         mForce == aTouch->Force() &&
-         mRotationAngle == aTouch->RotationAngle() &&
-         mRadius.x == aTouch->RadiusX() &&
-         mRadius.y == aTouch->RadiusY();
+         mForce == aTouch->mForce &&
+         mRotationAngle == aTouch->mRotationAngle &&
+         mRadius.x == aTouch->mRadius.x &&
+         mRadius.y == aTouch->mRadius.y;
 }
 
 JSObject*
 Touch::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
 {
   return TouchBinding::Wrap(aCx, this, aGivenProto);
 }
 
--- a/dom/events/Touch.h
+++ b/dom/events/Touch.h
@@ -69,20 +69,20 @@ public:
   int32_t Identifier() const { return mIdentifier; }
   EventTarget* GetTarget() const;
   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; }
   int32_t PageY() const { return mPagePoint.y; }
-  int32_t RadiusX() const { return mRadius.x; }
-  int32_t RadiusY() const { return mRadius.y; }
-  float RotationAngle() const { return mRotationAngle; }
-  float Force() const { return mForce; }
+  int32_t RadiusX(CallerType aCallerType) const;
+  int32_t RadiusY(CallerType aCallerType) const;
+  float RotationAngle(CallerType aCallerType) const;
+  float Force(CallerType aCallerType) const;
 
   nsCOMPtr<EventTarget> mTarget;
   LayoutDeviceIntPoint mRefPoint;
   bool mChanged;
   uint32_t mMessage;
   int32_t mIdentifier;
   CSSIntPoint mPagePoint;
   CSSIntPoint mClientPoint;
--- a/dom/webidl/Touch.webidl
+++ b/dom/webidl/Touch.webidl
@@ -33,13 +33,17 @@ interface Touch {
   [NeedsCallerType]
   readonly    attribute long         screenX;
   [NeedsCallerType]
   readonly    attribute long         screenY;
   readonly    attribute long         clientX;
   readonly    attribute long         clientY;
   readonly    attribute long         pageX;
   readonly    attribute long         pageY;
+  [NeedsCallerType]
   readonly    attribute long         radiusX;
+  [NeedsCallerType]
   readonly    attribute long         radiusY;
+  [NeedsCallerType]
   readonly    attribute float        rotationAngle;
+  [NeedsCallerType]
   readonly    attribute float        force;
 };
--- a/layout/base/PresShell.cpp
+++ b/layout/base/PresShell.cpp
@@ -7087,18 +7087,18 @@ DispatchPointerFromMouseOrTouch(PresShel
       }
 
       WidgetPointerEvent event(touchEvent->IsTrusted(), pointerMessage,
                                touchEvent->mWidget);
       event.mIsPrimary = i == 0;
       event.pointerId = touch->Identifier();
       event.mRefPoint = touch->mRefPoint;
       event.mModifiers = touchEvent->mModifiers;
-      event.mWidth = touch->RadiusX();
-      event.mHeight = touch->RadiusY();
+      event.mWidth = touch->RadiusX(CallerType::System);
+      event.mHeight = touch->RadiusY(CallerType::System);
       event.tiltX = touch->tiltX;
       event.tiltY = touch->tiltY;
       event.mTime = touchEvent->mTime;
       event.mTimeStamp = touchEvent->mTimeStamp;
       event.mFlags = touchEvent->mFlags;
       event.button = button;
       event.buttons = buttons;
       event.inputSource = nsIDOMMouseEvent::MOZ_SOURCE_TOUCH;
--- a/widget/InputData.cpp
+++ b/widget/InputData.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* 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/. */
 
 #include "InputData.h"
 
 #include "mozilla/dom/Touch.h"
+#include "nsContentUtils.h"
 #include "nsDebug.h"
 #include "nsThreadUtils.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/TouchEvents.h"
 #include "UnitTransforms.h"
 
 namespace mozilla {
 
@@ -125,20 +126,20 @@ MultiTouchInput::MultiTouchInput(const W
       break;
   }
 
   for (size_t i = 0; i < aTouchEvent.mTouches.Length(); i++) {
     const Touch* domTouch = aTouchEvent.mTouches[i];
 
     // Extract data from weird interfaces.
     int32_t identifier = domTouch->Identifier();
-    int32_t radiusX = domTouch->RadiusX();
-    int32_t radiusY = domTouch->RadiusY();
-    float rotationAngle = domTouch->RotationAngle();
-    float force = domTouch->Force();
+    int32_t radiusX = domTouch->RadiusX(CallerType::System);
+    int32_t radiusY = domTouch->RadiusY(CallerType::System);
+    float rotationAngle = domTouch->RotationAngle(CallerType::System);
+    float force = domTouch->Force(CallerType::System);
 
     SingleTouchData data(identifier,
                          ViewAs<ScreenPixel>(domTouch->mRefPoint,
                                              PixelCastJustification::LayoutDeviceIsScreenForUntransformedEvent),
                          ScreenSize(radiusX, radiusY),
                          rotationAngle,
                          force);