Bug 1393359 - Register active user media on top level window. r=smaug,jib

This commit is contained in:
Andreas Farre 2017-09-01 10:32:33 +02:00
Родитель 8941d14a90
Коммит 2a3cdfc4f6
4 изменённых файлов: 44 добавлений и 3 удалений

Просмотреть файл

@ -1258,8 +1258,7 @@ TimeoutManager::BudgetThrottlingEnabled(bool aIsBackground) const
} }
// Check if we have active GetUserMedia // Check if we have active GetUserMedia
if (MediaManager::Exists() && if (mWindow.AsInner()->HasActiveUserMedia()) {
MediaManager::Get()->IsWindowStillActive(mWindow.WindowID())) {
return false; return false;
} }

Просмотреть файл

@ -1039,7 +1039,8 @@ nsPIDOMWindow<T>::nsPIDOMWindow(nsPIDOMWindowOuter *aOuterWindow)
mLargeAllocStatus(LargeAllocStatus::NONE), mLargeAllocStatus(LargeAllocStatus::NONE),
mHasTriedToCacheTopInnerWindow(false), mHasTriedToCacheTopInnerWindow(false),
mNumOfIndexedDBDatabases(0), mNumOfIndexedDBDatabases(0),
mNumOfOpenWebSockets(0) mNumOfOpenWebSockets(0),
mNumOfActiveUserMedia(0)
{ {
if (aOuterWindow) { if (aOuterWindow) {
mTimeoutManager = mTimeoutManager =
@ -4524,6 +4525,30 @@ nsPIDOMWindowInner::HasOpenWebSockets() const
: mNumOfOpenWebSockets) > 0; : mNumOfOpenWebSockets) > 0;
} }
void
nsPIDOMWindowInner::UpdateUserMediaCount(int32_t aDelta)
{
MOZ_ASSERT(NS_IsMainThread());
if (aDelta == 0) {
return;
}
uint32_t& counter = mTopInnerWindow ? mTopInnerWindow->mNumOfActiveUserMedia
: mNumOfActiveUserMedia;
MOZ_DIAGNOSTIC_ASSERT(aDelta > 0 || ((aDelta + counter) < counter));
counter += aDelta;
}
bool
nsPIDOMWindowInner::HasActiveUserMedia() const
{
return (mTopInnerWindow ? mTopInnerWindow->mNumOfActiveUserMedia
: mNumOfActiveUserMedia) > 0;
}
void void
nsPIDOMWindowOuter::MaybeActiveMediaComponents() nsPIDOMWindowOuter::MaybeActiveMediaComponents()
{ {

Просмотреть файл

@ -751,6 +751,9 @@ protected:
// The number of open WebSockets. Inner window only. // The number of open WebSockets. Inner window only.
uint32_t mNumOfOpenWebSockets; uint32_t mNumOfOpenWebSockets;
// The number of active user media. Inner window only.
uint32_t mNumOfActiveUserMedia;
}; };
#define NS_PIDOMWINDOWINNER_IID \ #define NS_PIDOMWINDOWINNER_IID \
@ -936,6 +939,12 @@ public:
// timeout-throttling. // timeout-throttling.
bool HasOpenWebSockets() const; bool HasOpenWebSockets() const;
// Increase/Decrease the number of active user media.
void UpdateUserMediaCount(int32_t aDelta);
// Return true if there are any currently ongoing user media.
bool HasActiveUserMedia() const;
protected: protected:
void CreatePerformanceObjectIfNeeded(); void CreatePerformanceObjectIfNeeded();
}; };

Просмотреть файл

@ -2926,6 +2926,12 @@ MediaManager::AddWindowID(uint64_t aWindowId,
MOZ_ASSERT(false, "Window already added"); MOZ_ASSERT(false, "Window already added");
return; return;
} }
auto* window = nsGlobalWindow::GetInnerWindowWithId(aWindowId);
if (window) {
window->AsInner()->UpdateUserMediaCount(1);
}
GetActiveWindows()->Put(aWindowId, aListener); GetActiveWindows()->Put(aWindowId, aListener);
} }
@ -2941,6 +2947,8 @@ MediaManager::RemoveWindowID(uint64_t aWindowId)
return; return;
} }
window->AsInner()->UpdateUserMediaCount(-1);
nsPIDOMWindowOuter* outer = window->AsInner()->GetOuterWindow(); nsPIDOMWindowOuter* outer = window->AsInner()->GetOuterWindow();
if (!outer) { if (!outer) {
LOG(("No outer window for inner %" PRIu64, aWindowId)); LOG(("No outer window for inner %" PRIu64, aWindowId));