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); | |
mlamouri (slow - plz ping)
2016/09/29 10:26:40
Should you sanitize the |mojo_icon|?
Zhiqiang Zhang (Slow)
2016/09/30 19:38:01
Yes, I need to sanitize it. But we are now sending
| |
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) { | |
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 |