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" | 11 #include "base/guid.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
14 #include "chrome/browser/media/router/create_presentation_session_request.h" | 14 #include "chrome/browser/media/router/create_presentation_session_request.h" |
15 #include "chrome/browser/media/router/media_route.h" | 15 #include "chrome/browser/media/router/media_route.h" |
16 #include "chrome/browser/media/router/media_router.h" | 16 #include "chrome/browser/media/router/media_router.h" |
17 #include "chrome/browser/media/router/media_router_mojo_impl.h" | 17 #include "chrome/browser/media/router/media_router_dialog_controller.h" |
18 #include "chrome/browser/media/router/media_router_mojo_impl_factory.h" | 18 #include "chrome/browser/media/router/media_router_factory.h" |
19 #include "chrome/browser/media/router/media_sink.h" | 19 #include "chrome/browser/media/router/media_sink.h" |
20 #include "chrome/browser/media/router/media_source_helper.h" | 20 #include "chrome/browser/media/router/media_source_helper.h" |
21 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" | 21 #include "chrome/browser/media/router/presentation_media_sinks_observer.h" |
22 #include "chrome/browser/media/router/presentation_session_state_observer.h" | 22 #include "chrome/browser/media/router/presentation_session_state_observer.h" |
23 #include "chrome/browser/sessions/session_tab_helper.h" | 23 #include "chrome/browser/sessions/session_tab_helper.h" |
24 #include "chrome/browser/ui/webui/media_router/media_router_dialog_controller.h" | |
25 #include "content/public/browser/presentation_screen_availability_listener.h" | 24 #include "content/public/browser/presentation_screen_availability_listener.h" |
26 #include "content/public/browser/presentation_session.h" | 25 #include "content/public/browser/presentation_session.h" |
27 #include "content/public/browser/render_frame_host.h" | 26 #include "content/public/browser/render_frame_host.h" |
28 #include "content/public/browser/render_process_host.h" | 27 #include "content/public/browser/render_process_host.h" |
29 | 28 |
30 DEFINE_WEB_CONTENTS_USER_DATA_KEY( | 29 DEFINE_WEB_CONTENTS_USER_DATA_KEY( |
31 media_router::PresentationServiceDelegateImpl); | 30 media_router::PresentationServiceDelegateImpl); |
32 | 31 |
33 using content::RenderFrameHost; | 32 using content::RenderFrameHost; |
34 | 33 |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 content::WebContents* web_contents) { | 406 content::WebContents* web_contents) { |
408 DCHECK(web_contents); | 407 DCHECK(web_contents); |
409 // CreateForWebContents does nothing if the delegate instance already exists. | 408 // CreateForWebContents does nothing if the delegate instance already exists. |
410 PresentationServiceDelegateImpl::CreateForWebContents(web_contents); | 409 PresentationServiceDelegateImpl::CreateForWebContents(web_contents); |
411 return PresentationServiceDelegateImpl::FromWebContents(web_contents); | 410 return PresentationServiceDelegateImpl::FromWebContents(web_contents); |
412 } | 411 } |
413 | 412 |
414 PresentationServiceDelegateImpl::PresentationServiceDelegateImpl( | 413 PresentationServiceDelegateImpl::PresentationServiceDelegateImpl( |
415 content::WebContents* web_contents) | 414 content::WebContents* web_contents) |
416 : web_contents_(web_contents), | 415 : web_contents_(web_contents), |
417 router_(MediaRouterMojoImplFactory::GetApiForBrowserContext( | 416 router_(MediaRouterFactory::GetApiForBrowserContext( |
418 web_contents_->GetBrowserContext())), | 417 web_contents_->GetBrowserContext())), |
419 frame_manager_(new PresentationFrameManager(web_contents, router_)), | 418 frame_manager_(new PresentationFrameManager(web_contents, router_)), |
420 weak_factory_(this) { | 419 weak_factory_(this) { |
421 DCHECK(web_contents_); | 420 DCHECK(web_contents_); |
422 DCHECK(router_); | 421 DCHECK(router_); |
423 } | 422 } |
424 | 423 |
425 PresentationServiceDelegateImpl::~PresentationServiceDelegateImpl() { | 424 PresentationServiceDelegateImpl::~PresentationServiceDelegateImpl() { |
426 } | 425 } |
427 | 426 |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 new CreatePresentationSessionRequest( | 563 new CreatePresentationSessionRequest( |
565 presentation_url, presentation_id, | 564 presentation_url, presentation_id, |
566 GetLastCommittedURLForFrame(render_frame_host_id), | 565 GetLastCommittedURLForFrame(render_frame_host_id), |
567 base::Bind(&PresentationServiceDelegateImpl::OnStartSessionSucceeded, | 566 base::Bind(&PresentationServiceDelegateImpl::OnStartSessionSucceeded, |
568 weak_factory_.GetWeakPtr(), render_process_id, | 567 weak_factory_.GetWeakPtr(), render_process_id, |
569 render_frame_id, success_cb), | 568 render_frame_id, success_cb), |
570 error_cb)); | 569 error_cb)); |
571 // NOTE: Currently this request is ignored if a dialog is already open, e.g. | 570 // NOTE: Currently this request is ignored if a dialog is already open, e.g. |
572 // via browser action. In practice, this should rarely happen, but log | 571 // via browser action. In practice, this should rarely happen, but log |
573 // an error message in case it does. | 572 // an error message in case it does. |
574 MediaRouterDialogController::CreateForWebContents(web_contents_); | |
575 MediaRouterDialogController* controller = | 573 MediaRouterDialogController* controller = |
576 MediaRouterDialogController::FromWebContents(web_contents_); | 574 MediaRouterDialogController::GetOrCreateForWebContents(web_contents_); |
577 | 575 |
578 if (!controller->ShowMediaRouterDialogForPresentation(context.Pass())) { | 576 if (!controller->ShowMediaRouterDialogForPresentation(context.Pass())) { |
579 LOG(ERROR) << "Media router dialog already exists. Ignoring StartSession."; | 577 LOG(ERROR) << "Media router dialog already exists. Ignoring StartSession."; |
580 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, | 578 error_cb.Run(content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, |
581 "Unable to create dialog.")); | 579 "Unable to create dialog.")); |
582 return; | 580 return; |
583 } | 581 } |
584 } | 582 } |
585 | 583 |
586 void PresentationServiceDelegateImpl::JoinSession( | 584 void PresentationServiceDelegateImpl::JoinSession( |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( | 707 bool PresentationServiceDelegateImpl::HasScreenAvailabilityListenerForTest( |
710 int render_process_id, | 708 int render_process_id, |
711 int render_frame_id, | 709 int render_frame_id, |
712 const MediaSource::Id& source_id) const { | 710 const MediaSource::Id& source_id) const { |
713 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 711 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
714 return frame_manager_->HasScreenAvailabilityListenerForTest( | 712 return frame_manager_->HasScreenAvailabilityListenerForTest( |
715 render_frame_host_id, source_id); | 713 render_frame_host_id, source_id); |
716 } | 714 } |
717 | 715 |
718 } // namespace media_router | 716 } // namespace media_router |
OLD | NEW |