From 9e4d1c7549c123d308b7f48b89da09f033cf5fa2 Mon Sep 17 00:00:00 2001 From: Alastor Wu Date: Fri, 3 Feb 2017 10:48:38 +0800 Subject: [PATCH] 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 --- dom/audiochannel/AudioChannelAgent.cpp | 3 +++ dom/audiochannel/AudioChannelService.cpp | 7 +++++++ dom/audiochannel/AudioChannelService.h | 2 ++ dom/base/nsDocument.cpp | 4 +++- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/dom/audiochannel/AudioChannelAgent.cpp b/dom/audiochannel/AudioChannelAgent.cpp index 700ecc37814b..629b3abf2ec1 100644 --- a/dom/audiochannel/AudioChannelAgent.cpp +++ b/dom/audiochannel/AudioChannelAgent.cpp @@ -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 service = AudioChannelService::GetOrCreate(); } AudioChannelAgent::~AudioChannelAgent() diff --git a/dom/audiochannel/AudioChannelService.cpp b/dom/audiochannel/AudioChannelService.cpp index c20a4de69409..8d4cbfdca980 100644 --- a/dom/audiochannel/AudioChannelService.cpp +++ b/dom/audiochannel/AudioChannelService.cpp @@ -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::GetOrCreate() { diff --git a/dom/audiochannel/AudioChannelService.h b/dom/audiochannel/AudioChannelService.h index 55f8bb323b7e..a63071e9e7f3 100644 --- a/dom/audiochannel/AudioChannelService.h +++ b/dom/audiochannel/AudioChannelService.h @@ -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. diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 8ba5b0c7691b..ae17aa5dac28 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -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); } }