Bug 1183700 - Don't prevent playback of media elements in a muted tab on desktop, r=ehsan

This commit is contained in:
Andrea Marchesini
2015-07-16 19:34:30 +01:00
parent f6434f2663
commit c8c652d9d4
11 changed files with 291 additions and 90 deletions

View File

@@ -1831,7 +1831,7 @@ void HTMLMediaElement::SetMutedInternal(uint32_t aMuted)
void HTMLMediaElement::SetVolumeInternal()
{
float effectiveVolume = mMuted ? 0.0f : float(mVolume * mAudioChannelVolume);
float effectiveVolume = ComputedVolume();
if (mDecoder) {
mDecoder->SetVolume(effectiveVolume);
@@ -4040,7 +4040,7 @@ HTMLMediaElement::NotifyOwnerDocumentActivityChangedInternal()
mDecoder->NotifyOwnerActivityChanged();
}
bool pauseElement = !IsActive() || (mMuted & MUTED_BY_AUDIO_CHANNEL);
bool pauseElement = !IsActive() || ComputedMuted();
SuspendOrResumeElement(pauseElement, !IsActive());
@@ -4470,19 +4470,21 @@ nsresult HTMLMediaElement::UpdateChannelMuteState(float aVolume, bool aMuted)
}
// We have to mute this channel.
if (aMuted && !(mMuted & MUTED_BY_AUDIO_CHANNEL)) {
if (aMuted && !ComputedMuted()) {
SetMutedInternal(mMuted | MUTED_BY_AUDIO_CHANNEL);
if (UseAudioChannelAPI()) {
DispatchAsyncEvent(NS_LITERAL_STRING("mozinterruptbegin"));
}
} else if (!aMuted && (mMuted & MUTED_BY_AUDIO_CHANNEL)) {
} else if (!aMuted && ComputedMuted()) {
SetMutedInternal(mMuted & ~MUTED_BY_AUDIO_CHANNEL);
if (UseAudioChannelAPI()) {
DispatchAsyncEvent(NS_LITERAL_STRING("mozinterruptend"));
}
}
SuspendOrResumeElement(mMuted & MUTED_BY_AUDIO_CHANNEL, false);
#ifdef MOZ_B2G
SuspendOrResumeElement(ComputedMuted(), false);
#endif
return NS_OK;
}
@@ -4546,7 +4548,11 @@ NS_IMETHODIMP HTMLMediaElement::WindowVolumeChanged(float aVolume, bool aMuted)
NS_ENSURE_TRUE(nsContentUtils::IsCallerChrome(), NS_ERROR_NOT_AVAILABLE);
UpdateChannelMuteState(aVolume, aMuted);
#ifdef MOZ_B2G
mPaused.SetCanPlay(!aMuted);
#endif
return NS_OK;
}
@@ -4768,5 +4774,17 @@ HTMLMediaElement::NextFrameStatus()
return NEXT_FRAME_UNINITIALIZED;
}
float
HTMLMediaElement::ComputedVolume() const
{
return mMuted ? 0.0f : float(mVolume * mAudioChannelVolume);
}
bool
HTMLMediaElement::ComputedMuted() const
{
return (mMuted & MUTED_BY_AUDIO_CHANNEL);
}
} // namespace dom
} // namespace mozilla