| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "chrome/browser/media/router/presentation_service_delegate_impl.h" | 5 #include "chrome/browser/media/router/presentation_service_delegate_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <unordered_map> | 8 #include <unordered_map> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/containers/small_map.h" | 12 #include "base/containers/small_map.h" |
| 13 #include "base/guid.h" | 13 #include "base/guid.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 17 #include "chrome/browser/media/router/create_presentation_connection_request.h" | 17 #include "chrome/browser/media/router/create_presentation_connection_request.h" |
| 18 #include "chrome/browser/media/router/media_route.h" | 18 #include "chrome/browser/media/router/media_route.h" |
| 19 #include "chrome/browser/media/router/media_router.h" | 19 #include "chrome/browser/media/router/media_router.h" |
| 20 #include "chrome/browser/media/router/media_router_dialog_controller.h" | 20 #include "chrome/browser/media/router/media_router_dialog_controller.h" |
| 21 #include "chrome/browser/media/router/media_router_factory.h" | 21 #include "chrome/browser/media/router/media_router_factory.h" |
| 22 #include "chrome/browser/media/router/media_sink.h" | 22 #include "chrome/browser/media/router/media_sink.h" |
| 23 #include "chrome/browser/media/router/media_source_helper.h" | 23 #include "chrome/browser/media/router/media_source_helper.h" |
| 24 #include "chrome/browser/media/router/offscreen_presentation_manager.h" |
| 25 #include "chrome/browser/media/router/offscreen_presentation_manager_factory.h" |
| 24 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" | 26 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" |
| 25 #include "chrome/browser/media/router/route_message.h" | 27 #include "chrome/browser/media/router/route_message.h" |
| 26 #include "chrome/browser/media/router/route_message_observer.h" | 28 #include "chrome/browser/media/router/route_message_observer.h" |
| 27 #include "chrome/browser/media/router/route_request_result.h" | 29 #include "chrome/browser/media/router/route_request_result.h" |
| 28 #include "chrome/browser/sessions/session_tab_helper.h" | 30 #include "chrome/browser/sessions/session_tab_helper.h" |
| 29 #include "content/public/browser/browser_context.h" | 31 #include "content/public/browser/browser_context.h" |
| 30 #include "content/public/browser/presentation_screen_availability_listener.h" | 32 #include "content/public/browser/presentation_screen_availability_listener.h" |
| 31 #include "content/public/browser/presentation_session.h" | 33 #include "content/public/browser/presentation_session.h" |
| 32 #include "content/public/browser/render_frame_host.h" | 34 #include "content/public/browser/render_frame_host.h" |
| 33 #include "content/public/browser/render_process_host.h" | 35 #include "content/public/browser/render_process_host.h" |
| 36 #include "url/gurl.h" |
| 34 | 37 |
| 35 DEFINE_WEB_CONTENTS_USER_DATA_KEY( | 38 DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
| 36 media_router::PresentationServiceDelegateImpl); | 39 media_router::PresentationServiceDelegateImpl); |
| 37 | 40 |
| 38 using content::RenderFrameHost; | 41 using content::RenderFrameHost; |
| 39 | 42 |
| 40 namespace media_router { | 43 namespace media_router { |
| 41 | 44 |
| 42 namespace { | 45 namespace { |
| 43 | 46 |
| 44 using DelegateObserver = content::PresentationServiceDelegate::Observer; | 47 using DelegateObserver = content::PresentationServiceDelegateBase::Observer; |
| 45 | 48 |
| 46 // Returns the unique identifier for the supplied RenderFrameHost. | 49 // Returns the unique identifier for the supplied RenderFrameHost. |
| 47 RenderFrameHostId GetRenderFrameHostId(RenderFrameHost* render_frame_host) { | 50 RenderFrameHostId GetRenderFrameHostId(RenderFrameHost* render_frame_host) { |
| 48 int render_process_id = render_frame_host->GetProcess()->GetID(); | 51 int render_process_id = render_frame_host->GetProcess()->GetID(); |
| 49 int render_frame_id = render_frame_host->GetRoutingID(); | 52 int render_frame_id = render_frame_host->GetRoutingID(); |
| 50 return RenderFrameHostId(render_process_id, render_frame_id); | 53 return RenderFrameHostId(render_process_id, render_frame_id); |
| 51 } | 54 } |
| 52 | 55 |
| 53 // Gets the last committed URL for the render frame specified by | 56 // Gets the last committed URL for the render frame specified by |
| 54 // |render_frame_host_id|. | 57 // |render_frame_host_id|. |
| (...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 PresentationServiceDelegateImpl::CreateForWebContents(web_contents); | 662 PresentationServiceDelegateImpl::CreateForWebContents(web_contents); |
| 660 return PresentationServiceDelegateImpl::FromWebContents(web_contents); | 663 return PresentationServiceDelegateImpl::FromWebContents(web_contents); |
| 661 } | 664 } |
| 662 | 665 |
| 663 PresentationServiceDelegateImpl::PresentationServiceDelegateImpl( | 666 PresentationServiceDelegateImpl::PresentationServiceDelegateImpl( |
| 664 content::WebContents* web_contents) | 667 content::WebContents* web_contents) |
| 665 : web_contents_(web_contents), | 668 : web_contents_(web_contents), |
| 666 router_(MediaRouterFactory::GetApiForBrowserContext( | 669 router_(MediaRouterFactory::GetApiForBrowserContext( |
| 667 web_contents_->GetBrowserContext())), | 670 web_contents_->GetBrowserContext())), |
| 668 frame_manager_(new PresentationFrameManager(web_contents, router_)), | 671 frame_manager_(new PresentationFrameManager(web_contents, router_)), |
| 672 offscreen_presentation_manager_( |
| 673 OffscreenPresentationManagerFactory:: |
| 674 GetOrCreateForControllerBrowserContext(web_contents_)), |
| 669 weak_factory_(this) { | 675 weak_factory_(this) { |
| 670 DCHECK(web_contents_); | 676 DCHECK(web_contents_); |
| 671 DCHECK(router_); | 677 DCHECK(router_); |
| 672 } | 678 } |
| 673 | 679 |
| 674 PresentationServiceDelegateImpl::~PresentationServiceDelegateImpl() { | 680 PresentationServiceDelegateImpl::~PresentationServiceDelegateImpl() { |
| 675 } | 681 } |
| 676 | 682 |
| 677 void PresentationServiceDelegateImpl::AddObserver(int render_process_id, | 683 void PresentationServiceDelegateImpl::AddObserver(int render_process_id, |
| 678 int render_frame_id, | 684 int render_frame_id, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 result.route()->media_route_id()); | 755 result.route()->media_route_id()); |
| 750 success_cb.Run(session); | 756 success_cb.Run(session); |
| 751 } | 757 } |
| 752 } | 758 } |
| 753 | 759 |
| 754 void PresentationServiceDelegateImpl::OnStartSessionSucceeded( | 760 void PresentationServiceDelegateImpl::OnStartSessionSucceeded( |
| 755 int render_process_id, | 761 int render_process_id, |
| 756 int render_frame_id, | 762 int render_frame_id, |
| 757 const content::PresentationSessionStartedCallback& success_cb, | 763 const content::PresentationSessionStartedCallback& success_cb, |
| 758 const content::PresentationSessionInfo& new_session, | 764 const content::PresentationSessionInfo& new_session, |
| 759 const MediaRoute::Id& route_id) { | 765 const MediaRoute& route) { |
| 766 const MediaRoute::Id& route_id = route.media_route_id(); |
| 760 DVLOG(1) << "OnStartSessionSucceeded: " | 767 DVLOG(1) << "OnStartSessionSucceeded: " |
| 761 << "route_id: " << route_id | 768 << "route_id: " << route_id |
| 762 << ", presentation URL: " << new_session.presentation_url | 769 << ", presentation URL: " << new_session.presentation_url |
| 763 << ", presentation ID: " << new_session.presentation_id; | 770 << ", presentation ID: " << new_session.presentation_id |
| 771 << ", is_offscreen_presentation: " |
| 772 << new_session.is_offscreen_presentation; |
| 764 frame_manager_->OnPresentationSessionStarted( | 773 frame_manager_->OnPresentationSessionStarted( |
| 765 RenderFrameHostId(render_process_id, render_frame_id), new_session, | 774 RenderFrameHostId(render_process_id, render_frame_id), new_session, |
| 766 route_id); | 775 route_id); |
| 767 success_cb.Run(new_session); | 776 success_cb.Run(new_session); |
| 768 } | 777 } |
| 769 | 778 |
| 770 void PresentationServiceDelegateImpl::StartSession( | 779 void PresentationServiceDelegateImpl::StartSession( |
| 771 int render_process_id, | 780 int render_process_id, |
| 772 int render_frame_id, | 781 int render_frame_id, |
| 773 const std::vector<GURL>& presentation_urls, | 782 const std::vector<GURL>& presentation_urls, |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 int render_process_id, | 917 int render_process_id, |
| 909 int render_frame_id, | 918 int render_frame_id, |
| 910 const content::PresentationSessionInfo& connection, | 919 const content::PresentationSessionInfo& connection, |
| 911 const content::PresentationConnectionStateChangedCallback& | 920 const content::PresentationConnectionStateChangedCallback& |
| 912 state_changed_cb) { | 921 state_changed_cb) { |
| 913 frame_manager_->ListenForConnectionStateChange( | 922 frame_manager_->ListenForConnectionStateChange( |
| 914 RenderFrameHostId(render_process_id, render_frame_id), connection, | 923 RenderFrameHostId(render_process_id, render_frame_id), connection, |
| 915 state_changed_cb); | 924 state_changed_cb); |
| 916 } | 925 } |
| 917 | 926 |
| 927 void PresentationServiceDelegateImpl::RegisterOffscreenPresentationConnection( |
| 928 int render_process_id, |
| 929 int render_frame_id, |
| 930 const content::PresentationSessionInfo& session, |
| 931 content::PresentationConnectionPtr connection) { |
| 932 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
| 933 offscreen_presentation_manager_->RegisterOffscreenPresentationController( |
| 934 session.presentation_id, GURL(session.presentation_url), |
| 935 render_frame_host_id, std::move(connection)); |
| 936 } |
| 937 |
| 918 void PresentationServiceDelegateImpl::OnRouteResponse( | 938 void PresentationServiceDelegateImpl::OnRouteResponse( |
| 919 const PresentationRequest& presentation_request, | 939 const PresentationRequest& presentation_request, |
| 920 const RouteRequestResult& result) { | 940 const RouteRequestResult& result) { |
| 921 if (!result.route()) | 941 if (!result.route()) |
| 922 return; | 942 return; |
| 923 | 943 |
| 924 content::PresentationSessionInfo session_info( | 944 content::PresentationSessionInfo session_info( |
| 925 presentation_request.presentation_url(), result.presentation_id()); | 945 presentation_request.presentation_url(), result.presentation_id()); |
| 926 frame_manager_->OnDefaultPresentationSessionStarted( | 946 frame_manager_->OnDefaultPresentationSessionStarted( |
| 927 presentation_request, session_info, result.route()->media_route_id()); | 947 presentation_request, session_info, result.route()->media_route_id()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 961 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( | 981 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( |
| 962 int render_process_id, | 982 int render_process_id, |
| 963 int render_frame_id, | 983 int render_frame_id, |
| 964 const MediaSource::Id& source_id) const { | 984 const MediaSource::Id& source_id) const { |
| 965 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 985 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
| 966 return frame_manager_->HasScreenAvailabilityListenerForTest( | 986 return frame_manager_->HasScreenAvailabilityListenerForTest( |
| 967 render_frame_host_id, source_id); | 987 render_frame_host_id, source_id); |
| 968 } | 988 } |
| 969 | 989 |
| 970 } // namespace media_router | 990 } // namespace media_router |
| OLD | NEW |