| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/webaudio/AudioContext.h" | 5 #include "modules/webaudio/AudioContext.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionMessages.h" | 7 #include "bindings/core/v8/ExceptionMessages.h" |
| 8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
| 9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 namespace blink { | 21 namespace blink { |
| 22 | 22 |
| 23 // Don't allow more than this number of simultaneous AudioContexts | 23 // Don't allow more than this number of simultaneous AudioContexts |
| 24 // talking to hardware. | 24 // talking to hardware. |
| 25 const unsigned MaxHardwareContexts = 6; | 25 const unsigned MaxHardwareContexts = 6; |
| 26 static unsigned s_hardwareContextCount = 0; | 26 static unsigned s_hardwareContextCount = 0; |
| 27 static unsigned s_contextId = 0; | 27 static unsigned s_contextId = 0; |
| 28 | 28 |
| 29 BaseAudioContext* AudioContext::create(Document& document, ExceptionState& excep
tionState) | 29 BaseAudioContext* AudioContext::create(Document& document, ExceptionState& excep
tionState) |
| 30 { | 30 { |
| 31 ASSERT(isMainThread()); | 31 DCHECK(isMainThread()); |
| 32 | 32 |
| 33 UseCounter::countCrossOriginIframe(document, UseCounter::AudioContextCrossOr
iginIframe); | 33 UseCounter::countCrossOriginIframe(document, UseCounter::AudioContextCrossOr
iginIframe); |
| 34 | 34 |
| 35 if (s_hardwareContextCount >= MaxHardwareContexts) { | 35 if (s_hardwareContextCount >= MaxHardwareContexts) { |
| 36 exceptionState.throwDOMException( | 36 exceptionState.throwDOMException( |
| 37 NotSupportedError, | 37 NotSupportedError, |
| 38 ExceptionMessages::indexExceedsMaximumBound( | 38 ExceptionMessages::indexExceedsMaximumBound( |
| 39 "number of hardware contexts", | 39 "number of hardware contexts", |
| 40 s_hardwareContextCount, | 40 s_hardwareContextCount, |
| 41 MaxHardwareContexts)); | 41 MaxHardwareContexts)); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } | 95 } |
| 96 | 96 |
| 97 DEFINE_TRACE(AudioContext) | 97 DEFINE_TRACE(AudioContext) |
| 98 { | 98 { |
| 99 visitor->trace(m_closeResolver); | 99 visitor->trace(m_closeResolver); |
| 100 BaseAudioContext::trace(visitor); | 100 BaseAudioContext::trace(visitor); |
| 101 } | 101 } |
| 102 | 102 |
| 103 ScriptPromise AudioContext::suspendContext(ScriptState* scriptState) | 103 ScriptPromise AudioContext::suspendContext(ScriptState* scriptState) |
| 104 { | 104 { |
| 105 ASSERT(isMainThread()); | 105 DCHECK(isMainThread()); |
| 106 AutoLocker locker(this); | 106 AutoLocker locker(this); |
| 107 | 107 |
| 108 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 108 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 109 ScriptPromise promise = resolver->promise(); | 109 ScriptPromise promise = resolver->promise(); |
| 110 | 110 |
| 111 if (contextState() == Closed) { | 111 if (contextState() == Closed) { |
| 112 resolver->reject( | 112 resolver->reject( |
| 113 DOMException::create(InvalidStateError, "Cannot suspend a context th
at has been closed")); | 113 DOMException::create(InvalidStateError, "Cannot suspend a context th
at has been closed")); |
| 114 } else { | 114 } else { |
| 115 // Stop rendering now. | 115 // Stop rendering now. |
| 116 if (destination()) | 116 if (destination()) |
| 117 stopRendering(); | 117 stopRendering(); |
| 118 | 118 |
| 119 // Since we don't have any way of knowing when the hardware actually sto
ps, we'll just | 119 // Since we don't have any way of knowing when the hardware actually sto
ps, we'll just |
| 120 // resolve the promise now. | 120 // resolve the promise now. |
| 121 resolver->resolve(); | 121 resolver->resolve(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 return promise; | 124 return promise; |
| 125 } | 125 } |
| 126 | 126 |
| 127 ScriptPromise AudioContext::resumeContext(ScriptState* scriptState) | 127 ScriptPromise AudioContext::resumeContext(ScriptState* scriptState) |
| 128 { | 128 { |
| 129 ASSERT(isMainThread()); | 129 DCHECK(isMainThread()); |
| 130 | 130 |
| 131 if (isContextClosed()) { | 131 if (isContextClosed()) { |
| 132 return ScriptPromise::rejectWithDOMException( | 132 return ScriptPromise::rejectWithDOMException( |
| 133 scriptState, | 133 scriptState, |
| 134 DOMException::create( | 134 DOMException::create( |
| 135 InvalidAccessError, | 135 InvalidAccessError, |
| 136 "cannot resume a closed AudioContext")); | 136 "cannot resume a closed AudioContext")); |
| 137 } | 137 } |
| 138 | 138 |
| 139 recordUserGestureState(); | 139 recordUserGestureState(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 180 |
| 181 return promise; | 181 return promise; |
| 182 } | 182 } |
| 183 | 183 |
| 184 void AudioContext::didClose() | 184 void AudioContext::didClose() |
| 185 { | 185 { |
| 186 // This is specific to AudioContexts. OfflineAudioContexts | 186 // This is specific to AudioContexts. OfflineAudioContexts |
| 187 // are closed in their completion event. | 187 // are closed in their completion event. |
| 188 setContextState(Closed); | 188 setContextState(Closed); |
| 189 | 189 |
| 190 ASSERT(s_hardwareContextCount); | 190 DCHECK(s_hardwareContextCount); |
| 191 --s_hardwareContextCount; | 191 --s_hardwareContextCount; |
| 192 | 192 |
| 193 if (m_closeResolver) | 193 if (m_closeResolver) |
| 194 m_closeResolver->resolve(); | 194 m_closeResolver->resolve(); |
| 195 } | 195 } |
| 196 | 196 |
| 197 bool AudioContext::isContextClosed() const | 197 bool AudioContext::isContextClosed() const |
| 198 { | 198 { |
| 199 return m_closeResolver || BaseAudioContext::isContextClosed(); | 199 return m_closeResolver || BaseAudioContext::isContextClosed(); |
| 200 } | 200 } |
| 201 | 201 |
| 202 void AudioContext::stopRendering() | 202 void AudioContext::stopRendering() |
| 203 { | 203 { |
| 204 ASSERT(isMainThread()); | 204 DCHECK(isMainThread()); |
| 205 ASSERT(destination()); | 205 DCHECK(destination()); |
| 206 | 206 |
| 207 if (contextState() == Running) { | 207 if (contextState() == Running) { |
| 208 destination()->audioDestinationHandler().stopRendering(); | 208 destination()->audioDestinationHandler().stopRendering(); |
| 209 setContextState(Suspended); | 209 setContextState(Suspended); |
| 210 deferredTaskHandler().clearHandlersToBeDeleted(); | 210 deferredTaskHandler().clearHandlersToBeDeleted(); |
| 211 } | 211 } |
| 212 } | 212 } |
| 213 | 213 |
| 214 } // namespace blink | 214 } // namespace blink |
| OLD | NEW |