| 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> |
| (...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 705 frame_manager_->RemoveScreenAvailabilityListener( | 705 frame_manager_->RemoveScreenAvailabilityListener( |
| 706 RenderFrameHostId(render_process_id, render_frame_id), listener); | 706 RenderFrameHostId(render_process_id, render_frame_id), listener); |
| 707 } | 707 } |
| 708 | 708 |
| 709 void PresentationServiceDelegateImpl::Reset(int render_process_id, | 709 void PresentationServiceDelegateImpl::Reset(int render_process_id, |
| 710 int render_frame_id) { | 710 int render_frame_id) { |
| 711 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 711 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
| 712 frame_manager_->Reset(render_frame_host_id); | 712 frame_manager_->Reset(render_frame_host_id); |
| 713 } | 713 } |
| 714 | 714 |
| 715 void PresentationServiceDelegateImpl::SetDefaultPresentationUrl( | 715 void PresentationServiceDelegateImpl::SetDefaultPresentationUrls( |
| 716 int render_process_id, | 716 int render_process_id, |
| 717 int render_frame_id, | 717 int render_frame_id, |
| 718 const std::string& default_presentation_url, | 718 const std::vector<std::string>& default_presentation_urls, |
| 719 const content::PresentationSessionStartedCallback& callback) { | 719 const content::PresentationSessionStartedCallback& callback) { |
| 720 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 720 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
| 721 frame_manager_->SetDefaultPresentationUrl(render_frame_host_id, | 721 if (default_presentation_urls.empty()) { |
| 722 default_presentation_url, callback); | 722 frame_manager_->SetDefaultPresentationUrl(render_frame_host_id, |
| 723 std::string(), callback); |
| 724 } else { |
| 725 // TODO(crbug.com/627655): Handle multiple URLs. |
| 726 frame_manager_->SetDefaultPresentationUrl( |
| 727 render_frame_host_id, default_presentation_urls[0], callback); |
| 728 } |
| 723 } | 729 } |
| 724 | 730 |
| 725 void PresentationServiceDelegateImpl::OnJoinRouteResponse( | 731 void PresentationServiceDelegateImpl::OnJoinRouteResponse( |
| 726 int render_process_id, | 732 int render_process_id, |
| 727 int render_frame_id, | 733 int render_frame_id, |
| 728 const content::PresentationSessionInfo& session, | 734 const content::PresentationSessionInfo& session, |
| 729 const content::PresentationSessionStartedCallback& success_cb, | 735 const content::PresentationSessionStartedCallback& success_cb, |
| 730 const content::PresentationSessionErrorCallback& error_cb, | 736 const content::PresentationSessionErrorCallback& error_cb, |
| 731 const RouteRequestResult& result) { | 737 const RouteRequestResult& result) { |
| 732 if (!result.route()) { | 738 if (!result.route()) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 757 << ", presentation ID: " << new_session.presentation_id; | 763 << ", presentation ID: " << new_session.presentation_id; |
| 758 frame_manager_->OnPresentationSessionStarted( | 764 frame_manager_->OnPresentationSessionStarted( |
| 759 RenderFrameHostId(render_process_id, render_frame_id), new_session, | 765 RenderFrameHostId(render_process_id, render_frame_id), new_session, |
| 760 route_id); | 766 route_id); |
| 761 success_cb.Run(new_session); | 767 success_cb.Run(new_session); |
| 762 } | 768 } |
| 763 | 769 |
| 764 void PresentationServiceDelegateImpl::StartSession( | 770 void PresentationServiceDelegateImpl::StartSession( |
| 765 int render_process_id, | 771 int render_process_id, |
| 766 int render_frame_id, | 772 int render_frame_id, |
| 767 const std::string& presentation_url, | 773 const std::vector<std::string>& presentation_urls, |
| 768 const content::PresentationSessionStartedCallback& success_cb, | 774 const content::PresentationSessionStartedCallback& success_cb, |
| 769 const content::PresentationSessionErrorCallback& error_cb) { | 775 const content::PresentationSessionErrorCallback& error_cb) { |
| 776 if (presentation_urls.empty()) { |
| 777 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, |
| 778 "Invalid presentation arguments.")); |
| 779 return; |
| 780 } |
| 781 |
| 782 // TODO(crbug.com/627655): Handle multiple URLs. |
| 783 const std::string& presentation_url = presentation_urls[0]; |
| 770 if (presentation_url.empty() || !IsValidPresentationUrl(presentation_url)) { | 784 if (presentation_url.empty() || !IsValidPresentationUrl(presentation_url)) { |
| 771 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, | 785 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, |
| 772 "Invalid presentation arguments.")); | 786 "Invalid presentation arguments.")); |
| 773 return; | 787 return; |
| 774 } | 788 } |
| 775 | 789 |
| 776 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 790 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
| 777 std::unique_ptr<CreatePresentationConnectionRequest> request( | 791 std::unique_ptr<CreatePresentationConnectionRequest> request( |
| 778 new CreatePresentationConnectionRequest( | 792 new CreatePresentationConnectionRequest( |
| 779 render_frame_host_id, presentation_url, | 793 render_frame_host_id, presentation_url, |
| 780 GetLastCommittedURLForFrame(render_frame_host_id), | 794 GetLastCommittedURLForFrame(render_frame_host_id), |
| 781 base::Bind(&PresentationServiceDelegateImpl::OnStartSessionSucceeded, | 795 base::Bind(&PresentationServiceDelegateImpl::OnStartSessionSucceeded, |
| 782 weak_factory_.GetWeakPtr(), render_process_id, | 796 weak_factory_.GetWeakPtr(), render_process_id, |
| 783 render_frame_id, success_cb), | 797 render_frame_id, success_cb), |
| 784 error_cb)); | 798 error_cb)); |
| 785 MediaRouterDialogController* controller = | 799 MediaRouterDialogController* controller = |
| 786 MediaRouterDialogController::GetOrCreateForWebContents(web_contents_); | 800 MediaRouterDialogController::GetOrCreateForWebContents(web_contents_); |
| 787 if (!controller->ShowMediaRouterDialogForPresentation(std::move(request))) { | 801 if (!controller->ShowMediaRouterDialogForPresentation(std::move(request))) { |
| 788 LOG(ERROR) << "Media router dialog already exists. Ignoring StartSession."; | 802 LOG(ERROR) << "Media router dialog already exists. Ignoring StartSession."; |
| 789 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, | 803 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, |
| 790 "Unable to create dialog.")); | 804 "Unable to create dialog.")); |
| 791 return; | 805 return; |
| 792 } | 806 } |
| 793 } | 807 } |
| 794 | 808 |
| 795 void PresentationServiceDelegateImpl::JoinSession( | 809 void PresentationServiceDelegateImpl::JoinSession( |
| 796 int render_process_id, | 810 int render_process_id, |
| 797 int render_frame_id, | 811 int render_frame_id, |
| 798 const std::string& presentation_url, | 812 const std::vector<std::string>& presentation_urls, |
| 799 const std::string& presentation_id, | 813 const std::string& presentation_id, |
| 800 const content::PresentationSessionStartedCallback& success_cb, | 814 const content::PresentationSessionStartedCallback& success_cb, |
| 801 const content::PresentationSessionErrorCallback& error_cb) { | 815 const content::PresentationSessionErrorCallback& error_cb) { |
| 816 if (presentation_urls.empty()) { |
| 817 error_cb.Run(content::PresentationError( |
| 818 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, |
| 819 "Invalid presentation arguments.")); |
| 820 } |
| 821 |
| 822 // TODO(crbug.com/627655): Handle multiple URLs. |
| 823 const std::string& presentation_url = presentation_urls[0]; |
| 802 bool incognito = web_contents_->GetBrowserContext()->IsOffTheRecord(); | 824 bool incognito = web_contents_->GetBrowserContext()->IsOffTheRecord(); |
| 803 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 825 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 804 route_response_callbacks.push_back(base::Bind( | 826 route_response_callbacks.push_back(base::Bind( |
| 805 &PresentationServiceDelegateImpl::OnJoinRouteResponse, | 827 &PresentationServiceDelegateImpl::OnJoinRouteResponse, |
| 806 weak_factory_.GetWeakPtr(), render_process_id, render_frame_id, | 828 weak_factory_.GetWeakPtr(), render_process_id, render_frame_id, |
| 807 content::PresentationSessionInfo(presentation_url, presentation_id), | 829 content::PresentationSessionInfo(presentation_url, presentation_id), |
| 808 success_cb, error_cb)); | 830 success_cb, error_cb)); |
| 809 router_->JoinRoute( | 831 router_->JoinRoute( |
| 810 MediaSourceForPresentationUrl(presentation_url).id(), presentation_id, | 832 MediaSourceForPresentationUrl(presentation_url).id(), presentation_id, |
| 811 GetLastCommittedURLForFrame( | 833 GetLastCommittedURLForFrame( |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( | 960 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( |
| 939 int render_process_id, | 961 int render_process_id, |
| 940 int render_frame_id, | 962 int render_frame_id, |
| 941 const MediaSource::Id& source_id) const { | 963 const MediaSource::Id& source_id) const { |
| 942 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 964 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
| 943 return frame_manager_->HasScreenAvailabilityListenerForTest( | 965 return frame_manager_->HasScreenAvailabilityListenerForTest( |
| 944 render_frame_host_id, source_id); | 966 render_frame_host_id, source_id); |
| 945 } | 967 } |
| 946 | 968 |
| 947 } // namespace media_router | 969 } // namespace media_router |
| OLD | NEW |