Bug 1532411 - Pass a document pointer to nsContentUtils::ShouldResistFingerprinting() callers in the gamepad API; r=baku
authorEhsan Akhgari <ehsan@mozilla.com>
Tue, 05 Mar 2019 12:42:51 +0000
changeset 520323 14b6b6f8a599748d3a7d8435f57c37e696a97df7
parent 520322 e2b8ea7e00d9ccb32e57775b343667bf833e50ab
child 520324 ff14d3c64e53dad7b4720c983b8f19bb494ed28a
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1532411
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1532411 - Pass a document pointer to nsContentUtils::ShouldResistFingerprinting() callers in the gamepad API; r=baku Differential Revision: https://phabricator.services.mozilla.com/D21996
dom/base/nsGlobalWindowInner.cpp
dom/gamepad/GamepadManager.cpp
dom/gamepad/GamepadManager.h
--- a/dom/base/nsGlobalWindowInner.cpp
+++ b/dom/base/nsGlobalWindowInner.cpp
@@ -5922,17 +5922,17 @@ void nsGlobalWindowInner::SetHasSeenGame
 }
 
 bool nsGlobalWindowInner::HasSeenGamepadInput() { return mHasSeenGamepadInput; }
 
 void nsGlobalWindowInner::SyncGamepadState() {
   if (mHasSeenGamepadInput) {
     RefPtr<GamepadManager> gamepadManager(GamepadManager::GetService());
     for (auto iter = mGamepads.Iter(); !iter.Done(); iter.Next()) {
-      gamepadManager->SyncGamepadState(iter.Key(), iter.UserData());
+      gamepadManager->SyncGamepadState(iter.Key(), this, iter.UserData());
     }
   }
 }
 
 void nsGlobalWindowInner::StopGamepadHaptics() {
   if (mHasSeenGamepadInput) {
     RefPtr<GamepadManager> gamepadManager(GamepadManager::GetService());
     gamepadManager->StopHaptics();
--- a/dom/gamepad/GamepadManager.cpp
+++ b/dom/gamepad/GamepadManager.cpp
@@ -147,17 +147,17 @@ void GamepadManager::AddListener(nsGloba
       // Construct VRManagerChannel and ask adding the connected
       // VR controllers to GamepadManager
       gfx::VRManagerChild* vm = gfx::VRManagerChild::Get();
       vm->SendControllerListenerAdded();
     }
   }
 
   if (!mEnabled || mShuttingDown ||
-      nsContentUtils::ShouldResistFingerprinting()) {
+      nsContentUtils::ShouldResistFingerprinting(aWindow->GetExtantDoc())) {
     return;
   }
 
   if (mListeners.IndexOf(aWindow) != NoIndex) {
     return;  // already exists
   }
 
   mListeners.AppendElement(aWindow);
@@ -284,37 +284,38 @@ void GamepadManager::FireAxisMoveEvent(E
       aTarget, NS_LITERAL_STRING("gamepadaxismove"), init);
 
   event->SetTrusted(true);
 
   aTarget->DispatchEvent(*event);
 }
 
 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;
   }
 
   // Hold on to listeners in a separate array because firing events
   // can mutate the mListeners array.
   nsTArray<RefPtr<nsGlobalWindowInner>> listeners(mListeners);
 
   if (aConnected) {
     for (uint32_t i = 0; i < listeners.Length(); i++) {
+      // Do not fire gamepadconnected and gamepaddisconnected events when
+      // privacy.resistFingerprinting is true.
+      if (nsContentUtils::ShouldResistFingerprinting(
+              listeners[i]->GetExtantDoc())) {
+        continue;
+      }
+
       // Only send events to non-background windows
       if (!listeners[i]->AsInner()->IsCurrentInnerWindow() ||
           listeners[i]->GetOuterWindow()->IsBackground()) {
         continue;
       }
 
       // We don't fire a connected event here unless the window
       // has seen input from at least one device.
@@ -332,16 +333,23 @@ void GamepadManager::NewConnectionEvent(
     }
   } else {
     // For disconnection events, fire one at every window that has received
     // data from this gamepad.
     for (uint32_t i = 0; i < listeners.Length(); i++) {
       // Even background windows get these events, so we don't have to
       // deal with the hassle of syncing the state of removed gamepads.
 
+      // Do not fire gamepadconnected and gamepaddisconnected events when
+      // privacy.resistFingerprinting is true.
+      if (nsContentUtils::ShouldResistFingerprinting(
+              listeners[i]->GetExtantDoc())) {
+        continue;
+      }
+
       if (WindowHasSeenGamepad(listeners[i], aIndex)) {
         RefPtr<Gamepad> listenerGamepad = listeners[i]->GetGamepad(aIndex);
         if (listenerGamepad) {
           listenerGamepad->SetConnected(false);
           // Fire event
           FireConnectionEvent(listeners[i], listenerGamepad, false);
           listeners[i]->RemoveGamepad(aIndex);
         }
@@ -360,19 +368,21 @@ void GamepadManager::FireConnectionEvent
   init.mGamepad = aGamepad;
   RefPtr<GamepadEvent> event = GamepadEvent::Constructor(aTarget, name, init);
 
   event->SetTrusted(true);
 
   aTarget->DispatchEvent(*event);
 }
 
-void GamepadManager::SyncGamepadState(uint32_t aIndex, Gamepad* aGamepad) {
+void GamepadManager::SyncGamepadState(uint32_t aIndex,
+                                      nsGlobalWindowInner* aWindow,
+                                      Gamepad* aGamepad) {
   if (mShuttingDown || !mEnabled ||
-      nsContentUtils::ShouldResistFingerprinting()) {
+      nsContentUtils::ShouldResistFingerprinting(aWindow->GetExtantDoc())) {
     return;
   }
 
   RefPtr<Gamepad> gamepad = GetGamepad(aIndex);
   if (!gamepad) {
     return;
   }
 
--- a/dom/gamepad/GamepadManager.h
+++ b/dom/gamepad/GamepadManager.h
@@ -51,17 +51,18 @@ class GamepadManager final : public nsIO
                   GamepadServiceType aServiceType, uint32_t aDisplayID,
                   uint32_t aNumButtons, uint32_t aNumAxes,
                   uint32_t aNumHaptics);
 
   // Remove the gamepad at |aIndex| from the list of known gamepads.
   void RemoveGamepad(uint32_t aIndex, GamepadServiceType aServiceType);
 
   // Synchronize the state of |aGamepad| to match the gamepad stored at |aIndex|
-  void SyncGamepadState(uint32_t aIndex, Gamepad* aGamepad);
+  void SyncGamepadState(uint32_t aIndex, nsGlobalWindowInner* aWindow,
+                        Gamepad* aGamepad);
 
   // Returns gamepad object if index exists, null otherwise
   already_AddRefed<Gamepad> GetGamepad(uint32_t aIndex) const;
 
   // Returns gamepad object if GamepadId exists, null otherwise
   already_AddRefed<Gamepad> GetGamepad(uint32_t aGamepadId,
                                        GamepadServiceType aServiceType) const;