Chromium Code Reviews| Index: third_party/WebKit/Source/modules/mediasession/MediaSession.cpp |
| diff --git a/third_party/WebKit/Source/modules/mediasession/MediaSession.cpp b/third_party/WebKit/Source/modules/mediasession/MediaSession.cpp |
| index b723323b95aebfa0441d76589fd913e89b82099c..29e69d142da2e08dbf8e493dfbe59054b3940173 100644 |
| --- a/third_party/WebKit/Source/modules/mediasession/MediaSession.cpp |
| +++ b/third_party/WebKit/Source/modules/mediasession/MediaSession.cpp |
| @@ -66,10 +66,41 @@ WTF::Optional<MediaSessionAction> eventNameToMojomAction( |
| return WTF::nullopt; |
| } |
| +const AtomicString& mediaSessionPlaybackStateToString( |
| + mojom::blink::MediaSessionPlaybackState state) { |
| + DEFINE_STATIC_LOCAL(const AtomicString, noneValue, ("none")); |
| + DEFINE_STATIC_LOCAL(const AtomicString, pausedValue, ("paused")); |
| + DEFINE_STATIC_LOCAL(const AtomicString, playingValue, ("playing")); |
| + |
| + switch (state) { |
| + case mojom::blink::MediaSessionPlaybackState::NONE: |
| + return noneValue; |
| + case mojom::blink::MediaSessionPlaybackState::PAUSED: |
| + return pausedValue; |
| + case mojom::blink::MediaSessionPlaybackState::PLAYING: |
| + return playingValue; |
| + default: |
| + 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.
|
| + } |
| + return WTF::emptyAtom; |
|
mlamouri (slow - plz ping)
2016/12/16 15:49:14
NOTREACHED()?
Zhiqiang Zhang (Slow)
2016/12/16 18:26:15
Done.
|
| +} |
| + |
| +mojom::blink::MediaSessionPlaybackState stringToMediaSessionPlaybackState( |
| + const String& stateName) { |
| + if (stateName == "none") |
| + return mojom::blink::MediaSessionPlaybackState::NONE; |
| + if (stateName == "paused") |
| + return mojom::blink::MediaSessionPlaybackState::PAUSED; |
| + DCHECK_EQ(stateName, "playing"); |
| + return mojom::blink::MediaSessionPlaybackState::PLAYING; |
| +} |
| + |
| } // anonymous namespace |
| MediaSession::MediaSession(ExecutionContext* executionContext) |
| - : ContextLifecycleObserver(executionContext), m_clientBinding(this) {} |
| + : ContextLifecycleObserver(executionContext), |
| + m_playbackState(mojom::blink::MediaSessionPlaybackState::NONE), |
| + m_clientBinding(this) {} |
| MediaSession* MediaSession::create(ExecutionContext* executionContext) { |
| return new MediaSession(executionContext); |
| @@ -79,6 +110,17 @@ void MediaSession::dispose() { |
| m_clientBinding.Close(); |
| } |
| +void MediaSession::setPlaybackState(const String& playbackState) { |
| + m_playbackState = stringToMediaSessionPlaybackState(playbackState); |
| + mojom::blink::MediaSessionService* service = getService(); |
| + if (service) |
| + service->SetPlaybackState(m_playbackState); |
| +} |
| + |
| +String MediaSession::playbackState() { |
| + return mediaSessionPlaybackStateToString(m_playbackState); |
| +} |
| + |
| void MediaSession::setMetadata(MediaMetadata* metadata) { |
| if (mojom::blink::MediaSessionService* service = getService()) { |
| service->SetMetadata(MediaMetadataSanitizer::sanitizeAndConvertToMojo( |