| 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" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 MediaSessionServiceImpl* impl = | 36 MediaSessionServiceImpl* impl = |
| 37 new MediaSessionServiceImpl(render_frame_host); | 37 new MediaSessionServiceImpl(render_frame_host); |
| 38 impl->Bind(std::move(request)); | 38 impl->Bind(std::move(request)); |
| 39 } | 39 } |
| 40 | 40 |
| 41 RenderFrameHost* MediaSessionServiceImpl::GetRenderFrameHost() { | 41 RenderFrameHost* MediaSessionServiceImpl::GetRenderFrameHost() { |
| 42 return RenderFrameHost::FromID(render_frame_process_id_, | 42 return RenderFrameHost::FromID(render_frame_process_id_, |
| 43 render_frame_routing_id_); | 43 render_frame_routing_id_); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void MediaSessionServiceImpl::DidFinishNavigation() { |
| 47 // At this point the BrowsingContext of the frame has changed, so the members |
| 48 // need to be reset, and notify MediaSessionImpl. |
| 49 SetPlaybackState(blink::mojom::MediaSessionPlaybackState::NONE); |
| 50 SetMetadata(base::nullopt); |
| 51 ClearActions(); |
| 52 } |
| 53 |
| 46 void MediaSessionServiceImpl::SetClient( | 54 void MediaSessionServiceImpl::SetClient( |
| 47 blink::mojom::MediaSessionClientPtr client) { | 55 blink::mojom::MediaSessionClientPtr client) { |
| 48 client_ = std::move(client); | 56 client_ = std::move(client); |
| 49 } | 57 } |
| 50 | 58 |
| 51 void MediaSessionServiceImpl::SetPlaybackState( | 59 void MediaSessionServiceImpl::SetPlaybackState( |
| 52 blink::mojom::MediaSessionPlaybackState state) { | 60 blink::mojom::MediaSessionPlaybackState state) { |
| 53 playback_state_ = state; | 61 playback_state_ = state; |
| 54 MediaSessionImpl* session = GetMediaSession(); | 62 MediaSessionImpl* session = GetMediaSession(); |
| 55 if (session) | 63 if (session) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 85 } | 93 } |
| 86 | 94 |
| 87 void MediaSessionServiceImpl::DisableAction( | 95 void MediaSessionServiceImpl::DisableAction( |
| 88 blink::mojom::MediaSessionAction action) { | 96 blink::mojom::MediaSessionAction action) { |
| 89 actions_.erase(action); | 97 actions_.erase(action); |
| 90 MediaSessionImpl* session = GetMediaSession(); | 98 MediaSessionImpl* session = GetMediaSession(); |
| 91 if (session) | 99 if (session) |
| 92 session->OnMediaSessionActionsChanged(this); | 100 session->OnMediaSessionActionsChanged(this); |
| 93 } | 101 } |
| 94 | 102 |
| 103 void MediaSessionServiceImpl::ClearActions() { |
| 104 actions_.clear(); |
| 105 MediaSessionImpl* session = GetMediaSession(); |
| 106 if (session) |
| 107 session->OnMediaSessionActionsChanged(this); |
| 108 } |
| 109 |
| 95 MediaSessionImpl* MediaSessionServiceImpl::GetMediaSession() { | 110 MediaSessionImpl* MediaSessionServiceImpl::GetMediaSession() { |
| 96 RenderFrameHost* rfh = GetRenderFrameHost(); | 111 RenderFrameHost* rfh = GetRenderFrameHost(); |
| 97 if (!rfh) | 112 if (!rfh) |
| 98 return nullptr; | 113 return nullptr; |
| 99 | 114 |
| 100 WebContentsImpl* contents = | 115 WebContentsImpl* contents = |
| 101 static_cast<WebContentsImpl*>(WebContentsImpl::FromRenderFrameHost(rfh)); | 116 static_cast<WebContentsImpl*>(WebContentsImpl::FromRenderFrameHost(rfh)); |
| 102 if (!contents) | 117 if (!contents) |
| 103 return nullptr; | 118 return nullptr; |
| 104 | 119 |
| 105 return MediaSessionImpl::Get(contents); | 120 return MediaSessionImpl::Get(contents); |
| 106 } | 121 } |
| 107 | 122 |
| 108 void MediaSessionServiceImpl::Bind( | 123 void MediaSessionServiceImpl::Bind( |
| 109 blink::mojom::MediaSessionServiceRequest request) { | 124 blink::mojom::MediaSessionServiceRequest request) { |
| 110 binding_.reset(new mojo::Binding<blink::mojom::MediaSessionService>( | 125 binding_.reset(new mojo::Binding<blink::mojom::MediaSessionService>( |
| 111 this, std::move(request))); | 126 this, std::move(request))); |
| 112 } | 127 } |
| 113 | 128 |
| 114 } // namespace content | 129 } // namespace content |
| OLD | NEW |