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

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

Issue 2627463003: Convert MediaRouter mojom apis to intake url::Origin objects instead of strings (Closed)
Patch Set: Add missing dependency for extensions_renderer_resources target 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/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 <unordered_map> 9 #include <unordered_map>
10 #include <utility> 10 #include <utility>
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 icu::Collator::createInstance(icu::Locale(locale.c_str()), error)); 270 icu::Collator::createInstance(icu::Locale(locale.c_str()), error));
271 if (U_FAILURE(error)) { 271 if (U_FAILURE(error)) {
272 DLOG(ERROR) << "Failed to create collator for locale " << locale; 272 DLOG(ERROR) << "Failed to create collator for locale " << locale;
273 collator_.reset(); 273 collator_.reset();
274 } 274 }
275 275
276 query_result_manager_.reset(new QueryResultManager(router_)); 276 query_result_manager_.reset(new QueryResultManager(router_));
277 query_result_manager_->AddObserver(this); 277 query_result_manager_->AddObserver(this);
278 278
279 // Use a placeholder URL as origin for mirroring. 279 // Use a placeholder URL as origin for mirroring.
280 GURL origin(chrome::kChromeUIMediaRouterURL); 280 url::Origin origin{GURL(chrome::kChromeUIMediaRouterURL)};
281 281
282 // Desktop mirror mode is always available. 282 // Desktop mirror mode is always available.
283 query_result_manager_->SetSourcesForCastMode( 283 query_result_manager_->SetSourcesForCastMode(
284 MediaCastMode::DESKTOP_MIRROR, {MediaSourceForDesktop()}, origin); 284 MediaCastMode::DESKTOP_MIRROR, {MediaSourceForDesktop()}, origin);
285 initiator_ = initiator; 285 initiator_ = initiator;
286 SessionID::id_type tab_id = SessionTabHelper::IdForTab(initiator); 286 SessionID::id_type tab_id = SessionTabHelper::IdForTab(initiator);
287 if (tab_id != -1) { 287 if (tab_id != -1) {
288 MediaSource mirroring_source(MediaSourceForTab(tab_id)); 288 MediaSource mirroring_source(MediaSourceForTab(tab_id));
289 query_result_manager_->SetSourcesForCastMode(MediaCastMode::TAB_MIRROR, 289 query_result_manager_->SetSourcesForCastMode(MediaCastMode::TAB_MIRROR,
290 {mirroring_source}, origin); 290 {mirroring_source}, origin);
(...skipping 20 matching lines...) Expand all
311 OnDefaultPresentationChanged( 311 OnDefaultPresentationChanged(
312 create_session_request_->presentation_request()); 312 create_session_request_->presentation_request());
313 } 313 }
314 } 314 }
315 315
316 void MediaRouterUI::OnDefaultPresentationChanged( 316 void MediaRouterUI::OnDefaultPresentationChanged(
317 const PresentationRequest& presentation_request) { 317 const PresentationRequest& presentation_request) {
318 std::vector<MediaSource> sources = presentation_request.GetMediaSources(); 318 std::vector<MediaSource> sources = presentation_request.GetMediaSources();
319 presentation_request_.reset(new PresentationRequest(presentation_request)); 319 presentation_request_.reset(new PresentationRequest(presentation_request));
320 query_result_manager_->SetSourcesForCastMode( 320 query_result_manager_->SetSourcesForCastMode(
321 MediaCastMode::DEFAULT, sources, 321 MediaCastMode::DEFAULT, sources, presentation_request_->frame_origin());
322 presentation_request_->frame_url().GetOrigin());
323 // Register for MediaRoute updates. NOTE(mfoltz): If there are multiple 322 // Register for MediaRoute updates. NOTE(mfoltz): If there are multiple
324 // sources that can be connected to via the dialog, this will break. We will 323 // sources that can be connected to via the dialog, this will break. We will
325 // need to observe multiple sources (keyed by sinks) in that case. As this is 324 // need to observe multiple sources (keyed by sinks) in that case. As this is
326 // Cast-specific for the forseeable future, it may be simpler to plumb a new 325 // Cast-specific for the forseeable future, it may be simpler to plumb a new
327 // observer API for this case. 326 // observer API for this case.
328 const MediaSource source_for_route_observer = 327 const MediaSource source_for_route_observer =
329 GetSourceForRouteObserver(sources); 328 GetSourceForRouteObserver(sources);
330 routes_observer_.reset(new UIMediaRoutesObserver( 329 routes_observer_.reset(new UIMediaRoutesObserver(
331 router_, source_for_route_observer.id(), 330 router_, source_for_route_observer.id(),
332 base::Bind(&MediaRouterUI::OnRoutesUpdated, base::Unretained(this)))); 331 base::Bind(&MediaRouterUI::OnRoutesUpdated, base::Unretained(this))));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 ui_initialized_ = true; 383 ui_initialized_ = true;
385 384
386 // Register for Issue updates. 385 // Register for Issue updates.
387 issues_observer_.reset(new UIIssuesObserver(router_, this)); 386 issues_observer_.reset(new UIIssuesObserver(router_, this));
388 issues_observer_->Init(); 387 issues_observer_->Init();
389 } 388 }
390 389
391 bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id, 390 bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id,
392 MediaCastMode cast_mode) { 391 MediaCastMode cast_mode) {
393 MediaSource::Id source_id; 392 MediaSource::Id source_id;
394 GURL origin; 393 url::Origin origin;
395 std::vector<MediaRouteResponseCallback> route_response_callbacks; 394 std::vector<MediaRouteResponseCallback> route_response_callbacks;
396 base::TimeDelta timeout; 395 base::TimeDelta timeout;
397 bool incognito; 396 bool incognito;
398 if (!SetRouteParameters(sink_id, cast_mode, &source_id, &origin, 397 if (!SetRouteParameters(sink_id, cast_mode, &source_id, &origin,
399 &route_response_callbacks, &timeout, &incognito)) { 398 &route_response_callbacks, &timeout, &incognito)) {
400 SendIssueForUnableToCast(cast_mode); 399 SendIssueForUnableToCast(cast_mode);
401 return false; 400 return false;
402 } 401 }
403 router_->CreateRoute(source_id, sink_id, origin, initiator_, 402 router_->CreateRoute(source_id, sink_id, origin, initiator_,
404 route_response_callbacks, timeout, incognito); 403 route_response_callbacks, timeout, incognito);
405 return true; 404 return true;
406 } 405 }
407 406
408 bool MediaRouterUI::SetRouteParameters( 407 bool MediaRouterUI::SetRouteParameters(
409 const MediaSink::Id& sink_id, 408 const MediaSink::Id& sink_id,
410 MediaCastMode cast_mode, 409 MediaCastMode cast_mode,
411 MediaSource::Id* source_id, 410 MediaSource::Id* source_id,
412 GURL* origin, 411 url::Origin* origin,
413 std::vector<MediaRouteResponseCallback>* route_response_callbacks, 412 std::vector<MediaRouteResponseCallback>* route_response_callbacks,
414 base::TimeDelta* timeout, 413 base::TimeDelta* timeout,
415 bool* incognito) { 414 bool* incognito) {
416 DCHECK(query_result_manager_.get()); 415 DCHECK(query_result_manager_.get());
417 DCHECK(initiator_); 416 DCHECK(initiator_);
418 417
419 // Note that there is a rarely-encountered bug, where the MediaCastMode to 418 // Note that there is a rarely-encountered bug, where the MediaCastMode to
420 // MediaSource mapping could have been updated, between when the user clicked 419 // MediaSource mapping could have been updated, between when the user clicked
421 // on the UI to start a create route request, and when this function is 420 // on the UI to start a create route request, and when this function is
422 // called. However, since the user does not have visibility into the 421 // called. However, since the user does not have visibility into the
423 // MediaSource, and that it occurs very rarely in practice, we leave it as-is 422 // MediaSource, and that it occurs very rarely in practice, we leave it as-is
424 // for now. 423 // for now.
425 std::unique_ptr<MediaSource> source = 424 std::unique_ptr<MediaSource> source =
426 query_result_manager_->GetSourceForCastModeAndSink(cast_mode, sink_id); 425 query_result_manager_->GetSourceForCastModeAndSink(cast_mode, sink_id);
427 if (!source) { 426 if (!source) {
428 LOG(ERROR) << "No corresponding MediaSource for cast mode " 427 LOG(ERROR) << "No corresponding MediaSource for cast mode "
429 << static_cast<int>(cast_mode) << " and sink " << sink_id; 428 << static_cast<int>(cast_mode) << " and sink " << sink_id;
430 return false; 429 return false;
431 } 430 }
432 *source_id = source->id(); 431 *source_id = source->id();
433 432
434 bool for_default_source = cast_mode == MediaCastMode::DEFAULT; 433 bool for_default_source = cast_mode == MediaCastMode::DEFAULT;
435 if (for_default_source && !presentation_request_) { 434 if (for_default_source && !presentation_request_) {
436 DLOG(ERROR) << "Requested to create a route for presentation, but " 435 DLOG(ERROR) << "Requested to create a route for presentation, but "
437 << "presentation request is missing."; 436 << "presentation request is missing.";
438 return false; 437 return false;
439 } 438 }
440 439
441 current_route_request_id_ = ++route_request_counter_; 440 current_route_request_id_ = ++route_request_counter_;
442 *origin = for_default_source ? presentation_request_->frame_url().GetOrigin() 441 *origin = for_default_source
443 : GURL(chrome::kChromeUIMediaRouterURL); 442 ? presentation_request_->frame_origin()
443 : url::Origin(GURL(chrome::kChromeUIMediaRouterURL));
444 DVLOG(1) << "DoCreateRoute: origin: " << *origin; 444 DVLOG(1) << "DoCreateRoute: origin: " << *origin;
445 445
446 // There are 3 cases. In cases (1) and (3) the MediaRouterUI will need to be 446 // There are 3 cases. In cases (1) and (3) the MediaRouterUI will need to be
447 // notified. In case (2) the dialog will be closed. 447 // notified. In case (2) the dialog will be closed.
448 // (1) Non-presentation route request (e.g., mirroring). No additional 448 // (1) Non-presentation route request (e.g., mirroring). No additional
449 // notification necessary. 449 // notification necessary.
450 // (2) Presentation route request for a Presentation API startSession call. 450 // (2) Presentation route request for a Presentation API startSession call.
451 // The startSession (CreatePresentationConnectionRequest) will need to be 451 // The startSession (CreatePresentationConnectionRequest) will need to be
452 // answered with the route response. 452 // answered with the route response.
453 // (3) Browser-initiated presentation route request. If successful, 453 // (3) Browser-initiated presentation route request. If successful,
(...skipping 25 matching lines...) Expand all
479 479
480 *timeout = GetRouteRequestTimeout(cast_mode); 480 *timeout = GetRouteRequestTimeout(cast_mode);
481 *incognito = Profile::FromWebUI(web_ui())->IsOffTheRecord(); 481 *incognito = Profile::FromWebUI(web_ui())->IsOffTheRecord();
482 482
483 return true; 483 return true;
484 } 484 }
485 485
486 bool MediaRouterUI::ConnectRoute(const MediaSink::Id& sink_id, 486 bool MediaRouterUI::ConnectRoute(const MediaSink::Id& sink_id,
487 const MediaRoute::Id& route_id) { 487 const MediaRoute::Id& route_id) {
488 MediaSource::Id source_id; 488 MediaSource::Id source_id;
489 GURL origin; 489 url::Origin origin;
490 std::vector<MediaRouteResponseCallback> route_response_callbacks; 490 std::vector<MediaRouteResponseCallback> route_response_callbacks;
491 base::TimeDelta timeout; 491 base::TimeDelta timeout;
492 bool incognito; 492 bool incognito;
493 if (!SetRouteParameters(sink_id, MediaCastMode::DEFAULT, &source_id, &origin, 493 if (!SetRouteParameters(sink_id, MediaCastMode::DEFAULT, &source_id, &origin,
494 &route_response_callbacks, &timeout, &incognito)) { 494 &route_response_callbacks, &timeout, &incognito)) {
495 SendIssueForUnableToCast(MediaCastMode::DEFAULT); 495 SendIssueForUnableToCast(MediaCastMode::DEFAULT);
496 return false; 496 return false;
497 } 497 }
498 router_->ConnectRouteByRouteId(source_id, route_id, origin, initiator_, 498 router_->ConnectRouteByRouteId(source_id, route_id, origin, initiator_,
499 route_response_callbacks, timeout, incognito); 499 route_response_callbacks, timeout, incognito);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 Close(); 645 Close();
646 } 646 }
647 647
648 void MediaRouterUI::OnSearchSinkResponseReceived( 648 void MediaRouterUI::OnSearchSinkResponseReceived(
649 MediaCastMode cast_mode, 649 MediaCastMode cast_mode,
650 const MediaSink::Id& found_sink_id) { 650 const MediaSink::Id& found_sink_id) {
651 DVLOG(1) << "OnSearchSinkResponseReceived"; 651 DVLOG(1) << "OnSearchSinkResponseReceived";
652 handler_->ReturnSearchResult(found_sink_id); 652 handler_->ReturnSearchResult(found_sink_id);
653 653
654 MediaSource::Id source_id; 654 MediaSource::Id source_id;
655 GURL origin; 655 url::Origin origin;
656 std::vector<MediaRouteResponseCallback> route_response_callbacks; 656 std::vector<MediaRouteResponseCallback> route_response_callbacks;
657 base::TimeDelta timeout; 657 base::TimeDelta timeout;
658 bool incognito; 658 bool incognito;
659 if (!SetRouteParameters(found_sink_id, cast_mode, &source_id, &origin, 659 if (!SetRouteParameters(found_sink_id, cast_mode, &source_id, &origin,
660 &route_response_callbacks, &timeout, &incognito)) { 660 &route_response_callbacks, &timeout, &incognito)) {
661 SendIssueForUnableToCast(cast_mode); 661 SendIssueForUnableToCast(cast_mode);
662 return; 662 return;
663 } 663 }
664 router_->CreateRoute(source_id, found_sink_id, origin, initiator_, 664 router_->CreateRoute(source_id, found_sink_id, origin, initiator_,
665 route_response_callbacks, timeout, incognito); 665 route_response_callbacks, timeout, incognito);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 (cast_mode == MediaCastMode::DESKTOP_MIRROR) 700 (cast_mode == MediaCastMode::DESKTOP_MIRROR)
701 ? l10n_util::GetStringUTF8( 701 ? l10n_util::GetStringUTF8(
702 IDS_MEDIA_ROUTER_ISSUE_UNABLE_TO_CAST_DESKTOP) 702 IDS_MEDIA_ROUTER_ISSUE_UNABLE_TO_CAST_DESKTOP)
703 : l10n_util::GetStringUTF8( 703 : l10n_util::GetStringUTF8(
704 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB); 704 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB);
705 AddIssue(IssueInfo(issue_title, IssueInfo::Action::DISMISS, 705 AddIssue(IssueInfo(issue_title, IssueInfo::Action::DISMISS,
706 IssueInfo::Severity::WARNING)); 706 IssueInfo::Severity::WARNING));
707 } 707 }
708 708
709 GURL MediaRouterUI::GetFrameURL() const { 709 GURL MediaRouterUI::GetFrameURL() const {
710 return presentation_request_ ? presentation_request_->frame_url() : GURL(); 710 return presentation_request_ ? presentation_request_->frame_origin().GetURL()
711 : GURL();
711 } 712 }
712 713
713 std::string MediaRouterUI::GetPresentationRequestSourceName() const { 714 std::string MediaRouterUI::GetPresentationRequestSourceName() const {
714 GURL gurl = GetFrameURL(); 715 GURL gurl = GetFrameURL();
715 return gurl.SchemeIs(extensions::kExtensionScheme) 716 return gurl.SchemeIs(extensions::kExtensionScheme)
716 ? GetExtensionName(gurl, extensions::ExtensionRegistry::Get( 717 ? GetExtensionName(gurl, extensions::ExtensionRegistry::Get(
717 Profile::FromWebUI(web_ui()))) 718 Profile::FromWebUI(web_ui())))
718 : GetHostFromURL(gurl); 719 : GetHostFromURL(gurl);
719 } 720 }
720 721
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 } 762 }
762 763
763 std::string MediaRouterUI::GetSerializedInitiatorOrigin() const { 764 std::string MediaRouterUI::GetSerializedInitiatorOrigin() const {
764 url::Origin origin = initiator_ 765 url::Origin origin = initiator_
765 ? url::Origin(initiator_->GetLastCommittedURL()) 766 ? url::Origin(initiator_->GetLastCommittedURL())
766 : url::Origin(); 767 : url::Origin();
767 return origin.Serialize(); 768 return origin.Serialize();
768 } 769 }
769 770
770 } // namespace media_router 771 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698