Bug 1337161 - Hide information of connected gamepads from content when privacy.resistFingerprinting is true draft
authorChung-Sheng Fu <cfu@mozilla.com>
Thu, 15 Jun 2017 17:59:26 +0800
changeset 601614 2ea460876c4264654c1300119efb763491a4c4f4
parent 601524 217b7fcf58944f927118b465769faeb1e613130a
child 601615 ca03bce8b0947b4a8dd799444ec98e5331543830
push id66146
push userbmo:cfu@mozilla.com
push dateWed, 28 Jun 2017 23:15:04 +0000
bugs1337161
milestone56.0a1
Bug 1337161 - Hide information of connected gamepads from content when privacy.resistFingerprinting is true MozReview-Commit-ID: Di6ba9B4w0d
dom/base/nsGlobalWindow.cpp
dom/gamepad/GamepadManager.cpp
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -13865,16 +13865,23 @@ nsGlobalWindow::RemoveGamepad(uint32_t a
   mGamepads.Remove(aIndex);
 }
 
 void
 nsGlobalWindow::GetGamepads(nsTArray<RefPtr<Gamepad> >& aGamepads)
 {
   MOZ_ASSERT(IsInnerWindow());
   aGamepads.Clear();
+
+  // navigator.getGamepads() always returns an empty array when
+  // privacy.resistFingerprinting is true.
+  if (nsContentUtils::ShouldResistFingerprinting()) {
+    return;
+  }
+
   // mGamepads.Count() may not be sufficient, but it's not harmful.
   aGamepads.SetCapacity(mGamepads.Count());
   for (auto iter = mGamepads.Iter(); !iter.Done(); iter.Next()) {
     Gamepad* gamepad = iter.UserData();
     aGamepads.EnsureLengthAtLeast(gamepad->Index() + 1);
     aGamepads[gamepad->Index()] = gamepad;
   }
 }
--- a/dom/gamepad/GamepadManager.cpp
+++ b/dom/gamepad/GamepadManager.cpp
@@ -15,16 +15,17 @@
 
 #include "mozilla/ipc/BackgroundChild.h"
 #include "mozilla/ipc/PBackgroundChild.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/StaticPtr.h"
 
 #include "nsAutoPtr.h"
+#include "nsContentUtils.h"
 #include "nsGlobalWindow.h"
 #include "nsIDOMEvent.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMWindow.h"
 #include "nsIObserver.h"
 #include "nsIObserverService.h"
 #include "nsIServiceManager.h"
 #include "nsThreadUtils.h"
@@ -133,17 +134,17 @@ GamepadManager::BeginShutdown()
 
 void
 GamepadManager::AddListener(nsGlobalWindow* aWindow)
 {
   MOZ_ASSERT(aWindow);
   MOZ_ASSERT(aWindow->IsInnerWindow());
   MOZ_ASSERT(NS_IsMainThread());
 
-  if (!mEnabled || mShuttingDown) {
+  if (!mEnabled || mShuttingDown || nsContentUtils::ShouldResistFingerprinting()) {
     return;
   }
 
   if (mListeners.IndexOf(aWindow) != NoIndex) {
     return; // already exists
   }
 
   mListeners.AppendElement(aWindow);
@@ -310,16 +311,22 @@ GamepadManager::FireAxisMoveEvent(EventT
 
   bool defaultActionEnabled = true;
   aTarget->DispatchEvent(event, &defaultActionEnabled);
 }
 
 void
 GamepadManager::NewConnectionEvent(uint32_t aIndex, bool aConnected)
 {
+  // Do not fire gamepadconnected and gamepaddisconnected events when
+  // privacy.resistFingerprinting is true.
+  if (nsContentUtils::ShouldResistFingerprinting()) {
+    return;
+  }
+
   if (mShuttingDown) {
     return;
   }
 
   RefPtr<Gamepad> gamepad = GetGamepad(aIndex);
   if (!gamepad) {
     return;
   }
@@ -393,17 +400,17 @@ GamepadManager::FireConnectionEvent(Even
 
   bool defaultActionEnabled = true;
   aTarget->DispatchEvent(event, &defaultActionEnabled);
 }
 
 void
 GamepadManager::SyncGamepadState(uint32_t aIndex, Gamepad* aGamepad)
 {
-  if (mShuttingDown || !mEnabled) {
+  if (mShuttingDown || !mEnabled || nsContentUtils::ShouldResistFingerprinting()) {
     return;
   }
 
   RefPtr<Gamepad> gamepad = GetGamepad(aIndex);
   if (!gamepad) {
     return;
   }