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
parent 8941d14a90
commit 2a3cdfc4f6
4 changed files with 44 additions and 3 deletions

View File

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

View File

@ -1039,7 +1039,8 @@ nsPIDOMWindow<T>::nsPIDOMWindow(nsPIDOMWindowOuter *aOuterWindow)
mLargeAllocStatus(LargeAllocStatus::NONE),
mHasTriedToCacheTopInnerWindow(false),
mNumOfIndexedDBDatabases(0),
mNumOfOpenWebSockets(0)
mNumOfOpenWebSockets(0),
mNumOfActiveUserMedia(0)
{
if (aOuterWindow) {
mTimeoutManager =
@ -4524,6 +4525,30 @@ nsPIDOMWindowInner::HasOpenWebSockets() const
: 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
nsPIDOMWindowOuter::MaybeActiveMediaComponents()
{

View File

@ -751,6 +751,9 @@ protected:
// The number of open WebSockets. Inner window only.
uint32_t mNumOfOpenWebSockets;
// The number of active user media. Inner window only.
uint32_t mNumOfActiveUserMedia;
};
#define NS_PIDOMWINDOWINNER_IID \
@ -936,6 +939,12 @@ public:
// timeout-throttling.
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:
void CreatePerformanceObjectIfNeeded();
};

View File

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