Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: third_party/WebKit/Source/modules/audio_output_devices/HTMLMediaElementAudioOutputDevice.cpp

Issue 1416123005: Implement setSinkId() for media elements without src. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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);
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 ScriptPromise promise = resolver->promise();
40 ExecutionContext* context = scriptState->executionContext(); 41 ExecutionContext* context = scriptState->executionContext();
41 ASSERT(context && context->isDocument()); 42 ASSERT(context && context->isDocument());
42 43
43 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 44 if (webMediaPlayer) {
44 webMediaPlayer->setSinkId(sinkId, WebSecurityOrigin(context->securityOrigin( )), new SetSinkIdCallbacks(resolver, element, sinkId)); 45 webMediaPlayer->setSinkId(sinkId, WebSecurityOrigin(context->securityOri gin()), callbacks.leakPtr());
46 } else {
47 if (AudioOutputDeviceClient* client = AudioOutputDeviceClient::from(cont ext)) {
48 client->checkAudioSink(context, sinkId, callbacks.release());
49 } else {
50 // The context has been detached. The promise will never settle.
51 ASSERT(context->activeDOMObjectsAreStopped());
52 }
53 }
54
45 return resolver->promise(); 55 return resolver->promise();
46 } 56 }
47 57
48 const char* HTMLMediaElementAudioOutputDevice::supplementName() 58 const char* HTMLMediaElementAudioOutputDevice::supplementName()
49 { 59 {
50 return "HTMLMediaElementAudioOutputDevice"; 60 return "HTMLMediaElementAudioOutputDevice";
51 } 61 }
52 62
53 HTMLMediaElementAudioOutputDevice& HTMLMediaElementAudioOutputDevice::from(HTMLM ediaElement& element) 63 HTMLMediaElementAudioOutputDevice& HTMLMediaElementAudioOutputDevice::from(HTMLM ediaElement& element)
54 { 64 {
55 HTMLMediaElementAudioOutputDevice* supplement = static_cast<HTMLMediaElement AudioOutputDevice*>(WillBeHeapSupplement<HTMLMediaElement>::from(element, supple mentName())); 65 HTMLMediaElementAudioOutputDevice* supplement = static_cast<HTMLMediaElement AudioOutputDevice*>(WillBeHeapSupplement<HTMLMediaElement>::from(element, supple mentName()));
56 if (!supplement) { 66 if (!supplement) {
57 supplement = new HTMLMediaElementAudioOutputDevice(); 67 supplement = new HTMLMediaElementAudioOutputDevice();
58 provideTo(element, supplementName(), adoptPtrWillBeNoop(supplement)); 68 provideTo(element, supplementName(), adoptPtrWillBeNoop(supplement));
59 } 69 }
60 return *supplement; 70 return *supplement;
61 } 71 }
62 72
63 DEFINE_TRACE(HTMLMediaElementAudioOutputDevice) 73 DEFINE_TRACE(HTMLMediaElementAudioOutputDevice)
64 { 74 {
65 WillBeHeapSupplement<HTMLMediaElement>::trace(visitor); 75 WillBeHeapSupplement<HTMLMediaElement>::trace(visitor);
66 } 76 }
67 77
68 } // namespace blink 78 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698