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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 const content::PresentationConnectionStateChangedCallback& | 148 const content::PresentationConnectionStateChangedCallback& |
| 149 state_changed_cb); | 149 state_changed_cb); |
| 150 void ListenForSessionMessages( | 150 void ListenForSessionMessages( |
| 151 const content::PresentationSessionInfo& session, | 151 const content::PresentationSessionInfo& session, |
| 152 const content::PresentationConnectionMessageCallback& message_cb); | 152 const content::PresentationConnectionMessageCallback& message_cb); |
| 153 | 153 |
| 154 void Reset(); | 154 void Reset(); |
| 155 void RemoveConnection(const std::string& presentation_id, | 155 void RemoveConnection(const std::string& presentation_id, |
| 156 const MediaRoute::Id& route_id); | 156 const MediaRoute::Id& route_id); |
| 157 | 157 |
| 158 const MediaRoute::Id GetRouteId(const std::string& presentation_id) const; | 158 const MediaRoute* GetRoute(const std::string& presentation_id) const; |
| 159 | 159 |
| 160 void OnPresentationSessionStarted( | 160 void OnPresentationSessionStarted( |
| 161 const content::PresentationSessionInfo& session, | 161 const content::PresentationSessionInfo& session, |
| 162 const MediaRoute& route); | 162 const MediaRoute& route); |
| 163 void OnPresentationServiceDelegateDestroyed() const; | 163 void OnPresentationServiceDelegateDestroyed() const; |
| 164 | 164 |
| 165 bool IsOffscreenPresentation(const std::string& presentation_id) const; | |
| 166 void ConnectToPresentation( | 165 void ConnectToPresentation( |
| 167 const content::PresentationSessionInfo& session, | 166 const content::PresentationSessionInfo& session, |
| 168 content::PresentationConnectionPtr controller_connection_ptr, | 167 content::PresentationConnectionPtr controller_connection_ptr, |
| 169 content::PresentationConnectionRequest receiver_connection_request); | 168 content::PresentationConnectionRequest receiver_connection_request); |
| 170 | 169 |
| 171 private: | 170 private: |
| 172 MediaSource GetMediaSourceFromListener( | 171 MediaSource GetMediaSourceFromListener( |
| 173 content::PresentationScreenAvailabilityListener* listener) const; | 172 content::PresentationScreenAvailabilityListener* listener) const; |
| 174 base::SmallMap<std::map<std::string, MediaRoute>> presentation_id_to_route_; | 173 base::SmallMap<std::map<std::string, MediaRoute>> presentation_id_to_route_; |
| 175 base::SmallMap< | 174 base::SmallMap< |
| 176 std::map<std::string, std::unique_ptr<PresentationMediaSinksObserver>>> | 175 std::map<std::string, std::unique_ptr<PresentationMediaSinksObserver>>> |
| 177 url_to_sinks_observer_; | 176 url_to_sinks_observer_; |
| 178 std::unordered_map< | 177 std::unordered_map< |
| 179 MediaRoute::Id, | 178 MediaRoute::Id, |
| 180 std::unique_ptr<PresentationConnectionStateSubscription>> | 179 std::unique_ptr<PresentationConnectionStateSubscription>> |
| 181 connection_state_subscriptions_; | 180 connection_state_subscriptions_; |
| 182 std::unordered_map< | 181 std::unordered_map< |
| 183 MediaRoute::Id, | 182 MediaRoute::Id, |
| 184 std::unique_ptr<PresentationSessionMessagesObserver>> | 183 std::unique_ptr<PresentationSessionMessagesObserver>> |
| 185 session_messages_observers_; | 184 session_messages_observers_; |
| 186 std::unordered_map<MediaRoute::Id, | 185 std::unordered_map<MediaRoute::Id, |
| 187 std::unique_ptr<BrowserPresentationConnectionProxy>> | 186 std::unique_ptr<BrowserPresentationConnectionProxy>> |
| 188 browser_connection_proxies_; | 187 browser_connection_proxies_; |
| 189 | 188 |
| 190 RenderFrameHostId render_frame_host_id_; | 189 RenderFrameHostId render_frame_host_id_; |
| 191 | 190 |
| 192 // References to the owning WebContents, and the corresponding MediaRouter. | 191 // References to the owning WebContents, and the corresponding MediaRouter. |
| 193 content::WebContents* web_contents_; | 192 content::WebContents* web_contents_; |
| 194 MediaRouter* router_; | 193 MediaRouter* router_; |
| 194 OffscreenPresentationManager* offscreen_presentation_manager_; | |
| 195 }; | 195 }; |
| 196 | 196 |
| 197 PresentationFrame::PresentationFrame( | 197 PresentationFrame::PresentationFrame( |
| 198 const RenderFrameHostId& render_frame_host_id, | 198 const RenderFrameHostId& render_frame_host_id, |
| 199 content::WebContents* web_contents, | 199 content::WebContents* web_contents, |
| 200 MediaRouter* router) | 200 MediaRouter* router) |
| 201 : render_frame_host_id_(render_frame_host_id), | 201 : render_frame_host_id_(render_frame_host_id), |
| 202 web_contents_(web_contents), | 202 web_contents_(web_contents), |
| 203 router_(router) { | 203 router_(router), |
| 204 offscreen_presentation_manager_( | |
| 205 OffscreenPresentationManagerFactory::GetOrCreateForWebContents( | |
| 206 web_contents_)) { | |
| 204 DCHECK(web_contents_); | 207 DCHECK(web_contents_); |
| 205 DCHECK(router_); | 208 DCHECK(router_); |
| 206 } | 209 } |
| 207 | 210 |
| 208 PresentationFrame::~PresentationFrame() { | 211 PresentationFrame::~PresentationFrame() { |
| 209 } | 212 } |
| 210 | 213 |
| 211 void PresentationFrame::OnPresentationSessionStarted( | 214 void PresentationFrame::OnPresentationSessionStarted( |
| 212 const content::PresentationSessionInfo& session, | 215 const content::PresentationSessionInfo& session, |
| 213 const MediaRoute& route) { | 216 const MediaRoute& route) { |
| 214 presentation_id_to_route_.insert( | 217 presentation_id_to_route_.insert( |
| 215 std::make_pair(session.presentation_id, route)); | 218 std::make_pair(session.presentation_id, route)); |
| 219 | |
| 220 if (route.is_offscreen_presentation() && | |
| 221 !offscreen_presentation_manager_->GetRoute(session.presentation_id)) { | |
| 222 offscreen_presentation_manager_->RegisterOffscreenPresentationRoute( | |
| 223 session.presentation_id, session.presentation_url, route); | |
| 224 } | |
| 216 } | 225 } |
| 217 | 226 |
| 218 const MediaRoute::Id PresentationFrame::GetRouteId( | 227 const MediaRoute* PresentationFrame::GetRoute( |
| 219 const std::string& presentation_id) const { | 228 const std::string& presentation_id) const { |
| 220 auto it = presentation_id_to_route_.find(presentation_id); | 229 auto it = presentation_id_to_route_.find(presentation_id); |
| 221 return it != presentation_id_to_route_.end() ? it->second.media_route_id() | 230 return it != presentation_id_to_route_.end() ? &it->second : nullptr; |
| 222 : ""; | |
| 223 } | 231 } |
| 224 | 232 |
| 225 bool PresentationFrame::SetScreenAvailabilityListener( | 233 bool PresentationFrame::SetScreenAvailabilityListener( |
| 226 content::PresentationScreenAvailabilityListener* listener) { | 234 content::PresentationScreenAvailabilityListener* listener) { |
| 227 MediaSource source(GetMediaSourceFromListener(listener)); | 235 MediaSource source(GetMediaSourceFromListener(listener)); |
| 228 auto& sinks_observer = url_to_sinks_observer_[source.id()]; | 236 auto& sinks_observer = url_to_sinks_observer_[source.id()]; |
| 229 if (sinks_observer && sinks_observer->listener() == listener) | 237 if (sinks_observer && sinks_observer->listener() == listener) |
| 230 return false; | 238 return false; |
| 231 | 239 |
| 232 sinks_observer.reset(new PresentationMediaSinksObserver( | 240 sinks_observer.reset(new PresentationMediaSinksObserver( |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 253 } | 261 } |
| 254 return false; | 262 return false; |
| 255 } | 263 } |
| 256 | 264 |
| 257 bool PresentationFrame::HasScreenAvailabilityListenerForTest( | 265 bool PresentationFrame::HasScreenAvailabilityListenerForTest( |
| 258 const MediaSource::Id& source_id) const { | 266 const MediaSource::Id& source_id) const { |
| 259 return url_to_sinks_observer_.find(source_id) != url_to_sinks_observer_.end(); | 267 return url_to_sinks_observer_.find(source_id) != url_to_sinks_observer_.end(); |
| 260 } | 268 } |
| 261 | 269 |
| 262 void PresentationFrame::Reset() { | 270 void PresentationFrame::Reset() { |
| 263 auto* offscreen_presentation_manager = | |
| 264 OffscreenPresentationManagerFactory::GetOrCreateForWebContents( | |
| 265 web_contents_); | |
| 266 | |
| 267 for (const auto& pid_route : presentation_id_to_route_) { | 271 for (const auto& pid_route : presentation_id_to_route_) { |
| 268 if (IsOffscreenPresentation(pid_route.first)) { | 272 if (pid_route.second.is_offscreen_presentation()) { |
| 269 offscreen_presentation_manager->UnregisterOffscreenPresentationController( | 273 offscreen_presentation_manager_ |
| 270 pid_route.first, render_frame_host_id_); | 274 ->UnregisterOffscreenPresentationController(pid_route.first, |
| 275 render_frame_host_id_); | |
| 276 } else { | |
| 277 router_->DetachRoute(pid_route.second.media_route_id()); | |
| 271 } | 278 } |
| 272 router_->DetachRoute(pid_route.second.media_route_id()); | |
| 273 } | 279 } |
| 274 | 280 |
| 275 presentation_id_to_route_.clear(); | 281 presentation_id_to_route_.clear(); |
| 276 url_to_sinks_observer_.clear(); | 282 url_to_sinks_observer_.clear(); |
| 277 connection_state_subscriptions_.clear(); | 283 connection_state_subscriptions_.clear(); |
| 278 session_messages_observers_.clear(); | 284 session_messages_observers_.clear(); |
| 279 browser_connection_proxies_.clear(); | 285 browser_connection_proxies_.clear(); |
| 280 } | 286 } |
| 281 | 287 |
| 282 void PresentationFrame::RemoveConnection(const std::string& presentation_id, | 288 void PresentationFrame::RemoveConnection(const std::string& presentation_id, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 } | 354 } |
| 349 | 355 |
| 350 MediaSource PresentationFrame::GetMediaSourceFromListener( | 356 MediaSource PresentationFrame::GetMediaSourceFromListener( |
| 351 content::PresentationScreenAvailabilityListener* listener) const { | 357 content::PresentationScreenAvailabilityListener* listener) const { |
| 352 // If the default presentation URL is empty then fall back to tab mirroring. | 358 // If the default presentation URL is empty then fall back to tab mirroring. |
| 353 return listener->GetAvailabilityUrl().is_empty() | 359 return listener->GetAvailabilityUrl().is_empty() |
| 354 ? MediaSourceForTab(SessionTabHelper::IdForTab(web_contents_)) | 360 ? MediaSourceForTab(SessionTabHelper::IdForTab(web_contents_)) |
| 355 : MediaSourceForPresentationUrl(listener->GetAvailabilityUrl()); | 361 : MediaSourceForPresentationUrl(listener->GetAvailabilityUrl()); |
| 356 } | 362 } |
| 357 | 363 |
| 358 bool PresentationFrame::IsOffscreenPresentation( | |
| 359 const std::string& presentation_id) const { | |
| 360 const auto it = presentation_id_to_route_.find(presentation_id); | |
| 361 if (it == presentation_id_to_route_.end()) { | |
| 362 DLOG(WARNING) << "No route for [presentation_id]: " << presentation_id; | |
| 363 return false; | |
| 364 } | |
| 365 | |
| 366 return it->second.is_offscreen_presentation(); | |
| 367 } | |
| 368 | |
| 369 void PresentationFrame::ConnectToPresentation( | 364 void PresentationFrame::ConnectToPresentation( |
| 370 const content::PresentationSessionInfo& session, | 365 const content::PresentationSessionInfo& session, |
| 371 content::PresentationConnectionPtr controller_connection_ptr, | 366 content::PresentationConnectionPtr controller_connection_ptr, |
| 372 content::PresentationConnectionRequest receiver_connection_request) { | 367 content::PresentationConnectionRequest receiver_connection_request) { |
| 373 const auto pid_route_it = | 368 const auto pid_route_it = |
| 374 presentation_id_to_route_.find(session.presentation_id); | 369 presentation_id_to_route_.find(session.presentation_id); |
| 375 | 370 |
| 376 if (pid_route_it == presentation_id_to_route_.end()) { | 371 if (pid_route_it == presentation_id_to_route_.end()) { |
| 377 DLOG(WARNING) << "No route for [presentation_id]: " | 372 DLOG(WARNING) << "No route for [presentation_id]: " |
| 378 << session.presentation_id; | 373 << session.presentation_id; |
| 379 return; | 374 return; |
| 380 } | 375 } |
| 381 | 376 |
| 382 if (IsOffscreenPresentation(session.presentation_id)) { | 377 if (pid_route_it->second.is_offscreen_presentation()) { |
| 383 auto* const offscreen_presentation_manager = | 378 offscreen_presentation_manager_->RegisterOffscreenPresentationController( |
| 384 OffscreenPresentationManagerFactory::GetOrCreateForWebContents( | |
| 385 web_contents_); | |
| 386 offscreen_presentation_manager->RegisterOffscreenPresentationController( | |
| 387 session.presentation_id, session.presentation_url, | 379 session.presentation_id, session.presentation_url, |
| 388 render_frame_host_id_, std::move(controller_connection_ptr), | 380 render_frame_host_id_, std::move(controller_connection_ptr), |
| 389 std::move(receiver_connection_request)); | 381 std::move(receiver_connection_request)); |
| 390 } else { | 382 } else { |
| 391 DVLOG(2) | 383 DVLOG(2) |
| 392 << "Creating BrowserPresentationConnectionProxy for [presentation_id]: " | 384 << "Creating BrowserPresentationConnectionProxy for [presentation_id]: " |
| 393 << session.presentation_id; | 385 << session.presentation_id; |
| 394 MediaRoute::Id route_id = pid_route_it->second.media_route_id(); | 386 MediaRoute::Id route_id = pid_route_it->second.media_route_id(); |
| 395 auto* proxy = new BrowserPresentationConnectionProxy( | 387 auto* proxy = new BrowserPresentationConnectionProxy( |
| 396 router_, route_id, std::move(receiver_connection_request), | 388 router_, route_id, std::move(receiver_connection_request), |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 const PresentationRequest& request, | 450 const PresentationRequest& request, |
| 459 const content::PresentationSessionInfo& session, | 451 const content::PresentationSessionInfo& session, |
| 460 const MediaRoute& route); | 452 const MediaRoute& route); |
| 461 | 453 |
| 462 void ConnectToPresentation( | 454 void ConnectToPresentation( |
| 463 const RenderFrameHostId& render_frame_host_id, | 455 const RenderFrameHostId& render_frame_host_id, |
| 464 const content::PresentationSessionInfo& session, | 456 const content::PresentationSessionInfo& session, |
| 465 content::PresentationConnectionPtr controller_connection_ptr, | 457 content::PresentationConnectionPtr controller_connection_ptr, |
| 466 content::PresentationConnectionRequest receiver_connection_request); | 458 content::PresentationConnectionRequest receiver_connection_request); |
| 467 | 459 |
| 468 const MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id, | 460 const MediaRoute* GetRoute(const RenderFrameHostId& render_frame_host_id, |
| 469 const std::string& presentation_id) const; | 461 const std::string& presentation_id) const; |
| 470 | 462 |
| 471 const PresentationRequest* default_presentation_request() const { | 463 const PresentationRequest* default_presentation_request() const { |
| 472 return default_presentation_request_.get(); | 464 return default_presentation_request_.get(); |
| 473 } | 465 } |
| 474 | 466 |
| 475 private: | 467 private: |
| 476 PresentationFrame* GetOrAddPresentationFrame( | 468 PresentationFrame* GetOrAddPresentationFrame( |
| 477 const RenderFrameHostId& render_frame_host_id); | 469 const RenderFrameHostId& render_frame_host_id); |
| 478 | 470 |
| 479 // Sets the default presentation request for the owning WebContents and | 471 // Sets the default presentation request for the owning WebContents and |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 546 const RenderFrameHostId& render_frame_host_id, | 538 const RenderFrameHostId& render_frame_host_id, |
| 547 const content::PresentationSessionInfo& session, | 539 const content::PresentationSessionInfo& session, |
| 548 content::PresentationConnectionPtr controller_connection_ptr, | 540 content::PresentationConnectionPtr controller_connection_ptr, |
| 549 content::PresentationConnectionRequest receiver_connection_request) { | 541 content::PresentationConnectionRequest receiver_connection_request) { |
| 550 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); | 542 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); |
| 551 presentation_frame->ConnectToPresentation( | 543 presentation_frame->ConnectToPresentation( |
| 552 session, std::move(controller_connection_ptr), | 544 session, std::move(controller_connection_ptr), |
| 553 std::move(receiver_connection_request)); | 545 std::move(receiver_connection_request)); |
| 554 } | 546 } |
| 555 | 547 |
| 556 const MediaRoute::Id PresentationFrameManager::GetRouteId( | 548 const MediaRoute* PresentationFrameManager::GetRoute( |
| 557 const RenderFrameHostId& render_frame_host_id, | 549 const RenderFrameHostId& render_frame_host_id, |
| 558 const std::string& presentation_id) const { | 550 const std::string& presentation_id) const { |
| 559 const auto it = presentation_frames_.find(render_frame_host_id); | 551 const auto it = presentation_frames_.find(render_frame_host_id); |
| 560 return it != presentation_frames_.end() | 552 return it != presentation_frames_.end() |
| 561 ? it->second->GetRouteId(presentation_id) : MediaRoute::Id(); | 553 ? it->second->GetRoute(presentation_id) |
| 554 : nullptr; | |
| 562 } | 555 } |
| 563 | 556 |
| 564 bool PresentationFrameManager::SetScreenAvailabilityListener( | 557 bool PresentationFrameManager::SetScreenAvailabilityListener( |
| 565 const RenderFrameHostId& render_frame_host_id, | 558 const RenderFrameHostId& render_frame_host_id, |
| 566 content::PresentationScreenAvailabilityListener* listener) { | 559 content::PresentationScreenAvailabilityListener* listener) { |
| 567 DCHECK(listener); | 560 DCHECK(listener); |
| 568 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); | 561 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); |
| 569 return presentation_frame->SetScreenAvailabilityListener(listener); | 562 return presentation_frame->SetScreenAvailabilityListener(listener); |
| 570 } | 563 } |
| 571 | 564 |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 883 #if !defined(OS_ANDROID) | 876 #if !defined(OS_ANDROID) |
| 884 if (IsAutoJoinPresentationId(presentation_id) && | 877 if (IsAutoJoinPresentationId(presentation_id) && |
| 885 ShouldCancelAutoJoinForOrigin(origin)) { | 878 ShouldCancelAutoJoinForOrigin(origin)) { |
| 886 error_cb.Run(content::PresentationError( | 879 error_cb.Run(content::PresentationError( |
| 887 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, | 880 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, |
| 888 "Auto-join request cancelled by user preferences.")); | 881 "Auto-join request cancelled by user preferences.")); |
| 889 return; | 882 return; |
| 890 } | 883 } |
| 891 #endif // !defined(OS_ANDROID) | 884 #endif // !defined(OS_ANDROID) |
| 892 | 885 |
| 893 // TODO(crbug.com/627655): Handle multiple URLs. | 886 auto* offscreen_presentation_manager = |
| 894 const GURL& presentation_url = presentation_urls[0]; | 887 OffscreenPresentationManagerFactory::GetOrCreateForWebContents( |
| 895 bool incognito = web_contents_->GetBrowserContext()->IsOffTheRecord(); | 888 web_contents_); |
| 896 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 889 // Check offscreen presentation across frames. |
| 897 route_response_callbacks.push_back( | 890 if (offscreen_presentation_manager->IsOffscreenPresentation( |
| 898 base::Bind(&PresentationServiceDelegateImpl::OnJoinRouteResponse, | 891 presentation_id)) { |
| 899 weak_factory_.GetWeakPtr(), render_process_id, render_frame_id, | 892 auto* route = offscreen_presentation_manager->GetRoute(presentation_id); |
| 900 presentation_url, presentation_id, success_cb, error_cb)); | 893 DCHECK(route); |
| 901 router_->JoinRoute(MediaSourceForPresentationUrl(presentation_url).id(), | 894 auto result = RouteRequestResult::FromSuccess(*route, presentation_id); |
| 902 presentation_id, origin, web_contents_, | 895 OnJoinRouteResponse(render_process_id, render_frame_id, |
| 903 route_response_callbacks, base::TimeDelta(), incognito); | 896 presentation_urls[0], presentation_id, success_cb, |
|
mark a. foltz
2017/03/01 06:26:32
Connection requires matching both presentation ID
zhaobin
2017/03/15 18:18:57
Done.
| |
| 897 error_cb, *result); | |
| 898 } else { | |
| 899 // TODO(crbug.com/627655): Handle multiple URLs. | |
| 900 const GURL& presentation_url = presentation_urls[0]; | |
| 901 bool incognito = web_contents_->GetBrowserContext()->IsOffTheRecord(); | |
| 902 std::vector<MediaRouteResponseCallback> route_response_callbacks; | |
| 903 route_response_callbacks.push_back(base::Bind( | |
| 904 &PresentationServiceDelegateImpl::OnJoinRouteResponse, | |
| 905 weak_factory_.GetWeakPtr(), render_process_id, render_frame_id, | |
| 906 presentation_url, presentation_id, success_cb, error_cb)); | |
| 907 router_->JoinRoute(MediaSourceForPresentationUrl(presentation_url).id(), | |
| 908 presentation_id, origin, web_contents_, | |
| 909 route_response_callbacks, base::TimeDelta(), incognito); | |
| 910 } | |
| 904 } | 911 } |
| 905 | 912 |
| 906 void PresentationServiceDelegateImpl::CloseConnection( | 913 void PresentationServiceDelegateImpl::CloseConnection( |
| 907 int render_process_id, | 914 int render_process_id, |
| 908 int render_frame_id, | 915 int render_frame_id, |
| 909 const std::string& presentation_id) { | 916 const std::string& presentation_id) { |
| 910 const RenderFrameHostId rfh_id(render_process_id, render_frame_id); | 917 const RenderFrameHostId rfh_id(render_process_id, render_frame_id); |
| 911 const MediaRoute::Id& route_id = | 918 auto* route = frame_manager_->GetRoute(rfh_id, presentation_id); |
| 912 frame_manager_->GetRouteId(rfh_id, presentation_id); | 919 if (!route) { |
| 913 if (route_id.empty()) { | |
| 914 DVLOG(1) << "No active route for: " << presentation_id; | 920 DVLOG(1) << "No active route for: " << presentation_id; |
| 915 return; | 921 return; |
| 916 } | 922 } |
| 917 | 923 |
| 918 router_->DetachRoute(route_id); | 924 if (route->is_offscreen_presentation()) { |
| 919 frame_manager_->RemoveConnection(rfh_id, presentation_id, route_id); | 925 auto* offscreen_presentation_manager = |
| 926 OffscreenPresentationManagerFactory::GetOrCreateForWebContents( | |
| 927 web_contents_); | |
| 928 offscreen_presentation_manager->UnregisterOffscreenPresentationController( | |
|
imcheng
2017/02/24 01:37:46
Do we currently change state on close() for 1-UA o
zhaobin
2017/02/24 02:35:34
Have a different patch for change state on close()
| |
| 929 presentation_id, rfh_id); | |
| 930 } else { | |
| 931 router_->DetachRoute(route->media_route_id()); | |
| 932 } | |
| 933 frame_manager_->RemoveConnection(rfh_id, presentation_id, | |
| 934 route->media_route_id()); | |
| 920 // TODO(mfoltz): close() should always succeed so there is no need to keep the | 935 // TODO(mfoltz): close() should always succeed so there is no need to keep the |
| 921 // state_changed_cb around - remove it and fire the ChangeEvent on the | 936 // state_changed_cb around - remove it and fire the ChangeEvent on the |
| 922 // PresentationConnection in Blink. | 937 // PresentationConnection in Blink. |
| 923 } | 938 } |
| 924 | 939 |
| 925 void PresentationServiceDelegateImpl::Terminate( | 940 void PresentationServiceDelegateImpl::Terminate( |
| 926 int render_process_id, | 941 int render_process_id, |
| 927 int render_frame_id, | 942 int render_frame_id, |
| 928 const std::string& presentation_id) { | 943 const std::string& presentation_id) { |
| 929 const RenderFrameHostId rfh_id(render_process_id, render_frame_id); | 944 const RenderFrameHostId rfh_id(render_process_id, render_frame_id); |
| 930 const MediaRoute::Id& route_id = | 945 auto* route = frame_manager_->GetRoute(rfh_id, presentation_id); |
| 931 frame_manager_->GetRouteId(rfh_id, presentation_id); | 946 if (!route) { |
| 932 if (route_id.empty()) { | |
| 933 DVLOG(1) << "No active route for: " << presentation_id; | 947 DVLOG(1) << "No active route for: " << presentation_id; |
| 934 return; | 948 return; |
| 935 } | 949 } |
| 936 router_->TerminateRoute(route_id); | 950 router_->TerminateRoute(route->media_route_id()); |
| 937 frame_manager_->RemoveConnection(rfh_id, presentation_id, route_id); | 951 frame_manager_->RemoveConnection(rfh_id, presentation_id, |
| 952 route->media_route_id()); | |
| 938 } | 953 } |
| 939 | 954 |
| 940 void PresentationServiceDelegateImpl::ListenForConnectionMessages( | 955 void PresentationServiceDelegateImpl::ListenForConnectionMessages( |
| 941 int render_process_id, | 956 int render_process_id, |
| 942 int render_frame_id, | 957 int render_frame_id, |
| 943 const content::PresentationSessionInfo& session, | 958 const content::PresentationSessionInfo& session, |
| 944 const content::PresentationConnectionMessageCallback& message_cb) { | 959 const content::PresentationConnectionMessageCallback& message_cb) { |
| 945 frame_manager_->ListenForSessionMessages( | 960 frame_manager_->ListenForSessionMessages( |
| 946 RenderFrameHostId(render_process_id, render_frame_id), session, | 961 RenderFrameHostId(render_process_id, render_frame_id), session, |
| 947 message_cb); | 962 message_cb); |
| 948 } | 963 } |
| 949 | 964 |
| 950 void PresentationServiceDelegateImpl::SendMessage( | 965 void PresentationServiceDelegateImpl::SendMessage( |
| 951 int render_process_id, | 966 int render_process_id, |
| 952 int render_frame_id, | 967 int render_frame_id, |
| 953 const content::PresentationSessionInfo& session, | 968 const content::PresentationSessionInfo& session, |
| 954 std::unique_ptr<content::PresentationConnectionMessage> message, | 969 std::unique_ptr<content::PresentationConnectionMessage> message, |
| 955 const SendMessageCallback& send_message_cb) { | 970 const SendMessageCallback& send_message_cb) { |
| 956 const MediaRoute::Id& route_id = frame_manager_->GetRouteId( | 971 auto* route = frame_manager_->GetRoute( |
| 957 RenderFrameHostId(render_process_id, render_frame_id), | 972 RenderFrameHostId(render_process_id, render_frame_id), |
| 958 session.presentation_id); | 973 session.presentation_id); |
| 959 if (route_id.empty()) { | 974 if (!route) { |
| 960 DVLOG(1) << "No active route for " << session.presentation_id; | 975 DVLOG(1) << "No active route for " << session.presentation_id; |
| 961 send_message_cb.Run(false); | 976 send_message_cb.Run(false); |
| 962 return; | 977 return; |
| 963 } | 978 } |
| 964 | 979 |
| 965 if (message->is_binary()) { | 980 if (message->is_binary()) { |
| 966 router_->SendRouteBinaryMessage(route_id, std::move(message->data), | 981 router_->SendRouteBinaryMessage(route->media_route_id(), |
| 967 send_message_cb); | 982 std::move(message->data), send_message_cb); |
| 968 } else { | 983 } else { |
| 969 router_->SendRouteMessage(route_id, message->message, send_message_cb); | 984 router_->SendRouteMessage(route->media_route_id(), message->message, |
| 985 send_message_cb); | |
| 970 } | 986 } |
| 971 } | 987 } |
| 972 | 988 |
| 973 void PresentationServiceDelegateImpl::ListenForConnectionStateChange( | 989 void PresentationServiceDelegateImpl::ListenForConnectionStateChange( |
| 974 int render_process_id, | 990 int render_process_id, |
| 975 int render_frame_id, | 991 int render_frame_id, |
| 976 const content::PresentationSessionInfo& connection, | 992 const content::PresentationSessionInfo& connection, |
| 977 const content::PresentationConnectionStateChangedCallback& | 993 const content::PresentationConnectionStateChangedCallback& |
| 978 state_changed_cb) { | 994 state_changed_cb) { |
| 979 frame_manager_->ListenForConnectionStateChange( | 995 frame_manager_->ListenForConnectionStateChange( |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1054 const base::ListValue* origins = | 1070 const base::ListValue* origins = |
| 1055 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) | 1071 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) |
| 1056 ->GetPrefs() | 1072 ->GetPrefs() |
| 1057 ->GetList(prefs::kMediaRouterTabMirroringSources); | 1073 ->GetList(prefs::kMediaRouterTabMirroringSources); |
| 1058 return origins && | 1074 return origins && |
| 1059 origins->Find(base::StringValue(origin.Serialize())) != origins->end(); | 1075 origins->Find(base::StringValue(origin.Serialize())) != origins->end(); |
| 1060 } | 1076 } |
| 1061 #endif // !defined(OS_ANDROID) | 1077 #endif // !defined(OS_ANDROID) |
| 1062 | 1078 |
| 1063 } // namespace media_router | 1079 } // namespace media_router |
| OLD | NEW |