| 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/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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 AddMediaRouterUIResources(html_source.get()); | 189 AddMediaRouterUIResources(html_source.get()); |
| 190 // Ownership of |html_source| is transferred to the BrowserContext. | 190 // Ownership of |html_source| is transferred to the BrowserContext. |
| 191 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), | 191 content::WebUIDataSource::Add(Profile::FromWebUI(web_ui), |
| 192 html_source.release()); | 192 html_source.release()); |
| 193 | 193 |
| 194 // Ownership of |handler_| is transferred to |web_ui|. | 194 // Ownership of |handler_| is transferred to |web_ui|. |
| 195 web_ui->AddMessageHandler(handler_); | 195 web_ui->AddMessageHandler(handler_); |
| 196 } | 196 } |
| 197 | 197 |
| 198 MediaRouterUI::~MediaRouterUI() { | 198 MediaRouterUI::~MediaRouterUI() { |
| 199 if (issues_observer_) issues_observer_->UnregisterObserver(); | |
| 200 | |
| 201 if (query_result_manager_.get()) query_result_manager_->RemoveObserver(this); | 199 if (query_result_manager_.get()) query_result_manager_->RemoveObserver(this); |
| 202 if (presentation_service_delegate_.get()) | 200 if (presentation_service_delegate_.get()) |
| 203 presentation_service_delegate_->RemoveDefaultPresentationRequestObserver( | 201 presentation_service_delegate_->RemoveDefaultPresentationRequestObserver( |
| 204 this); | 202 this); |
| 205 // If |create_session_request_| still exists, then it means presentation route | 203 // If |create_session_request_| still exists, then it means presentation route |
| 206 // request was never attempted. | 204 // request was never attempted. |
| 207 if (create_session_request_) { | 205 if (create_session_request_) { |
| 208 bool presentation_sinks_available = std::any_of( | 206 bool presentation_sinks_available = std::any_of( |
| 209 sinks_.begin(), sinks_.end(), [](const MediaSinkWithCastModes& sink) { | 207 sinks_.begin(), sinks_.end(), [](const MediaSinkWithCastModes& sink) { |
| 210 return base::ContainsValue(sink.cast_modes, MediaCastMode::DEFAULT); | 208 return base::ContainsValue(sink.cast_modes, MediaCastMode::DEFAULT); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 delegate->GetWebDialogDelegate()->OnDialogClosed(std::string()); | 354 delegate->GetWebDialogDelegate()->OnDialogClosed(std::string()); |
| 357 delegate->OnDialogCloseFromWebUI(); | 355 delegate->OnDialogCloseFromWebUI(); |
| 358 } | 356 } |
| 359 } | 357 } |
| 360 | 358 |
| 361 void MediaRouterUI::UIInitialized() { | 359 void MediaRouterUI::UIInitialized() { |
| 362 TRACE_EVENT_NESTABLE_ASYNC_END0("media_router", "UI", initiator_); | 360 TRACE_EVENT_NESTABLE_ASYNC_END0("media_router", "UI", initiator_); |
| 363 ui_initialized_ = true; | 361 ui_initialized_ = true; |
| 364 | 362 |
| 365 // Register for Issue updates. | 363 // Register for Issue updates. |
| 366 if (!issues_observer_) | 364 issues_observer_.reset(new UIIssuesObserver(router_, this)); |
| 367 issues_observer_.reset(new UIIssuesObserver(router_, this)); | 365 issues_observer_->Init(); |
| 368 issues_observer_->RegisterObserver(); | |
| 369 } | 366 } |
| 370 | 367 |
| 371 bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id, | 368 bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id, |
| 372 MediaCastMode cast_mode) { | 369 MediaCastMode cast_mode) { |
| 373 MediaSource::Id source_id; | 370 MediaSource::Id source_id; |
| 374 GURL origin; | 371 GURL origin; |
| 375 std::vector<MediaRouteResponseCallback> route_response_callbacks; | 372 std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| 376 base::TimeDelta timeout; | 373 base::TimeDelta timeout; |
| 377 bool incognito; | 374 bool incognito; |
| 378 if (!SetRouteParameters(sink_id, cast_mode, &source_id, &origin, | 375 if (!SetRouteParameters(sink_id, cast_mode, &source_id, &origin, |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 } | 476 } |
| 480 router_->ConnectRouteByRouteId(source_id, route_id, origin, initiator_, | 477 router_->ConnectRouteByRouteId(source_id, route_id, origin, initiator_, |
| 481 route_response_callbacks, timeout, incognito); | 478 route_response_callbacks, timeout, incognito); |
| 482 return true; | 479 return true; |
| 483 } | 480 } |
| 484 | 481 |
| 485 void MediaRouterUI::CloseRoute(const MediaRoute::Id& route_id) { | 482 void MediaRouterUI::CloseRoute(const MediaRoute::Id& route_id) { |
| 486 router_->TerminateRoute(route_id); | 483 router_->TerminateRoute(route_id); |
| 487 } | 484 } |
| 488 | 485 |
| 489 void MediaRouterUI::AddIssue(const Issue& issue) { router_->AddIssue(issue); } | 486 void MediaRouterUI::AddIssue(const IssueInfo& issue) { |
| 487 router_->AddIssue(issue); |
| 488 } |
| 490 | 489 |
| 491 void MediaRouterUI::ClearIssue(const std::string& issue_id) { | 490 void MediaRouterUI::ClearIssue(const Issue::Id& issue_id) { |
| 492 router_->ClearIssue(issue_id); | 491 router_->ClearIssue(issue_id); |
| 493 } | 492 } |
| 494 | 493 |
| 495 void MediaRouterUI::SearchSinksAndCreateRoute( | 494 void MediaRouterUI::SearchSinksAndCreateRoute( |
| 496 const MediaSink::Id& sink_id, | 495 const MediaSink::Id& sink_id, |
| 497 const std::string& search_criteria, | 496 const std::string& search_criteria, |
| 498 const std::string& domain, | 497 const std::string& domain, |
| 499 MediaCastMode cast_mode) { | 498 MediaCastMode cast_mode) { |
| 500 std::unique_ptr<MediaSource> source = | 499 std::unique_ptr<MediaSource> source = |
| 501 query_result_manager_->GetSourceForCastModeAndSink(cast_mode, sink_id); | 500 query_result_manager_->GetSourceForCastModeAndSink(cast_mode, sink_id); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB); | 618 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB); |
| 620 break; | 619 break; |
| 621 case DESKTOP_MIRROR: | 620 case DESKTOP_MIRROR: |
| 622 issue_title = l10n_util::GetStringUTF8( | 621 issue_title = l10n_util::GetStringUTF8( |
| 623 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_DESKTOP); | 622 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_DESKTOP); |
| 624 break; | 623 break; |
| 625 default: | 624 default: |
| 626 NOTREACHED(); | 625 NOTREACHED(); |
| 627 } | 626 } |
| 628 | 627 |
| 629 Issue issue(issue_title, std::string(), | 628 AddIssue(IssueInfo(issue_title, IssueInfo::Action::DISMISS, |
| 630 IssueAction(IssueAction::TYPE_DISMISS), | 629 IssueInfo::Severity::NOTIFICATION)); |
| 631 std::vector<IssueAction>(), std::string(), Issue::NOTIFICATION, | |
| 632 false, -1); | |
| 633 AddIssue(issue); | |
| 634 } | 630 } |
| 635 | 631 |
| 636 void MediaRouterUI::SendIssueForUnableToCast(MediaCastMode cast_mode) { | 632 void MediaRouterUI::SendIssueForUnableToCast(MediaCastMode cast_mode) { |
| 637 // For a generic error, claim a tab error unless it was specifically desktop | 633 // For a generic error, claim a tab error unless it was specifically desktop |
| 638 // mirroring. | 634 // mirroring. |
| 639 std::string issue_title = | 635 std::string issue_title = |
| 640 (cast_mode == MediaCastMode::DESKTOP_MIRROR) | 636 (cast_mode == MediaCastMode::DESKTOP_MIRROR) |
| 641 ? l10n_util::GetStringUTF8( | 637 ? l10n_util::GetStringUTF8( |
| 642 IDS_MEDIA_ROUTER_ISSUE_UNABLE_TO_CAST_DESKTOP) | 638 IDS_MEDIA_ROUTER_ISSUE_UNABLE_TO_CAST_DESKTOP) |
| 643 : l10n_util::GetStringUTF8( | 639 : l10n_util::GetStringUTF8( |
| 644 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB); | 640 IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB); |
| 645 AddIssue(Issue(issue_title, std::string(), | 641 AddIssue(IssueInfo(issue_title, IssueInfo::Action::DISMISS, |
| 646 IssueAction(IssueAction::TYPE_DISMISS), | 642 IssueInfo::Severity::WARNING)); |
| 647 std::vector<IssueAction>(), std::string(), Issue::WARNING, | |
| 648 false, -1)); | |
| 649 } | 643 } |
| 650 | 644 |
| 651 GURL MediaRouterUI::GetFrameURL() const { | 645 GURL MediaRouterUI::GetFrameURL() const { |
| 652 return presentation_request_ ? presentation_request_->frame_url() : GURL(); | 646 return presentation_request_ ? presentation_request_->frame_url() : GURL(); |
| 653 } | 647 } |
| 654 | 648 |
| 655 std::string MediaRouterUI::GetPresentationRequestSourceName() const { | 649 std::string MediaRouterUI::GetPresentationRequestSourceName() const { |
| 656 GURL gurl = GetFrameURL(); | 650 GURL gurl = GetFrameURL(); |
| 657 return gurl.SchemeIs(extensions::kExtensionScheme) | 651 return gurl.SchemeIs(extensions::kExtensionScheme) |
| 658 ? GetExtensionName(gurl, extensions::ExtensionRegistry::Get( | 652 ? GetExtensionName(gurl, extensions::ExtensionRegistry::Get( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 base::Time::Now() - start_time_); | 686 base::Time::Now() - start_time_); |
| 693 start_time_ = base::Time(); | 687 start_time_ = base::Time(); |
| 694 } | 688 } |
| 695 } | 689 } |
| 696 | 690 |
| 697 void MediaRouterUI::UpdateMaxDialogHeight(int height) { | 691 void MediaRouterUI::UpdateMaxDialogHeight(int height) { |
| 698 handler_->UpdateMaxDialogHeight(height); | 692 handler_->UpdateMaxDialogHeight(height); |
| 699 } | 693 } |
| 700 | 694 |
| 701 } // namespace media_router | 695 } // namespace media_router |
| OLD | NEW |