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> |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 } | 56 } |
| 57 | 57 |
| 58 // Gets the last committed URL for the render frame specified by | 58 // Gets the last committed URL for the render frame specified by |
| 59 // |render_frame_host_id|. | 59 // |render_frame_host_id|. |
| 60 GURL GetLastCommittedURLForFrame(RenderFrameHostId render_frame_host_id) { | 60 GURL GetLastCommittedURLForFrame(RenderFrameHostId render_frame_host_id) { |
| 61 RenderFrameHost* render_frame_host = RenderFrameHost::FromID( | 61 RenderFrameHost* render_frame_host = RenderFrameHost::FromID( |
| 62 render_frame_host_id.first, render_frame_host_id.second); | 62 render_frame_host_id.first, render_frame_host_id.second); |
| 63 if (!render_frame_host) | 63 if (!render_frame_host) |
| 64 return GURL(); | 64 return GURL(); |
| 65 | 65 |
| 66 // TODO(crbug.com/632623): Use url::Origin in place of GURL for origins | 66 // TODO(crbug.com/632623): Use url::Origin in place of GURL for origins |
|
mark a. foltz
2017/01/20 18:26:40
Note this TODO: Verify that we only use the origin
steimel
2017/01/23 19:24:59
Done.
| |
| 67 return render_frame_host->GetLastCommittedOrigin().GetURL(); | 67 return render_frame_host->GetLastCommittedOrigin().GetURL(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 // Observes messages originating from the MediaSink connected to a MediaRoute | 70 // Observes messages originating from the MediaSink connected to a MediaRoute |
| 71 // that represents a presentation. Converts the messages into | 71 // that represents a presentation. Converts the messages into |
| 72 // content::PresentationSessionMessages and dispatches them via the provided | 72 // content::PresentationSessionMessages and dispatches them via the provided |
| 73 // PresentationSessionMessageCallback. | 73 // PresentationSessionMessageCallback. |
| 74 class PresentationSessionMessagesObserver : public RouteMessageObserver { | 74 class PresentationSessionMessagesObserver : public RouteMessageObserver { |
| 75 public: | 75 public: |
| 76 // |message_cb|: The callback to invoke whenever messages are received. | 76 // |message_cb|: The callback to invoke whenever messages are received. |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 | 229 |
| 230 bool PresentationFrame::SetScreenAvailabilityListener( | 230 bool PresentationFrame::SetScreenAvailabilityListener( |
| 231 content::PresentationScreenAvailabilityListener* listener) { | 231 content::PresentationScreenAvailabilityListener* listener) { |
| 232 MediaSource source(GetMediaSourceFromListener(listener)); | 232 MediaSource source(GetMediaSourceFromListener(listener)); |
| 233 auto& sinks_observer = url_to_sinks_observer_[source.id()]; | 233 auto& sinks_observer = url_to_sinks_observer_[source.id()]; |
| 234 if (sinks_observer && sinks_observer->listener() == listener) | 234 if (sinks_observer && sinks_observer->listener() == listener) |
| 235 return false; | 235 return false; |
| 236 | 236 |
| 237 sinks_observer.reset(new PresentationMediaSinksObserver( | 237 sinks_observer.reset(new PresentationMediaSinksObserver( |
| 238 router_, listener, source, | 238 router_, listener, source, |
| 239 GetLastCommittedURLForFrame(render_frame_host_id_).GetOrigin())); | 239 url::Origin( |
| 240 GetLastCommittedURLForFrame(render_frame_host_id_).GetOrigin()))); | |
| 240 | 241 |
| 241 if (!sinks_observer->Init()) { | 242 if (!sinks_observer->Init()) { |
| 242 url_to_sinks_observer_.erase(source.id()); | 243 url_to_sinks_observer_.erase(source.id()); |
| 243 listener->OnScreenAvailabilityNotSupported(); | 244 listener->OnScreenAvailabilityNotSupported(); |
| 244 return false; | 245 return false; |
| 245 } | 246 } |
| 246 | 247 |
| 247 return true; | 248 return true; |
| 248 } | 249 } |
| 249 | 250 |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 846 | 847 |
| 847 // TODO(crbug.com/627655): Handle multiple URLs. | 848 // TODO(crbug.com/627655): Handle multiple URLs. |
| 848 const GURL& presentation_url = presentation_urls[0]; | 849 const GURL& presentation_url = presentation_urls[0]; |
| 849 bool incognito = web_contents_->GetBrowserContext()->IsOffTheRecord(); | 850 bool incognito = web_contents_->GetBrowserContext()->IsOffTheRecord(); |
| 850 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 851 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 851 route_response_callbacks.push_back( | 852 route_response_callbacks.push_back( |
| 852 base::Bind(&PresentationServiceDelegateImpl::OnJoinRouteResponse, | 853 base::Bind(&PresentationServiceDelegateImpl::OnJoinRouteResponse, |
| 853 weak_factory_.GetWeakPtr(), render_process_id, render_frame_id, | 854 weak_factory_.GetWeakPtr(), render_process_id, render_frame_id, |
| 854 presentation_url, presentation_id, success_cb, error_cb)); | 855 presentation_url, presentation_id, success_cb, error_cb)); |
| 855 router_->JoinRoute(MediaSourceForPresentationUrl(presentation_url).id(), | 856 router_->JoinRoute(MediaSourceForPresentationUrl(presentation_url).id(), |
| 856 presentation_id, origin.GetURL(), web_contents_, | 857 presentation_id, origin, web_contents_, |
| 857 route_response_callbacks, base::TimeDelta(), incognito); | 858 route_response_callbacks, base::TimeDelta(), incognito); |
| 858 } | 859 } |
| 859 | 860 |
| 860 void PresentationServiceDelegateImpl::CloseConnection( | 861 void PresentationServiceDelegateImpl::CloseConnection( |
| 861 int render_process_id, | 862 int render_process_id, |
| 862 int render_frame_id, | 863 int render_frame_id, |
| 863 const std::string& presentation_id) { | 864 const std::string& presentation_id) { |
| 864 const RenderFrameHostId rfh_id(render_process_id, render_frame_id); | 865 const RenderFrameHostId rfh_id(render_process_id, render_frame_id); |
| 865 const MediaRoute::Id& route_id = | 866 const MediaRoute::Id& route_id = |
| 866 frame_manager_->GetRouteId(rfh_id, presentation_id); | 867 frame_manager_->GetRouteId(rfh_id, presentation_id); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 996 const base::ListValue* origins = | 997 const base::ListValue* origins = |
| 997 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) | 998 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) |
| 998 ->GetPrefs() | 999 ->GetPrefs() |
| 999 ->GetList(prefs::kMediaRouterTabMirroringSources); | 1000 ->GetList(prefs::kMediaRouterTabMirroringSources); |
| 1000 return origins && | 1001 return origins && |
| 1001 origins->Find(base::StringValue(origin.Serialize())) != origins->end(); | 1002 origins->Find(base::StringValue(origin.Serialize())) != origins->end(); |
| 1002 } | 1003 } |
| 1003 #endif // !defined(OS_ANDROID) | 1004 #endif // !defined(OS_ANDROID) |
| 1004 | 1005 |
| 1005 } // namespace media_router | 1006 } // namespace media_router |
| OLD | NEW |