AudioBufferSourceNode start method causes OfflineAudioContext to start running
https://bugs.webkit.org/show_bug.cgi?id=181939
<rdar://problem/36755393>
Reviewed by Eric Carlson.
Source/WebCore:
Test: webaudio/offlineaudiocontext-restriction.html
Don't respect playback restrictions for offline AudioContexts.
* Modules/webaudio/AudioContext.cpp:
(WebCore::AudioContext::constructCommon):
* Modules/webaudio/AudioContext.h:
(WebCore::AudioContext::isOfflineContext const):
(WebCore::AudioContext::userGestureRequiredForAudioStart const):
(WebCore::AudioContext::pageConsentRequiredForAudioStart const):
(WebCore::AudioContext::isOfflineContext): Deleted.
LayoutTests:
* webaudio/offlineaudiocontext-restriction-expected.txt: Added.
* webaudio/offlineaudiocontext-restriction.html: Added.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@230158 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 0c08b1e..2dbde75 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,14 @@
+2018-04-02 Jer Noble <jer.noble@apple.com>
+
+ AudioBufferSourceNode start method causes OfflineAudioContext to start running
+ https://bugs.webkit.org/show_bug.cgi?id=181939
+ <rdar://problem/36755393>
+
+ Reviewed by Eric Carlson.
+
+ * webaudio/offlineaudiocontext-restriction-expected.txt: Added.
+ * webaudio/offlineaudiocontext-restriction.html: Added.
+
2018-03-31 Brent Fulgham <bfulgham@apple.com>
Show punycode if URL contains hyphen character
diff --git a/LayoutTests/webaudio/offlineaudiocontext-restriction-expected.txt b/LayoutTests/webaudio/offlineaudiocontext-restriction-expected.txt
new file mode 100644
index 0000000..c9ccf4e
--- /dev/null
+++ b/LayoutTests/webaudio/offlineaudiocontext-restriction-expected.txt
@@ -0,0 +1,14 @@
+OfflineAudioContexts should not have behavior restrictions.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+PASS context.state is "suspended"
+node.connect(context.destination)
+node.start()
+PASS context.state is "suspended"
+Calling context.startRendering() without a user gesture
+PASS context.state is "running"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/webaudio/offlineaudiocontext-restriction.html b/LayoutTests/webaudio/offlineaudiocontext-restriction.html
new file mode 100644
index 0000000..f9d6a6f
--- /dev/null
+++ b/LayoutTests/webaudio/offlineaudiocontext-restriction.html
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+<script src="../resources/js-test.js"></script>
+<script type="text/javascript" src="resources/audio-testing.js"></script>
+</head>
+
+<body>
+<div id="description"></div>
+<div id="console"></div>
+
+<script>
+description('OfflineAudioContexts should not have behavior restrictions.');
+
+var context = null;
+var node = null;
+var calledResumeWithUserGesture = false;
+
+function runTest() {
+ window.jsTestIsAsync = true;
+
+ context = new webkitOfflineAudioContext(2, 1000, 44100);
+
+ if (window.internals)
+ internals.setAudioContextRestrictions(context, 'RequireUserGestureForAudioStart');
+
+ shouldBe('context.state', '"suspended"');
+
+ node = context.createBufferSource();
+ evalAndLog('node.connect(context.destination)');
+ evalAndLog('node.start()');
+ shouldBe('context.state', '"suspended"');
+
+ debug('Calling context.startRendering() without a user gesture');
+ context.startRendering();
+ shouldBe('context.state', '"running"');
+ finishJSTest();
+}
+
+runTest();
+
+</script>
+</body>
+</html>
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 20222cb..9d203ae 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,23 @@
+2018-04-02 Jer Noble <jer.noble@apple.com>
+
+ AudioBufferSourceNode start method causes OfflineAudioContext to start running
+ https://bugs.webkit.org/show_bug.cgi?id=181939
+ <rdar://problem/36755393>
+
+ Reviewed by Eric Carlson.
+
+ Test: webaudio/offlineaudiocontext-restriction.html
+
+ Don't respect playback restrictions for offline AudioContexts.
+
+ * Modules/webaudio/AudioContext.cpp:
+ (WebCore::AudioContext::constructCommon):
+ * Modules/webaudio/AudioContext.h:
+ (WebCore::AudioContext::isOfflineContext const):
+ (WebCore::AudioContext::userGestureRequiredForAudioStart const):
+ (WebCore::AudioContext::pageConsentRequiredForAudioStart const):
+ (WebCore::AudioContext::isOfflineContext): Deleted.
+
2018-04-02 Alejandro G. Castro <alex@igalia.com>
[GTK] Make libwebrtc backend buildable for GTK port
diff --git a/Source/WebCore/Modules/webaudio/AudioContext.cpp b/Source/WebCore/Modules/webaudio/AudioContext.cpp
index dc6462b..5bb2b03 100644
--- a/Source/WebCore/Modules/webaudio/AudioContext.cpp
+++ b/Source/WebCore/Modules/webaudio/AudioContext.cpp
@@ -166,12 +166,10 @@
m_listener = AudioListener::create();
-#if PLATFORM(IOS)
- if (document()->settings().audioPlaybackRequiresUserGesture())
+ if (document()->audioPlaybackRequiresUserGesture())
addBehaviorRestriction(RequireUserGestureForAudioStartRestriction);
else
m_restrictions = NoRestrictions;
-#endif
#if PLATFORM(COCOA)
addBehaviorRestriction(RequirePageConsentForAudioStartRestriction);
diff --git a/Source/WebCore/Modules/webaudio/AudioContext.h b/Source/WebCore/Modules/webaudio/AudioContext.h
index 0cc077f..2b8a2b1 100644
--- a/Source/WebCore/Modules/webaudio/AudioContext.h
+++ b/Source/WebCore/Modules/webaudio/AudioContext.h
@@ -85,7 +85,7 @@
bool isInitialized() const;
- bool isOfflineContext() { return m_isOfflineContext; }
+ bool isOfflineContext() const { return m_isOfflineContext; }
Document* document() const; // ASSERTs if document no longer exists.
@@ -276,8 +276,8 @@
bool willBeginPlayback();
bool willPausePlayback();
- bool userGestureRequiredForAudioStart() const { return m_restrictions & RequireUserGestureForAudioStartRestriction; }
- bool pageConsentRequiredForAudioStart() const { return m_restrictions & RequirePageConsentForAudioStartRestriction; }
+ bool userGestureRequiredForAudioStart() const { return !isOfflineContext() && m_restrictions & RequireUserGestureForAudioStartRestriction; }
+ bool pageConsentRequiredForAudioStart() const { return !isOfflineContext() && m_restrictions & RequirePageConsentForAudioStartRestriction; }
void setState(State);