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/SetSinkIdCallbacks.h" | |
| 11 #include "platform/Logging.h" | 12 #include "platform/Logging.h" |
| 12 | 13 |
| 13 namespace blink { | 14 namespace blink { |
| 14 | 15 |
| 15 HTMLMediaElementAudioOutputDevice::HTMLMediaElementAudioOutputDevice() | 16 HTMLMediaElementAudioOutputDevice::HTMLMediaElementAudioOutputDevice() |
| 16 : m_sinkId("") | 17 : m_sinkId("") |
| 17 { | 18 { |
| 18 } | 19 } |
| 19 | 20 |
| 20 String HTMLMediaElementAudioOutputDevice::sinkId(HTMLMediaElement& element) | 21 String HTMLMediaElementAudioOutputDevice::sinkId(HTMLMediaElement& element) |
| 21 { | 22 { |
| 22 WTF_LOG(Media, __FUNCTION__); | 23 WTF_LOG(Media, __FUNCTION__); |
| 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 ScriptPromise HTMLMediaElementAudioOutputDevice::setSinkId(ScriptState* scriptSt ate, HTMLMediaElement& element, const String& newSinkId) | 28 void HTMLMediaElementAudioOutputDevice::setSinkId(const String& sinkId) |
| 29 { | |
| 30 m_sinkId = sinkId; | |
| 31 } | |
| 32 | |
| 33 ScriptPromise HTMLMediaElementAudioOutputDevice::setSinkId(ScriptState* scriptSt ate, HTMLMediaElement& element, const String& sinkId) | |
| 28 { | 34 { |
| 29 WTF_LOG(Media, __FUNCTION__); | 35 WTF_LOG(Media, __FUNCTION__); |
| 30 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(NotSupportedError, "Operation not supported")); | 36 WebMediaPlayer* webMediaPlayer = element.webMediaPlayer(); |
| 37 if (!webMediaPlayer) | |
| 38 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(AbortError, "No media player available")); | |
|
Peter Beverloo
2015/06/18 14:33:15
As in the other CL - should this be an ASSERT()?
Guido Urdaneta
2015/06/18 23:09:05
In this case the check is valid.
For empty media e
| |
| 39 | |
| 40 RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver:: create(scriptState); | |
| 41 HTMLMediaElementAudioOutputDevice& aodElement = HTMLMediaElementAudioOutputD evice::from(element); | |
| 42 if (sinkId == aodElement.m_sinkId) | |
| 43 resolver->resolve(); | |
| 44 else | |
| 45 webMediaPlayer->setSinkId(sinkId, new SetSinkIdCallbacks(resolver, eleme nt, sinkId)); | |
| 46 | |
| 47 return resolver->promise(); | |
| 31 } | 48 } |
| 32 | 49 |
| 33 const char* HTMLMediaElementAudioOutputDevice::supplementName() | 50 const char* HTMLMediaElementAudioOutputDevice::supplementName() |
| 34 { | 51 { |
| 35 return "HTMLMediaElementAudioOutputDevice"; | 52 return "HTMLMediaElementAudioOutputDevice"; |
| 36 } | 53 } |
| 37 | 54 |
| 38 HTMLMediaElementAudioOutputDevice& HTMLMediaElementAudioOutputDevice::from(HTMLM ediaElement& element) | 55 HTMLMediaElementAudioOutputDevice& HTMLMediaElementAudioOutputDevice::from(HTMLM ediaElement& element) |
| 39 { | 56 { |
| 40 HTMLMediaElementAudioOutputDevice* supplement = static_cast<HTMLMediaElement AudioOutputDevice*>(WillBeHeapSupplement<HTMLMediaElement>::from(element, supple mentName())); | 57 HTMLMediaElementAudioOutputDevice* supplement = static_cast<HTMLMediaElement AudioOutputDevice*>(WillBeHeapSupplement<HTMLMediaElement>::from(element, supple mentName())); |
| 41 if (!supplement) { | 58 if (!supplement) { |
| 42 supplement = new HTMLMediaElementAudioOutputDevice(); | 59 supplement = new HTMLMediaElementAudioOutputDevice(); |
| 43 provideTo(element, supplementName(), adoptPtrWillBeNoop(supplement)); | 60 provideTo(element, supplementName(), adoptPtrWillBeNoop(supplement)); |
| 44 } | 61 } |
| 45 return *supplement; | 62 return *supplement; |
| 46 } | 63 } |
| 47 | 64 |
| 48 DEFINE_TRACE(HTMLMediaElementAudioOutputDevice) | 65 DEFINE_TRACE(HTMLMediaElementAudioOutputDevice) |
| 49 { | 66 { |
| 50 WillBeHeapSupplement<HTMLMediaElement>::trace(visitor); | 67 WillBeHeapSupplement<HTMLMediaElement>::trace(visitor); |
| 51 } | 68 } |
| 52 | 69 |
| 53 } // namespace blink | 70 } // namespace blink |
| OLD | NEW |