Bug 1319771 - part1 : only resume the window when there has active media components. r=baku

For the first pinned tab, it would be set to visible first and then set to
invisible if there exists other tabs after restarting the whole browser.

If the tab is set to visible, we would activate the media component (set the
|mMediaSuspended| in outer window to none-suspend). In this case, the first
pinned tab would be set to visible briefly, but it doesn't mean the tab is in
the foreground, it's just how DOM manage the tab's visibility.

In that moment, none of the media component has been created yet. Therefore, we
would only activate the media component after the audio channel service exists.

MozReview-Commit-ID: 1FgdMq84yWX

--HG--
extra : rebase_source : d5d7568b9f4bfddf2abd0b2c2a4e9391a856882b
This commit is contained in:
Alastor Wu 2017-02-03 10:48:38 +08:00
Родитель 504a266d7c
Коммит 9e4d1c7549
4 изменённых файлов: 15 добавлений и 1 удалений

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

@ -41,6 +41,9 @@ AudioChannelAgent::AudioChannelAgent()
, mInnerWindowID(0)
, mIsRegToService(false)
{
// Init service in the begining, it can help us to know whether there is any
// created media component via AudioChannelService::IsServiceStarted().
RefPtr<AudioChannelService> service = AudioChannelService::GetOrCreate();
}
AudioChannelAgent::~AudioChannelAgent()

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

@ -201,6 +201,13 @@ AudioChannelService::CreateServiceIfNeeded()
}
}
/* static */ bool
AudioChannelService::IsServiceStarted()
{
// The service would start when the first AudioChannelAgent is created.
return !!gAudioChannelService;
}
/* static */ already_AddRefed<AudioChannelService>
AudioChannelService::GetOrCreate()
{

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

@ -100,6 +100,8 @@ public:
static bool IsEnableAudioCompeting();
static bool IsServiceStarted();
/**
* Any audio channel agent that starts playing should register itself to
* this service, sharing the AudioChannel.

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

@ -8,6 +8,7 @@
* Base class for all our document implementations.
*/
#include "AudioChannelService.h"
#include "nsDocument.h"
#include "nsIDocumentInlines.h"
#include "mozilla/AnimationComparator.h"
@ -12084,7 +12085,8 @@ nsDocument::MaybeActiveMediaComponents()
}
mEverInForeground = true;
if (GetWindow()->GetMediaSuspend() == nsISuspendedTypes::SUSPENDED_BLOCK) {
if (GetWindow()->GetMediaSuspend() == nsISuspendedTypes::SUSPENDED_BLOCK &&
AudioChannelService::IsServiceStarted()) {
GetWindow()->SetMediaSuspend(nsISuspendedTypes::NONE_SUSPENDED);
}
}