| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "chrome/browser/media/router/create_presentation_session_request.h" | 10 #include "chrome/browser/media/router/create_presentation_session_request.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 #include "content/public/browser/web_ui_data_source.h" | 31 #include "content/public/browser/web_ui_data_source.h" |
| 32 #include "ui/web_dialogs/web_dialog_delegate.h" | 32 #include "ui/web_dialogs/web_dialog_delegate.h" |
| 33 | 33 |
| 34 namespace media_router { | 34 namespace media_router { |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 void HandleRouteResponseForPresentationApi( | 38 void HandleRouteResponseForPresentationApi( |
| 39 scoped_ptr<CreatePresentationSessionRequest> presentation_request, | 39 scoped_ptr<CreatePresentationSessionRequest> presentation_request, |
| 40 const MediaRoute* route, | 40 const MediaRoute* route, |
| 41 const std::string& presentation_id, |
| 41 const std::string& error) { | 42 const std::string& error) { |
| 42 DCHECK(presentation_request); | 43 DCHECK(presentation_request); |
| 43 if (!route) { | 44 if (!route) { |
| 44 presentation_request->MaybeInvokeErrorCallback( | 45 presentation_request->MaybeInvokeErrorCallback( |
| 45 content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, error)); | 46 content::PresentationError(content::PRESENTATION_ERROR_UNKNOWN, error)); |
| 46 } else { | 47 } else { |
| 48 // Presentation ID should not have changed. |
| 49 DCHECK_EQ(presentation_request->presentation_info().presentation_id, |
| 50 presentation_id); |
| 47 presentation_request->MaybeInvokeSuccessCallback(route->media_route_id()); | 51 presentation_request->MaybeInvokeSuccessCallback(route->media_route_id()); |
| 48 } | 52 } |
| 49 } | 53 } |
| 50 | 54 |
| 51 std::string GetHostFromURL(const GURL& gurl) { | 55 std::string GetHostFromURL(const GURL& gurl) { |
| 52 if (gurl.is_empty()) | 56 if (gurl.is_empty()) |
| 53 return std::string(); | 57 return std::string(); |
| 54 std::string host = gurl.host(); | 58 std::string host = gurl.host(); |
| 55 if (base::StartsWith(host, "www.", base::CompareCase::INSENSITIVE_ASCII)) | 59 if (base::StartsWith(host, "www.", base::CompareCase::INSENSITIVE_ASCII)) |
| 56 host = host.substr(4); | 60 host = host.substr(4); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 handler_->UpdateIssue(issue); | 279 handler_->UpdateIssue(issue); |
| 276 } | 280 } |
| 277 | 281 |
| 278 void MediaRouterUI::OnRoutesUpdated(const std::vector<MediaRoute>& routes) { | 282 void MediaRouterUI::OnRoutesUpdated(const std::vector<MediaRoute>& routes) { |
| 279 routes_ = routes; | 283 routes_ = routes; |
| 280 if (ui_initialized_) | 284 if (ui_initialized_) |
| 281 handler_->UpdateRoutes(routes_); | 285 handler_->UpdateRoutes(routes_); |
| 282 } | 286 } |
| 283 | 287 |
| 284 void MediaRouterUI::OnRouteResponseReceived(const MediaRoute* route, | 288 void MediaRouterUI::OnRouteResponseReceived(const MediaRoute* route, |
| 289 const std::string& presentation_id, |
| 285 const std::string& error) { | 290 const std::string& error) { |
| 286 DVLOG(1) << "OnRouteResponseReceived"; | 291 DVLOG(1) << "OnRouteResponseReceived"; |
| 287 // TODO(imcheng): Display error in UI. (crbug.com/490372) | 292 // TODO(imcheng): Display error in UI. (crbug.com/490372) |
| 288 if (!route) | 293 if (!route) |
| 289 LOG(ERROR) << "MediaRouteResponse returned error: " << error; | 294 LOG(ERROR) << "MediaRouteResponse returned error: " << error; |
| 290 else | 295 else |
| 291 handler_->AddRoute(*route); | 296 handler_->AddRoute(*route); |
| 292 | 297 |
| 293 has_pending_route_request_ = false; | 298 has_pending_route_request_ = false; |
| 294 requesting_route_for_default_source_ = false; | 299 requesting_route_for_default_source_ = false; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 | 364 |
| 360 std::string MediaRouterUI::GetFrameURLHost() const { | 365 std::string MediaRouterUI::GetFrameURLHost() const { |
| 361 return GetHostFromURL(frame_url_); | 366 return GetHostFromURL(frame_url_); |
| 362 } | 367 } |
| 363 | 368 |
| 364 const std::string& MediaRouterUI::GetRouteProviderExtensionId() const { | 369 const std::string& MediaRouterUI::GetRouteProviderExtensionId() const { |
| 365 return router_->media_route_provider_extension_id(); | 370 return router_->media_route_provider_extension_id(); |
| 366 } | 371 } |
| 367 | 372 |
| 368 } // namespace media_router | 373 } // namespace media_router |
| OLD | NEW |