Chromium Code Reviews| 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 "config.h" | 5 #include "config.h" |
| 6 #include "modules/audio_output_devices/HTMLMediaElementAudioOutputDevice.h" | 6 #include "modules/audio_output_devices/HTMLMediaElementAudioOutputDevice.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
| 10 #include "core/dom/ExecutionContext.h" | 10 #include "core/dom/ExecutionContext.h" |
| 11 #include "modules/audio_output_devices/AudioOutputDeviceClient.h" | |
| 11 #include "modules/audio_output_devices/SetSinkIdCallbacks.h" | 12 #include "modules/audio_output_devices/SetSinkIdCallbacks.h" |
| 12 #include "public/platform/WebSecurityOrigin.h" | 13 #include "public/platform/WebSecurityOrigin.h" |
| 13 | 14 |
| 14 namespace blink { | 15 namespace blink { |
| 15 | 16 |
| 16 HTMLMediaElementAudioOutputDevice::HTMLMediaElementAudioOutputDevice() | 17 HTMLMediaElementAudioOutputDevice::HTMLMediaElementAudioOutputDevice() |
| 17 : m_sinkId("") | 18 : m_sinkId("") |
| 18 { | 19 { |
| 19 } | 20 } |
| 20 | 21 |
| 21 String HTMLMediaElementAudioOutputDevice::sinkId(HTMLMediaElement& element) | 22 String HTMLMediaElementAudioOutputDevice::sinkId(HTMLMediaElement& element) |
| 22 { | 23 { |
| 23 HTMLMediaElementAudioOutputDevice& aodElement = HTMLMediaElementAudioOutputD evice::from(element); | 24 HTMLMediaElementAudioOutputDevice& aodElement = HTMLMediaElementAudioOutputD evice::from(element); |
| 24 return aodElement.m_sinkId; | 25 return aodElement.m_sinkId; |
| 25 } | 26 } |
| 26 | 27 |
| 27 void HTMLMediaElementAudioOutputDevice::setSinkId(const String& sinkId) | 28 void HTMLMediaElementAudioOutputDevice::setSinkId(const String& sinkId) |
| 28 { | 29 { |
| 29 m_sinkId = sinkId; | 30 m_sinkId = sinkId; |
| 30 } | 31 } |
| 31 | 32 |
| 32 ScriptPromise HTMLMediaElementAudioOutputDevice::setSinkId(ScriptState* scriptSt ate, HTMLMediaElement& element, const String& sinkId) | 33 ScriptPromise HTMLMediaElementAudioOutputDevice::setSinkId(ScriptState* scriptSt ate, HTMLMediaElement& element, const String& sinkId) |
| 33 { | 34 { |
| 34 ASSERT(scriptState); | 35 ASSERT(scriptState); |
|
Peter Beverloo
2015/11/09 20:05:06
note: We seem to be missing step 1 of the algorith
Guido Urdaneta
2015/11/10 15:36:51
Done.
| |
| 35 | 36 |
| 36 WebMediaPlayer* webMediaPlayer = element.webMediaPlayer(); | 37 WebMediaPlayer* webMediaPlayer = element.webMediaPlayer(); |
| 37 if (!webMediaPlayer) | 38 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; |
| 38 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(AbortError, "No media player available")); | 39 OwnPtr<SetSinkIdCallbacks> callbacks = adoptPtr(new SetSinkIdCallbacks(resol ver, element, sinkId)); |
| 39 | |
| 40 ExecutionContext* context = scriptState->executionContext(); | 40 ExecutionContext* context = scriptState->executionContext(); |
| 41 ASSERT(context && context->isDocument()); | 41 ASSERT(context && context->isDocument()); |
| 42 | 42 |
| 43 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | 43 if (webMediaPlayer) { |
| 44 webMediaPlayer->setSinkId(sinkId, WebSecurityOrigin(context->securityOrigin( )), new SetSinkIdCallbacks(resolver, element, sinkId)); | 44 // Using leakPtr() to transfer ownership because |webMediaPlayer| is a p latform object that takes raw pointers |
| 45 webMediaPlayer->setSinkId(sinkId, WebSecurityOrigin(context->securityOri gin()), callbacks.leakPtr()); | |
| 46 } else { | |
| 47 if (AudioOutputDeviceClient* client = AudioOutputDeviceClient::from(cont ext)) { | |
| 48 client->checkIfAudioSinkExistsAndIsAuthorized(context, sinkId, callb acks.release()); | |
| 49 } else { | |
| 50 // The context has been detached. Impossible to get a security origi n to check. | |
| 51 ASSERT(context->activeDOMObjectsAreStopped()); | |
| 52 resolver->reject(); | |
|
Peter Beverloo
2015/11/09 20:05:06
nit: why not reject the resolver with the dom erro
Guido Urdaneta
2015/11/10 15:36:51
Done. Note that the implementation is slightly dif
| |
| 53 return ScriptPromise::rejectWithDOMException(scriptState, DOMExcept ion::create(SecurityError, "Impossible to authorize device for detached context" )); | |
| 54 } | |
| 55 } | |
| 56 | |
| 45 return resolver->promise(); | 57 return resolver->promise(); |
| 46 } | 58 } |
| 47 | 59 |
| 48 const char* HTMLMediaElementAudioOutputDevice::supplementName() | 60 const char* HTMLMediaElementAudioOutputDevice::supplementName() |
| 49 { | 61 { |
| 50 return "HTMLMediaElementAudioOutputDevice"; | 62 return "HTMLMediaElementAudioOutputDevice"; |
| 51 } | 63 } |
| 52 | 64 |
| 53 HTMLMediaElementAudioOutputDevice& HTMLMediaElementAudioOutputDevice::from(HTMLM ediaElement& element) | 65 HTMLMediaElementAudioOutputDevice& HTMLMediaElementAudioOutputDevice::from(HTMLM ediaElement& element) |
| 54 { | 66 { |
| 55 HTMLMediaElementAudioOutputDevice* supplement = static_cast<HTMLMediaElement AudioOutputDevice*>(WillBeHeapSupplement<HTMLMediaElement>::from(element, supple mentName())); | 67 HTMLMediaElementAudioOutputDevice* supplement = static_cast<HTMLMediaElement AudioOutputDevice*>(WillBeHeapSupplement<HTMLMediaElement>::from(element, supple mentName())); |
| 56 if (!supplement) { | 68 if (!supplement) { |
| 57 supplement = new HTMLMediaElementAudioOutputDevice(); | 69 supplement = new HTMLMediaElementAudioOutputDevice(); |
| 58 provideTo(element, supplementName(), adoptPtrWillBeNoop(supplement)); | 70 provideTo(element, supplementName(), adoptPtrWillBeNoop(supplement)); |
| 59 } | 71 } |
| 60 return *supplement; | 72 return *supplement; |
| 61 } | 73 } |
| 62 | 74 |
| 63 DEFINE_TRACE(HTMLMediaElementAudioOutputDevice) | 75 DEFINE_TRACE(HTMLMediaElementAudioOutputDevice) |
| 64 { | 76 { |
| 65 WillBeHeapSupplement<HTMLMediaElement>::trace(visitor); | 77 WillBeHeapSupplement<HTMLMediaElement>::trace(visitor); |
| 66 } | 78 } |
| 67 | 79 |
| 68 } // namespace blink | 80 } // namespace blink |
| OLD | NEW |