Chromium Code Reviews| 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/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 #include "chrome/browser/profiles/profile.h" | |
| 28 #include "chrome/browser/sessions/session_tab_helper.h" | 29 #include "chrome/browser/sessions/session_tab_helper.h" |
| 30 #include "chrome/common/pref_names.h" | |
| 31 #include "components/prefs/pref_service.h" | |
| 29 #include "content/public/browser/browser_context.h" | 32 #include "content/public/browser/browser_context.h" |
| 30 #include "content/public/browser/presentation_screen_availability_listener.h" | 33 #include "content/public/browser/presentation_screen_availability_listener.h" |
| 31 #include "content/public/browser/presentation_session.h" | 34 #include "content/public/browser/presentation_session.h" |
| 32 #include "content/public/browser/render_frame_host.h" | 35 #include "content/public/browser/render_frame_host.h" |
| 33 #include "content/public/browser/render_process_host.h" | 36 #include "content/public/browser/render_process_host.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 |
| 47 // This value must be the same as |chrome.cast.AUTO_JOIN_PRESENTATION_ID| in the | |
| 48 // component extension. | |
| 49 const char kAutoJoinPresentationId[] = "auto-join"; | |
|
mark a. foltz
2016/11/22 22:23:21
Slight preference for moving the logic for detecti
takumif
2016/12/03 00:46:48
Done.
| |
| 50 | |
| 44 using DelegateObserver = content::PresentationServiceDelegate::Observer; | 51 using DelegateObserver = content::PresentationServiceDelegate::Observer; |
| 45 | 52 |
| 46 // Returns the unique identifier for the supplied RenderFrameHost. | 53 // Returns the unique identifier for the supplied RenderFrameHost. |
| 47 RenderFrameHostId GetRenderFrameHostId(RenderFrameHost* render_frame_host) { | 54 RenderFrameHostId GetRenderFrameHostId(RenderFrameHost* render_frame_host) { |
| 48 int render_process_id = render_frame_host->GetProcess()->GetID(); | 55 int render_process_id = render_frame_host->GetProcess()->GetID(); |
| 49 int render_frame_id = render_frame_host->GetRoutingID(); | 56 int render_frame_id = render_frame_host->GetRoutingID(); |
| 50 return RenderFrameHostId(render_process_id, render_frame_id); | 57 return RenderFrameHostId(render_process_id, render_frame_id); |
| 51 } | 58 } |
| 52 | 59 |
| 53 // Gets the last committed URL for the render frame specified by | 60 // Gets the last committed URL for the render frame specified by |
| (...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 811 int render_process_id, | 818 int render_process_id, |
| 812 int render_frame_id, | 819 int render_frame_id, |
| 813 const std::vector<GURL>& presentation_urls, | 820 const std::vector<GURL>& presentation_urls, |
| 814 const std::string& presentation_id, | 821 const std::string& presentation_id, |
| 815 const content::PresentationSessionStartedCallback& success_cb, | 822 const content::PresentationSessionStartedCallback& success_cb, |
| 816 const content::PresentationSessionErrorCallback& error_cb) { | 823 const content::PresentationSessionErrorCallback& error_cb) { |
| 817 if (presentation_urls.empty()) { | 824 if (presentation_urls.empty()) { |
| 818 error_cb.Run(content::PresentationError( | 825 error_cb.Run(content::PresentationError( |
| 819 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, | 826 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, |
| 820 "Invalid presentation arguments.")); | 827 "Invalid presentation arguments.")); |
| 828 return; | |
| 829 } | |
| 830 | |
| 831 GURL origin = GetLastCommittedURLForFrame( | |
|
mark a. foltz
2016/11/22 22:23:21
We should use url::Origin for origins going forwar
takumif
2016/12/03 00:46:48
Done.
| |
| 832 RenderFrameHostId(render_process_id, render_frame_id)) | |
| 833 .GetOrigin(); | |
| 834 | |
| 835 if (presentation_id == kAutoJoinPresentationId && | |
| 836 ShouldOverrideAutoJoinForOrigin(origin)) { | |
| 837 error_cb.Run(content::PresentationError( | |
| 838 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, | |
| 839 "Auto-join request overridden by user preferences.")); | |
| 840 return; | |
| 821 } | 841 } |
| 822 | 842 |
| 823 // TODO(crbug.com/627655): Handle multiple URLs. | 843 // TODO(crbug.com/627655): Handle multiple URLs. |
| 824 const GURL& presentation_url = presentation_urls[0]; | 844 const GURL& presentation_url = presentation_urls[0]; |
| 825 bool incognito = web_contents_->GetBrowserContext()->IsOffTheRecord(); | 845 bool incognito = web_contents_->GetBrowserContext()->IsOffTheRecord(); |
| 826 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 846 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 827 route_response_callbacks.push_back(base::Bind( | 847 route_response_callbacks.push_back(base::Bind( |
| 828 &PresentationServiceDelegateImpl::OnJoinRouteResponse, | 848 &PresentationServiceDelegateImpl::OnJoinRouteResponse, |
| 829 weak_factory_.GetWeakPtr(), render_process_id, render_frame_id, | 849 weak_factory_.GetWeakPtr(), render_process_id, render_frame_id, |
| 830 content::PresentationSessionInfo(presentation_url, presentation_id), | 850 content::PresentationSessionInfo(presentation_url, presentation_id), |
| 831 success_cb, error_cb)); | 851 success_cb, error_cb)); |
| 832 router_->JoinRoute( | 852 router_->JoinRoute(MediaSourceForPresentationUrl(presentation_url).id(), |
| 833 MediaSourceForPresentationUrl(presentation_url).id(), presentation_id, | 853 presentation_id, origin, web_contents_, |
| 834 GetLastCommittedURLForFrame( | 854 route_response_callbacks, base::TimeDelta(), incognito); |
| 835 RenderFrameHostId(render_process_id, render_frame_id)) | |
| 836 .GetOrigin(), | |
| 837 web_contents_, route_response_callbacks, base::TimeDelta(), incognito); | |
| 838 } | 855 } |
| 839 | 856 |
| 840 void PresentationServiceDelegateImpl::CloseConnection( | 857 void PresentationServiceDelegateImpl::CloseConnection( |
| 841 int render_process_id, | 858 int render_process_id, |
| 842 int render_frame_id, | 859 int render_frame_id, |
| 843 const std::string& presentation_id) { | 860 const std::string& presentation_id) { |
| 844 const RenderFrameHostId rfh_id(render_process_id, render_frame_id); | 861 const RenderFrameHostId rfh_id(render_process_id, render_frame_id); |
| 845 const MediaRoute::Id& route_id = | 862 const MediaRoute::Id& route_id = |
| 846 frame_manager_->GetRouteId(rfh_id, presentation_id); | 863 frame_manager_->GetRouteId(rfh_id, presentation_id); |
| 847 if (route_id.empty()) { | 864 if (route_id.empty()) { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 960 | 977 |
| 961 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( | 978 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( |
| 962 int render_process_id, | 979 int render_process_id, |
| 963 int render_frame_id, | 980 int render_frame_id, |
| 964 const MediaSource::Id& source_id) const { | 981 const MediaSource::Id& source_id) const { |
| 965 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 982 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
| 966 return frame_manager_->HasScreenAvailabilityListenerForTest( | 983 return frame_manager_->HasScreenAvailabilityListenerForTest( |
| 967 render_frame_host_id, source_id); | 984 render_frame_host_id, source_id); |
| 968 } | 985 } |
| 969 | 986 |
| 987 bool PresentationServiceDelegateImpl::ShouldOverrideAutoJoinForOrigin( | |
| 988 const GURL& origin) const { | |
| 989 const base::ListValue* hostnames = | |
|
mark a. foltz
2016/11/22 22:23:21
What if hostnames is not set?
takumif
2016/12/03 00:46:48
Adding a check for that.
| |
| 990 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) | |
|
mark a. foltz
2016/11/22 22:23:21
What if this is an incognito window?
takumif
2016/12/03 00:46:48
I think we should ignore the preferences (and don'
| |
| 991 ->GetPrefs() | |
| 992 ->GetList(prefs::kMediaRouterTabMirroringSources); | |
|
mark a. foltz
2016/11/22 22:23:21
How expensive is looking up this pref? Can it cha
takumif
2016/11/29 23:56:45
I'm not sure how expensive this is. It's a disk re
mark a. foltz
2016/12/01 00:04:34
It appears unlikely to cause a disk read. But it
takumif
2016/12/03 00:46:48
Got it. Keeping it as is, as MediaRouterUI changes
| |
| 993 return hostnames->Find(base::StringValue(origin.spec())) != | |
| 994 hostnames->end(); | |
| 995 } | |
| 996 | |
| 970 } // namespace media_router | 997 } // namespace media_router |
| OLD | NEW |