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

Side by Side Diff: chrome/browser/ui/webui/media_router/media_router_ui.cc

Issue 1784533004: [Media Router] Add origins to sink query results. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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/ui/webui/media_router/media_router_ui.h" 5 #include "chrome/browser/ui/webui/media_router/media_router_ui.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 collator_.reset( 257 collator_.reset(
258 icu::Collator::createInstance(icu::Locale(locale.c_str()), error)); 258 icu::Collator::createInstance(icu::Locale(locale.c_str()), error));
259 if (U_FAILURE(error)) { 259 if (U_FAILURE(error)) {
260 DLOG(ERROR) << "Failed to create collator for locale " << locale; 260 DLOG(ERROR) << "Failed to create collator for locale " << locale;
261 collator_.reset(); 261 collator_.reset();
262 } 262 }
263 263
264 query_result_manager_.reset(new QueryResultManager(router_)); 264 query_result_manager_.reset(new QueryResultManager(router_));
265 query_result_manager_->AddObserver(this); 265 query_result_manager_->AddObserver(this);
266 266
267 GURL origin = GetOrigin(false);
267 // Desktop mirror mode is always available. 268 // Desktop mirror mode is always available.
268 query_result_manager_->StartSinksQuery(MediaCastMode::DESKTOP_MIRROR, 269 query_result_manager_->StartSinksQuery(MediaCastMode::DESKTOP_MIRROR,
269 MediaSourceForDesktop()); 270 MediaSourceForDesktop(), origin);
270 initiator_ = initiator; 271 initiator_ = initiator;
271 SessionID::id_type tab_id = SessionTabHelper::IdForTab(initiator); 272 SessionID::id_type tab_id = SessionTabHelper::IdForTab(initiator);
272 if (tab_id != -1) { 273 if (tab_id != -1) {
273 MediaSource mirroring_source(MediaSourceForTab(tab_id)); 274 MediaSource mirroring_source(MediaSourceForTab(tab_id));
274 query_result_manager_->StartSinksQuery(MediaCastMode::TAB_MIRROR, 275 query_result_manager_->StartSinksQuery(MediaCastMode::TAB_MIRROR,
275 mirroring_source); 276 mirroring_source, origin);
276 } 277 }
277 UpdateCastModes(); 278 UpdateCastModes();
278 } 279 }
279 280
280 void MediaRouterUI::InitForTest(MediaRouter* router, 281 void MediaRouterUI::InitForTest(MediaRouter* router,
281 content::WebContents* initiator, 282 content::WebContents* initiator,
282 MediaRouterWebUIMessageHandler* handler) { 283 MediaRouterWebUIMessageHandler* handler) {
283 router_ = router; 284 router_ = router;
284 handler_ = handler; 285 handler_ = handler;
285 InitCommon(initiator); 286 InitCommon(initiator);
286 } 287 }
287 288
288 void MediaRouterUI::OnDefaultPresentationChanged( 289 void MediaRouterUI::OnDefaultPresentationChanged(
289 const PresentationRequest& presentation_request) { 290 const PresentationRequest& presentation_request) {
290 MediaSource source = presentation_request.GetMediaSource(); 291 MediaSource source = presentation_request.GetMediaSource();
291 presentation_request_.reset(new PresentationRequest(presentation_request)); 292 presentation_request_.reset(new PresentationRequest(presentation_request));
292 query_result_manager_->StartSinksQuery(MediaCastMode::DEFAULT, source); 293 query_result_manager_->StartSinksQuery(MediaCastMode::DEFAULT, source,
294 GetOrigin(true));
293 // Register for MediaRoute updates. 295 // Register for MediaRoute updates.
294 routes_observer_.reset(new UIMediaRoutesObserver( 296 routes_observer_.reset(new UIMediaRoutesObserver(
295 router_, source.id(), 297 router_, source.id(),
296 base::Bind(&MediaRouterUI::OnRoutesUpdated, base::Unretained(this)))); 298 base::Bind(&MediaRouterUI::OnRoutesUpdated, base::Unretained(this))));
297 299
298 UpdateCastModes(); 300 UpdateCastModes();
299 } 301 }
300 302
301 void MediaRouterUI::OnDefaultPresentationRemoved() { 303 void MediaRouterUI::OnDefaultPresentationRemoved() {
302 presentation_request_.reset(); 304 presentation_request_.reset();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 } 361 }
360 362
361 bool for_default_source = cast_mode == MediaCastMode::DEFAULT; 363 bool for_default_source = cast_mode == MediaCastMode::DEFAULT;
362 if (for_default_source && !presentation_request_) { 364 if (for_default_source && !presentation_request_) {
363 DLOG(ERROR) << "Requested to create a route for presentation, but " 365 DLOG(ERROR) << "Requested to create a route for presentation, but "
364 << "presentation request is missing."; 366 << "presentation request is missing.";
365 return false; 367 return false;
366 } 368 }
367 369
368 current_route_request_id_ = ++route_request_counter_; 370 current_route_request_id_ = ++route_request_counter_;
369 GURL origin; 371 GURL origin = GetOrigin(for_default_source);
370 if (for_default_source) {
371 origin = presentation_request_->frame_url().GetOrigin();
372 } else {
373 // Requesting route for mirroring. Use a placeholder URL as origin.
374 origin = GURL(chrome::kChromeUIMediaRouterURL);
375 }
376 DCHECK(origin.is_valid()); 372 DCHECK(origin.is_valid());
377 373
378 DVLOG(1) << "DoCreateRoute: origin: " << origin; 374 DVLOG(1) << "DoCreateRoute: origin: " << origin;
379 375
380 // There are 3 cases. In all cases the MediaRouterUI will need to be notified. 376 // There are 3 cases. In all cases the MediaRouterUI will need to be notified.
381 // (1) Non-presentation route request (e.g., mirroring). No additional 377 // (1) Non-presentation route request (e.g., mirroring). No additional
382 // notification necessary. 378 // notification necessary.
383 // (2) Presentation route request for a Presentation API startSession call. 379 // (2) Presentation route request for a Presentation API startSession call.
384 // The startSession (CreatePresentationConnectionRequest) will need to be 380 // The startSession (CreatePresentationConnectionRequest) will need to be
385 // answered with the 381 // answered with the
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 IssueAction(IssueAction::TYPE_DISMISS), 523 IssueAction(IssueAction::TYPE_DISMISS),
528 std::vector<IssueAction>(), std::string(), Issue::NOTIFICATION, 524 std::vector<IssueAction>(), std::string(), Issue::NOTIFICATION,
529 false, std::string()); 525 false, std::string());
530 AddIssue(issue); 526 AddIssue(issue);
531 } 527 }
532 528
533 GURL MediaRouterUI::GetFrameURL() const { 529 GURL MediaRouterUI::GetFrameURL() const {
534 return presentation_request_ ? presentation_request_->frame_url() : GURL(); 530 return presentation_request_ ? presentation_request_->frame_url() : GURL();
535 } 531 }
536 532
533 GURL MediaRouterUI::GetOrigin(bool for_default_source) const {
mark a. foltz 2016/03/11 01:20:23 I don't think we need a method for this. Just pas
imcheng 2016/03/14 21:30:20 Done.
534 DCHECK(!for_default_source || presentation_request_);
535 // Use a placeholder URL as origin for mirroring.
536 return for_default_source ? presentation_request_->frame_url().GetOrigin()
537 : GURL(chrome::kChromeUIMediaRouterURL);
538 }
539
537 std::string MediaRouterUI::GetPresentationRequestSourceName() const { 540 std::string MediaRouterUI::GetPresentationRequestSourceName() const {
538 GURL gurl = GetFrameURL(); 541 GURL gurl = GetFrameURL();
539 return gurl.SchemeIs(extensions::kExtensionScheme) 542 return gurl.SchemeIs(extensions::kExtensionScheme)
540 ? GetExtensionName(gurl, extensions::ExtensionRegistry::Get( 543 ? GetExtensionName(gurl, extensions::ExtensionRegistry::Get(
541 Profile::FromWebUI(web_ui()))) 544 Profile::FromWebUI(web_ui())))
542 : GetHostFromURL(gurl); 545 : GetHostFromURL(gurl);
543 } 546 }
544 547
545 std::string MediaRouterUI::GetTruncatedPresentationRequestSourceName() const { 548 std::string MediaRouterUI::GetTruncatedPresentationRequestSourceName() const {
546 GURL gurl = GetFrameURL(); 549 GURL gurl = GetFrameURL();
(...skipping 27 matching lines...) Expand all
574 base::Time::Now() - start_time_); 577 base::Time::Now() - start_time_);
575 start_time_ = base::Time(); 578 start_time_ = base::Time();
576 } 579 }
577 } 580 }
578 581
579 void MediaRouterUI::UpdateMaxDialogHeight(int height) { 582 void MediaRouterUI::UpdateMaxDialogHeight(int height) {
580 handler_->UpdateMaxDialogHeight(height); 583 handler_->UpdateMaxDialogHeight(height);
581 } 584 }
582 585
583 } // namespace media_router 586 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698