| 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 <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 frame_manager_->RemoveScreenAvailabilityListener( | 655 frame_manager_->RemoveScreenAvailabilityListener( |
| 656 RenderFrameHostId(render_process_id, render_frame_id), listener); | 656 RenderFrameHostId(render_process_id, render_frame_id), listener); |
| 657 } | 657 } |
| 658 | 658 |
| 659 void PresentationServiceDelegateImpl::Reset(int render_process_id, | 659 void PresentationServiceDelegateImpl::Reset(int render_process_id, |
| 660 int render_frame_id) { | 660 int render_frame_id) { |
| 661 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 661 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
| 662 frame_manager_->Reset(render_frame_host_id); | 662 frame_manager_->Reset(render_frame_host_id); |
| 663 } | 663 } |
| 664 | 664 |
| 665 void PresentationServiceDelegateImpl::SetDefaultPresentationUrl( | 665 void PresentationServiceDelegateImpl::SetDefaultPresentationUrls( |
| 666 int render_process_id, | 666 int render_process_id, |
| 667 int render_frame_id, | 667 int render_frame_id, |
| 668 const std::string& default_presentation_url, | 668 const std::vector<std::string>& default_presentation_urls, |
| 669 const content::PresentationSessionStartedCallback& callback) { | 669 const content::PresentationSessionStartedCallback& callback) { |
| 670 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 670 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
| 671 frame_manager_->SetDefaultPresentationUrl(render_frame_host_id, | 671 if (default_presentation_urls.empty()) { |
| 672 default_presentation_url, callback); | 672 frame_manager_->SetDefaultPresentationUrl(render_frame_host_id, |
| 673 std::string(), callback); |
| 674 } else { |
| 675 // TODO(crbug.com/627655): Handle multiple URLs. |
| 676 frame_manager_->SetDefaultPresentationUrl( |
| 677 render_frame_host_id, default_presentation_urls[0], callback); |
| 678 } |
| 673 } | 679 } |
| 674 | 680 |
| 675 void PresentationServiceDelegateImpl::OnJoinRouteResponse( | 681 void PresentationServiceDelegateImpl::OnJoinRouteResponse( |
| 676 int render_process_id, | 682 int render_process_id, |
| 677 int render_frame_id, | 683 int render_frame_id, |
| 678 const content::PresentationSessionInfo& session, | 684 const content::PresentationSessionInfo& session, |
| 679 const content::PresentationSessionStartedCallback& success_cb, | 685 const content::PresentationSessionStartedCallback& success_cb, |
| 680 const content::PresentationSessionErrorCallback& error_cb, | 686 const content::PresentationSessionErrorCallback& error_cb, |
| 681 const RouteRequestResult& result) { | 687 const RouteRequestResult& result) { |
| 682 if (!result.route()) { | 688 if (!result.route()) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 707 << ", presentation ID: " << new_session.presentation_id; | 713 << ", presentation ID: " << new_session.presentation_id; |
| 708 frame_manager_->OnPresentationSessionStarted( | 714 frame_manager_->OnPresentationSessionStarted( |
| 709 RenderFrameHostId(render_process_id, render_frame_id), new_session, | 715 RenderFrameHostId(render_process_id, render_frame_id), new_session, |
| 710 route_id); | 716 route_id); |
| 711 success_cb.Run(new_session); | 717 success_cb.Run(new_session); |
| 712 } | 718 } |
| 713 | 719 |
| 714 void PresentationServiceDelegateImpl::StartSession( | 720 void PresentationServiceDelegateImpl::StartSession( |
| 715 int render_process_id, | 721 int render_process_id, |
| 716 int render_frame_id, | 722 int render_frame_id, |
| 717 const std::string& presentation_url, | 723 const std::vector<std::string>& presentation_urls, |
| 718 const content::PresentationSessionStartedCallback& success_cb, | 724 const content::PresentationSessionStartedCallback& success_cb, |
| 719 const content::PresentationSessionErrorCallback& error_cb) { | 725 const content::PresentationSessionErrorCallback& error_cb) { |
| 726 if (presentation_urls.empty()) { |
| 727 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, |
| 728 "Invalid presentation arguments.")); |
| 729 return; |
| 730 } |
| 731 |
| 732 // TODO(crbug.com/627655): Handle multiple URLs. |
| 733 const std::string& presentation_url = presentation_urls[0]; |
| 720 if (presentation_url.empty() || !IsValidPresentationUrl(presentation_url)) { | 734 if (presentation_url.empty() || !IsValidPresentationUrl(presentation_url)) { |
| 721 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, | 735 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, |
| 722 "Invalid presentation arguments.")); | 736 "Invalid presentation arguments.")); |
| 723 return; | 737 return; |
| 724 } | 738 } |
| 725 | 739 |
| 726 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 740 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
| 727 std::unique_ptr<CreatePresentationConnectionRequest> request( | 741 std::unique_ptr<CreatePresentationConnectionRequest> request( |
| 728 new CreatePresentationConnectionRequest( | 742 new CreatePresentationConnectionRequest( |
| 729 render_frame_host_id, presentation_url, | 743 render_frame_host_id, presentation_url, |
| 730 GetLastCommittedURLForFrame(render_frame_host_id), | 744 GetLastCommittedURLForFrame(render_frame_host_id), |
| 731 base::Bind(&PresentationServiceDelegateImpl::OnStartSessionSucceeded, | 745 base::Bind(&PresentationServiceDelegateImpl::OnStartSessionSucceeded, |
| 732 weak_factory_.GetWeakPtr(), render_process_id, | 746 weak_factory_.GetWeakPtr(), render_process_id, |
| 733 render_frame_id, success_cb), | 747 render_frame_id, success_cb), |
| 734 error_cb)); | 748 error_cb)); |
| 735 MediaRouterDialogController* controller = | 749 MediaRouterDialogController* controller = |
| 736 MediaRouterDialogController::GetOrCreateForWebContents(web_contents_); | 750 MediaRouterDialogController::GetOrCreateForWebContents(web_contents_); |
| 737 if (!controller->ShowMediaRouterDialogForPresentation(std::move(request))) { | 751 if (!controller->ShowMediaRouterDialogForPresentation(std::move(request))) { |
| 738 LOG(ERROR) << "Media router dialog already exists. Ignoring StartSession."; | 752 LOG(ERROR) << "Media router dialog already exists. Ignoring StartSession."; |
| 739 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, | 753 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, |
| 740 "Unable to create dialog.")); | 754 "Unable to create dialog.")); |
| 741 return; | 755 return; |
| 742 } | 756 } |
| 743 } | 757 } |
| 744 | 758 |
| 745 void PresentationServiceDelegateImpl::JoinSession( | 759 void PresentationServiceDelegateImpl::JoinSession( |
| 746 int render_process_id, | 760 int render_process_id, |
| 747 int render_frame_id, | 761 int render_frame_id, |
| 748 const std::string& presentation_url, | 762 const std::vector<std::string>& presentation_urls, |
| 749 const std::string& presentation_id, | 763 const std::string& presentation_id, |
| 750 const content::PresentationSessionStartedCallback& success_cb, | 764 const content::PresentationSessionStartedCallback& success_cb, |
| 751 const content::PresentationSessionErrorCallback& error_cb) { | 765 const content::PresentationSessionErrorCallback& error_cb) { |
| 766 if (presentation_urls.empty()) { |
| 767 error_cb.Run(content::PresentationError( |
| 768 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, |
| 769 "Invalid presentation arguments.")); |
| 770 } |
| 771 |
| 772 // TODO(crbug.com/627655): Handle multiple URLs. |
| 773 const std::string& presentation_url = presentation_urls[0]; |
| 752 bool incognito = web_contents_->GetBrowserContext()->IsOffTheRecord(); | 774 bool incognito = web_contents_->GetBrowserContext()->IsOffTheRecord(); |
| 753 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 775 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 754 route_response_callbacks.push_back(base::Bind( | 776 route_response_callbacks.push_back(base::Bind( |
| 755 &PresentationServiceDelegateImpl::OnJoinRouteResponse, | 777 &PresentationServiceDelegateImpl::OnJoinRouteResponse, |
| 756 weak_factory_.GetWeakPtr(), render_process_id, render_frame_id, | 778 weak_factory_.GetWeakPtr(), render_process_id, render_frame_id, |
| 757 content::PresentationSessionInfo(presentation_url, presentation_id), | 779 content::PresentationSessionInfo(presentation_url, presentation_id), |
| 758 success_cb, error_cb)); | 780 success_cb, error_cb)); |
| 759 router_->JoinRoute( | 781 router_->JoinRoute( |
| 760 MediaSourceForPresentationUrl(presentation_url).id(), presentation_id, | 782 MediaSourceForPresentationUrl(presentation_url).id(), presentation_id, |
| 761 GetLastCommittedURLForFrame( | 783 GetLastCommittedURLForFrame( |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 888 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( | 910 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( |
| 889 int render_process_id, | 911 int render_process_id, |
| 890 int render_frame_id, | 912 int render_frame_id, |
| 891 const MediaSource::Id& source_id) const { | 913 const MediaSource::Id& source_id) const { |
| 892 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 914 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
| 893 return frame_manager_->HasScreenAvailabilityListenerForTest( | 915 return frame_manager_->HasScreenAvailabilityListenerForTest( |
| 894 render_frame_host_id, source_id); | 916 render_frame_host_id, source_id); |
| 895 } | 917 } |
| 896 | 918 |
| 897 } // namespace media_router | 919 } // namespace media_router |
| OLD | NEW |