Bug 1347758 - part1 : window should know whehter there is any alive media component and decide to resume the tab or not. r=Ehsan

We should let window decide whether resume the media component, not document.
Because we might have media component which is not in DOM tree, but we still
want to play it.

Window should be resumed when all following conditions are true,
(1) the tab is in the foreground
(2) there is any alive media component (MediaElement/WebAudio/PlugIn...)
(3) the window is blocked (nsISuspendedTypes::SUSPENDED_BLOCK)

MozReview-Commit-ID: JXw5MA4FCxF

--HG--
extra : rebase_source : 416113dd2282a979ea26c4694878c2f2db578274
This commit is contained in:
Alastor Wu 2017-03-24 12:01:43 +08:00
Родитель 9f3f895b0e
Коммит 8b4c678479
4 изменённых файлов: 18 добавлений и 24 удалений

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

@ -1327,7 +1327,6 @@ nsIDocument::nsIDocument()
mFontFaceSetDirty(true),
mGetUserFontSetCalled(false),
mPostedFlushUserFontSet(false),
mEverInForeground(false),
mCompatMode(eCompatibility_FullStandards),
mReadyState(ReadyState::READYSTATE_UNINITIALIZED),
mStyleBackendType(StyleBackendType::None),
@ -1426,8 +1425,6 @@ nsDocument::nsDocument(const char* aContentType)
// void state used to differentiate an empty source from an unselected source
mPreloadPictureFoundSource.SetIsVoid(true);
mEverInForeground = false;
}
void
@ -12212,19 +12209,10 @@ nsDocument::PostVisibilityUpdateEvent()
void
nsDocument::MaybeActiveMediaComponents()
{
if (mEverInForeground) {
return;
}
if (!mWindow) {
return;
}
if (mMediaContent.IsEmpty()) {
return;
}
mEverInForeground = true;
GetWindow()->MaybeActiveMediaComponents();
}

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

@ -989,7 +989,8 @@ nsPIDOMWindow<T>::nsPIDOMWindow(nsPIDOMWindowOuter *aOuterWindow)
// Make sure no actual window ends up with mWindowID == 0
mWindowID(NextWindowID()), mHasNotifiedGlobalCreated(false),
mMarkedCCGeneration(0), mServiceWorkersTestingEnabled(false),
mLargeAllocStatus(LargeAllocStatus::NONE)
mLargeAllocStatus(LargeAllocStatus::NONE),
mShouldResumeOnFirstActiveMediaComponent(false)
{
if (aOuterWindow) {
mTimeoutManager =
@ -4348,9 +4349,8 @@ nsPIDOMWindowInner::IsRunningTimeout()
void
nsPIDOMWindowOuter::NotifyCreatedNewMediaComponent()
{
if (mMediaSuspend != nsISuspendedTypes::SUSPENDED_BLOCK) {
return;
}
// 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
@ -4367,21 +4367,26 @@ nsPIDOMWindowOuter::MaybeActiveMediaComponents()
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) {
if (!doc || doc->Hidden()) {
return;
}
if (!doc->Hidden() &&
mMediaSuspend == nsISuspendedTypes::SUSPENDED_BLOCK) {
SetMediaSuspend(nsISuspendedTypes::NONE_SUSPENDED);
}
}
SuspendTypes
nsPIDOMWindowOuter::GetMediaSuspend() const

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

@ -3186,9 +3186,6 @@ protected:
// Do we currently have an event posted to call FlushUserFontSet?
bool mPostedFlushUserFontSet : 1;
// True is document has ever been in a foreground window.
bool mEverInForeground : 1;
// Compatibility mode
nsCompatibility mCompatMode;

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

@ -737,6 +737,10 @@ protected:
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;
};
#define NS_PIDOMWINDOWINNER_IID \