[WebAudio] AudioContext does not remove user-gesture restriction during resume()
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Apr 2015 21:35:03 +0000 (21:35 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Apr 2015 21:35:03 +0000 (21:35 +0000)
commit3292affcb5edbea9d167afaeacc2ea2e1edeef2e
tree15510e33f9921488ee7f731d103b073ef52b95ac
parent6f06ab8b3438bfb923fcf2dc53992fd0890c5960
[WebAudio] AudioContext does not remove user-gesture restriction during resume()
https://bugs.webkit.org/show_bug.cgi?id=144211

Reviewed by Eric Carlson.

Source/WebCore:

Tests: webaudio/audiocontext-restriction-audiobuffersourcenode-start.html
       webaudio/audiocontext-restriction.html

Before the introduction of resume(), suspend(), and stop(), AudioContexts which required
a user-gesture would start normally, but would effectively mute their outputs. Now that
the AudioContext's state property is exposed to JavaScript, the AudioContext should stay
in the "suspended" state until the user-gesture restriction is lifted.

Add a new method, willBeginPlayback() which checks and potentially clears the context's
behavior restrictions before checking with the MediaSession. Call this new willBeginPlayback()
method when the state would transition to "running".

Because they may be called before any nodes are created, make sure to call lazyInitialize()
from within the JS-exposed resumePlayback(), suspendPlayback(), and stopPlayback() methods.

Instead of clearing the behavior restrictions directly, scheduled AudioNodes should instead
call a new method nodeWillBeginPlayback(). Because existing sites will call AudioNode.start()
inside a user-gesture handler to clear the user-gesture restriction, call startRendering()
from nodeWillBeginPlayback(). But because we don't want AudioNode.start() to resume playback
unconditionally, only do so when the user-gesture restriction is set.

Now that an AudioContext will not transition to "running" state without a user-gesture (if
that restriction is set), there's no reason to check for that restriction from inside
AudioDestinationNode.

Add some internal methods to set and clear AudioContext BehaviorRestrictions for testing purposes.

* Modules/webaudio/AudioBufferSourceNode.cpp:
(WebCore::AudioBufferSourceNode::startPlaying):
* Modules/webaudio/AudioContext.cpp:
(WebCore::AudioContext::nodeWillBeginPlayback):
(WebCore::AudioContext::willBeginPlayback):
(WebCore::AudioContext::willPausePlayback):
(WebCore::AudioContext::startRendering):
(WebCore::AudioContext::suspendContext):
(WebCore::AudioContext::resumeContext):
(WebCore::AudioContext::closeContext):
(WebCore::AudioContext::suspendPlayback):
(WebCore::AudioContext::mayResumePlayback):
* Modules/webaudio/AudioContext.h:
(WebCore::AudioContext::behaviorRestrictions):
(WebCore::AudioContext::userGestureRequiredForAudioStart):
(WebCore::AudioContext::pageConsentRequiredForAudioStart):
* Modules/webaudio/AudioDestinationNode.cpp:
(WebCore::AudioDestinationNode::render):
* Modules/webaudio/AudioScheduledSourceNode.cpp:
(WebCore::AudioScheduledSourceNode::start):
* testing/Internals.cpp:
(WebCore::Internals::setAudioContextRestrictions):
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

* webaudio/audiocontext-restriction-audiobuffersourcenode-start-expected.txt: Added.
* webaudio/audiocontext-restriction-audiobuffersourcenode-start.html: Added.
* webaudio/audiocontext-restriction-expected.txt: Added.
* webaudio/audiocontext-restriction.html: Added.
* webaudio/resources/audio-testing.js:
(runWithKeyDown):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@183424 268f45cc-cd09-0410-ab3c-d52691b4dbfc
15 files changed:
LayoutTests/ChangeLog
LayoutTests/webaudio/audiocontext-restriction-audiobuffersourcenode-start-expected.txt [new file with mode: 0644]
LayoutTests/webaudio/audiocontext-restriction-audiobuffersourcenode-start.html [new file with mode: 0644]
LayoutTests/webaudio/audiocontext-restriction-expected.txt [new file with mode: 0644]
LayoutTests/webaudio/audiocontext-restriction.html [new file with mode: 0644]
LayoutTests/webaudio/resources/audio-testing.js
Source/WebCore/ChangeLog
Source/WebCore/Modules/webaudio/AudioBufferSourceNode.cpp
Source/WebCore/Modules/webaudio/AudioContext.cpp
Source/WebCore/Modules/webaudio/AudioContext.h
Source/WebCore/Modules/webaudio/AudioDestinationNode.cpp
Source/WebCore/Modules/webaudio/AudioScheduledSourceNode.cpp
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl