Bug 1347791 - part2 : the tab would always be resumed when it goes to foreground first time.
Since now we move the block/resume logic to front-end side, we can remove
the changing from bug1319771 and other related bugs which are used to ensure the
pinned tab should be blocked successfully after session restore.
MozReview-Commit-ID: Ixe7tOvCEhv
--- a/dom/audiochannel/AudioChannelAgent.cpp
+++ b/dom/audiochannel/AudioChannelAgent.cpp
@@ -179,19 +179,16 @@ AudioChannelAgent::InitInternal(nsPIDOMW
mAudioChannelType = aChannelType;
if (aUseWeakRef) {
mWeakCallback = do_GetWeakReference(aCallback);
} else {
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,
mWindow.get(), (!!mCallback || !!mWeakCallback)));
return NS_OK;
}
--- a/dom/audiochannel/AudioChannelService.cpp
+++ b/dom/audiochannel/AudioChannelService.cpp
@@ -318,29 +318,16 @@ AudioChannelService::AudioChannelService
"dom.audiochannel.audioCompeting.allAgents");
}
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)
{
MOZ_ASSERT(aAgent);
uint64_t windowID = aAgent->WindowID();
AudioChannelWindow* winData = GetWindowData(windowID);
if (!winData) {
--- a/dom/audiochannel/AudioChannelService.h
+++ b/dom/audiochannel/AudioChannelService.h
@@ -141,18 +141,16 @@ public:
void SetWindowAudioCaptured(nsPIDOMWindowOuter* aWindow,
uint64_t aInnerWindowID,
bool aCapture);
static const nsAttrValue::EnumTable* GetAudioChannelTable();
static AudioChannel GetAudioChannel(const nsAString& aString);
static AudioChannel GetDefaultAudioChannel();
- void NotifyCreatedNewAgent(AudioChannelAgent* aAgent);
-
void NotifyMediaResumedFromBlock(nsPIDOMWindowOuter* aWindow);
private:
AudioChannelService();
~AudioChannelService();
void RefreshAgents(nsPIDOMWindowOuter* aWindow,
const std::function<void(AudioChannelAgent*)>& aFunc);
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -1008,17 +1008,16 @@ nsPIDOMWindow<T>::nsPIDOMWindow(nsPIDOMW
nsISuspendedTypes::SUSPENDED_BLOCK : nsISuspendedTypes::NONE_SUSPENDED),
mAudioMuted(false), mAudioVolume(1.0), mAudioCaptured(false),
mDesktopModeViewport(false), mIsRootOuterWindow(false), mInnerWindow(nullptr),
mOuterWindow(aOuterWindow),
// Make sure no actual window ends up with mWindowID == 0
mWindowID(NextWindowID()), mHasNotifiedGlobalCreated(false),
mMarkedCCGeneration(0), mServiceWorkersTestingEnabled(false),
mLargeAllocStatus(LargeAllocStatus::NONE),
- mShouldResumeOnFirstActiveMediaComponent(false),
mHasTriedToCacheTopInnerWindow(false),
mNumOfIndexedDBDatabases(0)
{
if (aOuterWindow) {
mTimeoutManager =
MakeUnique<mozilla::dom::TimeoutManager>(*nsGlobalWindow::Cast(AsInner()));
}
}
@@ -4489,51 +4488,23 @@ nsPIDOMWindowInner::HasActiveIndexedDBDa
MOZ_ASSERT(NS_IsMainThread());
return mTopInnerWindow ?
mTopInnerWindow->mNumOfIndexedDBDatabases > 0 :
mNumOfIndexedDBDatabases > 0;
}
void
-nsPIDOMWindowOuter::NotifyCreatedNewMediaComponent()
-{
- // We would only active media component when there is any alive one.
- mShouldResumeOnFirstActiveMediaComponent = true;
-
- // 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();
}
- // Resume the media when the tab was blocked and the tab already has
- // alive media components.
- if (!mShouldResumeOnFirstActiveMediaComponent ||
- mMediaSuspend != nsISuspendedTypes::SUSPENDED_BLOCK) {
- return;
- }
-
- nsCOMPtr<nsPIDOMWindowInner> inner = GetCurrentInnerWindow();
- if (!inner) {
- return;
- }
-
- // If the document is not visible, don't need to resume it.
- nsCOMPtr<nsIDocument> doc = inner->GetExtantDoc();
- if (!doc || doc->Hidden()) {
+ if (mMediaSuspend != nsISuspendedTypes::SUSPENDED_BLOCK) {
return;
}
MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
("nsPIDOMWindowOuter, MaybeActiveMediaComponents, "
"resume the window from blocked, this = %p\n", this));
SetMediaSuspend(nsISuspendedTypes::NONE_SUSPENDED);
--- a/dom/base/nsPIDOMWindow.h
+++ b/dom/base/nsPIDOMWindow.h
@@ -756,20 +756,16 @@ protected:
uint32_t mMarkedCCGeneration;
// Let the service workers plumbing know that some feature are enabled while
// testing.
bool mServiceWorkersTestingEnabled;
mozilla::dom::LargeAllocStatus mLargeAllocStatus; // Outer window only
- // When there is any created alive media component, we can consider to resume
- // the media content in the window.
- bool mShouldResumeOnFirstActiveMediaComponent;
-
// mTopInnerWindow is only used on inner windows for tab-wise check by timeout
// throttling. It could be null.
nsCOMPtr<nsPIDOMWindowInner> mTopInnerWindow;
// The evidence that we have tried to cache mTopInnerWindow only once from
// SetNewDocument(). Note: We need this extra flag because mTopInnerWindow
// could be null and we don't want it to be set multiple times.
bool mHasTriedToCacheTopInnerWindow;
@@ -1014,17 +1010,16 @@ public:
void SetMediaSuspend(SuspendTypes aSuspend);
bool GetAudioMuted() const;
void SetAudioMuted(bool aMuted);
float GetAudioVolume() const;
nsresult SetAudioVolume(float aVolume);
- void NotifyCreatedNewMediaComponent();
void MaybeActiveMediaComponents();
void SetServiceWorkersTestingEnabled(bool aEnabled);
bool GetServiceWorkersTestingEnabled();
float GetDevicePixelRatio(mozilla::dom::CallerType aCallerType);
void SetLargeAllocStatus(mozilla::dom::LargeAllocStatus aStatus);