Bug 1321196 part 2 - rework the IsAllowedToPlay policy; r=alwu,jwwang

MozReview-Commit-ID: 8mrXoLRK42y
This commit is contained in:
Kaku Kuo
2016-11-30 16:01:36 +08:00
parent dd95108d31
commit 1b0552843e

View File

@@ -673,15 +673,8 @@ public:
}
bool
IsAllowedToPlay()
IsPlaybackBlocked()
{
// The media element has already been paused or blocked, so it can't start
// playback again by script or user's intend until resuming by audio channel.
if (mSuspended == nsISuspendedTypes::SUSPENDED_PAUSE ||
mSuspended == nsISuspendedTypes::SUSPENDED_BLOCK) {
return false;
}
// If the tab hasn't been activated yet, the media element in that tab can't
// be playback now until the tab goes to foreground first time or user clicks
// the unblocking tab icon.
@@ -689,10 +682,10 @@ public:
// Even we haven't start playing yet, we still need to notify the audio
// channe system because we need to receive the resume notification later.
UpdateAudioChannelPlayingState(true /* force to start */);
return false;
return true;
}
return true;
return false;
}
float
@@ -3568,7 +3561,8 @@ HTMLMediaElement::NotifyXPCOMShutdown()
void
HTMLMediaElement::Play(ErrorResult& aRv)
{
if (!IsAllowedToPlay()) {
if (mAudioChannelWrapper && mAudioChannelWrapper->IsPlaybackBlocked()) {
// NOTE: for promise-based-play, will return a pending promise here.
MaybeDoLoad();
return;
}
@@ -3584,6 +3578,11 @@ HTMLMediaElement::Play(ErrorResult& aRv)
nsresult
HTMLMediaElement::PlayInternal()
{
if (!IsAllowedToPlay()) {
// NOTE: for promise-based-play, will return a rejected promise here.
return NS_OK;
}
// Play was not blocked so assume user interacted with the element.
mHasUserInteraction = true;
@@ -3657,7 +3656,8 @@ HTMLMediaElement::MaybeDoLoad()
NS_IMETHODIMP HTMLMediaElement::Play()
{
if (!IsAllowedToPlay()) {
if (mAudioChannelWrapper && mAudioChannelWrapper->IsPlaybackBlocked()) {
// NOTE: for promise-based-play, will return a pending promise here.
MaybeDoLoad();
return NS_OK;
}
@@ -5489,8 +5489,13 @@ bool HTMLMediaElement::CanActivateAutoplay()
return false;
}
if (mAudioChannelWrapper && !mAudioChannelWrapper->IsAllowedToPlay()) {
return false;
if (mAudioChannelWrapper) {
// Note: SUSPENDED_PAUSE and SUSPENDED_BLOCK will be merged into one single state.
if (mAudioChannelWrapper->GetSuspendType() == nsISuspendedTypes::SUSPENDED_PAUSE ||
mAudioChannelWrapper->GetSuspendType() == nsISuspendedTypes::SUSPENDED_BLOCK ||
mAudioChannelWrapper->IsPlaybackBlocked()) {
return false;
}
}
bool hasData =
@@ -6315,7 +6320,13 @@ HTMLMediaElement::IsAllowedToPlay()
// Check our custom playback policy.
if (mAudioChannelWrapper) {
return mAudioChannelWrapper->IsAllowedToPlay();
// Note: SUSPENDED_PAUSE and SUSPENDED_BLOCK will be merged into one single state.
if (mAudioChannelWrapper->GetSuspendType() == nsISuspendedTypes::SUSPENDED_PAUSE ||
mAudioChannelWrapper->GetSuspendType() == nsISuspendedTypes::SUSPENDED_BLOCK) {
return false;
}
return true;
}
// If the mAudioChannelWrapper doesn't exist that means the CC happened.