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/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.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/presentation_media_sinks_observer.h" | 24 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" |
25 #include "chrome/browser/media/router/route_message.h" | 25 #include "chrome/browser/media/router/route_message.h" |
26 #include "chrome/browser/media/router/route_message_observer.h" | 26 #include "chrome/browser/media/router/route_message_observer.h" |
27 #include "chrome/browser/media/router/route_request_result.h" | 27 #include "chrome/browser/media/router/route_request_result.h" |
28 #if !defined(OS_ANDROID) | |
apacible
2016/12/07 00:53:09
nit: move all #if !defined(OS_ANDROID) includes to
takumif
2016/12/08 00:01:30
Done.
| |
29 #include "chrome/browser/profiles/profile.h" | |
30 #endif | |
28 #include "chrome/browser/sessions/session_tab_helper.h" | 31 #include "chrome/browser/sessions/session_tab_helper.h" |
32 #if !defined(OS_ANDROID) | |
33 #include "chrome/common/pref_names.h" | |
34 #include "components/prefs/pref_service.h" | |
35 #endif | |
29 #include "content/public/browser/browser_context.h" | 36 #include "content/public/browser/browser_context.h" |
30 #include "content/public/browser/presentation_screen_availability_listener.h" | 37 #include "content/public/browser/presentation_screen_availability_listener.h" |
31 #include "content/public/browser/presentation_session.h" | 38 #include "content/public/browser/presentation_session.h" |
32 #include "content/public/browser/render_frame_host.h" | 39 #include "content/public/browser/render_frame_host.h" |
33 #include "content/public/browser/render_process_host.h" | 40 #include "content/public/browser/render_process_host.h" |
34 | 41 |
35 DEFINE_WEB_CONTENTS_USER_DATA_KEY( | 42 DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
36 media_router::PresentationServiceDelegateImpl); | 43 media_router::PresentationServiceDelegateImpl); |
37 | 44 |
38 using content::RenderFrameHost; | 45 using content::RenderFrameHost; |
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
811 MediaRouterDialogController* controller = | 818 MediaRouterDialogController* controller = |
812 MediaRouterDialogController::GetOrCreateForWebContents(web_contents_); | 819 MediaRouterDialogController::GetOrCreateForWebContents(web_contents_); |
813 if (!controller->ShowMediaRouterDialogForPresentation(std::move(request))) { | 820 if (!controller->ShowMediaRouterDialogForPresentation(std::move(request))) { |
814 LOG(ERROR) << "Media router dialog already exists. Ignoring StartSession."; | 821 LOG(ERROR) << "Media router dialog already exists. Ignoring StartSession."; |
815 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, | 822 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, |
816 "Unable to create dialog.")); | 823 "Unable to create dialog.")); |
817 return; | 824 return; |
818 } | 825 } |
819 } | 826 } |
820 | 827 |
821 void PresentationServiceDelegateImpl::JoinSession( | 828 void PresentationServiceDelegateImpl::JoinSession( |
apacible
2016/12/07 00:53:09
Remind me -- when does JoinSession get called? Is
takumif
2016/12/08 00:01:30
It's called with "auto-join" presentation ID when
| |
822 int render_process_id, | 829 int render_process_id, |
823 int render_frame_id, | 830 int render_frame_id, |
824 const std::vector<GURL>& presentation_urls, | 831 const std::vector<GURL>& presentation_urls, |
825 const std::string& presentation_id, | 832 const std::string& presentation_id, |
826 const content::PresentationSessionStartedCallback& success_cb, | 833 const content::PresentationSessionStartedCallback& success_cb, |
827 const content::PresentationSessionErrorCallback& error_cb) { | 834 const content::PresentationSessionErrorCallback& error_cb) { |
828 if (presentation_urls.empty()) { | 835 if (presentation_urls.empty()) { |
829 error_cb.Run(content::PresentationError( | 836 error_cb.Run(content::PresentationError( |
830 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, | 837 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, |
831 "Invalid presentation arguments.")); | 838 "Invalid presentation arguments.")); |
839 return; | |
832 } | 840 } |
833 | 841 |
842 url::Origin origin = url::Origin(GetLastCommittedURLForFrame( | |
mark a. foltz
2016/12/07 04:19:01
Use a const ref
takumif
2016/12/08 00:01:30
Done.
| |
843 RenderFrameHostId(render_process_id, render_frame_id), web_contents_)); | |
844 | |
845 #if !defined(OS_ANDROID) | |
846 if (IsAutoJoinPresentationId(presentation_id) && | |
847 ShouldCancelAutoJoinForOrigin(origin)) { | |
848 error_cb.Run(content::PresentationError( | |
849 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, | |
850 "Auto-join request cancelled by user preferences.")); | |
851 return; | |
852 } | |
853 #endif // !defined(OS_ANDROID) | |
854 | |
834 // TODO(crbug.com/627655): Handle multiple URLs. | 855 // TODO(crbug.com/627655): Handle multiple URLs. |
835 const GURL& presentation_url = presentation_urls[0]; | 856 const GURL& presentation_url = presentation_urls[0]; |
836 bool incognito = web_contents_->GetBrowserContext()->IsOffTheRecord(); | 857 bool incognito = web_contents_->GetBrowserContext()->IsOffTheRecord(); |
837 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 858 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
838 route_response_callbacks.push_back( | 859 route_response_callbacks.push_back( |
839 base::Bind(&PresentationServiceDelegateImpl::OnJoinRouteResponse, | 860 base::Bind(&PresentationServiceDelegateImpl::OnJoinRouteResponse, |
840 weak_factory_.GetWeakPtr(), render_process_id, render_frame_id, | 861 weak_factory_.GetWeakPtr(), render_process_id, render_frame_id, |
841 presentation_url, presentation_id, success_cb, error_cb)); | 862 presentation_url, presentation_id, success_cb, error_cb)); |
842 router_->JoinRoute( | 863 router_->JoinRoute(MediaSourceForPresentationUrl(presentation_url).id(), |
843 MediaSourceForPresentationUrl(presentation_url).id(), presentation_id, | 864 presentation_id, origin.GetURL(), web_contents_, |
844 GetLastCommittedURLForFrame( | 865 route_response_callbacks, base::TimeDelta(), incognito); |
845 RenderFrameHostId(render_process_id, render_frame_id), web_contents_) | |
846 .GetOrigin(), | |
847 web_contents_, route_response_callbacks, base::TimeDelta(), incognito); | |
848 } | 866 } |
849 | 867 |
850 void PresentationServiceDelegateImpl::CloseConnection( | 868 void PresentationServiceDelegateImpl::CloseConnection( |
851 int render_process_id, | 869 int render_process_id, |
852 int render_frame_id, | 870 int render_frame_id, |
853 const std::string& presentation_id) { | 871 const std::string& presentation_id) { |
854 const RenderFrameHostId rfh_id(render_process_id, render_frame_id); | 872 const RenderFrameHostId rfh_id(render_process_id, render_frame_id); |
855 const MediaRoute::Id& route_id = | 873 const MediaRoute::Id& route_id = |
856 frame_manager_->GetRouteId(rfh_id, presentation_id); | 874 frame_manager_->GetRouteId(rfh_id, presentation_id); |
857 if (route_id.empty()) { | 875 if (route_id.empty()) { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
970 | 988 |
971 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( | 989 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( |
972 int render_process_id, | 990 int render_process_id, |
973 int render_frame_id, | 991 int render_frame_id, |
974 const MediaSource::Id& source_id) const { | 992 const MediaSource::Id& source_id) const { |
975 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 993 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
976 return frame_manager_->HasScreenAvailabilityListenerForTest( | 994 return frame_manager_->HasScreenAvailabilityListenerForTest( |
977 render_frame_host_id, source_id); | 995 render_frame_host_id, source_id); |
978 } | 996 } |
979 | 997 |
998 #if !defined(OS_ANDROID) | |
999 bool PresentationServiceDelegateImpl::ShouldCancelAutoJoinForOrigin( | |
1000 const url::Origin& origin) const { | |
1001 Profile* profile = | |
1002 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | |
1003 // If this is a guest or incognito profile, ignore the preferences. | |
mark a. foltz
2016/12/07 04:19:01
The design doc describes how to override prefs in
takumif
2016/12/08 00:01:30
We are using user_prefs (checked by calling PrefSe
| |
1004 if (profile->IsOffTheRecord()) | |
1005 return false; | |
1006 | |
1007 const base::ListValue* origins = | |
1008 profile->GetPrefs()->GetList(prefs::kMediaRouterTabMirroringSources); | |
1009 return origins && | |
1010 origins->Find(base::StringValue(origin.Serialize())) != origins->end(); | |
1011 } | |
1012 #endif // !defined(OS_ANDROID) | |
1013 | |
980 } // namespace media_router | 1014 } // namespace media_router |
OLD | NEW |