Chromium Code Reviews| Index: chrome/browser/ui/webui/media_router/media_router_ui.cc |
| diff --git a/chrome/browser/ui/webui/media_router/media_router_ui.cc b/chrome/browser/ui/webui/media_router/media_router_ui.cc |
| index 30b76029fc9654d52c1987a02cea80fc4e7c5bc4..e5d830654ace38493da44e0921131226d7602f01 100644 |
| --- a/chrome/browser/ui/webui/media_router/media_router_ui.cc |
| +++ b/chrome/browser/ui/webui/media_router/media_router_ui.cc |
| @@ -57,8 +57,7 @@ std::string GetTruncatedHostFromURL(const GURL& gurl) { |
| const std::string truncated = |
| net::registry_controlled_domains::GetDomainAndRegistry( |
| - host, |
| - net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); |
| + host, net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); |
| // The truncation will be empty in some scenarios (e.g. host is |
| // simply an IP address). Fail gracefully. |
| if (truncated.empty()) |
| @@ -107,8 +106,8 @@ void MediaRouterUI::UIMediaRoutesObserver::OnRoutesUpdated( |
| for (const MediaRoute& existing_route : routes_for_display) { |
| if (existing_route.media_sink_id() == route.media_sink_id()) { |
| DVLOG(2) << "Received another route for display with the same sink" |
| - << " id as an existing route. " |
| - << route.media_route_id() << " has the same sink id as " |
| + << " id as an existing route. " << route.media_route_id() |
| + << " has the same sink id as " |
| << existing_route.media_sink_id() << "."; |
| } |
| } |
| @@ -216,13 +215,13 @@ void MediaRouterUI::InitCommon(content::WebContents* initiator, |
| query_result_manager_->AddObserver(this); |
| // These modes are always available. |
| - query_result_manager_->StartSinksQuery( |
| - MediaCastMode::DESKTOP_MIRROR, MediaSourceForDesktop()); |
| + query_result_manager_->StartSinksQuery(MediaCastMode::DESKTOP_MIRROR, |
| + MediaSourceForDesktop()); |
| initiator_ = initiator; |
| MediaSource mirroring_source( |
| MediaSourceForTab(SessionTabHelper::IdForTab(initiator))); |
| - query_result_manager_->StartSinksQuery( |
| - MediaCastMode::TAB_MIRROR, mirroring_source); |
| + query_result_manager_->StartSinksQuery(MediaCastMode::TAB_MIRROR, |
| + mirroring_source); |
| OnDefaultMediaSourceChanged(default_source, default_frame_url); |
| } |
| @@ -305,10 +304,9 @@ bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id, |
| // treat subsequent route requests from a Presentation API-initiated dialogs |
| // as browser-initiated. |
| std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| - route_response_callbacks.push_back( |
| - base::Bind(&MediaRouterUI::OnRouteResponseReceived, |
| - weak_factory_.GetWeakPtr(), current_route_request_id_, |
| - sink_id)); |
| + route_response_callbacks.push_back(base::Bind( |
| + &MediaRouterUI::OnRouteResponseReceived, weak_factory_.GetWeakPtr(), |
| + current_route_request_id_, sink_id)); |
| if (requesting_route_for_default_source_) { |
| if (presentation_request_) { |
| // |presentation_request_| will be nullptr after this call, as the |
| @@ -325,8 +323,8 @@ bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id, |
| // Start the timer. |
| route_creation_timer_.Start( |
| - FROM_HERE, base::TimeDelta::FromSeconds(kCreateRouteTimeoutSeconds), |
| - this, &MediaRouterUI::RouteCreationTimeout); |
| + FROM_HERE, base::TimeDelta::FromSeconds(kCreateRouteTimeoutSeconds), this, |
| + &MediaRouterUI::RouteCreationTimeout); |
| router_->CreateRoute(source.id(), sink_id, origin, |
| SessionTabHelper::IdForTab(initiator_), |
| @@ -334,6 +332,71 @@ bool MediaRouterUI::CreateRoute(const MediaSink::Id& sink_id, |
| return true; |
| } |
| +bool MediaRouterUI::CanJoinRoute(const MediaRoute::Id& route_id) { |
| + DCHECK(query_result_manager_.get()); |
| + DCHECK(initiator_); |
| + |
| + DVLOG(0) << "MediaRouterUI::CanJoinRoute"; |
| + return true; |
| +} |
| + |
| +bool MediaRouterUI::JoinRoute(const MediaSink::Id& sink_id, |
| + const MediaRoute::Id& route_id) { |
| + DCHECK(query_result_manager_.get()); |
| + DCHECK(initiator_); |
| + |
| + current_route_request_id_ = ++route_request_counter_; |
| + GURL origin = frame_url_.GetOrigin(); |
| + |
| + MediaSource source = |
| + query_result_manager_->GetSourceForCastMode(MediaCastMode::DEFAULT); |
| + |
| + if (source.Empty()) { |
| + LOG(ERROR) << "No MediaSource to join"; |
| + return false; |
| + } |
| + |
| + DCHECK(origin.is_valid()); |
| + |
| + // There are 3 cases. In all cases the MediaRouterUI will need to be notified. |
| + // (1) Non-presentation route request (e.g., mirroring). No additional |
| + // notification necessary. |
| + // (2) Presentation route request for a Presentation API startSession call. |
| + // The startSession (CreatePresentationSessionRequest) will need to be |
| + // answered with the |
| + // route response. |
| + // (3) Browser-initiated presentation route request. If successful, |
| + // PresentationServiceDelegateImpl will have to be notified. Note that we |
| + // treat subsequent route requests from a Presentation API-initiated dialogs |
| + // as browser-initiated. |
| + std::vector<MediaRouteResponseCallback> route_response_callbacks; |
| + route_response_callbacks.push_back(base::Bind( |
| + &MediaRouterUI::OnRouteResponseReceived, weak_factory_.GetWeakPtr(), |
| + current_route_request_id_, sink_id)); |
| + if (presentation_request_) { |
| + // |presentation_request_| will be nullptr after this call, as the |
| + // object will be transferred to the callback. |
| + route_response_callbacks.push_back( |
|
imcheng
2015/11/03 19:28:03
We shouldn't need this callback. It's only for res
matt.boetger
2015/11/03 20:51:39
Yeah, this was obviously copy/pasted from CreateRo
|
| + base::Bind(&CreatePresentationSessionRequest::HandleRouteResponse, |
| + base::Passed(&presentation_request_))); |
| + } else if (presentation_service_delegate_) { |
| + route_response_callbacks.push_back( |
| + base::Bind(&PresentationServiceDelegateImpl::OnRouteResponse, |
| + presentation_service_delegate_)); |
| + } |
| + |
| + // Start the timer. |
| + route_creation_timer_.Start( |
| + FROM_HERE, base::TimeDelta::FromSeconds(kCreateRouteTimeoutSeconds), this, |
| + &MediaRouterUI::RouteCreationTimeout); |
| + std::string presentation_id("non-local-join_"); |
| + presentation_id += route_id; |
| + router_->JoinRoute(source.id(), presentation_id, origin, |
| + SessionTabHelper::IdForTab(initiator_), |
| + route_response_callbacks); |
| + return true; |
| +} |
| + |
| void MediaRouterUI::CloseRoute(const MediaRoute::Id& route_id) { |
| router_->CloseRoute(route_id); |
| } |
| @@ -370,6 +433,7 @@ void MediaRouterUI::OnRouteResponseReceived(const int route_request_id, |
| const std::string& presentation_id, |
| const std::string& error) { |
| DVLOG(1) << "OnRouteResponseReceived"; |
| + |
| // If we receive a new route that we aren't expecting, do nothing. |
| if (route_request_id != current_route_request_id_) |
| return; |
| @@ -393,16 +457,16 @@ void MediaRouterUI::RouteCreationTimeout() { |
| // TODO(apacible): Update error messages based on current cast mode |
| // (e.g. desktop). |
| - std::string issue_title = host.empty() ? |
| - l10n_util::GetStringUTF8( |
| - IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB) : |
| - l10n_util::GetStringFUTF8(IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT, |
| - host); |
| + std::string issue_title = |
| + host.empty() ? l10n_util::GetStringUTF8( |
| + IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT_FOR_TAB) |
| + : l10n_util::GetStringFUTF8( |
| + IDS_MEDIA_ROUTER_ISSUE_CREATE_ROUTE_TIMEOUT, host); |
| Issue issue(issue_title, std::string(), |
| - IssueAction(IssueAction::TYPE_DISMISS), |
| - std::vector<IssueAction>(), std::string(), Issue::NOTIFICATION, |
| - false, std::string()); |
| + IssueAction(IssueAction::TYPE_DISMISS), |
| + std::vector<IssueAction>(), std::string(), Issue::NOTIFICATION, |
| + false, std::string()); |
| AddIssue(issue); |
| handler_->NotifyRouteCreationTimeout(); |
| } |