| 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/browser_presentation_connection_proxy.h" |
| 16 #include "chrome/browser/media/router/create_presentation_connection_request.h" | 17 #include "chrome/browser/media/router/create_presentation_connection_request.h" |
| 17 #include "chrome/browser/media/router/media_route.h" | 18 #include "chrome/browser/media/router/media_route.h" |
| 18 #include "chrome/browser/media/router/media_router.h" | 19 #include "chrome/browser/media/router/media_router.h" |
| 19 #include "chrome/browser/media/router/media_router_dialog_controller.h" | 20 #include "chrome/browser/media/router/media_router_dialog_controller.h" |
| 20 #include "chrome/browser/media/router/media_router_factory.h" | 21 #include "chrome/browser/media/router/media_router_factory.h" |
| 21 #include "chrome/browser/media/router/media_sink.h" | 22 #include "chrome/browser/media/router/media_sink.h" |
| 22 #include "chrome/browser/media/router/media_source_helper.h" | 23 #include "chrome/browser/media/router/media_source_helper.h" |
| 23 #include "chrome/browser/media/router/offscreen_presentation_manager.h" | 24 #include "chrome/browser/media/router/offscreen_presentation_manager.h" |
| 24 #include "chrome/browser/media/router/offscreen_presentation_manager_factory.h" | 25 #include "chrome/browser/media/router/offscreen_presentation_manager_factory.h" |
| 25 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" | 26 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 | 158 |
| 158 void OnPresentationSessionStarted( | 159 void OnPresentationSessionStarted( |
| 159 const content::PresentationSessionInfo& session, | 160 const content::PresentationSessionInfo& session, |
| 160 const MediaRoute& route); | 161 const MediaRoute& route); |
| 161 void OnPresentationServiceDelegateDestroyed() const; | 162 void OnPresentationServiceDelegateDestroyed() const; |
| 162 | 163 |
| 163 void set_delegate_observer(DelegateObserver* observer) { | 164 void set_delegate_observer(DelegateObserver* observer) { |
| 164 delegate_observer_ = observer; | 165 delegate_observer_ = observer; |
| 165 } | 166 } |
| 166 | 167 |
| 168 bool IsOffscreenPresentation(const std::string& presentation_id) const; |
| 169 void ConnectToPresentation( |
| 170 const content::PresentationSessionInfo& session, |
| 171 content::PresentationConnectionPtr controller_connection_ptr, |
| 172 content::PresentationConnectionRequest receiver_connection_request); |
| 173 |
| 167 private: | 174 private: |
| 168 MediaSource GetMediaSourceFromListener( | 175 MediaSource GetMediaSourceFromListener( |
| 169 content::PresentationScreenAvailabilityListener* listener) const; | 176 content::PresentationScreenAvailabilityListener* listener) const; |
| 170 base::SmallMap<std::map<std::string, MediaRoute::Id>> | 177 base::SmallMap<std::map<std::string, MediaRoute>> presentation_id_to_route_; |
| 171 presentation_id_to_route_id_; | |
| 172 base::SmallMap< | 178 base::SmallMap< |
| 173 std::map<std::string, std::unique_ptr<PresentationMediaSinksObserver>>> | 179 std::map<std::string, std::unique_ptr<PresentationMediaSinksObserver>>> |
| 174 url_to_sinks_observer_; | 180 url_to_sinks_observer_; |
| 175 std::unordered_map< | 181 std::unordered_map< |
| 176 MediaRoute::Id, | 182 MediaRoute::Id, |
| 177 std::unique_ptr<PresentationConnectionStateSubscription>> | 183 std::unique_ptr<PresentationConnectionStateSubscription>> |
| 178 connection_state_subscriptions_; | 184 connection_state_subscriptions_; |
| 179 std::unordered_map< | 185 std::unordered_map< |
| 180 MediaRoute::Id, | 186 MediaRoute::Id, |
| 181 std::unique_ptr<PresentationSessionMessagesObserver>> | 187 std::unique_ptr<PresentationSessionMessagesObserver>> |
| 182 session_messages_observers_; | 188 session_messages_observers_; |
| 189 std::unordered_map<MediaRoute::Id, |
| 190 std::unique_ptr<BrowserPresentationConnectionProxy>> |
| 191 browser_connection_proxies_; |
| 183 | 192 |
| 184 RenderFrameHostId render_frame_host_id_; | 193 RenderFrameHostId render_frame_host_id_; |
| 185 | 194 |
| 186 // References to the owning WebContents, and the corresponding MediaRouter. | 195 // References to the owning WebContents, and the corresponding MediaRouter. |
| 187 content::WebContents* web_contents_; | 196 content::WebContents* web_contents_; |
| 188 MediaRouter* router_; | 197 MediaRouter* router_; |
| 189 | 198 |
| 190 DelegateObserver* delegate_observer_; | 199 DelegateObserver* delegate_observer_; |
| 191 }; | 200 }; |
| 192 | 201 |
| 193 PresentationFrame::PresentationFrame( | 202 PresentationFrame::PresentationFrame( |
| 194 const RenderFrameHostId& render_frame_host_id, | 203 const RenderFrameHostId& render_frame_host_id, |
| 195 content::WebContents* web_contents, | 204 content::WebContents* web_contents, |
| 196 MediaRouter* router) | 205 MediaRouter* router) |
| 197 : render_frame_host_id_(render_frame_host_id), | 206 : render_frame_host_id_(render_frame_host_id), |
| 198 web_contents_(web_contents), | 207 web_contents_(web_contents), |
| 199 router_(router) { | 208 router_(router) { |
| 200 DCHECK(web_contents_); | 209 DCHECK(web_contents_); |
| 201 DCHECK(router_); | 210 DCHECK(router_); |
| 202 } | 211 } |
| 203 | 212 |
| 204 PresentationFrame::~PresentationFrame() { | 213 PresentationFrame::~PresentationFrame() { |
| 205 } | 214 } |
| 206 | 215 |
| 207 void PresentationFrame::OnPresentationSessionStarted( | 216 void PresentationFrame::OnPresentationSessionStarted( |
| 208 const content::PresentationSessionInfo& session, | 217 const content::PresentationSessionInfo& session, |
| 209 const MediaRoute& route) { | 218 const MediaRoute& route) { |
| 210 presentation_id_to_route_id_[session.presentation_id] = | 219 presentation_id_to_route_.insert( |
| 211 route.media_route_id(); | 220 std::make_pair(session.presentation_id, route)); |
| 212 } | 221 } |
| 213 | 222 |
| 214 const MediaRoute::Id PresentationFrame::GetRouteId( | 223 const MediaRoute::Id PresentationFrame::GetRouteId( |
| 215 const std::string& presentation_id) const { | 224 const std::string& presentation_id) const { |
| 216 auto it = presentation_id_to_route_id_.find(presentation_id); | 225 auto it = presentation_id_to_route_.find(presentation_id); |
| 217 return it != presentation_id_to_route_id_.end() ? it->second : ""; | 226 return it != presentation_id_to_route_.end() ? it->second.media_route_id() |
| 227 : ""; |
| 218 } | 228 } |
| 219 | 229 |
| 220 const std::vector<MediaRoute::Id> PresentationFrame::GetRouteIds() const { | 230 const std::vector<MediaRoute::Id> PresentationFrame::GetRouteIds() const { |
| 221 std::vector<MediaRoute::Id> route_ids; | 231 std::vector<MediaRoute::Id> route_ids; |
| 222 for (const auto& e : presentation_id_to_route_id_) | 232 for (const auto& e : presentation_id_to_route_) |
| 223 route_ids.push_back(e.second); | 233 route_ids.push_back(e.second.media_route_id()); |
| 224 return route_ids; | 234 return route_ids; |
| 225 } | 235 } |
| 226 | 236 |
| 227 bool PresentationFrame::SetScreenAvailabilityListener( | 237 bool PresentationFrame::SetScreenAvailabilityListener( |
| 228 content::PresentationScreenAvailabilityListener* listener) { | 238 content::PresentationScreenAvailabilityListener* listener) { |
| 229 MediaSource source(GetMediaSourceFromListener(listener)); | 239 MediaSource source(GetMediaSourceFromListener(listener)); |
| 230 auto& sinks_observer = url_to_sinks_observer_[source.id()]; | 240 auto& sinks_observer = url_to_sinks_observer_[source.id()]; |
| 231 if (sinks_observer && sinks_observer->listener() == listener) | 241 if (sinks_observer && sinks_observer->listener() == listener) |
| 232 return false; | 242 return false; |
| 233 | 243 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 255 } | 265 } |
| 256 return false; | 266 return false; |
| 257 } | 267 } |
| 258 | 268 |
| 259 bool PresentationFrame::HasScreenAvailabilityListenerForTest( | 269 bool PresentationFrame::HasScreenAvailabilityListenerForTest( |
| 260 const MediaSource::Id& source_id) const { | 270 const MediaSource::Id& source_id) const { |
| 261 return url_to_sinks_observer_.find(source_id) != url_to_sinks_observer_.end(); | 271 return url_to_sinks_observer_.find(source_id) != url_to_sinks_observer_.end(); |
| 262 } | 272 } |
| 263 | 273 |
| 264 void PresentationFrame::Reset() { | 274 void PresentationFrame::Reset() { |
| 265 for (const auto& pid_route_id : presentation_id_to_route_id_) | 275 auto offscreen_presentation_manager = |
| 266 router_->DetachRoute(pid_route_id.second); | 276 OffscreenPresentationManagerFactory::GetOrCreateForWebContents( |
| 277 web_contents_); |
| 267 | 278 |
| 268 presentation_id_to_route_id_.clear(); | 279 for (const auto& pid_route : presentation_id_to_route_) { |
| 280 if (IsOffscreenPresentation(pid_route.first)) { |
| 281 offscreen_presentation_manager->UnregisterOffscreenPresentationController( |
| 282 pid_route.first, render_frame_host_id_); |
| 283 } |
| 284 router_->DetachRoute(pid_route.second.media_route_id()); |
| 285 } |
| 286 |
| 287 presentation_id_to_route_.clear(); |
| 269 url_to_sinks_observer_.clear(); | 288 url_to_sinks_observer_.clear(); |
| 270 connection_state_subscriptions_.clear(); | 289 connection_state_subscriptions_.clear(); |
| 271 session_messages_observers_.clear(); | 290 session_messages_observers_.clear(); |
| 291 browser_connection_proxies_.clear(); |
| 272 } | 292 } |
| 273 | 293 |
| 274 void PresentationFrame::RemoveConnection(const std::string& presentation_id, | 294 void PresentationFrame::RemoveConnection(const std::string& presentation_id, |
| 275 const MediaRoute::Id& route_id) { | 295 const MediaRoute::Id& route_id) { |
| 276 // Remove the presentation id mapping so a later call to Reset is a no-op. | 296 // Remove the presentation id mapping so a later call to Reset is a no-op. |
| 277 presentation_id_to_route_id_.erase(presentation_id); | 297 presentation_id_to_route_.erase(presentation_id); |
| 278 | 298 |
| 279 // We no longer need to observe route messages. | 299 // We no longer need to observe route messages. |
| 280 session_messages_observers_.erase(route_id); | 300 session_messages_observers_.erase(route_id); |
| 281 | 301 |
| 302 browser_connection_proxies_.erase(route_id); |
| 282 // We keep the PresentationConnectionStateChangedCallback registered with MR | 303 // We keep the PresentationConnectionStateChangedCallback registered with MR |
| 283 // so the MRP can tell us when terminate() completed. | 304 // so the MRP can tell us when terminate() completed. |
| 284 } | 305 } |
| 285 | 306 |
| 286 void PresentationFrame::ListenForConnectionStateChange( | 307 void PresentationFrame::ListenForConnectionStateChange( |
| 287 const content::PresentationSessionInfo& connection, | 308 const content::PresentationSessionInfo& connection, |
| 288 const content::PresentationConnectionStateChangedCallback& | 309 const content::PresentationConnectionStateChangedCallback& |
| 289 state_changed_cb) { | 310 state_changed_cb) { |
| 290 auto it = presentation_id_to_route_id_.find(connection.presentation_id); | 311 auto it = presentation_id_to_route_.find(connection.presentation_id); |
| 291 if (it == presentation_id_to_route_id_.end()) { | 312 if (it == presentation_id_to_route_.end()) { |
| 292 DLOG(ERROR) << __func__ << "route id not found for presentation: " | 313 DLOG(ERROR) << __func__ << "route id not found for presentation: " |
| 293 << connection.presentation_id; | 314 << connection.presentation_id; |
| 294 return; | 315 return; |
| 295 } | 316 } |
| 296 | 317 |
| 297 const MediaRoute::Id& route_id = it->second; | 318 const MediaRoute::Id& route_id = it->second.media_route_id(); |
| 298 if (connection_state_subscriptions_.find(route_id) != | 319 if (connection_state_subscriptions_.find(route_id) != |
| 299 connection_state_subscriptions_.end()) { | 320 connection_state_subscriptions_.end()) { |
| 300 DLOG(ERROR) << __func__ | 321 DLOG(ERROR) << __func__ |
| 301 << "Already listening connection state change for route: " | 322 << "Already listening connection state change for route: " |
| 302 << route_id; | 323 << route_id; |
| 303 return; | 324 return; |
| 304 } | 325 } |
| 305 | 326 |
| 306 connection_state_subscriptions_.insert(std::make_pair( | 327 connection_state_subscriptions_.insert(std::make_pair( |
| 307 route_id, router_->AddPresentationConnectionStateChangedCallback( | 328 route_id, router_->AddPresentationConnectionStateChangedCallback( |
| 308 it->second, state_changed_cb))); | 329 route_id, state_changed_cb))); |
| 309 } | 330 } |
| 310 | 331 |
| 311 void PresentationFrame::ListenForSessionMessages( | 332 void PresentationFrame::ListenForSessionMessages( |
| 312 const content::PresentationSessionInfo& session, | 333 const content::PresentationSessionInfo& session, |
| 313 const content::PresentationConnectionMessageCallback& message_cb) { | 334 const content::PresentationConnectionMessageCallback& message_cb) { |
| 314 auto it = presentation_id_to_route_id_.find(session.presentation_id); | 335 auto it = presentation_id_to_route_.find(session.presentation_id); |
| 315 if (it == presentation_id_to_route_id_.end()) { | 336 if (it == presentation_id_to_route_.end()) { |
| 316 DVLOG(2) << "ListenForSessionMessages: no route for " | 337 DVLOG(2) << "ListenForSessionMessages: no route for " |
| 317 << session.presentation_id; | 338 << session.presentation_id; |
| 318 return; | 339 return; |
| 319 } | 340 } |
| 320 | 341 |
| 321 const MediaRoute::Id& route_id = it->second; | 342 if (it->second.is_offscreen_presentation()) { |
| 343 DVLOG(2) << "ListenForSessionMessages: do not listen for offscreen " |
| 344 << "presentation [id]: " << session.presentation_id; |
| 345 return; |
| 346 } |
| 347 |
| 348 const MediaRoute::Id& route_id = it->second.media_route_id(); |
| 322 if (session_messages_observers_.find(route_id) != | 349 if (session_messages_observers_.find(route_id) != |
| 323 session_messages_observers_.end()) { | 350 session_messages_observers_.end()) { |
| 324 DLOG(ERROR) << __func__ | 351 DLOG(ERROR) << __func__ |
| 325 << "Already listening for session messages for route: " | 352 << "Already listening for session messages for route: " |
| 326 << route_id; | 353 << route_id; |
| 327 return; | 354 return; |
| 328 } | 355 } |
| 329 | 356 |
| 330 session_messages_observers_.insert(std::make_pair( | 357 session_messages_observers_.insert(std::make_pair( |
| 331 route_id, base::MakeUnique<PresentationSessionMessagesObserver>( | 358 route_id, base::MakeUnique<PresentationSessionMessagesObserver>( |
| 332 router_, it->second, message_cb))); | 359 router_, route_id, message_cb))); |
| 333 } | 360 } |
| 334 | 361 |
| 335 MediaSource PresentationFrame::GetMediaSourceFromListener( | 362 MediaSource PresentationFrame::GetMediaSourceFromListener( |
| 336 content::PresentationScreenAvailabilityListener* listener) const { | 363 content::PresentationScreenAvailabilityListener* listener) const { |
| 337 // If the default presentation URL is empty then fall back to tab mirroring. | 364 // If the default presentation URL is empty then fall back to tab mirroring. |
| 338 return listener->GetAvailabilityUrl().is_empty() | 365 return listener->GetAvailabilityUrl().is_empty() |
| 339 ? MediaSourceForTab(SessionTabHelper::IdForTab(web_contents_)) | 366 ? MediaSourceForTab(SessionTabHelper::IdForTab(web_contents_)) |
| 340 : MediaSourceForPresentationUrl(listener->GetAvailabilityUrl()); | 367 : MediaSourceForPresentationUrl(listener->GetAvailabilityUrl()); |
| 341 } | 368 } |
| 342 | 369 |
| 370 bool PresentationFrame::IsOffscreenPresentation( |
| 371 const std::string& presentation_id) const { |
| 372 const auto it = presentation_id_to_route_.find(presentation_id); |
| 373 if (it == presentation_id_to_route_.end()) { |
| 374 DLOG(WARNING) << "No route for [presentation_id]: " << presentation_id; |
| 375 return false; |
| 376 } |
| 377 |
| 378 return it->second.is_offscreen_presentation(); |
| 379 } |
| 380 |
| 381 void PresentationFrame::ConnectToPresentation( |
| 382 const content::PresentationSessionInfo& session, |
| 383 content::PresentationConnectionPtr controller_connection_ptr, |
| 384 content::PresentationConnectionRequest receiver_connection_request) { |
| 385 const auto pid_route_it = |
| 386 presentation_id_to_route_.find(session.presentation_id); |
| 387 |
| 388 if (pid_route_it == presentation_id_to_route_.end()) { |
| 389 DLOG(WARNING) << "No route for [presentation_id]: " |
| 390 << session.presentation_id; |
| 391 return; |
| 392 } |
| 393 |
| 394 if (IsOffscreenPresentation(session.presentation_id)) { |
| 395 auto* const offscreen_presentation_manager = |
| 396 OffscreenPresentationManagerFactory::GetOrCreateForWebContents( |
| 397 web_contents_); |
| 398 offscreen_presentation_manager->RegisterOffscreenPresentationController( |
| 399 session.presentation_id, session.presentation_url, |
| 400 render_frame_host_id_, std::move(controller_connection_ptr), |
| 401 std::move(receiver_connection_request)); |
| 402 } else { |
| 403 DVLOG(2) |
| 404 << "Creating BrowserPresentationConnectionProxy for [presentation_id]: " |
| 405 << session.presentation_id; |
| 406 MediaRoute::Id route_id = pid_route_it->second.media_route_id(); |
| 407 auto* proxy = new BrowserPresentationConnectionProxy( |
| 408 router_, route_id, std::move(receiver_connection_request), |
| 409 std::move(controller_connection_ptr)); |
| 410 |
| 411 browser_connection_proxies_.insert( |
| 412 std::make_pair(route_id, base::WrapUnique(proxy))); |
| 413 } |
| 414 } |
| 415 |
| 343 // Used by PresentationServiceDelegateImpl to manage PresentationFrames. | 416 // Used by PresentationServiceDelegateImpl to manage PresentationFrames. |
| 344 class PresentationFrameManager { | 417 class PresentationFrameManager { |
| 345 public: | 418 public: |
| 346 PresentationFrameManager(content::WebContents* web_contents, | 419 PresentationFrameManager(content::WebContents* web_contents, |
| 347 MediaRouter* router); | 420 MediaRouter* router); |
| 348 ~PresentationFrameManager(); | 421 ~PresentationFrameManager(); |
| 349 | 422 |
| 350 // Mirror corresponding APIs in PresentationServiceDelegateImpl. | 423 // Mirror corresponding APIs in PresentationServiceDelegateImpl. |
| 351 bool SetScreenAvailabilityListener( | 424 bool SetScreenAvailabilityListener( |
| 352 const RenderFrameHostId& render_frame_host_id, | 425 const RenderFrameHostId& render_frame_host_id, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 | 464 |
| 392 void OnPresentationSessionStarted( | 465 void OnPresentationSessionStarted( |
| 393 const RenderFrameHostId& render_frame_host_id, | 466 const RenderFrameHostId& render_frame_host_id, |
| 394 const content::PresentationSessionInfo& session, | 467 const content::PresentationSessionInfo& session, |
| 395 const MediaRoute& route); | 468 const MediaRoute& route); |
| 396 void OnDefaultPresentationSessionStarted( | 469 void OnDefaultPresentationSessionStarted( |
| 397 const PresentationRequest& request, | 470 const PresentationRequest& request, |
| 398 const content::PresentationSessionInfo& session, | 471 const content::PresentationSessionInfo& session, |
| 399 const MediaRoute& route); | 472 const MediaRoute& route); |
| 400 | 473 |
| 474 void ConnectToPresentation( |
| 475 const RenderFrameHostId& render_frame_host_id, |
| 476 const content::PresentationSessionInfo& session, |
| 477 content::PresentationConnectionPtr controller_connection_ptr, |
| 478 content::PresentationConnectionRequest receiver_connection_request); |
| 479 |
| 401 const MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id, | 480 const MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id, |
| 402 const std::string& presentation_id) const; | 481 const std::string& presentation_id) const; |
| 403 const std::vector<MediaRoute::Id> GetRouteIds( | 482 const std::vector<MediaRoute::Id> GetRouteIds( |
| 404 const RenderFrameHostId& render_frame_host_id) const; | 483 const RenderFrameHostId& render_frame_host_id) const; |
| 405 | 484 |
| 406 const PresentationRequest* default_presentation_request() const { | 485 const PresentationRequest* default_presentation_request() const { |
| 407 return default_presentation_request_.get(); | 486 return default_presentation_request_.get(); |
| 408 } | 487 } |
| 409 | 488 |
| 410 private: | 489 private: |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 const auto it = presentation_frames_.find(request.render_frame_host_id()); | 551 const auto it = presentation_frames_.find(request.render_frame_host_id()); |
| 473 if (it != presentation_frames_.end()) | 552 if (it != presentation_frames_.end()) |
| 474 it->second->OnPresentationSessionStarted(session, route); | 553 it->second->OnPresentationSessionStarted(session, route); |
| 475 | 554 |
| 476 if (default_presentation_request_ && | 555 if (default_presentation_request_ && |
| 477 default_presentation_request_->Equals(request)) { | 556 default_presentation_request_->Equals(request)) { |
| 478 default_presentation_started_callback_.Run(session); | 557 default_presentation_started_callback_.Run(session); |
| 479 } | 558 } |
| 480 } | 559 } |
| 481 | 560 |
| 561 void PresentationFrameManager::ConnectToPresentation( |
| 562 const RenderFrameHostId& render_frame_host_id, |
| 563 const content::PresentationSessionInfo& session, |
| 564 content::PresentationConnectionPtr controller_connection_ptr, |
| 565 content::PresentationConnectionRequest receiver_connection_request) { |
| 566 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); |
| 567 presentation_frame->ConnectToPresentation( |
| 568 session, std::move(controller_connection_ptr), |
| 569 std::move(receiver_connection_request)); |
| 570 } |
| 571 |
| 482 const MediaRoute::Id PresentationFrameManager::GetRouteId( | 572 const MediaRoute::Id PresentationFrameManager::GetRouteId( |
| 483 const RenderFrameHostId& render_frame_host_id, | 573 const RenderFrameHostId& render_frame_host_id, |
| 484 const std::string& presentation_id) const { | 574 const std::string& presentation_id) const { |
| 485 const auto it = presentation_frames_.find(render_frame_host_id); | 575 const auto it = presentation_frames_.find(render_frame_host_id); |
| 486 return it != presentation_frames_.end() | 576 return it != presentation_frames_.end() |
| 487 ? it->second->GetRouteId(presentation_id) : MediaRoute::Id(); | 577 ? it->second->GetRouteId(presentation_id) : MediaRoute::Id(); |
| 488 } | 578 } |
| 489 | 579 |
| 490 const std::vector<MediaRoute::Id> PresentationFrameManager::GetRouteIds( | 580 const std::vector<MediaRoute::Id> PresentationFrameManager::GetRouteIds( |
| 491 const RenderFrameHostId& render_frame_host_id) const { | 581 const RenderFrameHostId& render_frame_host_id) const { |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 int render_process_id, | 994 int render_process_id, |
| 905 int render_frame_id, | 995 int render_frame_id, |
| 906 const content::PresentationSessionInfo& connection, | 996 const content::PresentationSessionInfo& connection, |
| 907 const content::PresentationConnectionStateChangedCallback& | 997 const content::PresentationConnectionStateChangedCallback& |
| 908 state_changed_cb) { | 998 state_changed_cb) { |
| 909 frame_manager_->ListenForConnectionStateChange( | 999 frame_manager_->ListenForConnectionStateChange( |
| 910 RenderFrameHostId(render_process_id, render_frame_id), connection, | 1000 RenderFrameHostId(render_process_id, render_frame_id), connection, |
| 911 state_changed_cb); | 1001 state_changed_cb); |
| 912 } | 1002 } |
| 913 | 1003 |
| 914 void PresentationServiceDelegateImpl::ConnectToOffscreenPresentation( | 1004 void PresentationServiceDelegateImpl::ConnectToPresentation( |
| 915 int render_process_id, | 1005 int render_process_id, |
| 916 int render_frame_id, | 1006 int render_frame_id, |
| 917 const content::PresentationSessionInfo& session, | 1007 const content::PresentationSessionInfo& session, |
| 918 content::PresentationConnectionPtr controller_connection_ptr, | 1008 content::PresentationConnectionPtr controller_connection_ptr, |
| 919 content::PresentationConnectionRequest receiver_connection_request) { | 1009 content::PresentationConnectionRequest receiver_connection_request) { |
| 920 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 1010 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
| 921 auto* const offscreen_presentation_manager = | 1011 frame_manager_->ConnectToPresentation(render_frame_host_id, session, |
| 922 OffscreenPresentationManagerFactory::GetOrCreateForWebContents( | 1012 std::move(controller_connection_ptr), |
| 923 web_contents_); | 1013 std::move(receiver_connection_request)); |
| 924 offscreen_presentation_manager->RegisterOffscreenPresentationController( | |
| 925 session.presentation_id, session.presentation_url, render_frame_host_id, | |
| 926 std::move(controller_connection_ptr), | |
| 927 std::move(receiver_connection_request)); | |
| 928 } | 1014 } |
| 929 | 1015 |
| 930 void PresentationServiceDelegateImpl::OnRouteResponse( | 1016 void PresentationServiceDelegateImpl::OnRouteResponse( |
| 931 const PresentationRequest& presentation_request, | 1017 const PresentationRequest& presentation_request, |
| 932 const RouteRequestResult& result) { | 1018 const RouteRequestResult& result) { |
| 933 if (!result.route() || | 1019 if (!result.route() || |
| 934 !base::ContainsValue(presentation_request.presentation_urls(), | 1020 !base::ContainsValue(presentation_request.presentation_urls(), |
| 935 result.presentation_url())) { | 1021 result.presentation_url())) { |
| 936 return; | 1022 return; |
| 937 } | 1023 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 const base::ListValue* origins = | 1074 const base::ListValue* origins = |
| 989 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) | 1075 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) |
| 990 ->GetPrefs() | 1076 ->GetPrefs() |
| 991 ->GetList(prefs::kMediaRouterTabMirroringSources); | 1077 ->GetList(prefs::kMediaRouterTabMirroringSources); |
| 992 return origins && | 1078 return origins && |
| 993 origins->Find(base::StringValue(origin.Serialize())) != origins->end(); | 1079 origins->Find(base::StringValue(origin.Serialize())) != origins->end(); |
| 994 } | 1080 } |
| 995 #endif // !defined(OS_ANDROID) | 1081 #endif // !defined(OS_ANDROID) |
| 996 | 1082 |
| 997 } // namespace media_router | 1083 } // namespace media_router |
| OLD | NEW |