Bug 1324035 part 4. Change nsContentUtils::ResistFingerprinting to just take a dom::CallerType instead of having all its consumers check it. r=qdot
authorBoris Zbarsky <bzbarsky@mit.edu>
Sat, 17 Dec 2016 00:25:52 -0500
changeset 450701 13f20e14bb7e7f149713f269f2fe711b99d3a91a
parent 450700 414b97796bb7dbf87673b01264aeb8bd5101a22c
child 450702 dcc7b0c683ce81ed762d1fe4ff396ea9caeb0bea
push id38944
push userbmo:leftysolara@gmail.com
push dateSun, 18 Dec 2016 16:01:15 +0000
reviewersqdot
bugs1324035
milestone53.0a1
Bug 1324035 part 4. Change nsContentUtils::ResistFingerprinting to just take a dom::CallerType instead of having all its consumers check it. r=qdot
dom/base/nsContentUtils.h
dom/base/nsMimeTypeArray.cpp
dom/base/nsPluginArray.cpp
dom/events/MouseEvent.cpp
dom/events/Touch.cpp
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -23,16 +23,17 @@
 #include "mozilla/EventForwards.h"
 #include "mozilla/GuardObjects.h"
 #include "mozilla/TimeStamp.h"
 #include "nsContentListDeclarations.h"
 #include "nsMathUtils.h"
 #include "nsTArrayForwardDeclare.h"
 #include "Units.h"
 #include "mozilla/dom/AutocompleteInfoBinding.h"
+#include "mozilla/dom/BindingDeclarations.h" // For CallerType
 #include "mozilla/dom/ScriptSettings.h"
 #include "mozilla/FloatingPoint.h"
 #include "mozilla/net/ReferrerPolicy.h"
 #include "mozilla/Logging.h"
 #include "mozilla/NotNull.h"
 #include "nsIContentPolicy.h"
 #include "nsIDocument.h"
 #include "nsPIDOMWindow.h"
@@ -2077,23 +2078,24 @@ public:
    * Returns true if URL getters should percent decode the value of the segment
    */
   static bool GettersDecodeURLHash()
   {
     return sGettersDecodeURLHash && sEncodeDecodeURLHash;
   }
 
   /*
-   * Returns true if the browser should attempt to prevent content scripts
+   * Returns true if the browser should attempt to prevent the given caller type
    * from collecting distinctive information about the browser that could
    * be used to "fingerprint" and track the user across websites.
    */
-  static bool ResistFingerprinting()
+  static bool ResistFingerprinting(mozilla::dom::CallerType aCallerType)
   {
-    return sPrivacyResistFingerprinting;
+    return aCallerType != mozilla::dom::CallerType::System &&
+           sPrivacyResistFingerprinting;
   }
 
   /**
    * Returns true if the browser should show busy cursor when loading page.
    */
   static bool UseActivityCursor()
   {
     return sUseActivityCursor;
--- a/dom/base/nsMimeTypeArray.cpp
+++ b/dom/base/nsMimeTypeArray.cpp
@@ -37,22 +37,16 @@ nsMimeTypeArray::nsMimeTypeArray(nsPIDOM
   : mWindow(aWindow)
 {
 }
 
 nsMimeTypeArray::~nsMimeTypeArray()
 {
 }
 
-static bool
-ResistFingerprinting(CallerType aCallerType) {
-  return aCallerType != CallerType::System &&
-         nsContentUtils::ResistFingerprinting();
-}
-
 JSObject*
 nsMimeTypeArray::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
 {
   return MimeTypeArrayBinding::Wrap(aCx, this, aGivenProto);
 }
 
 void
 nsMimeTypeArray::Refresh()
@@ -83,17 +77,17 @@ nsMimeTypeArray::NamedItem(const nsAStri
 }
 
 nsMimeType*
 nsMimeTypeArray::IndexedGetter(uint32_t aIndex, bool &aFound,
                                CallerType aCallerType)
 {
   aFound = false;
 
-  if (ResistFingerprinting(aCallerType)) {
+  if (nsContentUtils::ResistFingerprinting(aCallerType)) {
     return nullptr;
   }
 
   EnsurePluginMimeTypes();
 
   if (aIndex >= mMimeTypes.Length()) {
     return nullptr;
   }
@@ -118,17 +112,17 @@ FindMimeType(const nsTArray<RefPtr<nsMim
 }
 
 nsMimeType*
 nsMimeTypeArray::NamedGetter(const nsAString& aName, bool &aFound,
                              CallerType aCallerType)
 {
   aFound = false;
 
-  if (ResistFingerprinting(aCallerType)) {
+  if (nsContentUtils::ResistFingerprinting(aCallerType)) {
     return nullptr;
   }
 
   EnsurePluginMimeTypes();
 
   nsString lowerName(aName);
   ToLowerCase(lowerName);
 
@@ -143,17 +137,17 @@ nsMimeTypeArray::NamedGetter(const nsASt
   }
 
   return nullptr;
 }
 
 uint32_t
 nsMimeTypeArray::Length(CallerType aCallerType)
 {
-  if (ResistFingerprinting(aCallerType)) {
+  if (nsContentUtils::ResistFingerprinting(aCallerType)) {
     return 0;
   }
 
   EnsurePluginMimeTypes();
 
   return mMimeTypes.Length();
 }
 
--- a/dom/base/nsPluginArray.cpp
+++ b/dom/base/nsPluginArray.cpp
@@ -40,22 +40,16 @@ nsPluginArray::Init()
     mozilla::services::GetObserverService();
   if (obsService) {
     obsService->AddObserver(this, "plugin-info-updated", true);
   }
 }
 
 nsPluginArray::~nsPluginArray() = default;
 
-static bool
-ResistFingerprinting(CallerType aCallerType) {
-  return aCallerType != CallerType::System &&
-         nsContentUtils::ResistFingerprinting();
-}
-
 nsPIDOMWindowInner*
 nsPluginArray::GetParentObject() const
 {
   MOZ_ASSERT(mWindow);
   return mWindow;
 }
 
 JSObject*
@@ -190,17 +184,17 @@ nsPluginArray::Refresh(bool aReloadDocum
   }
 }
 
 nsPluginElement*
 nsPluginArray::IndexedGetter(uint32_t aIndex, bool &aFound, CallerType aCallerType)
 {
   aFound = false;
 
-  if (!AllowPlugins() || ResistFingerprinting(aCallerType)) {
+  if (!AllowPlugins() || nsContentUtils::ResistFingerprinting(aCallerType)) {
     return nullptr;
   }
 
   EnsurePlugins();
 
   aFound = aIndex < mPlugins.Length();
 
   if (!aFound) {
@@ -238,17 +232,17 @@ FindPlugin(const nsTArray<RefPtr<nsPlugi
 }
 
 nsPluginElement*
 nsPluginArray::NamedGetter(const nsAString& aName, bool &aFound,
                            CallerType aCallerType)
 {
   aFound = false;
 
-  if (!AllowPlugins() || ResistFingerprinting(aCallerType)) {
+  if (!AllowPlugins() || nsContentUtils::ResistFingerprinting(aCallerType)) {
     return nullptr;
   }
 
   EnsurePlugins();
 
   nsPluginElement* plugin = FindPlugin(mPlugins, aName);
   aFound = (plugin != nullptr);
   if (!aFound) {
@@ -272,17 +266,17 @@ void nsPluginArray::NotifyHiddenPluginTo
   event->WidgetEventPtr()->mFlags.mOnlyChromeDispatch = true;
   bool dummy;
   doc->DispatchEvent(event, &dummy);
 }
 
 uint32_t
 nsPluginArray::Length(CallerType aCallerType)
 {
-  if (!AllowPlugins() || ResistFingerprinting(aCallerType)) {
+  if (!AllowPlugins() || nsContentUtils::ResistFingerprinting(aCallerType)) {
     return 0;
   }
 
   EnsurePlugins();
 
   return mPlugins.Length();
 }
 
--- a/dom/events/MouseEvent.cpp
+++ b/dom/events/MouseEvent.cpp
@@ -359,18 +359,17 @@ MouseEvent::GetScreenX(int32_t* aScreenX
   NS_ENSURE_ARG_POINTER(aScreenX);
   *aScreenX = ScreenX(CallerType::System);
   return NS_OK;
 }
 
 int32_t
 MouseEvent::ScreenX(CallerType aCallerType)
 {
-  if (aCallerType != CallerType::System &&
-      nsContentUtils::ResistFingerprinting()) {
+  if (nsContentUtils::ResistFingerprinting(aCallerType)) {
     // 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;
 }
@@ -381,18 +380,17 @@ MouseEvent::GetScreenY(int32_t* aScreenY
   NS_ENSURE_ARG_POINTER(aScreenY);
   *aScreenY = ScreenY(CallerType::System);
   return NS_OK;
 }
 
 int32_t
 MouseEvent::ScreenY(CallerType aCallerType)
 {
-  if (aCallerType != CallerType::System &&
-      nsContentUtils::ResistFingerprinting()) {
+  if (nsContentUtils::ResistFingerprinting(aCallerType)) {
     // 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;
 }
--- a/dom/events/Touch.cpp
+++ b/dom/events/Touch.cpp
@@ -138,29 +138,27 @@ Touch::GetTarget() const
   }
 
   return mTarget;
 }
 
 int32_t
 Touch::ScreenX(CallerType aCallerType) const
 {
-  if (aCallerType != CallerType::System &&
-      nsContentUtils::ResistFingerprinting()) {
+  if (nsContentUtils::ResistFingerprinting(aCallerType)) {
     return ClientX();
   }
 
   return mScreenPoint.x;
 }
 
 int32_t
 Touch::ScreenY(CallerType aCallerType) const
 {
-  if (aCallerType != CallerType::System &&
-      nsContentUtils::ResistFingerprinting()) {
+  if (nsContentUtils::ResistFingerprinting(aCallerType)) {
     return ClientY();
   }
 
   return mScreenPoint.y;
 }
 
 void
 Touch::InitializePoints(nsPresContext* aPresContext, WidgetEvent* aEvent)