зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
9f3f895b0e
Коммит
8b4c678479
|
@ -1327,7 +1327,6 @@ nsIDocument::nsIDocument()
|
||||||
mFontFaceSetDirty(true),
|
mFontFaceSetDirty(true),
|
||||||
mGetUserFontSetCalled(false),
|
mGetUserFontSetCalled(false),
|
||||||
mPostedFlushUserFontSet(false),
|
mPostedFlushUserFontSet(false),
|
||||||
mEverInForeground(false),
|
|
||||||
mCompatMode(eCompatibility_FullStandards),
|
mCompatMode(eCompatibility_FullStandards),
|
||||||
mReadyState(ReadyState::READYSTATE_UNINITIALIZED),
|
mReadyState(ReadyState::READYSTATE_UNINITIALIZED),
|
||||||
mStyleBackendType(StyleBackendType::None),
|
mStyleBackendType(StyleBackendType::None),
|
||||||
|
@ -1426,8 +1425,6 @@ nsDocument::nsDocument(const char* aContentType)
|
||||||
|
|
||||||
// void state used to differentiate an empty source from an unselected source
|
// void state used to differentiate an empty source from an unselected source
|
||||||
mPreloadPictureFoundSource.SetIsVoid(true);
|
mPreloadPictureFoundSource.SetIsVoid(true);
|
||||||
|
|
||||||
mEverInForeground = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -12212,19 +12209,10 @@ nsDocument::PostVisibilityUpdateEvent()
|
||||||
void
|
void
|
||||||
nsDocument::MaybeActiveMediaComponents()
|
nsDocument::MaybeActiveMediaComponents()
|
||||||
{
|
{
|
||||||
if (mEverInForeground) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mWindow) {
|
if (!mWindow) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mMediaContent.IsEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mEverInForeground = true;
|
|
||||||
GetWindow()->MaybeActiveMediaComponents();
|
GetWindow()->MaybeActiveMediaComponents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -989,7 +989,8 @@ nsPIDOMWindow<T>::nsPIDOMWindow(nsPIDOMWindowOuter *aOuterWindow)
|
||||||
// Make sure no actual window ends up with mWindowID == 0
|
// Make sure no actual window ends up with mWindowID == 0
|
||||||
mWindowID(NextWindowID()), mHasNotifiedGlobalCreated(false),
|
mWindowID(NextWindowID()), mHasNotifiedGlobalCreated(false),
|
||||||
mMarkedCCGeneration(0), mServiceWorkersTestingEnabled(false),
|
mMarkedCCGeneration(0), mServiceWorkersTestingEnabled(false),
|
||||||
mLargeAllocStatus(LargeAllocStatus::NONE)
|
mLargeAllocStatus(LargeAllocStatus::NONE),
|
||||||
|
mShouldResumeOnFirstActiveMediaComponent(false)
|
||||||
{
|
{
|
||||||
if (aOuterWindow) {
|
if (aOuterWindow) {
|
||||||
mTimeoutManager =
|
mTimeoutManager =
|
||||||
|
@ -4348,9 +4349,8 @@ nsPIDOMWindowInner::IsRunningTimeout()
|
||||||
void
|
void
|
||||||
nsPIDOMWindowOuter::NotifyCreatedNewMediaComponent()
|
nsPIDOMWindowOuter::NotifyCreatedNewMediaComponent()
|
||||||
{
|
{
|
||||||
if (mMediaSuspend != nsISuspendedTypes::SUSPENDED_BLOCK) {
|
// We would only active media component when there is any alive one.
|
||||||
return;
|
mShouldResumeOnFirstActiveMediaComponent = true;
|
||||||
}
|
|
||||||
|
|
||||||
// If the document is already on the foreground but the suspend state is still
|
// 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
|
// suspend-block, that means the media component was created after calling
|
||||||
|
@ -4367,21 +4367,26 @@ nsPIDOMWindowOuter::MaybeActiveMediaComponents()
|
||||||
return mOuterWindow->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();
|
nsCOMPtr<nsPIDOMWindowInner> inner = GetCurrentInnerWindow();
|
||||||
if (!inner) {
|
if (!inner) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the document is not visible, don't need to resume it.
|
||||||
nsCOMPtr<nsIDocument> doc = inner->GetExtantDoc();
|
nsCOMPtr<nsIDocument> doc = inner->GetExtantDoc();
|
||||||
if (!doc) {
|
if (!doc || doc->Hidden()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!doc->Hidden() &&
|
|
||||||
mMediaSuspend == nsISuspendedTypes::SUSPENDED_BLOCK) {
|
|
||||||
SetMediaSuspend(nsISuspendedTypes::NONE_SUSPENDED);
|
SetMediaSuspend(nsISuspendedTypes::NONE_SUSPENDED);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
SuspendTypes
|
SuspendTypes
|
||||||
nsPIDOMWindowOuter::GetMediaSuspend() const
|
nsPIDOMWindowOuter::GetMediaSuspend() const
|
||||||
|
|
|
@ -3186,9 +3186,6 @@ protected:
|
||||||
// Do we currently have an event posted to call FlushUserFontSet?
|
// Do we currently have an event posted to call FlushUserFontSet?
|
||||||
bool mPostedFlushUserFontSet : 1;
|
bool mPostedFlushUserFontSet : 1;
|
||||||
|
|
||||||
// True is document has ever been in a foreground window.
|
|
||||||
bool mEverInForeground : 1;
|
|
||||||
|
|
||||||
// Compatibility mode
|
// Compatibility mode
|
||||||
nsCompatibility mCompatMode;
|
nsCompatibility mCompatMode;
|
||||||
|
|
||||||
|
|
|
@ -737,6 +737,10 @@ protected:
|
||||||
bool mServiceWorkersTestingEnabled;
|
bool mServiceWorkersTestingEnabled;
|
||||||
|
|
||||||
mozilla::dom::LargeAllocStatus mLargeAllocStatus; // Outer window only
|
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 \
|
#define NS_PIDOMWINDOWINNER_IID \
|
||||||
|
|
Загрузка…
Ссылка в новой задаче