| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 media_router::PresentationServiceDelegateImpl); | 44 media_router::PresentationServiceDelegateImpl); |
| 45 | 45 |
| 46 using content::RenderFrameHost; | 46 using content::RenderFrameHost; |
| 47 | 47 |
| 48 namespace media_router { | 48 namespace media_router { |
| 49 | 49 |
| 50 namespace { | 50 namespace { |
| 51 | 51 |
| 52 using DelegateObserver = content::PresentationServiceDelegate::Observer; | 52 using DelegateObserver = content::PresentationServiceDelegate::Observer; |
| 53 | 53 |
| 54 // Returns the unique identifier for the supplied RenderFrameHost. | |
| 55 RenderFrameHostId GetRenderFrameHostId(RenderFrameHost* render_frame_host) { | |
| 56 int render_process_id = render_frame_host->GetProcess()->GetID(); | |
| 57 int render_frame_id = render_frame_host->GetRoutingID(); | |
| 58 return RenderFrameHostId(render_process_id, render_frame_id); | |
| 59 } | |
| 60 | |
| 61 // Gets the last committed URL for the render frame specified by | 54 // Gets the last committed URL for the render frame specified by |
| 62 // |render_frame_host_id|. | 55 // |render_frame_host_id|. |
| 63 url::Origin GetLastCommittedURLForFrame( | 56 url::Origin GetLastCommittedURLForFrame( |
| 64 RenderFrameHostId render_frame_host_id) { | 57 RenderFrameHostId render_frame_host_id) { |
| 65 RenderFrameHost* render_frame_host = RenderFrameHost::FromID( | 58 RenderFrameHost* render_frame_host = RenderFrameHost::FromID( |
| 66 render_frame_host_id.first, render_frame_host_id.second); | 59 render_frame_host_id.first, render_frame_host_id.second); |
| 67 DCHECK(render_frame_host); | 60 DCHECK(render_frame_host); |
| 68 return render_frame_host->GetLastCommittedOrigin(); | 61 return render_frame_host->GetLastCommittedOrigin(); |
| 69 } | 62 } |
| 70 | 63 |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 } | 369 } |
| 377 return presentation_frame.get(); | 370 return presentation_frame.get(); |
| 378 } | 371 } |
| 379 | 372 |
| 380 void PresentationServiceDelegateImpl::SetDefaultPresentationUrls( | 373 void PresentationServiceDelegateImpl::SetDefaultPresentationUrls( |
| 381 int render_process_id, | 374 int render_process_id, |
| 382 int render_frame_id, | 375 int render_frame_id, |
| 383 const std::vector<GURL>& default_presentation_urls, | 376 const std::vector<GURL>& default_presentation_urls, |
| 384 content::DefaultPresentationConnectionCallback callback) { | 377 content::DefaultPresentationConnectionCallback callback) { |
| 385 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); | 378 RenderFrameHostId render_frame_host_id(render_process_id, render_frame_id); |
| 386 if (!IsMainFrame(render_frame_host_id)) | |
| 387 return; | |
| 388 | |
| 389 if (default_presentation_urls.empty()) { | 379 if (default_presentation_urls.empty()) { |
| 390 ClearDefaultPresentationRequest(); | 380 ClearDefaultPresentationRequest(); |
| 391 return; | 381 return; |
| 392 } | 382 } |
| 393 | 383 |
| 394 DCHECK(!callback.is_null()); | 384 DCHECK(!callback.is_null()); |
| 395 auto frame_origin = GetLastCommittedURLForFrame(render_frame_host_id); | 385 auto frame_origin = GetLastCommittedURLForFrame(render_frame_host_id); |
| 396 PresentationRequest request(render_frame_host_id, default_presentation_urls, | 386 PresentationRequest request(render_frame_host_id, default_presentation_urls, |
| 397 frame_origin); | 387 frame_origin); |
| 398 default_presentation_started_callback_ = std::move(callback); | 388 default_presentation_started_callback_ = std::move(callback); |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 void PresentationServiceDelegateImpl::ClearDefaultPresentationRequest() { | 725 void PresentationServiceDelegateImpl::ClearDefaultPresentationRequest() { |
| 736 default_presentation_started_callback_.Reset(); | 726 default_presentation_started_callback_.Reset(); |
| 737 if (!default_presentation_request_) | 727 if (!default_presentation_request_) |
| 738 return; | 728 return; |
| 739 | 729 |
| 740 default_presentation_request_.reset(); | 730 default_presentation_request_.reset(); |
| 741 for (auto& observer : default_presentation_request_observers_) | 731 for (auto& observer : default_presentation_request_observers_) |
| 742 observer.OnDefaultPresentationRemoved(); | 732 observer.OnDefaultPresentationRemoved(); |
| 743 } | 733 } |
| 744 | 734 |
| 745 // TODO(imcheng): Move this check to PresentationServiceImpl. | |
| 746 bool PresentationServiceDelegateImpl::IsMainFrame( | |
| 747 const RenderFrameHostId& render_frame_host_id) const { | |
| 748 RenderFrameHost* main_frame = web_contents_->GetMainFrame(); | |
| 749 return main_frame && GetRenderFrameHostId(main_frame) == render_frame_host_id; | |
| 750 } | |
| 751 | |
| 752 MediaRoute::Id PresentationServiceDelegateImpl::GetRouteId( | 735 MediaRoute::Id PresentationServiceDelegateImpl::GetRouteId( |
| 753 const RenderFrameHostId& render_frame_host_id, | 736 const RenderFrameHostId& render_frame_host_id, |
| 754 const std::string& presentation_id) const { | 737 const std::string& presentation_id) const { |
| 755 const auto it = presentation_frames_.find(render_frame_host_id); | 738 const auto it = presentation_frames_.find(render_frame_host_id); |
| 756 return it != presentation_frames_.end() | 739 return it != presentation_frames_.end() |
| 757 ? it->second->GetRouteId(presentation_id) | 740 ? it->second->GetRouteId(presentation_id) |
| 758 : MediaRoute::Id(); | 741 : MediaRoute::Id(); |
| 759 } | 742 } |
| 760 | 743 |
| 761 #if !defined(OS_ANDROID) | 744 #if !defined(OS_ANDROID) |
| 762 bool PresentationServiceDelegateImpl::ShouldCancelAutoJoinForOrigin( | 745 bool PresentationServiceDelegateImpl::ShouldCancelAutoJoinForOrigin( |
| 763 const url::Origin& origin) const { | 746 const url::Origin& origin) const { |
| 764 const base::ListValue* origins = | 747 const base::ListValue* origins = |
| 765 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) | 748 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) |
| 766 ->GetPrefs() | 749 ->GetPrefs() |
| 767 ->GetList(prefs::kMediaRouterTabMirroringSources); | 750 ->GetList(prefs::kMediaRouterTabMirroringSources); |
| 768 return origins && | 751 return origins && |
| 769 origins->Find(base::Value(origin.Serialize())) != origins->end(); | 752 origins->Find(base::Value(origin.Serialize())) != origins->end(); |
| 770 } | 753 } |
| 771 #endif // !defined(OS_ANDROID) | 754 #endif // !defined(OS_ANDROID) |
| 772 | 755 |
| 773 } // namespace media_router | 756 } // namespace media_router |
| OLD | NEW |