From 3c96e8ce58cdfdabe8174700e10fb44145d08982 Mon Sep 17 00:00:00 2001 From: Drew Willcoxon Date: Tue, 28 Jul 2015 12:34:33 -0700 Subject: [PATCH] Bug 1183044 - Properly mute AudioContext when there's an attempt to mute it before it has a destination. r=ehsan --- dom/base/nsGlobalWindow.cpp | 7 +++---- dom/base/nsPIDOMWindow.h | 2 +- dom/media/webaudio/AudioContext.cpp | 7 ++++++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index f0b1e7787bd..98973f7608a 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -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 diff --git a/dom/base/nsPIDOMWindow.h b/dom/base/nsPIDOMWindow.h index 3e6404e9950..5cda6cba2f0 100644 --- a/dom/base/nsPIDOMWindow.h +++ b/dom/base/nsPIDOMWindow.h @@ -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(); diff --git a/dom/media/webaudio/AudioContext.cpp b/dom/media/webaudio/AudioContext.cpp index 9d2fdc73caa..b705970dce7 100644 --- a/dom/media/webaudio/AudioContext.cpp +++ b/dom/media/webaudio/AudioContext.cpp @@ -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