| 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 "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/dom/DocumentUserGestureToken.h" | 8 #include "core/dom/DocumentUserGestureToken.h" |
| 9 #include "core/dom/ExecutionContext.h" | 9 #include "core/dom/ExecutionContext.h" |
| 10 #include "core/events/Event.h" | 10 #include "core/events/Event.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 | 73 |
| 74 MediaSession* MediaSession::create(ExecutionContext* executionContext) { | 74 MediaSession* MediaSession::create(ExecutionContext* executionContext) { |
| 75 return new MediaSession(executionContext); | 75 return new MediaSession(executionContext); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void MediaSession::dispose() { | 78 void MediaSession::dispose() { |
| 79 m_clientBinding.Close(); | 79 m_clientBinding.Close(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void MediaSession::setMetadata(MediaMetadata* metadata) { | 82 void MediaSession::setMetadata(MediaMetadata* metadata) { |
| 83 if (mojom::blink::MediaSessionService* service = getService()) { | 83 if (metadata) |
| 84 service->SetMetadata(MediaMetadataSanitizer::sanitizeAndConvertToMojo( | 84 metadata->setSession(this); |
| 85 metadata, getExecutionContext())); | 85 |
| 86 } | 86 if (m_metadata) |
| 87 m_metadata->setSession(nullptr); |
| 88 |
| 89 m_metadata = metadata; |
| 90 onMetadataChanged(); |
| 87 } | 91 } |
| 88 | 92 |
| 89 MediaMetadata* MediaSession::metadata() const { | 93 MediaMetadata* MediaSession::metadata() const { |
| 90 return m_metadata; | 94 return m_metadata; |
| 91 } | 95 } |
| 92 | 96 |
| 97 void MediaSession::onMetadataChanged() { |
| 98 mojom::blink::MediaSessionService* service = getService(); |
| 99 if (!service) |
| 100 return; |
| 101 |
| 102 service->SetMetadata(MediaMetadataSanitizer::sanitizeAndConvertToMojo( |
| 103 m_metadata, getExecutionContext())); |
| 104 } |
| 105 |
| 93 const WTF::AtomicString& MediaSession::interfaceName() const { | 106 const WTF::AtomicString& MediaSession::interfaceName() const { |
| 94 return EventTargetNames::MediaSession; | 107 return EventTargetNames::MediaSession; |
| 95 } | 108 } |
| 96 | 109 |
| 97 ExecutionContext* MediaSession::getExecutionContext() const { | 110 ExecutionContext* MediaSession::getExecutionContext() const { |
| 98 return ContextLifecycleObserver::getExecutionContext(); | 111 return ContextLifecycleObserver::getExecutionContext(); |
| 99 } | 112 } |
| 100 | 113 |
| 101 mojom::blink::MediaSessionService* MediaSession::getService() { | 114 mojom::blink::MediaSessionService* MediaSession::getService() { |
| 102 if (m_service) | 115 if (m_service) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 dispatchEvent(Event::create(mojomActionToEventName(action))); | 167 dispatchEvent(Event::create(mojomActionToEventName(action))); |
| 155 } | 168 } |
| 156 | 169 |
| 157 DEFINE_TRACE(MediaSession) { | 170 DEFINE_TRACE(MediaSession) { |
| 158 visitor->trace(m_metadata); | 171 visitor->trace(m_metadata); |
| 159 EventTargetWithInlineData::trace(visitor); | 172 EventTargetWithInlineData::trace(visitor); |
| 160 ContextLifecycleObserver::trace(visitor); | 173 ContextLifecycleObserver::trace(visitor); |
| 161 } | 174 } |
| 162 | 175 |
| 163 } // namespace blink | 176 } // namespace blink |
| OLD | NEW |