Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: content/browser/media/session/media_session_service_impl.cc

Issue 2442303002: Adding new media controls to MediaNotification (Closed)
Patch Set: rebased onto MediaSession refactoring Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 "content/browser/media/session/media_session_service_impl.h" 5 #include "content/browser/media/session/media_session_service_impl.h"
6 6
7 #include "content/browser/media/session/media_metadata_sanitizer.h" 7 #include "content/browser/media/session/media_metadata_sanitizer.h"
8 #include "content/browser/media/session/media_session_impl.h" 8 #include "content/browser/media/session/media_session_impl.h"
9 #include "content/browser/web_contents/web_contents_impl.h" 9 #include "content/browser/web_contents/web_contents_impl.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/web_contents.h" 11 #include "content/public/browser/web_contents.h"
12 12
13 namespace content { 13 namespace content {
14 14
15 MediaSessionServiceImpl::MediaSessionServiceImpl( 15 MediaSessionServiceImpl::MediaSessionServiceImpl(
16 RenderFrameHost* render_frame_host) 16 RenderFrameHost* render_frame_host)
17 : render_frame_host_(render_frame_host) {} 17 : render_frame_host_(render_frame_host) {
18 if (MediaSessionImpl* session = GetMediaSession())
19 session->SetMediaSessionService(this);
20 }
18 21
19 MediaSessionServiceImpl::~MediaSessionServiceImpl() = default; 22 MediaSessionServiceImpl::~MediaSessionServiceImpl() {
23 if (MediaSessionImpl* session = GetMediaSession())
whywhat 2016/10/28 16:10:23 nit: can this be null here and below? I'd avoid in
Zhiqiang Zhang (Slow) 2016/11/01 15:24:15 Yes, currently we only bind the top-level frame se
24 session->SetMediaSessionService(nullptr);
25 }
20 26
21 // static 27 // static
22 void MediaSessionServiceImpl::Create( 28 void MediaSessionServiceImpl::Create(
23 RenderFrameHost* render_frame_host, 29 RenderFrameHost* render_frame_host,
24 blink::mojom::MediaSessionServiceRequest request) { 30 blink::mojom::MediaSessionServiceRequest request) {
25 MediaSessionServiceImpl* impl = 31 MediaSessionServiceImpl* impl =
26 new MediaSessionServiceImpl(render_frame_host); 32 new MediaSessionServiceImpl(render_frame_host);
27 impl->Bind(std::move(request)); 33 impl->Bind(std::move(request));
28 } 34 }
29 35
30 void MediaSessionServiceImpl::SetClient( 36 void MediaSessionServiceImpl::SetClient(
31 blink::mojom::MediaSessionClientPtr client) { 37 blink::mojom::MediaSessionClientPtr client) {
32 client_ = std::move(client); 38 client_ = std::move(client);
33 } 39 }
34 40
35 void MediaSessionServiceImpl::SetMetadata( 41 void MediaSessionServiceImpl::SetMetadata(
36 const base::Optional<content::MediaMetadata>& metadata) { 42 const base::Optional<content::MediaMetadata>& metadata) {
37 // When receiving a MediaMetadata, the browser process can't trust that it is 43 // When receiving a MediaMetadata, the browser process can't trust that it is
38 // coming from a known and secure source. It must be processed accordingly. 44 // coming from a known and secure source. It must be processed accordingly.
39 if (metadata.has_value() && 45 if (metadata.has_value() &&
40 !MediaMetadataSanitizer::CheckSanity(metadata.value())) { 46 !MediaMetadataSanitizer::CheckSanity(metadata.value())) {
41 render_frame_host_->GetProcess()->ShutdownForBadMessage( 47 render_frame_host_->GetProcess()->ShutdownForBadMessage(
42 RenderProcessHost::CrashReportMode::GENERATE_CRASH_DUMP); 48 RenderProcessHost::CrashReportMode::GENERATE_CRASH_DUMP);
43 return; 49 return;
44 } 50 }
45 51
46 WebContentsImpl* contents = static_cast<WebContentsImpl*>( 52 if (MediaSessionImpl* session = GetMediaSession())
47 WebContentsImpl::FromRenderFrameHost(render_frame_host_)); 53 session->SetMetadata(metadata);
48 if (contents)
49 MediaSessionImpl::Get(contents)->SetMetadata(metadata);
50 } 54 }
51 55
52 void MediaSessionServiceImpl::EnableAction( 56 void MediaSessionServiceImpl::EnableAction(
53 blink::mojom::MediaSessionAction action) { 57 blink::mojom::MediaSessionAction action) {
54 // TODO(zqzhang): Plumb this signal to Java. See https://crbug.com/656563 58 if (MediaSessionImpl* session = GetMediaSession())
55 NOTIMPLEMENTED(); 59 session->OnMediaSessionEnabledAction(action);
56 } 60 }
57 61
58 void MediaSessionServiceImpl::DisableAction( 62 void MediaSessionServiceImpl::DisableAction(
59 blink::mojom::MediaSessionAction action) { 63 blink::mojom::MediaSessionAction action) {
60 // TODO(zqzhang): Plumb this signal to Java. See https://crbug.com/656563 64 if (MediaSessionImpl* session = GetMediaSession())
61 NOTIMPLEMENTED(); 65 session->OnMediaSessionDisabledAction(action);
66 }
67
68 MediaSessionImpl* MediaSessionServiceImpl::GetMediaSession() {
69 WebContentsImpl* contents = static_cast<WebContentsImpl*>(
70 WebContentsImpl::FromRenderFrameHost(render_frame_host_));
71 if (!contents)
72 return nullptr;
73 if (render_frame_host_ != contents->GetMainFrame())
74 return nullptr;
75 return MediaSessionImpl::Get(contents);
62 } 76 }
63 77
64 void MediaSessionServiceImpl::Bind( 78 void MediaSessionServiceImpl::Bind(
65 blink::mojom::MediaSessionServiceRequest request) { 79 blink::mojom::MediaSessionServiceRequest request) {
66 binding_.reset(new mojo::Binding<blink::mojom::MediaSessionService>( 80 binding_.reset(new mojo::Binding<blink::mojom::MediaSessionService>(
67 this, std::move(request))); 81 this, std::move(request)));
68 } 82 }
69 83
70 } // namespace content 84 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698