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 "chrome/browser/media/router/create_presentation_connection_request.h" | 16 #include "chrome/browser/media/router/create_presentation_connection_request.h" |
17 #include "chrome/browser/media/router/media_route.h" | 17 #include "chrome/browser/media/router/media_route.h" |
18 #include "chrome/browser/media/router/media_router.h" | 18 #include "chrome/browser/media/router/media_router.h" |
19 #include "chrome/browser/media/router/media_router_dialog_controller.h" | 19 #include "chrome/browser/media/router/media_router_dialog_controller.h" |
20 #include "chrome/browser/media/router/media_router_factory.h" | 20 #include "chrome/browser/media/router/media_router_factory.h" |
21 #include "chrome/browser/media/router/media_sink.h" | 21 #include "chrome/browser/media/router/media_sink.h" |
22 #include "chrome/browser/media/router/media_source_helper.h" | 22 #include "chrome/browser/media/router/media_source_helper.h" |
23 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" | 23 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" |
24 #include "chrome/browser/media/router/route_message.h" | 24 #include "chrome/browser/media/router/route_message.h" |
25 #include "chrome/browser/media/router/route_message_observer.h" | 25 #include "chrome/browser/media/router/route_message_observer.h" |
26 #include "chrome/browser/media/router/route_request_result.h" | 26 #include "chrome/browser/media/router/route_request_result.h" |
27 #include "chrome/browser/profiles/profile.h" | |
27 #include "chrome/browser/sessions/session_tab_helper.h" | 28 #include "chrome/browser/sessions/session_tab_helper.h" |
29 #include "chrome/common/pref_names.h" | |
30 #include "components/prefs/pref_service.h" | |
28 #include "content/public/browser/browser_context.h" | 31 #include "content/public/browser/browser_context.h" |
29 #include "content/public/browser/presentation_screen_availability_listener.h" | 32 #include "content/public/browser/presentation_screen_availability_listener.h" |
30 #include "content/public/browser/presentation_session.h" | 33 #include "content/public/browser/presentation_session.h" |
31 #include "content/public/browser/render_frame_host.h" | 34 #include "content/public/browser/render_frame_host.h" |
32 #include "content/public/browser/render_process_host.h" | 35 #include "content/public/browser/render_process_host.h" |
33 | 36 |
34 DEFINE_WEB_CONTENTS_USER_DATA_KEY( | 37 DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
35 media_router::PresentationServiceDelegateImpl); | 38 media_router::PresentationServiceDelegateImpl); |
36 | 39 |
37 using content::RenderFrameHost; | 40 using content::RenderFrameHost; |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
814 int render_process_id, | 817 int render_process_id, |
815 int render_frame_id, | 818 int render_frame_id, |
816 const std::vector<GURL>& presentation_urls, | 819 const std::vector<GURL>& presentation_urls, |
817 const std::string& presentation_id, | 820 const std::string& presentation_id, |
818 const content::PresentationSessionStartedCallback& success_cb, | 821 const content::PresentationSessionStartedCallback& success_cb, |
819 const content::PresentationSessionErrorCallback& error_cb) { | 822 const content::PresentationSessionErrorCallback& error_cb) { |
820 if (presentation_urls.empty()) { | 823 if (presentation_urls.empty()) { |
821 error_cb.Run(content::PresentationError( | 824 error_cb.Run(content::PresentationError( |
822 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, | 825 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, |
823 "Invalid presentation arguments.")); | 826 "Invalid presentation arguments.")); |
827 return; | |
828 } | |
829 | |
830 url::Origin origin = url::Origin(GetLastCommittedURLForFrame( | |
mark a. foltz
2016/12/05 21:32:21
You'l need to rebase and pass |web_contents_| here
takumif
2016/12/06 02:21:57
Done.
| |
831 RenderFrameHostId(render_process_id, render_frame_id))); | |
832 | |
833 if (IsAutoJoinPresentationId(presentation_id) && | |
834 ShouldOverrideAutoJoinForOrigin(origin)) { | |
835 error_cb.Run(content::PresentationError( | |
836 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, | |
837 "Auto-join request overridden by user preferences.")); | |
mark a. foltz
2016/12/05 21:32:22
s/overridden/cancelled/
takumif
2016/12/06 02:21:57
Done.
| |
838 return; | |
824 } | 839 } |
825 | 840 |
826 // TODO(crbug.com/627655): Handle multiple URLs. | 841 // TODO(crbug.com/627655): Handle multiple URLs. |
827 const GURL& presentation_url = presentation_urls[0]; | 842 const GURL& presentation_url = presentation_urls[0]; |
828 bool incognito = web_contents_->GetBrowserContext()->IsOffTheRecord(); | 843 bool incognito = web_contents_->GetBrowserContext()->IsOffTheRecord(); |
829 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 844 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
830 route_response_callbacks.push_back( | 845 route_response_callbacks.push_back( |
831 base::Bind(&PresentationServiceDelegateImpl::OnJoinRouteResponse, | 846 base::Bind(&PresentationServiceDelegateImpl::OnJoinRouteResponse, |
832 weak_factory_.GetWeakPtr(), render_process_id, render_frame_id, | 847 weak_factory_.GetWeakPtr(), render_process_id, render_frame_id, |
833 presentation_url, presentation_id, success_cb, error_cb)); | 848 presentation_url, presentation_id, success_cb, error_cb)); |
834 router_->JoinRoute( | 849 router_->JoinRoute(MediaSourceForPresentationUrl(presentation_url).id(), |
835 MediaSourceForPresentationUrl(presentation_url).id(), presentation_id, | 850 presentation_id, origin.GetURL(), web_contents_, |
836 GetLastCommittedURLForFrame( | 851 route_response_callbacks, base::TimeDelta(), incognito); |
837 RenderFrameHostId(render_process_id, render_frame_id)) | |
838 .GetOrigin(), | |
839 web_contents_, route_response_callbacks, base::TimeDelta(), incognito); | |
840 } | 852 } |
841 | 853 |
842 void PresentationServiceDelegateImpl::CloseConnection( | 854 void PresentationServiceDelegateImpl::CloseConnection( |
843 int render_process_id, | 855 int render_process_id, |
844 int render_frame_id, | 856 int render_frame_id, |
845 const std::string& presentation_id) { | 857 const std::string& presentation_id) { |
846 const RenderFrameHostId rfh_id(render_process_id, render_frame_id); | 858 const RenderFrameHostId rfh_id(render_process_id, render_frame_id); |
847 const MediaRoute::Id& route_id = | 859 const MediaRoute::Id& route_id = |
848 frame_manager_->GetRouteId(rfh_id, presentation_id); | 860 frame_manager_->GetRouteId(rfh_id, presentation_id); |
849 if (route_id.empty()) { | 861 if (route_id.empty()) { |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
962 | 974 |
963 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( | 975 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( |
964 int render_process_id, | 976 int render_process_id, |
965 int render_frame_id, | 977 int render_frame_id, |
966 const MediaSource::Id& source_id) const { | 978 const MediaSource::Id& source_id) const { |
967 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 979 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
968 return frame_manager_->HasScreenAvailabilityListenerForTest( | 980 return frame_manager_->HasScreenAvailabilityListenerForTest( |
969 render_frame_host_id, source_id); | 981 render_frame_host_id, source_id); |
970 } | 982 } |
971 | 983 |
984 bool PresentationServiceDelegateImpl::ShouldOverrideAutoJoinForOrigin( | |
985 const url::Origin& origin) const { | |
986 Profile* profile = | |
imcheng
2016/12/05 20:12:33
would it be sufficient to just check IsOffTheRecor
takumif
2016/12/06 02:21:57
I think so. Changing.
| |
987 Profile::FromBrowserContext(web_contents_->GetBrowserContext()); | |
988 // If this is a guest or incognito profile, ignore the preferences. | |
mark a. foltz
2016/12/05 21:32:21
Why are we ignoring the preference for incognito p
takumif
2016/12/06 02:21:57
I thought that not reading/writing user pref would
| |
989 if (profile->GetProfileType() != Profile::ProfileType::REGULAR_PROFILE) | |
990 return false; | |
991 | |
992 const base::ListValue* origins = | |
993 profile->GetPrefs()->GetList(prefs::kMediaRouterTabMirroringSources); | |
994 return origins && | |
995 origins->Find(base::StringValue(origin.Serialize())) != origins->end(); | |
996 } | |
997 | |
972 } // namespace media_router | 998 } // namespace media_router |
OLD | NEW |