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

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

Issue 2678123003: Revert of Convert MediaRouter mojom apis to intake url::Origin objects instead of strings (Closed)
Patch Set: 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 url::Origin origin{GURL(chrome::kChromeUIMediaRouterURL)}; 280 GURL origin(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, presentation_request_->frame_origin()); 321 MediaCastMode::DEFAULT, sources,
322 presentation_request_->frame_url().GetOrigin());
322 // Register for MediaRoute updates. NOTE(mfoltz): If there are multiple 323 // Register for MediaRoute updates. NOTE(mfoltz): If there are multiple
323 // sources that can be connected to via the dialog, this will break. We will 324 // sources that can be connected to via the dialog, this will break. We will
324 // need to observe multiple sources (keyed by sinks) in that case. As this is 325 // need to observe multiple sources (keyed by sinks) in that case. As this is
325 // Cast-specific for the forseeable future, it may be simpler to plumb a new 326 // Cast-specific for the forseeable future, it may be simpler to plumb a new
326 // observer API for this case. 327 // observer API for this case.
327 const MediaSource source_for_route_observer = 328 const MediaSource source_for_route_observer =
328 GetSourceForRouteObserver(sources); 329 GetSourceForRouteObserver(sources);
329 routes_observer_.reset(new UIMediaRoutesObserver( 330 routes_observer_.reset(new UIMediaRoutesObserver(
330 router_, source_for_route_observer.id(), 331 router_, source_for_route_observer.id(),
331 base::Bind(&MediaRouterUI::OnRoutesUpdated, base::Unretained(this)))); 332 base::Bind(&MediaRouterUI::OnRoutesUpdated, base::Unretained(this))));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 ui_initialized_ = true; 384 ui_initialized_ = true;
384 385
385 // Register for Issue updates. 386 // Register for Issue updates.
386 issues_observer_.reset(new UIIssuesObserver(router_, this)); 387 issues_observer_.reset(new UIIssuesObserver(router_, this));
387 issues_observer_->Init(); 388 issues_observer_->Init();
388 } 389 }
389 390
390 bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id, 391 bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id,
391 MediaCastMode cast_mode) { 392 MediaCastMode cast_mode) {
392 MediaSource::Id source_id; 393 MediaSource::Id source_id;
393 url::Origin origin; 394 GURL origin;
394 std::vector<MediaRouteResponseCallback> route_response_callbacks; 395 std::vector<MediaRouteResponseCallback> route_response_callbacks;
395 base::TimeDelta timeout; 396 base::TimeDelta timeout;
396 bool incognito; 397 bool incognito;
397 if (!SetRouteParameters(sink_id, cast_mode, &source_id, &origin, 398 if (!SetRouteParameters(sink_id, cast_mode, &source_id, &origin,
398 &route_response_callbacks, &timeout, &incognito)) { 399 &route_response_callbacks, &timeout, &incognito)) {
399 SendIssueForUnableToCast(cast_mode); 400 SendIssueForUnableToCast(cast_mode);
400 return false; 401 return false;
401 } 402 }
402 router_->CreateRoute(source_id, sink_id, origin, initiator_, 403 router_->CreateRoute(source_id, sink_id, origin, initiator_,
403 route_response_callbacks, timeout, incognito); 404 route_response_callbacks, timeout, incognito);
404 return true; 405 return true;
405 } 406 }
406 407
407 bool MediaRouterUI::SetRouteParameters( 408 bool MediaRouterUI::SetRouteParameters(
408 const MediaSink::Id& sink_id, 409 const MediaSink::Id& sink_id,
409 MediaCastMode cast_mode, 410 MediaCastMode cast_mode,
410 MediaSource::Id* source_id, 411 MediaSource::Id* source_id,
411 url::Origin* origin, 412 GURL* origin,
412 std::vector<MediaRouteResponseCallback>* route_response_callbacks, 413 std::vector<MediaRouteResponseCallback>* route_response_callbacks,
413 base::TimeDelta* timeout, 414 base::TimeDelta* timeout,
414 bool* incognito) { 415 bool* incognito) {
415 DCHECK(query_result_manager_.get()); 416 DCHECK(query_result_manager_.get());
416 DCHECK(initiator_); 417 DCHECK(initiator_);
417 418
418 // Note that there is a rarely-encountered bug, where the MediaCastMode to 419 // Note that there is a rarely-encountered bug, where the MediaCastMode to
419 // MediaSource mapping could have been updated, between when the user clicked 420 // MediaSource mapping could have been updated, between when the user clicked
420 // on the UI to start a create route request, and when this function is 421 // on the UI to start a create route request, and when this function is
421 // called. However, since the user does not have visibility into the 422 // called. However, since the user does not have visibility into the
422 // MediaSource, and that it occurs very rarely in practice, we leave it as-is 423 // MediaSource, and that it occurs very rarely in practice, we leave it as-is
423 // for now. 424 // for now.
424 std::unique_ptr<MediaSource> source = 425 std::unique_ptr<MediaSource> source =
425 query_result_manager_->GetSourceForCastModeAndSink(cast_mode, sink_id); 426 query_result_manager_->GetSourceForCastModeAndSink(cast_mode, sink_id);
426 if (!source) { 427 if (!source) {
427 LOG(ERROR) << "No corresponding MediaSource for cast mode " 428 LOG(ERROR) << "No corresponding MediaSource for cast mode "
428 << static_cast<int>(cast_mode) << " and sink " << sink_id; 429 << static_cast<int>(cast_mode) << " and sink " << sink_id;
429 return false; 430 return false;
430 } 431 }
431 *source_id = source->id(); 432 *source_id = source->id();
432 433
433 bool for_default_source = cast_mode == MediaCastMode::DEFAULT; 434 bool for_default_source = cast_mode == MediaCastMode::DEFAULT;
434 if (for_default_source && !presentation_request_) { 435 if (for_default_source && !presentation_request_) {
435 DLOG(ERROR) << "Requested to create a route for presentation, but " 436 DLOG(ERROR) << "Requested to create a route for presentation, but "
436 << "presentation request is missing."; 437 << "presentation request is missing.";
437 return false; 438 return false;
438 } 439 }
439 440
440 current_route_request_id_ = ++route_request_counter_; 441 current_route_request_id_ = ++route_request_counter_;
441 *origin = for_default_source 442 *origin = for_default_source ? presentation_request_->frame_url().GetOrigin()
442 ? presentation_request_->frame_origin() 443 : GURL(chrome::kChromeUIMediaRouterURL);
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 url::Origin origin; 489 GURL 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 url::Origin origin; 655 GURL 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_origin().GetURL() 710 return presentation_request_ ? presentation_request_->frame_url() : GURL();
711 : GURL();
712 } 711 }
713 712
714 std::string MediaRouterUI::GetPresentationRequestSourceName() const { 713 std::string MediaRouterUI::GetPresentationRequestSourceName() const {
715 GURL gurl = GetFrameURL(); 714 GURL gurl = GetFrameURL();
716 return gurl.SchemeIs(extensions::kExtensionScheme) 715 return gurl.SchemeIs(extensions::kExtensionScheme)
717 ? GetExtensionName(gurl, extensions::ExtensionRegistry::Get( 716 ? GetExtensionName(gurl, extensions::ExtensionRegistry::Get(
718 Profile::FromWebUI(web_ui()))) 717 Profile::FromWebUI(web_ui())))
719 : GetHostFromURL(gurl); 718 : GetHostFromURL(gurl);
720 } 719 }
721 720
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 } 761 }
763 762
764 std::string MediaRouterUI::GetSerializedInitiatorOrigin() const { 763 std::string MediaRouterUI::GetSerializedInitiatorOrigin() const {
765 url::Origin origin = initiator_ 764 url::Origin origin = initiator_
766 ? url::Origin(initiator_->GetLastCommittedURL()) 765 ? url::Origin(initiator_->GetLastCommittedURL())
767 : url::Origin(); 766 : url::Origin();
768 return origin.Serialize(); 767 return origin.Serialize();
769 } 768 }
770 769
771 } // namespace media_router 770 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698