Bug 1413098 - AudioContext shouldn't be allowed to start if we disable autoplay.
Per spec [1], user agent could block AudioContext to start.
[1] https://webaudio.github.io/web-audio-api/#dfn-allowed-to-start
MozReview-Commit-ID: HBBtPMbSPuA
--- a/dom/media/webaudio/AudioContext.cpp
+++ b/dom/media/webaudio/AudioContext.cpp
@@ -146,16 +146,22 @@ AudioContext::AudioContext(nsPIDOMWindow
{
bool mute = aWindow->AddAudioContext(this);
// Note: AudioDestinationNode needs an AudioContext that must already be
// bound to the window.
mDestination = new AudioDestinationNode(this, aIsOffline,
aNumberOfChannels, aLength, aSampleRate);
+ if (!Preferences::GetBool("media.autoplay.enabled")) {
+ ErrorResult rv;
+ RefPtr<Promise> dummy = Suspend(rv);
+ NS_WARNING_ASSERTION(!rv.Failed(), "Fail to block autoplay audio context");
+ }
+
// The context can't be muted until it has a destination.
if (mute) {
Mute();
}
}
nsresult
AudioContext::Init()