Bug 1319771 - part2 : resume foreground window if it was still be blocked. r=baku

In previous patch, we modify the behavior of nsDocument, now it would only resume
window when document has active media components.

However, it causes another issue. If the tab really goes to foreground, but
there is no active media component, the tab would still be blocked and it won't
be resumed anymore.

Therefore, we need to resume it by ourself if the tab is on the foreground but
doesn't be resumed yet.

MozReview-Commit-ID: EdnQ7sRkSJK

--HG--
extra : rebase_source : c2ab932cc3134531e5c49581c5e63b4aabef6ca4
This commit is contained in:
Alastor Wu 2017-02-03 10:50:07 +08:00
Родитель 9e4d1c7549
Коммит b55cdff3c1
6 изменённых файлов: 61 добавлений и 4 удалений

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

@ -184,6 +184,9 @@ AudioChannelAgent::InitInternal(nsPIDOMWindowInner* aWindow,
mCallback = aCallback;
}
RefPtr<AudioChannelService> service = AudioChannelService::GetOrCreate();
service->NotifyCreatedNewAgent(this);
MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
("AudioChannelAgent, InitInternal, this = %p, type = %d, "
"owner = %p, hasCallback = %d\n", this, mAudioChannelType,

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

@ -293,6 +293,19 @@ AudioChannelService::~AudioChannelService()
{
}
void
AudioChannelService::NotifyCreatedNewAgent(AudioChannelAgent* aAgent)
{
MOZ_ASSERT(aAgent);
nsCOMPtr<nsPIDOMWindowOuter> window = aAgent->Window();
if (!window) {
return;
}
window->NotifyCreatedNewMediaComponent();
}
void
AudioChannelService::RegisterAudioChannelAgent(AudioChannelAgent* aAgent,
AudibleState aAudible)

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

@ -199,6 +199,8 @@ public:
void ChildStatusReceived(uint64_t aChildID, bool aTelephonyChannel,
bool aContentOrNormalChannel, bool aAnyChannel);
void NotifyCreatedNewAgent(AudioChannelAgent* aAgent);
private:
AudioChannelService();
~AudioChannelService();

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

@ -12085,10 +12085,7 @@ nsDocument::MaybeActiveMediaComponents()
}
mEverInForeground = true;
if (GetWindow()->GetMediaSuspend() == nsISuspendedTypes::SUSPENDED_BLOCK &&
AudioChannelService::IsServiceStarted()) {
GetWindow()->SetMediaSuspend(nsISuspendedTypes::NONE_SUSPENDED);
}
GetWindow()->MaybeActiveMediaComponents();
}
NS_IMETHODIMP

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

@ -4172,6 +4172,45 @@ nsPIDOMWindowInner::IsRunningTimeout()
return TimeoutManager().IsRunningTimeout();
}
void
nsPIDOMWindowOuter::NotifyCreatedNewMediaComponent()
{
if (mMediaSuspend != nsISuspendedTypes::SUSPENDED_BLOCK) {
return;
}
// If the document is already on the foreground but the suspend state is still
// suspend-block, that means the media component was created after calling
// MaybeActiveMediaComponents, so the window's suspend state doesn't be
// changed yet. Therefore, we need to call it again, because the state is only
// changed after there exists alive media within the window.
MaybeActiveMediaComponents();
}
void
nsPIDOMWindowOuter::MaybeActiveMediaComponents()
{
if (IsInnerWindow()) {
return mOuterWindow->MaybeActiveMediaComponents();
}
nsCOMPtr<nsPIDOMWindowInner> inner = GetCurrentInnerWindow();
if (!inner) {
return;
}
nsCOMPtr<nsIDocument> doc = inner->GetExtantDoc();
if (!doc) {
return;
}
if (!doc->Hidden() &&
mMediaSuspend == nsISuspendedTypes::SUSPENDED_BLOCK &&
AudioChannelService::IsServiceStarted()) {
SetMediaSuspend(nsISuspendedTypes::NONE_SUSPENDED);
}
}
SuspendTypes
nsPIDOMWindowOuter::GetMediaSuspend() const
{

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

@ -963,6 +963,9 @@ public:
float GetAudioVolume() const;
nsresult SetAudioVolume(float aVolume);
void NotifyCreatedNewMediaComponent();
void MaybeActiveMediaComponents();
void SetServiceWorkersTestingEnabled(bool aEnabled);
bool GetServiceWorkersTestingEnabled();