| 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/mediasession/MediaSession.h" | 5 #include "modules/mediasession/MediaSession.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 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/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 MediaSession::MediaSession(std::unique_ptr<WebMediaSession> webMediaSession) | 21 MediaSession::MediaSession(std::unique_ptr<WebMediaSession> webMediaSession) |
| 22 : m_webMediaSession(std::move(webMediaSession)) | 22 : m_webMediaSession(std::move(webMediaSession)) |
| 23 { | 23 { |
| 24 DCHECK(m_webMediaSession); | 24 DCHECK(m_webMediaSession); |
| 25 } | 25 } |
| 26 | 26 |
| 27 MediaSession* MediaSession::create(ExecutionContext* context, ExceptionState& ex
ceptionState) | 27 MediaSession* MediaSession::create(ExecutionContext* context, ExceptionState& ex
ceptionState) |
| 28 { | 28 { |
| 29 Document* document = toDocument(context); | 29 Document* document = toDocument(context); |
| 30 LocalFrame* frame = document->frame(); | 30 LocalFrame* frame = document->frame(); |
| 31 return create(frame, exceptionState); |
| 32 } |
| 33 |
| 34 MediaSession* MediaSession::create(LocalFrame* frame, ExceptionState& exceptionS
tate) |
| 35 { |
| 31 FrameLoaderClient* client = frame->loader().client(); | 36 FrameLoaderClient* client = frame->loader().client(); |
| 32 std::unique_ptr<WebMediaSession> webMediaSession = client->createWebMediaSes
sion(); | 37 std::unique_ptr<WebMediaSession> webMediaSession = client->createWebMediaSes
sion(); |
| 33 if (!webMediaSession) { | 38 if (!webMediaSession) { |
| 34 exceptionState.throwDOMException(NotSupportedError, "Missing platform im
plementation."); | 39 exceptionState.throwDOMException(NotSupportedError, "Missing platform im
plementation."); |
| 35 return nullptr; | 40 return nullptr; |
| 36 } | 41 } |
| 37 return new MediaSession(std::move(webMediaSession)); | 42 return new MediaSession(std::move(webMediaSession)); |
| 38 } | 43 } |
| 39 | 44 |
| 40 ScriptPromise MediaSession::activate(ScriptState* scriptState) | 45 ScriptPromise MediaSession::activate(ScriptState* scriptState) |
| 41 { | 46 { |
| 42 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 47 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 43 ScriptPromise promise = resolver->promise(); | 48 ScriptPromise promise = resolver->promise(); |
| 44 | 49 |
| 45 m_webMediaSession->activate(new CallbackPromiseAdapter<void, MediaSessionErr
or>(resolver)); | 50 m_webMediaSession->activate(new CallbackPromiseAdapter<void, MediaSessionErr
or>(resolver)); |
| 51 |
| 46 return promise; | 52 return promise; |
| 47 } | 53 } |
| 48 | 54 |
| 49 ScriptPromise MediaSession::deactivate(ScriptState* scriptState) | 55 ScriptPromise MediaSession::deactivate(ScriptState* scriptState) |
| 50 { | 56 { |
| 51 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 57 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 52 ScriptPromise promise = resolver->promise(); | 58 ScriptPromise promise = resolver->promise(); |
| 53 | 59 |
| 54 m_webMediaSession->deactivate(new CallbackPromiseAdapter<void, void>(resolve
r)); | 60 m_webMediaSession->deactivate(new CallbackPromiseAdapter<void, void>(resolve
r)); |
| 55 return promise; | 61 return promise; |
| 56 } | 62 } |
| 57 | 63 |
| 58 void MediaSession::setMetadata(MediaMetadata* metadata) | 64 void MediaSession::setMetadata(MediaMetadata* metadata) |
| 59 { | 65 { |
| 60 m_metadata = metadata; | 66 m_metadata = metadata; |
| 67 |
| 61 if (metadata) { | 68 if (metadata) { |
| 62 WebMediaMetadata webMetadata = (WebMediaMetadata) *metadata; | 69 WebMediaMetadata webMetadata = (WebMediaMetadata) *metadata; |
| 63 m_webMediaSession->setMetadata(&webMetadata); | 70 m_webMediaSession->setMetadata(&webMetadata); |
| 64 } else { | 71 } else { |
| 65 m_webMediaSession->setMetadata(nullptr); | 72 m_webMediaSession->setMetadata(nullptr); |
| 66 } | 73 } |
| 67 } | 74 } |
| 68 | 75 |
| 69 MediaMetadata* MediaSession::metadata() const | 76 MediaMetadata* MediaSession::metadata() const |
| 70 { | 77 { |
| 71 return m_metadata; | 78 return m_metadata; |
| 72 } | 79 } |
| 73 | 80 |
| 74 DEFINE_TRACE(MediaSession) | 81 DEFINE_TRACE(MediaSession) |
| 75 { | 82 { |
| 76 visitor->trace(m_metadata); | 83 visitor->trace(m_metadata); |
| 77 } | 84 } |
| 78 | 85 |
| 79 } // namespace blink | 86 } // namespace blink |
| OLD | NEW |