Bug 844323 - Prelude part 1: Use a pref to in nsHTMLMediaElement to control whether we talk to the audio service. r=amarchesini

Previously, we used #ifdef B2G.  Using a pref allows us to write mochitests which run in desktop Firefox that test the audio service and its interaction with other components.
This commit is contained in:
Justin Lebar 2013-04-25 20:53:25 -04:00
parent 229a8ae69c
commit b910dfe3b0
3 changed files with 34 additions and 20 deletions

View File

@ -665,6 +665,9 @@ pref("memory_info_dumper.watch_fifo.directory", "/data/local");
pref("general.useragent.enable_overrides", true);
// Make <audio> and <video> talk to the AudioChannelService.
pref("media.useAudioChannelService", true);
pref("b2g.version", @MOZ_B2G_VERSION@);
// Disable console buffering to save memory.
@ -673,4 +676,4 @@ pref("consoleservice.buffered", false);
#ifdef MOZ_WIDGET_GONK
// Performance testing suggests 2k is a better page size for SQLite.
pref("toolkit.storage.pageSize", 2048);
#endif
#endif

View File

@ -970,6 +970,11 @@ static bool IsAutoplayEnabled()
return Preferences::GetBool("media.autoplay.enabled");
}
static bool UseAudioChannelService()
{
return Preferences::GetBool("media.useAudioChannelService");
}
void HTMLMediaElement::UpdatePreloadAction()
{
PreloadAction nextAction = PRELOAD_UNDEFINED;
@ -2163,7 +2168,10 @@ bool HTMLMediaElement::ParseAttribute(int32_t aNamespaceID,
bool HTMLMediaElement::CheckAudioChannelPermissions(const nsAString& aString)
{
#ifdef ANDROID
if (!UseAudioChannelService()) {
return true;
}
// Only normal channel doesn't need permission.
if (!aString.EqualsASCII("normal")) {
nsCOMPtr<nsIPermissionManager> permissionManager =
@ -2179,7 +2187,7 @@ bool HTMLMediaElement::CheckAudioChannelPermissions(const nsAString& aString)
return false;
}
}
#endif
return true;
}
@ -3218,17 +3226,17 @@ void HTMLMediaElement::SuspendOrResumeElement(bool aPauseElement, bool aSuspendE
void HTMLMediaElement::NotifyOwnerDocumentActivityChanged()
{
nsIDocument* ownerDoc = OwnerDoc();
#ifdef ANDROID
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(OwnerDoc());
if (domDoc) {
bool hidden = false;
domDoc->GetHidden(&hidden);
// SetVisibilityState will update mChannelSuspended via the CanPlayChanged callback.
if (mPlayingThroughTheAudioChannel && mAudioChannelAgent) {
mAudioChannelAgent->SetVisibilityState(!hidden);
if (UseAudioChannelService()) {
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(OwnerDoc());
if (domDoc) {
bool hidden = false;
domDoc->GetHidden(&hidden);
// SetVisibilityState will update mChannelSuspended via the CanPlayChanged callback.
if (mPlayingThroughTheAudioChannel && mAudioChannelAgent) {
mAudioChannelAgent->SetVisibilityState(!hidden);
}
}
}
#endif
bool suspendEvents = !ownerDoc->IsActive() || !ownerDoc->IsVisible();
bool pauseElement = suspendEvents || mChannelSuspended;
@ -3656,9 +3664,10 @@ ImageContainer* HTMLMediaElement::GetImageContainer()
nsresult HTMLMediaElement::UpdateChannelMuteState(bool aCanPlay)
{
// Only on B2G we mute the HTMLMediaElement following the rules of
// AudioChannelService.
#ifdef ANDROID
if (!UseAudioChannelService()) {
return NS_OK;
}
// We have to mute this channel:
if (!aCanPlay && !mChannelSuspended) {
mChannelSuspended = true;
@ -3669,15 +3678,15 @@ nsresult HTMLMediaElement::UpdateChannelMuteState(bool aCanPlay)
}
SuspendOrResumeElement(mChannelSuspended, false);
#endif
return NS_OK;
}
void HTMLMediaElement::UpdateAudioChannelPlayingState()
{
// The HTMLMediaElement is registered to the AudioChannelService only on B2G.
#ifdef ANDROID
if (!UseAudioChannelService()) {
return;
}
bool playingThroughTheAudioChannel =
(!mPaused &&
(HasAttr(kNameSpaceID_None, nsGkAtoms::loop) ||
@ -3711,7 +3720,6 @@ void HTMLMediaElement::UpdateAudioChannelPlayingState()
mAudioChannelAgent = nullptr;
}
}
#endif
}
/* void canPlayChanged (in boolean canPlay); */

View File

@ -712,3 +712,6 @@ pref("media.webaudio.enabled", true);
// This needs more tests and stability fixes first, as well as UI.
pref("media.navigator.enabled", false);
pref("media.peerconnection.enabled", false);
// Make <audio> and <video> talk to the AudioChannelService.
pref("media.useAudioChannelService", true);