Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/media/android/media_session_service_impl.h" | |
| 6 | |
| 7 #include "base/strings/utf_string_conversions.h" | |
| 8 #include "content/browser/media/android/browser_media_session_manager.h" | |
| 9 #include "content/browser/media/android/media_web_contents_observer_android.h" | |
| 10 #include "content/browser/web_contents/web_contents_impl.h" | |
| 11 #include "content/public/browser/browser_thread.h" | |
| 12 #include "content/public/browser/web_contents.h" | |
| 13 #include "content/public/common/media_metadata.h" | |
| 14 | |
| 15 namespace content { | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 MediaMetadata::Artwork ToMediaMetadataIcon( | |
| 20 blink::mojom::MediaMetadataIconPtr mojo_icon) { | |
| 21 DCHECK(mojo_icon); | |
| 22 MediaMetadata::Artwork icon; | |
| 23 icon.src = GURL(mojo_icon->src); | |
| 24 icon.type = mojo_icon->type; | |
| 25 icon.sizes = mojo_icon->sizes; | |
| 26 return icon; | |
| 27 } | |
| 28 | |
| 29 base::Optional<MediaMetadata> ToMediaMetadata( | |
| 30 blink::mojom::MediaMetadataPtr mojo_metadata) { | |
| 31 if (!mojo_metadata) | |
| 32 return base::nullopt; | |
| 33 MediaMetadata metadata; | |
| 34 metadata.title = mojo_metadata->title; | |
| 35 metadata.artist = mojo_metadata->artist; | |
| 36 metadata.album = mojo_metadata->album; | |
| 37 for (auto& mojo_icon : mojo_metadata->artwork) | |
| 38 metadata.artwork.push_back(ToMediaMetadataIcon(std::move(mojo_icon))); | |
| 39 return metadata; | |
| 40 } | |
| 41 | |
| 42 } // anonymous namespace | |
| 43 | |
| 44 MediaSessionServiceImpl::MediaSessionServiceImpl( | |
| 45 RenderFrameHost* render_frame_host) | |
| 46 : render_frame_host_(render_frame_host) {} | |
| 47 | |
| 48 MediaSessionServiceImpl::~MediaSessionServiceImpl() = default; | |
| 49 | |
| 50 // static | |
| 51 void MediaSessionServiceImpl::Create( | |
| 52 RenderFrameHost* render_frame_host, | |
| 53 blink::mojom::MediaSessionServiceRequest request) { | |
| 54 MediaSessionServiceImpl* impl = new MediaSessionServiceImpl( | |
| 55 render_frame_host); | |
| 56 impl->Bind(std::move(request)); | |
| 57 } | |
| 58 | |
| 59 void MediaSessionServiceImpl::SetMetadata( | |
| 60 blink::mojom::MediaMetadataPtr metadata) { | |
|
xhwang
2016/09/30 23:24:58
Have you considered to use typemapping so that the
Zhiqiang Zhang (Slow)
2016/10/03 14:31:13
Done on the chromium side. The blink-side typemapi
| |
| 61 WebContentsImpl* contents = static_cast<WebContentsImpl*>( | |
| 62 WebContents::FromRenderFrameHost(render_frame_host_)); | |
| 63 DCHECK(contents); | |
| 64 MediaWebContentsObserverAndroid* observer = | |
| 65 static_cast<MediaWebContentsObserverAndroid*>( | |
| 66 contents->media_web_contents_observer()); | |
| 67 observer->GetMediaSessionManager(render_frame_host_) | |
| 68 ->OnSetMetadata(0, ToMediaMetadata(std::move(metadata))); | |
| 69 } | |
| 70 | |
| 71 void MediaSessionServiceImpl::Bind( | |
| 72 mojo::InterfaceRequest<blink::mojom::MediaSessionService> request) { | |
| 73 binding_.reset(new mojo::Binding<blink::mojom::MediaSessionService>( | |
| 74 this, std::move(request))); | |
| 75 } | |
| 76 | |
| 77 } // namespace content | |
| OLD | NEW |