| OLD | NEW |
| 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/media/session/media_session_service_router.h" |
| 9 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
| 10 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 12 | 13 |
| 13 namespace content { | 14 namespace content { |
| 14 | 15 |
| 15 MediaSessionServiceImpl::MediaSessionServiceImpl( | 16 MediaSessionServiceImpl::MediaSessionServiceImpl( |
| 16 RenderFrameHost* render_frame_host) | 17 RenderFrameHost* render_frame_host) |
| 17 : render_frame_host_(render_frame_host) { | 18 : render_frame_host_(render_frame_host) { |
| 18 MediaSessionImpl* session = GetMediaSession(); | 19 MediaSessionServiceRouter* router = GetMediaSessionServiceRouter(); |
| 19 if (session) | 20 if (router) |
| 20 session->SetMediaSessionService(this); | 21 router->OnServiceCreated(this); |
| 21 } | 22 } |
| 22 | 23 |
| 23 MediaSessionServiceImpl::~MediaSessionServiceImpl() { | 24 MediaSessionServiceImpl::~MediaSessionServiceImpl() { |
| 24 MediaSessionImpl* session = GetMediaSession(); | 25 MediaSessionServiceRouter* router = GetMediaSessionServiceRouter(); |
| 25 if (session && session->GetMediaSessionService() == this) | 26 if (router) |
| 26 session->SetMediaSessionService(nullptr); | 27 router->OnServiceDestroyed(this); |
| 27 } | 28 } |
| 28 | 29 |
| 29 // static | 30 // static |
| 30 void MediaSessionServiceImpl::Create( | 31 void MediaSessionServiceImpl::Create( |
| 31 RenderFrameHost* render_frame_host, | 32 RenderFrameHost* render_frame_host, |
| 32 blink::mojom::MediaSessionServiceRequest request) { | 33 blink::mojom::MediaSessionServiceRequest request) { |
| 33 MediaSessionServiceImpl* impl = | 34 MediaSessionServiceImpl* impl = |
| 34 new MediaSessionServiceImpl(render_frame_host); | 35 new MediaSessionServiceImpl(render_frame_host); |
| 35 impl->Bind(std::move(request)); | 36 impl->Bind(std::move(request)); |
| 36 } | 37 } |
| 37 | 38 |
| 38 void MediaSessionServiceImpl::SetClient( | 39 void MediaSessionServiceImpl::SetClient( |
| 39 blink::mojom::MediaSessionClientPtr client) { | 40 blink::mojom::MediaSessionClientPtr client) { |
| 40 client_ = std::move(client); | 41 client_ = std::move(client); |
| 41 } | 42 } |
| 42 | 43 |
| 43 void MediaSessionServiceImpl::SetMetadata( | 44 void MediaSessionServiceImpl::SetMetadata( |
| 44 const base::Optional<content::MediaMetadata>& metadata) { | 45 const base::Optional<content::MediaMetadata>& metadata) { |
| 45 // When receiving a MediaMetadata, the browser process can't trust that it is | 46 // When receiving a MediaMetadata, the browser process can't trust that it is |
| 46 // coming from a known and secure source. It must be processed accordingly. | 47 // coming from a known and secure source. It must be processed accordingly. |
| 47 if (metadata.has_value() && | 48 if (metadata.has_value() && |
| 48 !MediaMetadataSanitizer::CheckSanity(metadata.value())) { | 49 !MediaMetadataSanitizer::CheckSanity(metadata.value())) { |
| 49 render_frame_host_->GetProcess()->ShutdownForBadMessage( | 50 render_frame_host_->GetProcess()->ShutdownForBadMessage( |
| 50 RenderProcessHost::CrashReportMode::GENERATE_CRASH_DUMP); | 51 RenderProcessHost::CrashReportMode::GENERATE_CRASH_DUMP); |
| 51 return; | 52 return; |
| 52 } | 53 } |
| 54 metadata_ = metadata; |
| 53 | 55 |
| 54 MediaSessionImpl* session = GetMediaSession(); | 56 MediaSessionServiceRouter* router = GetMediaSessionServiceRouter(); |
| 55 if (session) | 57 if (router) |
| 56 session->SetMetadata(metadata); | 58 router->OnMediaSessionMetadataChanged(this); |
| 57 } | 59 } |
| 58 | 60 |
| 59 void MediaSessionServiceImpl::EnableAction( | 61 void MediaSessionServiceImpl::EnableAction( |
| 60 blink::mojom::MediaSessionAction action) { | 62 blink::mojom::MediaSessionAction action) { |
| 61 MediaSessionImpl* session = GetMediaSession(); | 63 actions_.insert(action); |
| 62 if (session) | 64 MediaSessionServiceRouter* router = GetMediaSessionServiceRouter(); |
| 63 session->OnMediaSessionEnabledAction(action); | 65 if (router) |
| 66 router->OnMediaSessionActionsChanged(this); |
| 64 } | 67 } |
| 65 | 68 |
| 66 void MediaSessionServiceImpl::DisableAction( | 69 void MediaSessionServiceImpl::DisableAction( |
| 67 blink::mojom::MediaSessionAction action) { | 70 blink::mojom::MediaSessionAction action) { |
| 68 MediaSessionImpl* session = GetMediaSession(); | 71 actions_.erase(action); |
| 69 if (session) | 72 MediaSessionServiceRouter* router = GetMediaSessionServiceRouter(); |
| 70 session->OnMediaSessionDisabledAction(action); | 73 if (router) |
| 74 router->OnMediaSessionActionsChanged(this); |
| 71 } | 75 } |
| 72 | 76 |
| 73 MediaSessionImpl* MediaSessionServiceImpl::GetMediaSession() { | 77 MediaSessionServiceRouter* |
| 78 MediaSessionServiceImpl::GetMediaSessionServiceRouter() { |
| 74 WebContentsImpl* contents = static_cast<WebContentsImpl*>( | 79 WebContentsImpl* contents = static_cast<WebContentsImpl*>( |
| 75 WebContentsImpl::FromRenderFrameHost(render_frame_host_)); | 80 WebContentsImpl::FromRenderFrameHost(render_frame_host_)); |
| 76 if (!contents) | 81 if (!contents) |
| 77 return nullptr; | 82 return nullptr; |
| 78 if (render_frame_host_ != contents->GetMainFrame()) | 83 return MediaSessionImpl::Get(contents)->GetMediaSessionServiceRouter(); |
| 79 return nullptr; | |
| 80 return MediaSessionImpl::Get(contents); | |
| 81 } | 84 } |
| 82 | 85 |
| 83 void MediaSessionServiceImpl::Bind( | 86 void MediaSessionServiceImpl::Bind( |
| 84 blink::mojom::MediaSessionServiceRequest request) { | 87 blink::mojom::MediaSessionServiceRequest request) { |
| 85 binding_.reset(new mojo::Binding<blink::mojom::MediaSessionService>( | 88 binding_.reset(new mojo::Binding<blink::mojom::MediaSessionService>( |
| 86 this, std::move(request))); | 89 this, std::move(request))); |
| 87 } | 90 } |
| 88 | 91 |
| 89 } // namespace content | 92 } // namespace content |
| OLD | NEW |