Bug 1337161 - Hide information of connected gamepads from content when privacy.resistFingerprinting is true
MozReview-Commit-ID: Di6ba9B4w0d
--- 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;
}