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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
59 return MediaSessionAction::NEXT_TRACK; | 59 return MediaSessionAction::NEXT_TRACK; |
60 if (EventTypeNames::seekbackward == eventName) | 60 if (EventTypeNames::seekbackward == eventName) |
61 return MediaSessionAction::SEEK_BACKWARD; | 61 return MediaSessionAction::SEEK_BACKWARD; |
62 if (EventTypeNames::seekforward == eventName) | 62 if (EventTypeNames::seekforward == eventName) |
63 return MediaSessionAction::SEEK_FORWARD; | 63 return MediaSessionAction::SEEK_FORWARD; |
64 | 64 |
65 NOTREACHED(); | 65 NOTREACHED(); |
66 return WTF::nullopt; | 66 return WTF::nullopt; |
67 } | 67 } |
68 | 68 |
69 const AtomicString& mediaSessionPlaybackStateToString( | |
70 mojom::blink::MediaSessionPlaybackState state) { | |
71 DEFINE_STATIC_LOCAL(const AtomicString, noneValue, ("none")); | |
72 DEFINE_STATIC_LOCAL(const AtomicString, pausedValue, ("paused")); | |
73 DEFINE_STATIC_LOCAL(const AtomicString, playingValue, ("playing")); | |
74 | |
75 switch (state) { | |
76 case mojom::blink::MediaSessionPlaybackState::NONE: | |
77 return noneValue; | |
78 case mojom::blink::MediaSessionPlaybackState::PAUSED: | |
79 return pausedValue; | |
80 case mojom::blink::MediaSessionPlaybackState::PLAYING: | |
81 return playingValue; | |
82 default: | |
83 NOTREACHED(); | |
mlamouri (slow - plz ping)
2016/12/16 15:49:14
No need for `default`, it will not compile if we a
Zhiqiang Zhang (Slow)
2016/12/16 18:26:15
Done.
| |
84 } | |
85 return WTF::emptyAtom; | |
mlamouri (slow - plz ping)
2016/12/16 15:49:14
NOTREACHED()?
Zhiqiang Zhang (Slow)
2016/12/16 18:26:15
Done.
| |
86 } | |
87 | |
88 mojom::blink::MediaSessionPlaybackState stringToMediaSessionPlaybackState( | |
89 const String& stateName) { | |
90 if (stateName == "none") | |
91 return mojom::blink::MediaSessionPlaybackState::NONE; | |
92 if (stateName == "paused") | |
93 return mojom::blink::MediaSessionPlaybackState::PAUSED; | |
94 DCHECK_EQ(stateName, "playing"); | |
95 return mojom::blink::MediaSessionPlaybackState::PLAYING; | |
96 } | |
97 | |
69 } // anonymous namespace | 98 } // anonymous namespace |
70 | 99 |
71 MediaSession::MediaSession(ExecutionContext* executionContext) | 100 MediaSession::MediaSession(ExecutionContext* executionContext) |
72 : ContextLifecycleObserver(executionContext), m_clientBinding(this) {} | 101 : ContextLifecycleObserver(executionContext), |
102 m_playbackState(mojom::blink::MediaSessionPlaybackState::NONE), | |
103 m_clientBinding(this) {} | |
73 | 104 |
74 MediaSession* MediaSession::create(ExecutionContext* executionContext) { | 105 MediaSession* MediaSession::create(ExecutionContext* executionContext) { |
75 return new MediaSession(executionContext); | 106 return new MediaSession(executionContext); |
76 } | 107 } |
77 | 108 |
78 void MediaSession::dispose() { | 109 void MediaSession::dispose() { |
79 m_clientBinding.Close(); | 110 m_clientBinding.Close(); |
80 } | 111 } |
81 | 112 |
113 void MediaSession::setPlaybackState(const String& playbackState) { | |
114 m_playbackState = stringToMediaSessionPlaybackState(playbackState); | |
115 mojom::blink::MediaSessionService* service = getService(); | |
116 if (service) | |
117 service->SetPlaybackState(m_playbackState); | |
118 } | |
119 | |
120 String MediaSession::playbackState() { | |
121 return mediaSessionPlaybackStateToString(m_playbackState); | |
122 } | |
123 | |
82 void MediaSession::setMetadata(MediaMetadata* metadata) { | 124 void MediaSession::setMetadata(MediaMetadata* metadata) { |
83 if (mojom::blink::MediaSessionService* service = getService()) { | 125 if (mojom::blink::MediaSessionService* service = getService()) { |
84 service->SetMetadata(MediaMetadataSanitizer::sanitizeAndConvertToMojo( | 126 service->SetMetadata(MediaMetadataSanitizer::sanitizeAndConvertToMojo( |
85 metadata, getExecutionContext())); | 127 metadata, getExecutionContext())); |
86 } | 128 } |
87 } | 129 } |
88 | 130 |
89 MediaMetadata* MediaSession::metadata() const { | 131 MediaMetadata* MediaSession::metadata() const { |
90 return m_metadata; | 132 return m_metadata; |
91 } | 133 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 dispatchEvent(Event::create(mojomActionToEventName(action))); | 196 dispatchEvent(Event::create(mojomActionToEventName(action))); |
155 } | 197 } |
156 | 198 |
157 DEFINE_TRACE(MediaSession) { | 199 DEFINE_TRACE(MediaSession) { |
158 visitor->trace(m_metadata); | 200 visitor->trace(m_metadata); |
159 EventTargetWithInlineData::trace(visitor); | 201 EventTargetWithInlineData::trace(visitor); |
160 ContextLifecycleObserver::trace(visitor); | 202 ContextLifecycleObserver::trace(visitor); |
161 } | 203 } |
162 | 204 |
163 } // namespace blink | 205 } // namespace blink |
OLD | NEW |