Bug 1183044 - Properly mute AudioContext when there's an attempt to mute it before it has a destination. r=ehsan

This commit is contained in:
Drew Willcoxon 2015-07-28 12:34:33 -07:00
parent 1f2429ca3f
commit 3c96e8ce58
3 changed files with 10 additions and 6 deletions

View File

@ -3475,17 +3475,16 @@ nsPIDOMWindow::SetFrameElementInternal(Element* aFrameElement)
mOuterWindow->SetFrameElementInternal(aFrameElement);
}
void
bool
nsPIDOMWindow::AddAudioContext(AudioContext* aAudioContext)
{
MOZ_ASSERT(IsInnerWindow());
mAudioContexts.AppendElement(aAudioContext);
// Return true if the context should be muted and false if not.
nsIDocShell* docShell = GetDocShell();
if (docShell && !docShell->GetAllowMedia() && !aAudioContext->IsOffline()) {
aAudioContext->Mute();
}
return docShell && !docShell->GetAllowMedia() && !aAudioContext->IsOffline();
}
void

View File

@ -718,7 +718,7 @@ public:
const nsAString& aPopupWindowFeatures) = 0;
// Inner windows only.
void AddAudioContext(mozilla::dom::AudioContext* aAudioContext);
bool AddAudioContext(mozilla::dom::AudioContext* aAudioContext);
void RemoveAudioContext(mozilla::dom::AudioContext* aAudioContext);
void MuteAudioContexts();
void UnmuteAudioContexts();

View File

@ -101,12 +101,17 @@ AudioContext::AudioContext(nsPIDOMWindow* aWindow,
, mIsShutDown(false)
, mCloseCalled(false)
{
aWindow->AddAudioContext(this);
bool mute = aWindow->AddAudioContext(this);
// Note: AudioDestinationNode needs an AudioContext that must already be
// bound to the window.
mDestination = new AudioDestinationNode(this, aIsOffline, aChannel,
aNumberOfChannels, aLength, aSampleRate);
// The context can't be muted until it has a destination.
if (mute) {
Mute();
}
}
void