| 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 <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // Use a placeholder URL as origin for mirroring. |
| 268 GURL origin(chrome::kChromeUIMediaRouterURL); |
| 269 |
| 267 // Desktop mirror mode is always available. | 270 // Desktop mirror mode is always available. |
| 268 query_result_manager_->StartSinksQuery(MediaCastMode::DESKTOP_MIRROR, | 271 query_result_manager_->StartSinksQuery(MediaCastMode::DESKTOP_MIRROR, |
| 269 MediaSourceForDesktop()); | 272 MediaSourceForDesktop(), origin); |
| 270 initiator_ = initiator; | 273 initiator_ = initiator; |
| 271 SessionID::id_type tab_id = SessionTabHelper::IdForTab(initiator); | 274 SessionID::id_type tab_id = SessionTabHelper::IdForTab(initiator); |
| 272 if (tab_id != -1) { | 275 if (tab_id != -1) { |
| 273 MediaSource mirroring_source(MediaSourceForTab(tab_id)); | 276 MediaSource mirroring_source(MediaSourceForTab(tab_id)); |
| 274 query_result_manager_->StartSinksQuery(MediaCastMode::TAB_MIRROR, | 277 query_result_manager_->StartSinksQuery(MediaCastMode::TAB_MIRROR, |
| 275 mirroring_source); | 278 mirroring_source, origin); |
| 276 } | 279 } |
| 277 UpdateCastModes(); | 280 UpdateCastModes(); |
| 278 } | 281 } |
| 279 | 282 |
| 280 void MediaRouterUI::InitForTest(MediaRouter* router, | 283 void MediaRouterUI::InitForTest(MediaRouter* router, |
| 281 content::WebContents* initiator, | 284 content::WebContents* initiator, |
| 282 MediaRouterWebUIMessageHandler* handler) { | 285 MediaRouterWebUIMessageHandler* handler) { |
| 283 router_ = router; | 286 router_ = router; |
| 284 handler_ = handler; | 287 handler_ = handler; |
| 285 InitCommon(initiator); | 288 InitCommon(initiator); |
| 286 } | 289 } |
| 287 | 290 |
| 288 void MediaRouterUI::OnDefaultPresentationChanged( | 291 void MediaRouterUI::OnDefaultPresentationChanged( |
| 289 const PresentationRequest& presentation_request) { | 292 const PresentationRequest& presentation_request) { |
| 290 MediaSource source = presentation_request.GetMediaSource(); | 293 MediaSource source = presentation_request.GetMediaSource(); |
| 291 presentation_request_.reset(new PresentationRequest(presentation_request)); | 294 presentation_request_.reset(new PresentationRequest(presentation_request)); |
| 292 query_result_manager_->StartSinksQuery(MediaCastMode::DEFAULT, source); | 295 query_result_manager_->StartSinksQuery( |
| 296 MediaCastMode::DEFAULT, source, |
| 297 presentation_request_->frame_url().GetOrigin()); |
| 293 // Register for MediaRoute updates. | 298 // Register for MediaRoute updates. |
| 294 routes_observer_.reset(new UIMediaRoutesObserver( | 299 routes_observer_.reset(new UIMediaRoutesObserver( |
| 295 router_, source.id(), | 300 router_, source.id(), |
| 296 base::Bind(&MediaRouterUI::OnRoutesUpdated, base::Unretained(this)))); | 301 base::Bind(&MediaRouterUI::OnRoutesUpdated, base::Unretained(this)))); |
| 297 | 302 |
| 298 UpdateCastModes(); | 303 UpdateCastModes(); |
| 299 } | 304 } |
| 300 | 305 |
| 301 void MediaRouterUI::OnDefaultPresentationRemoved() { | 306 void MediaRouterUI::OnDefaultPresentationRemoved() { |
| 302 presentation_request_.reset(); | 307 presentation_request_.reset(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 } | 364 } |
| 360 | 365 |
| 361 bool for_default_source = cast_mode == MediaCastMode::DEFAULT; | 366 bool for_default_source = cast_mode == MediaCastMode::DEFAULT; |
| 362 if (for_default_source && !presentation_request_) { | 367 if (for_default_source && !presentation_request_) { |
| 363 DLOG(ERROR) << "Requested to create a route for presentation, but " | 368 DLOG(ERROR) << "Requested to create a route for presentation, but " |
| 364 << "presentation request is missing."; | 369 << "presentation request is missing."; |
| 365 return false; | 370 return false; |
| 366 } | 371 } |
| 367 | 372 |
| 368 current_route_request_id_ = ++route_request_counter_; | 373 current_route_request_id_ = ++route_request_counter_; |
| 369 GURL origin; | 374 GURL origin = for_default_source |
| 370 if (for_default_source) { | 375 ? presentation_request_->frame_url().GetOrigin() |
| 371 origin = presentation_request_->frame_url().GetOrigin(); | 376 : GURL(chrome::kChromeUIMediaRouterURL); |
| 372 } else { | |
| 373 // Requesting route for mirroring. Use a placeholder URL as origin. | |
| 374 origin = GURL(chrome::kChromeUIMediaRouterURL); | |
| 375 } | |
| 376 DCHECK(origin.is_valid()); | 377 DCHECK(origin.is_valid()); |
| 377 | 378 |
| 378 DVLOG(1) << "DoCreateRoute: origin: " << origin; | 379 DVLOG(1) << "DoCreateRoute: origin: " << origin; |
| 379 | 380 |
| 380 // There are 3 cases. In all cases the MediaRouterUI will need to be notified. | 381 // 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 | 382 // (1) Non-presentation route request (e.g., mirroring). No additional |
| 382 // notification necessary. | 383 // notification necessary. |
| 383 // (2) Presentation route request for a Presentation API startSession call. | 384 // (2) Presentation route request for a Presentation API startSession call. |
| 384 // The startSession (CreatePresentationConnectionRequest) will need to be | 385 // The startSession (CreatePresentationConnectionRequest) will need to be |
| 385 // answered with the | 386 // answered with the |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 base::Time::Now() - start_time_); | 575 base::Time::Now() - start_time_); |
| 575 start_time_ = base::Time(); | 576 start_time_ = base::Time(); |
| 576 } | 577 } |
| 577 } | 578 } |
| 578 | 579 |
| 579 void MediaRouterUI::UpdateMaxDialogHeight(int height) { | 580 void MediaRouterUI::UpdateMaxDialogHeight(int height) { |
| 580 handler_->UpdateMaxDialogHeight(height); | 581 handler_->UpdateMaxDialogHeight(height); |
| 581 } | 582 } |
| 582 | 583 |
| 583 } // namespace media_router | 584 } // namespace media_router |
| OLD | NEW |