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/audio_output_devices/HTMLMediaElementAudioOutputDevice.h" | 5 #include "modules/audio_output_devices/HTMLMediaElementAudioOutputDevice.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
8 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
9 #include "core/dom/DOMException.h" | 9 #include "core/dom/DOMException.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/AudioOutputDeviceClient.h" |
12 #include "modules/audio_output_devices/SetSinkIdCallbacks.h" | 12 #include "modules/audio_output_devices/SetSinkIdCallbacks.h" |
13 #include "public/platform/WebSecurityOrigin.h" | 13 #include "public/platform/WebSecurityOrigin.h" |
| 14 #include "wtf/PtrUtil.h" |
| 15 #include <memory> |
14 | 16 |
15 namespace blink { | 17 namespace blink { |
16 | 18 |
17 namespace { | 19 namespace { |
18 | 20 |
19 class SetSinkIdResolver : public ScriptPromiseResolver { | 21 class SetSinkIdResolver : public ScriptPromiseResolver { |
20 WTF_MAKE_NONCOPYABLE(SetSinkIdResolver); | 22 WTF_MAKE_NONCOPYABLE(SetSinkIdResolver); |
21 public: | 23 public: |
22 static SetSinkIdResolver* create(ScriptState*, HTMLMediaElement&, const Stri
ng& sinkId); | 24 static SetSinkIdResolver* create(ScriptState*, HTMLMediaElement&, const Stri
ng& sinkId); |
23 ~SetSinkIdResolver() override = default; | 25 ~SetSinkIdResolver() override = default; |
(...skipping 28 matching lines...) Expand all Loading... |
52 | 54 |
53 void SetSinkIdResolver::startAsync() | 55 void SetSinkIdResolver::startAsync() |
54 { | 56 { |
55 m_timer.startOneShot(0, BLINK_FROM_HERE); | 57 m_timer.startOneShot(0, BLINK_FROM_HERE); |
56 } | 58 } |
57 | 59 |
58 void SetSinkIdResolver::timerFired(Timer<SetSinkIdResolver>* timer) | 60 void SetSinkIdResolver::timerFired(Timer<SetSinkIdResolver>* timer) |
59 { | 61 { |
60 ExecutionContext* context = getExecutionContext(); | 62 ExecutionContext* context = getExecutionContext(); |
61 ASSERT(context && context->isDocument()); | 63 ASSERT(context && context->isDocument()); |
62 OwnPtr<SetSinkIdCallbacks> callbacks = adoptPtr(new SetSinkIdCallbacks(this,
*m_element, m_sinkId)); | 64 std::unique_ptr<SetSinkIdCallbacks> callbacks = wrapUnique(new SetSinkIdCall
backs(this, *m_element, m_sinkId)); |
63 WebMediaPlayer* webMediaPlayer = m_element->webMediaPlayer(); | 65 WebMediaPlayer* webMediaPlayer = m_element->webMediaPlayer(); |
64 if (webMediaPlayer) { | 66 if (webMediaPlayer) { |
65 // Using leakPtr() to transfer ownership because |webMediaPlayer| is a p
latform object that takes raw pointers | 67 // Using release() to transfer ownership because |webMediaPlayer| is a p
latform object that takes raw pointers |
66 webMediaPlayer->setSinkId(m_sinkId, WebSecurityOrigin(context->getSecuri
tyOrigin()), callbacks.leakPtr()); | 68 webMediaPlayer->setSinkId(m_sinkId, WebSecurityOrigin(context->getSecuri
tyOrigin()), callbacks.release()); |
67 } else { | 69 } else { |
68 if (AudioOutputDeviceClient* client = AudioOutputDeviceClient::from(cont
ext)) { | 70 if (AudioOutputDeviceClient* client = AudioOutputDeviceClient::from(cont
ext)) { |
69 client->checkIfAudioSinkExistsAndIsAuthorized(context, m_sinkId, std
::move(callbacks)); | 71 client->checkIfAudioSinkExistsAndIsAuthorized(context, m_sinkId, std
::move(callbacks)); |
70 } else { | 72 } else { |
71 // The context has been detached. Impossible to get a security origi
n to check. | 73 // The context has been detached. Impossible to get a security origi
n to check. |
72 ASSERT(context->activeDOMObjectsAreStopped()); | 74 ASSERT(context->activeDOMObjectsAreStopped()); |
73 reject(DOMException::create(SecurityError, "Impossible to authorize
device for detached context")); | 75 reject(DOMException::create(SecurityError, "Impossible to authorize
device for detached context")); |
74 } | 76 } |
75 } | 77 } |
76 } | 78 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 } | 127 } |
126 return *supplement; | 128 return *supplement; |
127 } | 129 } |
128 | 130 |
129 DEFINE_TRACE(HTMLMediaElementAudioOutputDevice) | 131 DEFINE_TRACE(HTMLMediaElementAudioOutputDevice) |
130 { | 132 { |
131 Supplement<HTMLMediaElement>::trace(visitor); | 133 Supplement<HTMLMediaElement>::trace(visitor); |
132 } | 134 } |
133 | 135 |
134 } // namespace blink | 136 } // namespace blink |
OLD | NEW |