Chromium Code Reviews| 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/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/render_frame_host.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_process_id_(render_frame_host->GetProcess()->GetID()), |
| 19 render_frame_routing_id_(render_frame_host->GetRoutingID()), | |
| 18 playback_state_(blink::mojom::MediaSessionPlaybackState::NONE) { | 20 playback_state_(blink::mojom::MediaSessionPlaybackState::NONE) { |
| 19 MediaSessionImpl* session = GetMediaSession(); | 21 MediaSessionImpl* session = GetMediaSession(); |
| 20 if (session) | 22 if (session) |
| 21 session->OnServiceCreated(this); | 23 session->OnServiceCreated(this); |
| 22 } | 24 } |
| 23 | 25 |
| 24 MediaSessionServiceImpl::~MediaSessionServiceImpl() { | 26 MediaSessionServiceImpl::~MediaSessionServiceImpl() { |
| 25 MediaSessionImpl* session = GetMediaSession(); | 27 MediaSessionImpl* session = GetMediaSession(); |
| 26 if (session) | 28 if (session) |
| 27 session->OnServiceDestroyed(this); | 29 session->OnServiceDestroyed(this); |
| 28 } | 30 } |
| 29 | 31 |
| 30 // static | 32 // static |
| 31 void MediaSessionServiceImpl::Create( | 33 void MediaSessionServiceImpl::Create( |
| 32 RenderFrameHost* render_frame_host, | 34 RenderFrameHost* render_frame_host, |
| 33 blink::mojom::MediaSessionServiceRequest request) { | 35 blink::mojom::MediaSessionServiceRequest request) { |
| 34 MediaSessionServiceImpl* impl = | 36 MediaSessionServiceImpl* impl = |
| 35 new MediaSessionServiceImpl(render_frame_host); | 37 new MediaSessionServiceImpl(render_frame_host); |
| 36 impl->Bind(std::move(request)); | 38 impl->Bind(std::move(request)); |
| 37 } | 39 } |
| 38 | 40 |
| 41 RenderFrameHost* MediaSessionServiceImpl::GetRenderFrameHost() { | |
| 42 return content::RenderFrameHost::FromID(render_frame_process_id_, | |
| 43 render_frame_routing_id_); | |
| 44 } | |
| 45 | |
| 39 void MediaSessionServiceImpl::SetClient( | 46 void MediaSessionServiceImpl::SetClient( |
| 40 blink::mojom::MediaSessionClientPtr client) { | 47 blink::mojom::MediaSessionClientPtr client) { |
| 41 client_ = std::move(client); | 48 client_ = std::move(client); |
| 42 } | 49 } |
| 43 | 50 |
| 44 void MediaSessionServiceImpl::SetPlaybackState( | 51 void MediaSessionServiceImpl::SetPlaybackState( |
| 45 blink::mojom::MediaSessionPlaybackState state) { | 52 blink::mojom::MediaSessionPlaybackState state) { |
| 46 playback_state_ = state; | 53 playback_state_ = state; |
| 47 MediaSessionImpl* session = GetMediaSession(); | 54 MediaSessionImpl* session = GetMediaSession(); |
| 48 if (session) | 55 if (session) |
| 49 session->OnMediaSessionPlaybackStateChanged(this); | 56 session->OnMediaSessionPlaybackStateChanged(this); |
| 50 } | 57 } |
| 51 | 58 |
| 52 void MediaSessionServiceImpl::SetMetadata( | 59 void MediaSessionServiceImpl::SetMetadata( |
| 53 const base::Optional<content::MediaMetadata>& metadata) { | 60 const base::Optional<content::MediaMetadata>& metadata) { |
| 54 // When receiving a MediaMetadata, the browser process can't trust that it is | 61 // When receiving a MediaMetadata, the browser process can't trust that it is |
| 55 // coming from a known and secure source. It must be processed accordingly. | 62 // coming from a known and secure source. It must be processed accordingly. |
| 56 if (metadata.has_value() && | 63 if (metadata.has_value() && |
| 57 !MediaMetadataSanitizer::CheckSanity(metadata.value())) { | 64 !MediaMetadataSanitizer::CheckSanity(metadata.value())) { |
| 58 render_frame_host_->GetProcess()->ShutdownForBadMessage( | 65 if (GetRenderFrameHost()) { |
|
whywhat
2017/02/23 17:57:42
nit: maybe store GetRenderFrameHost() not to call
Zhiqiang Zhang (Slow)
2017/02/23 20:15:55
Done.
| |
| 59 RenderProcessHost::CrashReportMode::GENERATE_CRASH_DUMP); | 66 GetRenderFrameHost()->GetProcess()->ShutdownForBadMessage( |
| 67 RenderProcessHost::CrashReportMode::GENERATE_CRASH_DUMP); | |
| 68 } | |
| 60 return; | 69 return; |
| 61 } | 70 } |
| 62 metadata_ = metadata; | 71 metadata_ = metadata; |
| 63 | 72 |
| 64 MediaSessionImpl* session = GetMediaSession(); | 73 MediaSessionImpl* session = GetMediaSession(); |
| 65 if (session) | 74 if (session) |
| 66 session->OnMediaSessionMetadataChanged(this); | 75 session->OnMediaSessionMetadataChanged(this); |
| 67 } | 76 } |
| 68 | 77 |
| 69 void MediaSessionServiceImpl::EnableAction( | 78 void MediaSessionServiceImpl::EnableAction( |
| 70 blink::mojom::MediaSessionAction action) { | 79 blink::mojom::MediaSessionAction action) { |
| 71 actions_.insert(action); | 80 actions_.insert(action); |
| 72 MediaSessionImpl* session = GetMediaSession(); | 81 MediaSessionImpl* session = GetMediaSession(); |
| 73 if (session) | 82 if (session) |
| 74 session->OnMediaSessionActionsChanged(this); | 83 session->OnMediaSessionActionsChanged(this); |
| 75 } | 84 } |
| 76 | 85 |
| 77 void MediaSessionServiceImpl::DisableAction( | 86 void MediaSessionServiceImpl::DisableAction( |
| 78 blink::mojom::MediaSessionAction action) { | 87 blink::mojom::MediaSessionAction action) { |
| 79 actions_.erase(action); | 88 actions_.erase(action); |
| 80 MediaSessionImpl* session = GetMediaSession(); | 89 MediaSessionImpl* session = GetMediaSession(); |
| 81 if (session) | 90 if (session) |
| 82 session->OnMediaSessionActionsChanged(this); | 91 session->OnMediaSessionActionsChanged(this); |
| 83 } | 92 } |
| 84 | 93 |
| 85 MediaSessionImpl* MediaSessionServiceImpl::GetMediaSession() { | 94 MediaSessionImpl* MediaSessionServiceImpl::GetMediaSession() { |
| 86 WebContentsImpl* contents = static_cast<WebContentsImpl*>( | 95 RenderFrameHost* rfh = GetRenderFrameHost(); |
| 87 WebContentsImpl::FromRenderFrameHost(render_frame_host_)); | 96 WebContentsImpl* contents = |
| 97 static_cast<WebContentsImpl*>(WebContentsImpl::FromRenderFrameHost(rfh)); | |
|
whywhat
2017/02/23 17:57:42
nit: does it handle nullptr properly?
Zhiqiang Zhang (Slow)
2017/02/23 20:15:55
Yes. But let's be safe. Added a null-check.
| |
| 88 if (!contents) | 98 if (!contents) |
| 89 return nullptr; | 99 return nullptr; |
| 90 return MediaSessionImpl::Get(contents); | 100 return MediaSessionImpl::Get(contents); |
| 91 } | 101 } |
| 92 | 102 |
| 93 void MediaSessionServiceImpl::Bind( | 103 void MediaSessionServiceImpl::Bind( |
| 94 blink::mojom::MediaSessionServiceRequest request) { | 104 blink::mojom::MediaSessionServiceRequest request) { |
| 95 binding_.reset(new mojo::Binding<blink::mojom::MediaSessionService>( | 105 binding_.reset(new mojo::Binding<blink::mojom::MediaSessionService>( |
| 96 this, std::move(request))); | 106 this, std::move(request))); |
| 97 } | 107 } |
| 98 | 108 |
| 99 } // namespace content | 109 } // namespace content |
| OLD | NEW |