Bug 1322505 - part2 : reset suspend type for blocked media after calling media.pause(). r=baku

If the blocked media is paused before resuming it, we should not resume it again
after the tab is visible. The way to achieve that is to unregister the agent so
AudioChannelService can't resume that media because we have disconnected their
relationship.

MozReview-Commit-ID: 6Dq4K9hVsU0
This commit is contained in:
Alastor Wu
2017-01-20 11:30:03 +08:00
parent 077a2ef142
commit 96b3d80ac4

View File

@@ -654,15 +654,32 @@ public:
}
}
bool
ShouldResetSuspend() const
{
// The disposable-pause should be clear after media starts playing.
if (!mOwner->Paused() &&
mSuspended == nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE) {
return true;
}
// If the blocked media is paused, we don't need to resume it. We reset the
// mSuspended in order to unregister the agent.
if (mOwner->Paused() &&
mSuspended == nsISuspendedTypes::SUSPENDED_BLOCK) {
return true;
}
return false;
}
void
NotifyPlayStateChanged()
{
MOZ_ASSERT(!mIsShutDown);
// When owner's play state changed, we should reset the suspend type. If
// owner is playing, the suspend type should be 'NONE_SUSPENDED', and if
// owner paused, the suspend type also needs to be reset because the agent
// maybe need to be unregistered.
SetSuspended(nsISuspendedTypes::NONE_SUSPENDED);
if (ShouldResetSuspend()) {
SetSuspended(nsISuspendedTypes::NONE_SUSPENDED);
}
UpdateAudioChannelPlayingState();
}
@@ -881,7 +898,7 @@ private:
if (!IsSuspended()) {
MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
("HTMLMediaElement::AudioChannelAgentCallback, ResumeFromAudioChannel, "
"this = %p, Error : resume without suspended!\n", this));
"this = %p, don't need to be resumed!\n", this));
return;
}
@@ -2758,7 +2775,9 @@ HTMLMediaElement::Pause(ErrorResult& aRv)
// We changed mPaused and mAutoplaying which can affect AddRemoveSelfReference
AddRemoveSelfReference();
UpdateSrcMediaStreamPlaying();
UpdateAudioChannelPlayingState();
if (mAudioChannelWrapper) {
mAudioChannelWrapper->NotifyPlayStateChanged();
}
if (!oldPaused) {
FireTimeUpdate(false);