Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Side by Side Diff: chrome/browser/media/router/presentation_service_delegate_impl.cc

Issue 2627463003: Convert MediaRouter mojom apis to intake url::Origin objects instead of strings (Closed)
Patch Set: comment and ternary op Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 // Returns the unique identifier for the supplied RenderFrameHost. 51 // Returns the unique identifier for the supplied RenderFrameHost.
52 RenderFrameHostId GetRenderFrameHostId(RenderFrameHost* render_frame_host) { 52 RenderFrameHostId GetRenderFrameHostId(RenderFrameHost* render_frame_host) {
53 int render_process_id = render_frame_host->GetProcess()->GetID(); 53 int render_process_id = render_frame_host->GetProcess()->GetID();
54 int render_frame_id = render_frame_host->GetRoutingID(); 54 int render_frame_id = render_frame_host->GetRoutingID();
55 return RenderFrameHostId(render_process_id, render_frame_id); 55 return RenderFrameHostId(render_process_id, render_frame_id);
56 } 56 }
57 57
58 // Gets the last committed URL for the render frame specified by 58 // Gets the last committed URL for the render frame specified by
59 // |render_frame_host_id|. 59 // |render_frame_host_id|.
60 GURL GetLastCommittedURLForFrame(RenderFrameHostId render_frame_host_id) { 60 url::Origin GetLastCommittedURLForFrame(
61 RenderFrameHostId render_frame_host_id) {
61 RenderFrameHost* render_frame_host = RenderFrameHost::FromID( 62 RenderFrameHost* render_frame_host = RenderFrameHost::FromID(
62 render_frame_host_id.first, render_frame_host_id.second); 63 render_frame_host_id.first, render_frame_host_id.second);
63 if (!render_frame_host) 64 return render_frame_host ? render_frame_host->GetLastCommittedOrigin()
dcheng 2017/01/26 04:16:32 I was trying to figure out why |render_frame_host|
steimel 2017/01/27 00:28:59 Just had some offline discussion with mfoltz@ and
imcheng 2017/01/27 00:55:06 I think what dcheng@ is saying is the correspondin
imcheng 2017/01/27 01:04:36 Filed crbug.com/685879
dcheng 2017/01/27 09:11:11 So it sounds like for now, we still need the NULL
steimel 2017/01/27 18:55:19 Hmm so what's getting cleaned up? Do you mean remo
imcheng 2017/01/27 19:02:50 I do not think the nullptr check is necessary. To
64 return GURL(); 65 : url::Origin();
65
66 // TODO(crbug.com/632623): Use url::Origin in place of GURL for origins
67 return render_frame_host->GetLastCommittedOrigin().GetURL();
68 } 66 }
69 67
70 // Observes messages originating from the MediaSink connected to a MediaRoute 68 // Observes messages originating from the MediaSink connected to a MediaRoute
71 // that represents a presentation. Converts the messages into 69 // that represents a presentation. Converts the messages into
72 // content::PresentationSessionMessages and dispatches them via the provided 70 // content::PresentationSessionMessages and dispatches them via the provided
73 // PresentationSessionMessageCallback. 71 // PresentationSessionMessageCallback.
74 class PresentationSessionMessagesObserver : public RouteMessageObserver { 72 class PresentationSessionMessagesObserver : public RouteMessageObserver {
75 public: 73 public:
76 // |message_cb|: The callback to invoke whenever messages are received. 74 // |message_cb|: The callback to invoke whenever messages are received.
77 // |route_id|: ID of MediaRoute to listen for messages. 75 // |route_id|: ID of MediaRoute to listen for messages.
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 227
230 bool PresentationFrame::SetScreenAvailabilityListener( 228 bool PresentationFrame::SetScreenAvailabilityListener(
231 content::PresentationScreenAvailabilityListener* listener) { 229 content::PresentationScreenAvailabilityListener* listener) {
232 MediaSource source(GetMediaSourceFromListener(listener)); 230 MediaSource source(GetMediaSourceFromListener(listener));
233 auto& sinks_observer = url_to_sinks_observer_[source.id()]; 231 auto& sinks_observer = url_to_sinks_observer_[source.id()];
234 if (sinks_observer && sinks_observer->listener() == listener) 232 if (sinks_observer && sinks_observer->listener() == listener)
235 return false; 233 return false;
236 234
237 sinks_observer.reset(new PresentationMediaSinksObserver( 235 sinks_observer.reset(new PresentationMediaSinksObserver(
238 router_, listener, source, 236 router_, listener, source,
239 GetLastCommittedURLForFrame(render_frame_host_id_).GetOrigin())); 237 GetLastCommittedURLForFrame(render_frame_host_id_)));
240 238
241 if (!sinks_observer->Init()) { 239 if (!sinks_observer->Init()) {
242 url_to_sinks_observer_.erase(source.id()); 240 url_to_sinks_observer_.erase(source.id());
243 listener->OnScreenAvailabilityNotSupported(); 241 listener->OnScreenAvailabilityNotSupported();
244 return false; 242 return false;
245 } 243 }
246 244
247 return true; 245 return true;
248 } 246 }
249 247
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 const RenderFrameHostId& render_frame_host_id, 551 const RenderFrameHostId& render_frame_host_id,
554 const std::vector<GURL>& default_presentation_urls, 552 const std::vector<GURL>& default_presentation_urls,
555 const content::PresentationSessionStartedCallback& callback) { 553 const content::PresentationSessionStartedCallback& callback) {
556 if (!IsMainFrame(render_frame_host_id)) 554 if (!IsMainFrame(render_frame_host_id))
557 return; 555 return;
558 556
559 if (default_presentation_urls.empty()) { 557 if (default_presentation_urls.empty()) {
560 ClearDefaultPresentationRequest(); 558 ClearDefaultPresentationRequest();
561 } else { 559 } else {
562 DCHECK(!callback.is_null()); 560 DCHECK(!callback.is_null());
563 GURL frame_url(GetLastCommittedURLForFrame(render_frame_host_id)); 561 const auto& frame_origin =
562 GetLastCommittedURLForFrame(render_frame_host_id);
564 PresentationRequest request(render_frame_host_id, default_presentation_urls, 563 PresentationRequest request(render_frame_host_id, default_presentation_urls,
565 frame_url); 564 frame_origin);
566 default_presentation_started_callback_ = callback; 565 default_presentation_started_callback_ = callback;
567 SetDefaultPresentationRequest(request); 566 SetDefaultPresentationRequest(request);
568 } 567 }
569 } 568 }
570 569
571 void PresentationFrameManager::AddDelegateObserver( 570 void PresentationFrameManager::AddDelegateObserver(
572 const RenderFrameHostId& render_frame_host_id, 571 const RenderFrameHostId& render_frame_host_id,
573 DelegateObserver* observer) { 572 DelegateObserver* observer) {
574 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id); 573 auto* presentation_frame = GetOrAddPresentationFrame(render_frame_host_id);
575 presentation_frame->set_delegate_observer(observer); 574 presentation_frame->set_delegate_observer(observer);
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 const content::PresentationSessionStartedCallback& success_cb, 823 const content::PresentationSessionStartedCallback& success_cb,
825 const content::PresentationSessionErrorCallback& error_cb) { 824 const content::PresentationSessionErrorCallback& error_cb) {
826 DVLOG(2) << "PresentationServiceDelegateImpl::JoinSession"; 825 DVLOG(2) << "PresentationServiceDelegateImpl::JoinSession";
827 if (presentation_urls.empty()) { 826 if (presentation_urls.empty()) {
828 error_cb.Run(content::PresentationError( 827 error_cb.Run(content::PresentationError(
829 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND, 828 content::PRESENTATION_ERROR_NO_PRESENTATION_FOUND,
830 "Invalid presentation arguments.")); 829 "Invalid presentation arguments."));
831 return; 830 return;
832 } 831 }
833 832
834 const url::Origin& origin = url::Origin(GetLastCommittedURLForFrame( 833 const url::Origin& origin = GetLastCommittedURLForFrame(
835 RenderFrameHostId(render_process_id, render_frame_id))); 834 RenderFrameHostId(render_process_id, render_frame_id));
836 835
837 #if !defined(OS_ANDROID) 836 #if !defined(OS_ANDROID)
838 if (IsAutoJoinPresentationId(presentation_id) && 837 if (IsAutoJoinPresentationId(presentation_id) &&
839 ShouldCancelAutoJoinForOrigin(origin)) { 838 ShouldCancelAutoJoinForOrigin(origin)) {
840 error_cb.Run(content::PresentationError( 839 error_cb.Run(content::PresentationError(
841 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED, 840 content::PRESENTATION_ERROR_SESSION_REQUEST_CANCELLED,
842 "Auto-join request cancelled by user preferences.")); 841 "Auto-join request cancelled by user preferences."));
843 return; 842 return;
844 } 843 }
845 #endif // !defined(OS_ANDROID) 844 #endif // !defined(OS_ANDROID)
846 845
847 // TODO(crbug.com/627655): Handle multiple URLs. 846 // TODO(crbug.com/627655): Handle multiple URLs.
848 const GURL& presentation_url = presentation_urls[0]; 847 const GURL& presentation_url = presentation_urls[0];
849 bool incognito = web_contents_->GetBrowserContext()->IsOffTheRecord(); 848 bool incognito = web_contents_->GetBrowserContext()->IsOffTheRecord();
850 std::vector<MediaRouteResponseCallback> route_response_callbacks; 849 std::vector<MediaRouteResponseCallback> route_response_callbacks;
851 route_response_callbacks.push_back( 850 route_response_callbacks.push_back(
852 base::Bind(&PresentationServiceDelegateImpl::OnJoinRouteResponse, 851 base::Bind(&PresentationServiceDelegateImpl::OnJoinRouteResponse,
853 weak_factory_.GetWeakPtr(), render_process_id, render_frame_id, 852 weak_factory_.GetWeakPtr(), render_process_id, render_frame_id,
854 presentation_url, presentation_id, success_cb, error_cb)); 853 presentation_url, presentation_id, success_cb, error_cb));
855 router_->JoinRoute(MediaSourceForPresentationUrl(presentation_url).id(), 854 router_->JoinRoute(MediaSourceForPresentationUrl(presentation_url).id(),
856 presentation_id, origin.GetURL(), web_contents_, 855 presentation_id, origin, web_contents_,
857 route_response_callbacks, base::TimeDelta(), incognito); 856 route_response_callbacks, base::TimeDelta(), incognito);
858 } 857 }
859 858
860 void PresentationServiceDelegateImpl::CloseConnection( 859 void PresentationServiceDelegateImpl::CloseConnection(
861 int render_process_id, 860 int render_process_id,
862 int render_frame_id, 861 int render_frame_id,
863 const std::string& presentation_id) { 862 const std::string& presentation_id) {
864 const RenderFrameHostId rfh_id(render_process_id, render_frame_id); 863 const RenderFrameHostId rfh_id(render_process_id, render_frame_id);
865 const MediaRoute::Id& route_id = 864 const MediaRoute::Id& route_id =
866 frame_manager_->GetRouteId(rfh_id, presentation_id); 865 frame_manager_->GetRouteId(rfh_id, presentation_id);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 const base::ListValue* origins = 995 const base::ListValue* origins =
997 Profile::FromBrowserContext(web_contents_->GetBrowserContext()) 996 Profile::FromBrowserContext(web_contents_->GetBrowserContext())
998 ->GetPrefs() 997 ->GetPrefs()
999 ->GetList(prefs::kMediaRouterTabMirroringSources); 998 ->GetList(prefs::kMediaRouterTabMirroringSources);
1000 return origins && 999 return origins &&
1001 origins->Find(base::StringValue(origin.Serialize())) != origins->end(); 1000 origins->Find(base::StringValue(origin.Serialize())) != origins->end();
1002 } 1001 }
1003 #endif // !defined(OS_ANDROID) 1002 #endif // !defined(OS_ANDROID)
1004 1003
1005 } // namespace media_router 1004 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698