Bug 1337161 - Fix leak of GamepadPlatformService
MozReview-Commit-ID: CPLg8kyL0xH
--- a/dom/gamepad/GamepadManager.cpp
+++ b/dom/gamepad/GamepadManager.cpp
@@ -134,38 +134,36 @@ GamepadManager::BeginShutdown()
void
GamepadManager::AddListener(nsGlobalWindow* aWindow)
{
MOZ_ASSERT(aWindow);
MOZ_ASSERT(aWindow->IsInnerWindow());
MOZ_ASSERT(NS_IsMainThread());
+ // IPDL child has not been created
+ if (mChannelChildren.IsEmpty()) {
+ PBackgroundChild *actor = BackgroundChild::GetForCurrentThread();
+ //Try to get the PBackground Child actor
+ if (actor) {
+ ActorCreated(actor);
+ } else {
+ Unused << BackgroundChild::GetOrCreateForCurrentThread(this);
+ }
+ }
+
if (!mEnabled || mShuttingDown || nsContentUtils::ShouldResistFingerprinting()) {
return;
}
if (mListeners.IndexOf(aWindow) != NoIndex) {
return; // already exists
}
mListeners.AppendElement(aWindow);
-
- // IPDL child has been created
- if (!mChannelChildren.IsEmpty()) {
- return;
- }
-
- PBackgroundChild *actor = BackgroundChild::GetForCurrentThread();
- //Try to get the PBackground Child actor
- if (actor) {
- ActorCreated(actor);
- } else {
- Unused << BackgroundChild::GetOrCreateForCurrentThread(this);
- }
}
void
GamepadManager::RemoveListener(nsGlobalWindow* aWindow)
{
MOZ_ASSERT(aWindow);
MOZ_ASSERT(aWindow->IsInnerWindow());
@@ -496,17 +494,17 @@ GamepadManager::SetWindowHasSeenGamepad(
} else {
aWindow->RemoveGamepad(aIndex);
}
}
void
GamepadManager::Update(const GamepadChangeEvent& aEvent)
{
- if (mShuttingDown) {
+ if (!mEnabled || mShuttingDown || nsContentUtils::ShouldResistFingerprinting()) {
return;
}
if (aEvent.type() == GamepadChangeEvent::TGamepadAdded) {
const GamepadAdded& a = aEvent.get_GamepadAdded();
AddGamepad(a.index(), a.id(),
static_cast<GamepadMappingType>(a.mapping()),
static_cast<GamepadHand>(a.hand()),