| 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 | 8 |
| 9 #include "base/containers/scoped_ptr_hash_map.h" | 9 #include "base/containers/scoped_ptr_hash_map.h" |
| 10 #include "base/containers/small_map.h" | 10 #include "base/containers/small_map.h" |
| 11 #include "base/guid.h" | |
| 12 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 13 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 14 #include "chrome/browser/media/router/create_presentation_session_request.h" | 13 #include "chrome/browser/media/router/create_presentation_session_request.h" |
| 15 #include "chrome/browser/media/router/media_route.h" | 14 #include "chrome/browser/media/router/media_route.h" |
| 16 #include "chrome/browser/media/router/media_router.h" | 15 #include "chrome/browser/media/router/media_router.h" |
| 17 #include "chrome/browser/media/router/media_router_dialog_controller.h" | 16 #include "chrome/browser/media/router/media_router_dialog_controller.h" |
| 18 #include "chrome/browser/media/router/media_router_factory.h" | 17 #include "chrome/browser/media/router/media_router_factory.h" |
| 19 #include "chrome/browser/media/router/media_sink.h" | 18 #include "chrome/browser/media/router/media_sink.h" |
| 20 #include "chrome/browser/media/router/media_source_helper.h" | 19 #include "chrome/browser/media/router/media_source_helper.h" |
| 20 #include "chrome/browser/media/router/one_ua_presentation_router.h" |
| 21 #include "chrome/browser/media/router/one_ua_presentation_router_factory.h" |
| 21 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" | 22 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" |
| 22 #include "chrome/browser/media/router/presentation_session_messages_observer.h" | 23 #include "chrome/browser/media/router/presentation_session_messages_observer.h" |
| 23 #include "chrome/browser/media/router/presentation_session_state_observer.h" | 24 #include "chrome/browser/media/router/presentation_session_state_observer.h" |
| 24 #include "chrome/browser/sessions/session_tab_helper.h" | 25 #include "chrome/browser/sessions/session_tab_helper.h" |
| 25 #include "content/public/browser/presentation_screen_availability_listener.h" | 26 #include "content/public/browser/presentation_screen_availability_listener.h" |
| 26 #include "content/public/browser/presentation_session.h" | 27 #include "content/public/browser/presentation_session.h" |
| 27 #include "content/public/browser/render_frame_host.h" | 28 #include "content/public/browser/render_frame_host.h" |
| 28 #include "content/public/browser/render_process_host.h" | 29 #include "content/public/browser/render_process_host.h" |
| 29 | 30 |
| 30 DEFINE_WEB_CONTENTS_USER_DATA_KEY( | 31 DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
| 31 media_router::PresentationServiceDelegateImpl); | 32 media_router::PresentationServiceDelegateImpl); |
| 32 | 33 |
| 33 using content::RenderFrameHost; | 34 using content::RenderFrameHost; |
| 34 | 35 |
| 35 namespace media_router { | 36 namespace media_router { |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 39 using DelegateObserver = content::PresentationServiceDelegate::Observer; | 40 using DelegateObserver = content::PresentationServiceDelegate::Observer; |
| 40 using PresentationSessionErrorCallback = | 41 using PresentationSessionErrorCallback = |
| 41 content::PresentationServiceDelegate::PresentationSessionErrorCallback; | 42 content::PresentationServiceDelegate::PresentationSessionErrorCallback; |
| 42 using PresentationSessionSuccessCallback = | 43 using PresentationSessionSuccessCallback = |
| 43 content::PresentationServiceDelegate::PresentationSessionSuccessCallback; | 44 content::PresentationServiceDelegate::PresentationSessionSuccessCallback; |
| 44 | 45 |
| 45 using RenderFrameHostId = std::pair<int, int>; | |
| 46 | |
| 47 // Returns the unique identifier for the supplied RenderFrameHost. | 46 // Returns the unique identifier for the supplied RenderFrameHost. |
| 48 RenderFrameHostId GetRenderFrameHostId(RenderFrameHost* render_frame_host) { | 47 RenderFrameHostId GetRenderFrameHostId(RenderFrameHost* render_frame_host) { |
| 49 int render_process_id = render_frame_host->GetProcess()->GetID(); | 48 int render_process_id = render_frame_host->GetProcess()->GetID(); |
| 50 int render_frame_id = render_frame_host->GetRoutingID(); | 49 int render_frame_id = render_frame_host->GetRoutingID(); |
| 51 return RenderFrameHostId(render_process_id, render_frame_id); | 50 return RenderFrameHostId(render_process_id, render_frame_id); |
| 52 } | 51 } |
| 53 | 52 |
| 54 // Gets the last committed URL for the render frame specified by | 53 // Gets the last committed URL for the render frame specified by |
| 55 // |render_frame_host_id|. | 54 // |render_frame_host_id|. |
| 56 GURL GetLastCommittedURLForFrame(RenderFrameHostId render_frame_host_id) { | 55 GURL GetLastCommittedURLForFrame(RenderFrameHostId render_frame_host_id) { |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 std::string availability_url(listener->GetAvailabilityUrl()); | 241 std::string availability_url(listener->GetAvailabilityUrl()); |
| 243 return availability_url.empty() | 242 return availability_url.empty() |
| 244 ? MediaSourceForTab(SessionTabHelper::IdForTab(web_contents_)) | 243 ? MediaSourceForTab(SessionTabHelper::IdForTab(web_contents_)) |
| 245 : MediaSourceForPresentationUrl(availability_url); | 244 : MediaSourceForPresentationUrl(availability_url); |
| 246 } | 245 } |
| 247 | 246 |
| 248 // Used by PresentationServiceDelegateImpl to manage PresentationFrames. | 247 // Used by PresentationServiceDelegateImpl to manage PresentationFrames. |
| 249 class PresentationFrameManager { | 248 class PresentationFrameManager { |
| 250 public: | 249 public: |
| 251 PresentationFrameManager(content::WebContents* web_contents, | 250 PresentationFrameManager(content::WebContents* web_contents, |
| 252 MediaRouter* router); | 251 MediaRouter* router, |
| 252 OneUAPresentationRouter* one_ua_presentation_router); |
| 253 ~PresentationFrameManager(); | 253 ~PresentationFrameManager(); |
| 254 | 254 |
| 255 // Mirror corresponding APIs in PresentationServiceDelegateImpl. | 255 // Mirror corresponding APIs in PresentationServiceDelegateImpl. |
| 256 bool SetScreenAvailabilityListener( | 256 bool SetScreenAvailabilityListener( |
| 257 const RenderFrameHostId& render_frame_host_id, | 257 const RenderFrameHostId& render_frame_host_id, |
| 258 content::PresentationScreenAvailabilityListener* listener); | 258 content::PresentationScreenAvailabilityListener* listener); |
| 259 bool RemoveScreenAvailabilityListener( | 259 bool RemoveScreenAvailabilityListener( |
| 260 const RenderFrameHostId& render_frame_host_id, | 260 const RenderFrameHostId& render_frame_host_id, |
| 261 content::PresentationScreenAvailabilityListener* listener); | 261 content::PresentationScreenAvailabilityListener* listener); |
| 262 void SetDefaultPresentationUrl(const RenderFrameHostId& render_frame_host_id, | 262 void SetDefaultPresentationUrl(const RenderFrameHostId& render_frame_host_id, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 274 void Reset(const RenderFrameHostId& render_frame_host_id); | 274 void Reset(const RenderFrameHostId& render_frame_host_id); |
| 275 bool HasScreenAvailabilityListenerForTest( | 275 bool HasScreenAvailabilityListenerForTest( |
| 276 const RenderFrameHostId& render_frame_host_id, | 276 const RenderFrameHostId& render_frame_host_id, |
| 277 const MediaSource::Id& source_id) const; | 277 const MediaSource::Id& source_id) const; |
| 278 void SetMediaRouterForTest(MediaRouter* router); | 278 void SetMediaRouterForTest(MediaRouter* router); |
| 279 | 279 |
| 280 void OnPresentationSessionStarted( | 280 void OnPresentationSessionStarted( |
| 281 const RenderFrameHostId& render_frame_host_id, | 281 const RenderFrameHostId& render_frame_host_id, |
| 282 bool is_default_presentation, | 282 bool is_default_presentation, |
| 283 const content::PresentationSessionInfo& session, | 283 const content::PresentationSessionInfo& session, |
| 284 const MediaRoute::Id& route_id); | 284 const MediaRoute::Id& route_id, |
| 285 bool is_one_ua_presentation); |
| 285 | 286 |
| 286 void OnPresentationSessionClosed( | 287 void OnPresentationSessionClosed( |
| 287 const RenderFrameHostId& render_frame_host_id, | 288 const RenderFrameHostId& render_frame_host_id, |
| 288 const std::string& presentation_id); | 289 const std::string& presentation_id); |
| 289 const MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id, | 290 const MediaRoute::Id GetRouteId(const RenderFrameHostId& render_frame_host_id, |
| 290 const std::string& presentation_id) const; | 291 const std::string& presentation_id) const; |
| 291 const std::vector<MediaRoute::Id> GetRouteIds( | 292 const std::vector<MediaRoute::Id> GetRouteIds( |
| 292 const RenderFrameHostId& render_frame_host_id) const; | 293 const RenderFrameHostId& render_frame_host_id) const; |
| 293 | 294 |
| 294 private: | 295 private: |
| 295 PresentationFrame* GetOrAddPresentationFrame( | 296 PresentationFrame* GetOrAddPresentationFrame( |
| 296 const RenderFrameHostId& render_frame_host_id); | 297 const RenderFrameHostId& render_frame_host_id); |
| 297 | 298 |
| 298 // Maps a frame identifier to a PresentationFrame object for frames | 299 // Maps a frame identifier to a PresentationFrame object for frames |
| 299 // that are using presentation API. | 300 // that are using presentation API. |
| 300 base::ScopedPtrHashMap<RenderFrameHostId, scoped_ptr<PresentationFrame>> | 301 base::ScopedPtrHashMap<RenderFrameHostId, scoped_ptr<PresentationFrame>> |
| 301 presentation_frames_; | 302 presentation_frames_; |
| 302 | 303 |
| 303 // References to the owning WebContents, and the corresponding MediaRouter. | 304 // References to the owning WebContents, and the corresponding MediaRouter |
| 305 // and OneUAPresenationRouter. |
| 306 content::WebContents* const web_contents_; |
| 304 MediaRouter* router_; | 307 MediaRouter* router_; |
| 305 content::WebContents* web_contents_; | 308 OneUAPresentationRouter* const one_ua_presentation_router_; |
| 306 }; | 309 }; |
| 307 | 310 |
| 308 PresentationFrameManager::PresentationFrameManager( | 311 PresentationFrameManager::PresentationFrameManager( |
| 309 content::WebContents* web_contents, | 312 content::WebContents* web_contents, |
| 310 MediaRouter* router) | 313 MediaRouter* router, |
| 311 : router_(router), web_contents_(web_contents) { | 314 OneUAPresentationRouter* one_ua_presentation_router) |
| 315 : web_contents_(web_contents), |
| 316 router_(router), |
| 317 one_ua_presentation_router_(one_ua_presentation_router) { |
| 312 DCHECK(web_contents_); | 318 DCHECK(web_contents_); |
| 313 DCHECK(router_); | 319 DCHECK(router_); |
| 320 DCHECK(one_ua_presentation_router_); |
| 314 } | 321 } |
| 315 | 322 |
| 316 PresentationFrameManager::~PresentationFrameManager() { | 323 PresentationFrameManager::~PresentationFrameManager() { |
| 317 for (auto& frame : presentation_frames_) | 324 for (auto& frame : presentation_frames_) |
| 318 frame.second->OnPresentationServiceDelegateDestroyed(); | 325 frame.second->OnPresentationServiceDelegateDestroyed(); |
| 319 } | 326 } |
| 320 | 327 |
| 321 void PresentationFrameManager::OnPresentationSessionStarted( | 328 void PresentationFrameManager::OnPresentationSessionStarted( |
| 322 const RenderFrameHostId& render_frame_host_id, | 329 const RenderFrameHostId& render_frame_host_id, |
| 323 bool is_default_presentation, | 330 bool is_default_presentation, |
| 324 const content::PresentationSessionInfo& session, | 331 const content::PresentationSessionInfo& session, |
| 325 const MediaRoute::Id& route_id) { | 332 const MediaRoute::Id& route_id, |
| 333 bool is_one_ua_presentation) { |
| 326 auto presentation_frame = presentation_frames_.get(render_frame_host_id); | 334 auto presentation_frame = presentation_frames_.get(render_frame_host_id); |
| 327 if (presentation_frame) | 335 if (presentation_frame) { |
| 336 if (is_one_ua_presentation) { |
| 337 one_ua_presentation_router_->RegisterController(session, |
| 338 render_frame_host_id); |
| 339 } |
| 328 presentation_frame->OnPresentationSessionStarted(is_default_presentation, | 340 presentation_frame->OnPresentationSessionStarted(is_default_presentation, |
| 329 session, route_id); | 341 session, route_id); |
| 342 } |
| 330 } | 343 } |
| 331 | 344 |
| 332 void PresentationFrameManager::OnPresentationSessionClosed( | 345 void PresentationFrameManager::OnPresentationSessionClosed( |
| 333 const RenderFrameHostId& render_frame_host_id, | 346 const RenderFrameHostId& render_frame_host_id, |
| 334 const std::string& presentation_id) { | 347 const std::string& presentation_id) { |
| 335 auto presentation_frame = presentation_frames_.get(render_frame_host_id); | 348 auto presentation_frame = presentation_frames_.get(render_frame_host_id); |
| 336 if (presentation_frame) | 349 if (presentation_frame) |
| 337 presentation_frame->OnPresentationSessionClosed(presentation_id); | 350 presentation_frame->OnPresentationSessionClosed(presentation_id); |
| 338 } | 351 } |
| 339 | 352 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 const RenderFrameHostId& render_frame_host_id) { | 431 const RenderFrameHostId& render_frame_host_id) { |
| 419 auto presentation_frame = presentation_frames_.get(render_frame_host_id); | 432 auto presentation_frame = presentation_frames_.get(render_frame_host_id); |
| 420 if (presentation_frame) { | 433 if (presentation_frame) { |
| 421 presentation_frame->set_delegate_observer(nullptr); | 434 presentation_frame->set_delegate_observer(nullptr); |
| 422 presentation_frames_.erase(render_frame_host_id); | 435 presentation_frames_.erase(render_frame_host_id); |
| 423 } | 436 } |
| 424 } | 437 } |
| 425 | 438 |
| 426 void PresentationFrameManager::Reset( | 439 void PresentationFrameManager::Reset( |
| 427 const RenderFrameHostId& render_frame_host_id) { | 440 const RenderFrameHostId& render_frame_host_id) { |
| 441 one_ua_presentation_router_->Reset(render_frame_host_id); |
| 428 auto presentation_frame = presentation_frames_.get(render_frame_host_id); | 442 auto presentation_frame = presentation_frames_.get(render_frame_host_id); |
| 429 if (presentation_frame) | 443 if (presentation_frame) |
| 430 presentation_frame->Reset(); | 444 presentation_frame->Reset(); |
| 431 } | 445 } |
| 432 | 446 |
| 433 PresentationFrame* PresentationFrameManager::GetOrAddPresentationFrame( | 447 PresentationFrame* PresentationFrameManager::GetOrAddPresentationFrame( |
| 434 const RenderFrameHostId& render_frame_host_id) { | 448 const RenderFrameHostId& render_frame_host_id) { |
| 435 if (!presentation_frames_.contains(render_frame_host_id)) { | 449 if (!presentation_frames_.contains(render_frame_host_id)) { |
| 436 presentation_frames_.add( | 450 presentation_frames_.add( |
| 437 render_frame_host_id, | 451 render_frame_host_id, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 452 // CreateForWebContents does nothing if the delegate instance already exists. | 466 // CreateForWebContents does nothing if the delegate instance already exists. |
| 453 PresentationServiceDelegateImpl::CreateForWebContents(web_contents); | 467 PresentationServiceDelegateImpl::CreateForWebContents(web_contents); |
| 454 return PresentationServiceDelegateImpl::FromWebContents(web_contents); | 468 return PresentationServiceDelegateImpl::FromWebContents(web_contents); |
| 455 } | 469 } |
| 456 | 470 |
| 457 PresentationServiceDelegateImpl::PresentationServiceDelegateImpl( | 471 PresentationServiceDelegateImpl::PresentationServiceDelegateImpl( |
| 458 content::WebContents* web_contents) | 472 content::WebContents* web_contents) |
| 459 : web_contents_(web_contents), | 473 : web_contents_(web_contents), |
| 460 router_(MediaRouterFactory::GetApiForBrowserContext( | 474 router_(MediaRouterFactory::GetApiForBrowserContext( |
| 461 web_contents_->GetBrowserContext())), | 475 web_contents_->GetBrowserContext())), |
| 462 frame_manager_(new PresentationFrameManager(web_contents, router_)), | 476 one_ua_presentation_router_( |
| 477 OneUAPresentationRouterFactory::GetOrCreateForBrowserContext( |
| 478 web_contents_->GetBrowserContext())), |
| 479 frame_manager_(new PresentationFrameManager(web_contents, |
| 480 router_, |
| 481 one_ua_presentation_router_)), |
| 463 weak_factory_(this) { | 482 weak_factory_(this) { |
| 464 DCHECK(web_contents_); | 483 DCHECK(web_contents_); |
| 465 DCHECK(router_); | 484 DCHECK(router_); |
| 485 DCHECK(one_ua_presentation_router_); |
| 466 } | 486 } |
| 467 | 487 |
| 468 PresentationServiceDelegateImpl::~PresentationServiceDelegateImpl() { | 488 PresentationServiceDelegateImpl::~PresentationServiceDelegateImpl() { |
| 469 } | 489 } |
| 470 | 490 |
| 471 void PresentationServiceDelegateImpl::AddObserver(int render_process_id, | 491 void PresentationServiceDelegateImpl::AddObserver(int render_process_id, |
| 472 int render_frame_id, | 492 int render_frame_id, |
| 473 DelegateObserver* observer) { | 493 DelegateObserver* observer) { |
| 474 DCHECK(observer); | 494 DCHECK(observer); |
| 475 frame_manager_->AddDelegateObserver( | 495 frame_manager_->AddDelegateObserver( |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 } | 571 } |
| 552 | 572 |
| 553 void PresentationServiceDelegateImpl::OnJoinRouteResponse( | 573 void PresentationServiceDelegateImpl::OnJoinRouteResponse( |
| 554 int render_process_id, | 574 int render_process_id, |
| 555 int render_frame_id, | 575 int render_frame_id, |
| 556 const content::PresentationSessionInfo& session, | 576 const content::PresentationSessionInfo& session, |
| 557 const PresentationSessionSuccessCallback& success_cb, | 577 const PresentationSessionSuccessCallback& success_cb, |
| 558 const PresentationSessionErrorCallback& error_cb, | 578 const PresentationSessionErrorCallback& error_cb, |
| 559 const MediaRoute* route, | 579 const MediaRoute* route, |
| 560 const std::string& presentation_id, | 580 const std::string& presentation_id, |
| 561 const std::string& error_text) { | 581 const std::string& error_text, |
| 582 bool is_one_ua_presentation) { |
| 562 if (!route) { | 583 if (!route) { |
| 563 error_cb.Run(content::PresentationError( | 584 error_cb.Run(content::PresentationError( |
| 564 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, error_text)); | 585 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, error_text)); |
| 565 } else { | 586 } else { |
| 566 DVLOG(1) << "OnJoinRouteResponse: " | 587 DVLOG(1) << "OnJoinRouteResponse: " |
| 567 << "route_id: " << route->media_route_id() | 588 << "route_id: " << route->media_route_id() |
| 568 << ", presentation URL: " << session.presentation_url | 589 << ", presentation URL: " << session.presentation_url |
| 569 << ", presentation ID: " << session.presentation_id; | 590 << ", presentation ID: " << session.presentation_id << ", 1UA? " |
| 591 << is_one_ua_presentation; |
| 570 DCHECK_EQ(session.presentation_id, presentation_id); | 592 DCHECK_EQ(session.presentation_id, presentation_id); |
| 571 frame_manager_->OnPresentationSessionStarted( | 593 RenderFrameHostId rfh_id(render_process_id, render_frame_id); |
| 572 RenderFrameHostId(render_process_id, render_frame_id), false, session, | 594 frame_manager_->OnPresentationSessionStarted(rfh_id, false, session, |
| 573 route->media_route_id()); | 595 route->media_route_id(), |
| 596 is_one_ua_presentation); |
| 574 success_cb.Run(session); | 597 success_cb.Run(session); |
| 575 } | 598 } |
| 576 } | 599 } |
| 577 | 600 |
| 578 void PresentationServiceDelegateImpl::OnStartSessionSucceeded( | 601 void PresentationServiceDelegateImpl::OnStartSessionSucceeded( |
| 579 int render_process_id, | 602 int render_process_id, |
| 580 int render_frame_id, | 603 int render_frame_id, |
| 581 const PresentationSessionSuccessCallback& success_cb, | 604 const PresentationSessionSuccessCallback& success_cb, |
| 582 const content::PresentationSessionInfo& new_session, | 605 const content::PresentationSessionInfo& new_session, |
| 583 const MediaRoute::Id& route_id) { | 606 const MediaRoute::Id& route_id, |
| 607 bool is_one_ua_presentation) { |
| 584 DVLOG(1) << "OnStartSessionSucceeded: " | 608 DVLOG(1) << "OnStartSessionSucceeded: " |
| 585 << "route_id: " << route_id | 609 << "route_id: " << route_id |
| 586 << ", presentation URL: " << new_session.presentation_url | 610 << ", presentation URL: " << new_session.presentation_url |
| 587 << ", presentation ID: " << new_session.presentation_id; | 611 << ", presentation ID: " << new_session.presentation_id; |
| 612 RenderFrameHostId rfh_id(render_process_id, render_frame_id); |
| 588 frame_manager_->OnPresentationSessionStarted( | 613 frame_manager_->OnPresentationSessionStarted( |
| 589 RenderFrameHostId(render_process_id, render_frame_id), false, new_session, | 614 rfh_id, false, new_session, route_id, is_one_ua_presentation); |
| 590 route_id); | |
| 591 success_cb.Run(new_session); | 615 success_cb.Run(new_session); |
| 592 } | 616 } |
| 593 | 617 |
| 594 void PresentationServiceDelegateImpl::StartSession( | 618 void PresentationServiceDelegateImpl::StartSession( |
| 595 int render_process_id, | 619 int render_process_id, |
| 596 int render_frame_id, | 620 int render_frame_id, |
| 597 const std::string& presentation_url, | 621 const std::string& presentation_url, |
| 598 const PresentationSessionSuccessCallback& success_cb, | 622 const PresentationSessionSuccessCallback& success_cb, |
| 599 const PresentationSessionErrorCallback& error_cb) { | 623 const PresentationSessionErrorCallback& error_cb) { |
| 600 if (presentation_url.empty() || !IsValidPresentationUrl(presentation_url)) { | 624 if (presentation_url.empty() || !IsValidPresentationUrl(presentation_url)) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 return; | 677 return; |
| 654 } | 678 } |
| 655 router_->CloseRoute(route_id); | 679 router_->CloseRoute(route_id); |
| 656 } | 680 } |
| 657 | 681 |
| 658 void PresentationServiceDelegateImpl::ListenForSessionMessages( | 682 void PresentationServiceDelegateImpl::ListenForSessionMessages( |
| 659 int render_process_id, | 683 int render_process_id, |
| 660 int render_frame_id, | 684 int render_frame_id, |
| 661 const content::PresentationSessionInfo& session, | 685 const content::PresentationSessionInfo& session, |
| 662 const content::PresentationSessionMessageCallback& message_cb) { | 686 const content::PresentationSessionMessageCallback& message_cb) { |
| 663 frame_manager_->ListenForSessionMessages( | 687 DCHECK(!session.presentation_id.empty()); |
| 664 RenderFrameHostId(render_process_id, render_frame_id), session, | 688 DCHECK(!session.presentation_url.empty()); |
| 665 message_cb); | 689 |
| 690 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
| 691 if (one_ua_presentation_router_->IsController(session.presentation_id, |
| 692 render_frame_host_id)) { |
| 693 // 1-UA session; listen for messages with OneUAPresentationRouter. |
| 694 one_ua_presentation_router_->ListenForMessages(session, message_cb); |
| 695 } else { |
| 696 // Non 1-UA session; listen for messages with MediaRouter. |
| 697 frame_manager_->ListenForSessionMessages(render_frame_host_id, session, |
| 698 message_cb); |
| 699 } |
| 666 } | 700 } |
| 667 | 701 |
| 668 void PresentationServiceDelegateImpl::SendMessage( | 702 void PresentationServiceDelegateImpl::SendMessage( |
| 669 int render_process_id, | 703 int render_process_id, |
| 670 int render_frame_id, | 704 int render_frame_id, |
| 671 const content::PresentationSessionInfo& session, | 705 const content::PresentationSessionInfo& session, |
| 672 scoped_ptr<content::PresentationSessionMessage> message, | 706 scoped_ptr<content::PresentationSessionMessage> message, |
| 673 const SendMessageCallback& send_message_cb) { | 707 const content::SendMessageCallback& send_message_cb) { |
| 674 const MediaRoute::Id& route_id = frame_manager_->GetRouteId( | 708 DCHECK(!session.presentation_id.empty()); |
| 675 RenderFrameHostId(render_process_id, render_frame_id), | 709 DCHECK(!session.presentation_url.empty()); |
| 676 session.presentation_id); | 710 |
| 711 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
| 712 const MediaRoute::Id& route_id = |
| 713 frame_manager_->GetRouteId(render_frame_host_id, session.presentation_id); |
| 677 if (route_id.empty()) { | 714 if (route_id.empty()) { |
| 678 DVLOG(1) << "No active route for " << session.presentation_id; | 715 DVLOG(1) << "No active route for " << session.presentation_id; |
| 679 send_message_cb.Run(false); | 716 send_message_cb.Run(false); |
| 680 return; | 717 return; |
| 681 } | 718 } |
| 682 | 719 |
| 683 if (message->is_binary()) { | 720 if (one_ua_presentation_router_->IsController(session.presentation_id, |
| 684 router_->SendRouteBinaryMessage(route_id, message->data.Pass(), | 721 render_frame_host_id)) { |
| 685 send_message_cb); | 722 // 1-UA session; send message with OneUAPresentationRouter. |
| 723 one_ua_presentation_router_->SendMessage(session, message.Pass(), |
| 724 send_message_cb); |
| 686 } else { | 725 } else { |
| 687 router_->SendRouteMessage(route_id, message->message, send_message_cb); | 726 // Non 1-UA session; send message with MediaRouter. |
| 727 if (message->is_binary()) { |
| 728 router_->SendRouteBinaryMessage(route_id, message->data.Pass(), |
| 729 send_message_cb); |
| 730 } else { |
| 731 router_->SendRouteMessage(route_id, message->message, send_message_cb); |
| 732 } |
| 688 } | 733 } |
| 689 } | 734 } |
| 690 | 735 |
| 691 void PresentationServiceDelegateImpl::ListenForSessionStateChange( | 736 void PresentationServiceDelegateImpl::ListenForSessionStateChange( |
| 692 int render_process_id, | 737 int render_process_id, |
| 693 int render_frame_id, | 738 int render_frame_id, |
| 694 const content::SessionStateChangedCallback& state_changed_cb) { | 739 const content::SessionStateChangedCallback& state_changed_cb) { |
| 740 // TODO(imcheng): Implement 1-UA controller state change when |
| 741 // ListenForSessionStateChange takes a PresentationSessionInfo as input. |
| 695 frame_manager_->ListenForSessionStateChange( | 742 frame_manager_->ListenForSessionStateChange( |
| 696 RenderFrameHostId(render_process_id, render_frame_id), state_changed_cb); | 743 RenderFrameHostId(render_process_id, render_frame_id), state_changed_cb); |
| 697 } | 744 } |
| 698 | 745 |
| 746 void PresentationServiceDelegateImpl::GetPresenterSession( |
| 747 int render_process_id, |
| 748 int render_frame_id, |
| 749 const content::PresenterSessionAvailableCallback& success_callback, |
| 750 const base::Callback<void(const std::string&)>& error_callback) { |
| 751 // We only have presenters in offscreen tabs, which are created in incognito |
| 752 // Profiles. See IncognitoPresentationServiceDelegate. |
| 753 NOTIMPLEMENTED(); |
| 754 error_callback.Run("Not a presenter frame"); |
| 755 } |
| 756 |
| 757 std::vector<content::PresentationSessionInfo> |
| 758 PresentationServiceDelegateImpl::GetPresenterSessions(int render_process_id, |
| 759 int render_frame_id) { |
| 760 // See comment on GetPresentersession(). |
| 761 NOTIMPLEMENTED(); |
| 762 return std::vector<content::PresentationSessionInfo>(); |
| 763 } |
| 764 |
| 699 void PresentationServiceDelegateImpl::OnRouteResponse( | 765 void PresentationServiceDelegateImpl::OnRouteResponse( |
| 700 const MediaRoute* route, | 766 const MediaRoute* route, |
| 701 const std::string& presentation_id, | 767 const std::string& presentation_id, |
| 702 const std::string& error) { | 768 const std::string& error, |
| 769 bool is_one_ua_presentation) { |
| 703 if (!route) | 770 if (!route) |
| 704 return; | 771 return; |
| 772 |
| 705 const MediaSource& source = route->media_source(); | 773 const MediaSource& source = route->media_source(); |
| 706 DCHECK(!source.Empty()); | 774 DCHECK(!source.Empty()); |
| 707 if (!default_source_.Equals(source)) | 775 if (!default_source_.Equals(source)) |
| 708 return; | 776 return; |
| 777 |
| 709 RenderFrameHost* main_frame = web_contents_->GetMainFrame(); | 778 RenderFrameHost* main_frame = web_contents_->GetMainFrame(); |
| 710 if (!main_frame) | 779 if (!main_frame) |
| 711 return; | 780 return; |
| 781 |
| 712 RenderFrameHostId render_frame_host_id(GetRenderFrameHostId(main_frame)); | 782 RenderFrameHostId render_frame_host_id(GetRenderFrameHostId(main_frame)); |
| 713 frame_manager_->OnPresentationSessionStarted( | 783 content::PresentationSessionInfo session( |
| 714 render_frame_host_id, true, | 784 PresentationUrlFromMediaSource(source), presentation_id); |
| 715 content::PresentationSessionInfo(PresentationUrlFromMediaSource(source), | 785 |
| 716 presentation_id), | 786 frame_manager_->OnPresentationSessionStarted(render_frame_host_id, true, |
| 717 route->media_route_id()); | 787 session, route->media_route_id(), |
| 788 is_one_ua_presentation); |
| 718 } | 789 } |
| 719 | 790 |
| 720 void PresentationServiceDelegateImpl::AddDefaultMediaSourceObserver( | 791 void PresentationServiceDelegateImpl::AddDefaultMediaSourceObserver( |
| 721 DefaultMediaSourceObserver* observer) { | 792 DefaultMediaSourceObserver* observer) { |
| 722 default_media_source_observers_.AddObserver(observer); | 793 default_media_source_observers_.AddObserver(observer); |
| 723 } | 794 } |
| 724 | 795 |
| 725 void PresentationServiceDelegateImpl::RemoveDefaultMediaSourceObserver( | 796 void PresentationServiceDelegateImpl::RemoveDefaultMediaSourceObserver( |
| 726 DefaultMediaSourceObserver* observer) { | 797 DefaultMediaSourceObserver* observer) { |
| 727 default_media_source_observers_.RemoveObserver(observer); | 798 default_media_source_observers_.RemoveObserver(observer); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 741 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( | 812 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( |
| 742 int render_process_id, | 813 int render_process_id, |
| 743 int render_frame_id, | 814 int render_frame_id, |
| 744 const MediaSource::Id& source_id) const { | 815 const MediaSource::Id& source_id) const { |
| 745 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 816 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
| 746 return frame_manager_->HasScreenAvailabilityListenerForTest( | 817 return frame_manager_->HasScreenAvailabilityListenerForTest( |
| 747 render_frame_host_id, source_id); | 818 render_frame_host_id, source_id); |
| 748 } | 819 } |
| 749 | 820 |
| 750 } // namespace media_router | 821 } // namespace media_router |
| OLD | NEW |