From d959a50dfa96bd72f6273c8e61992f87b915e6a0 Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Tue, 13 Jun 2017 18:08:27 -0700 Subject: [PATCH] Bug 1371664 P2 Make nsGlobalWindow::SetIsBackground() call new TimeoutManager::UpdateBackgroundState(). r=ehsan --- dom/base/TimeoutManager.cpp | 8 ++++++++ dom/base/TimeoutManager.h | 4 ++++ dom/base/nsGlobalWindow.cpp | 10 +++++----- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/dom/base/TimeoutManager.cpp b/dom/base/TimeoutManager.cpp index 13535b680751..e7b18e75fa01 100644 --- a/dom/base/TimeoutManager.cpp +++ b/dom/base/TimeoutManager.cpp @@ -1152,6 +1152,14 @@ TimeoutManager::Thaw() }); } +void +TimeoutManager::UpdateBackgroundState() +{ + if (!IsBackground()) { + ResetTimersForThrottleReduction(); + } +} + bool TimeoutManager::IsTimeoutTracking(uint32_t aTimeoutId) { diff --git a/dom/base/TimeoutManager.h b/dom/base/TimeoutManager.h index ce73be58ad6f..c7878b262f53 100644 --- a/dom/base/TimeoutManager.h +++ b/dom/base/TimeoutManager.h @@ -77,6 +77,10 @@ public: void Freeze(); void Thaw(); + // This should be called by nsGlobalWindow when the window might have moved + // to the background or foreground. + void UpdateBackgroundState(); + // Initialize TimeoutManager before the first time it is accessed. static void Initialize(); diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 89f785add6d0..ed3f449e4d3a 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -10671,13 +10671,16 @@ void nsGlobalWindow::SetIsBackground(bool aIsBackground) { MOZ_ASSERT(IsOuterWindow()); - bool resetTimers = (!aIsBackground && AsOuter()->IsBackground()); + bool changed = aIsBackground != AsOuter()->IsBackground(); SetIsBackgroundInternal(aIsBackground); nsGlobalWindow* inner = GetCurrentInnerWindowInternal(); + if (inner && changed) { + inner->mTimeoutManager->UpdateBackgroundState(); + } + if (aIsBackground) { - MOZ_ASSERT(!resetTimers); // Notify gamepadManager we are at the background window, // we need to stop vibrate. if (inner) { @@ -10685,9 +10688,6 @@ void nsGlobalWindow::SetIsBackground(bool aIsBackground) } return; } else if (inner) { - if (resetTimers) { - inner->mTimeoutManager->ResetTimersForThrottleReduction(); - } inner->SyncGamepadState(); } }