| 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_webui_message_handle
r.h" | 5 #include "chrome/browser/ui/webui/media_router/media_router_webui_message_handle
r.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 // Message names. | 24 // Message names. |
| 25 const char kRequestInitialData[] = "requestInitialData"; | 25 const char kRequestInitialData[] = "requestInitialData"; |
| 26 const char kCreateRoute[] = "requestRoute"; | 26 const char kCreateRoute[] = "requestRoute"; |
| 27 const char kActOnIssue[] = "actOnIssue"; | 27 const char kActOnIssue[] = "actOnIssue"; |
| 28 const char kCloseRoute[] = "closeRoute"; | 28 const char kCloseRoute[] = "closeRoute"; |
| 29 const char kCloseDialog[] = "closeDialog"; | 29 const char kCloseDialog[] = "closeDialog"; |
| 30 | 30 |
| 31 // JS function names. | 31 // JS function names. |
| 32 const char kSetInitialData[] = "media_router.ui.setInitialData"; | 32 const char kSetInitialData[] = "media_router.ui.setInitialData"; |
| 33 const char kNotifyRouteCreationTimeout[] = |
| 34 "media_router.ui.onNotifyRouteCreationTimeout"; |
| 33 const char kOnCreateRouteResponseReceived[] = | 35 const char kOnCreateRouteResponseReceived[] = |
| 34 "media_router.ui.onCreateRouteResponseReceived"; | 36 "media_router.ui.onCreateRouteResponseReceived"; |
| 35 const char kSetIssue[] = "media_router.ui.setIssue"; | 37 const char kSetIssue[] = "media_router.ui.setIssue"; |
| 36 const char kSetSinkList[] = "media_router.ui.setSinkList"; | 38 const char kSetSinkList[] = "media_router.ui.setSinkList"; |
| 37 const char kSetRouteList[] = "media_router.ui.setRouteList"; | 39 const char kSetRouteList[] = "media_router.ui.setRouteList"; |
| 38 const char kSetCastModeList[] = "media_router.ui.setCastModeList"; | 40 const char kSetCastModeList[] = "media_router.ui.setCastModeList"; |
| 39 const char kWindowOpen[] = "window.open"; | 41 const char kWindowOpen[] = "window.open"; |
| 40 | 42 |
| 41 scoped_ptr<base::ListValue> SinksToValue( | 43 scoped_ptr<base::ListValue> SinksToValue( |
| 42 const std::vector<MediaSinkWithCastModes>& sinks) { | 44 const std::vector<MediaSinkWithCastModes>& sinks) { |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 DVLOG(2) << "UpdateIssue"; | 214 DVLOG(2) << "UpdateIssue"; |
| 213 if (issue) { | 215 if (issue) { |
| 214 scoped_ptr<base::DictionaryValue> issue_val(IssueToValue(*issue)); | 216 scoped_ptr<base::DictionaryValue> issue_val(IssueToValue(*issue)); |
| 215 web_ui()->CallJavascriptFunction(kSetIssue, *issue_val); | 217 web_ui()->CallJavascriptFunction(kSetIssue, *issue_val); |
| 216 } else { | 218 } else { |
| 217 // Clears the issue in the WebUI. | 219 // Clears the issue in the WebUI. |
| 218 web_ui()->CallJavascriptFunction(kSetIssue); | 220 web_ui()->CallJavascriptFunction(kSetIssue); |
| 219 } | 221 } |
| 220 } | 222 } |
| 221 | 223 |
| 224 void MediaRouterWebUIMessageHandler::NotifyRouteCreationTimeout() { |
| 225 DVLOG(2) << "NotifyRouteCreationTimeout"; |
| 226 web_ui()->CallJavascriptFunction(kNotifyRouteCreationTimeout); |
| 227 } |
| 228 |
| 222 void MediaRouterWebUIMessageHandler::RegisterMessages() { | 229 void MediaRouterWebUIMessageHandler::RegisterMessages() { |
| 223 web_ui()->RegisterMessageCallback( | 230 web_ui()->RegisterMessageCallback( |
| 224 kRequestInitialData, | 231 kRequestInitialData, |
| 225 base::Bind(&MediaRouterWebUIMessageHandler::OnRequestInitialData, | 232 base::Bind(&MediaRouterWebUIMessageHandler::OnRequestInitialData, |
| 226 base::Unretained(this))); | 233 base::Unretained(this))); |
| 227 web_ui()->RegisterMessageCallback( | 234 web_ui()->RegisterMessageCallback( |
| 228 kCreateRoute, | 235 kCreateRoute, |
| 229 base::Bind(&MediaRouterWebUIMessageHandler::OnCreateRoute, | 236 base::Bind(&MediaRouterWebUIMessageHandler::OnCreateRoute, |
| 230 base::Unretained(this))); | 237 base::Unretained(this))); |
| 231 web_ui()->RegisterMessageCallback( | 238 web_ui()->RegisterMessageCallback( |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 } | 293 } |
| 287 | 294 |
| 288 if (sink_id.empty()) { | 295 if (sink_id.empty()) { |
| 289 DVLOG(1) << "Media Route UI did not respond with a " | 296 DVLOG(1) << "Media Route UI did not respond with a " |
| 290 << "valid sink ID. Aborting."; | 297 << "valid sink ID. Aborting."; |
| 291 return; | 298 return; |
| 292 } | 299 } |
| 293 | 300 |
| 294 MediaRouterUI* media_router_ui = | 301 MediaRouterUI* media_router_ui = |
| 295 static_cast<MediaRouterUI*>(web_ui()->GetController()); | 302 static_cast<MediaRouterUI*>(web_ui()->GetController()); |
| 296 if (media_router_ui->has_pending_route_request()) { | 303 if (media_router_ui->HasPendingRouteRequest()) { |
| 297 DVLOG(1) << "UI already has pending route request. Ignoring."; | 304 DVLOG(1) << "UI already has pending route request. Ignoring."; |
| 298 Issue issue( | 305 Issue issue( |
| 299 l10n_util::GetStringUTF8(IDS_MEDIA_ROUTER_ISSUE_PENDING_ROUTE), | 306 l10n_util::GetStringUTF8(IDS_MEDIA_ROUTER_ISSUE_PENDING_ROUTE), |
| 300 std::string(), IssueAction(IssueAction::TYPE_DISMISS), | 307 std::string(), IssueAction(IssueAction::TYPE_DISMISS), |
| 301 std::vector<IssueAction>(), std::string(), Issue::NOTIFICATION, | 308 std::vector<IssueAction>(), std::string(), Issue::NOTIFICATION, |
| 302 false, std::string()); | 309 false, std::string()); |
| 303 media_router_ui_->AddIssue(issue); | 310 media_router_ui_->AddIssue(issue); |
| 304 return; | 311 return; |
| 305 } | 312 } |
| 306 | 313 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 open_args->AppendString(learn_more_url); | 388 open_args->AppendString(learn_more_url); |
| 382 web_ui()->CallJavascriptFunction(kWindowOpen, *open_args); | 389 web_ui()->CallJavascriptFunction(kWindowOpen, *open_args); |
| 383 return true; | 390 return true; |
| 384 } else { | 391 } else { |
| 385 // Do nothing; no other issue action types require any other action. | 392 // Do nothing; no other issue action types require any other action. |
| 386 return true; | 393 return true; |
| 387 } | 394 } |
| 388 } | 395 } |
| 389 | 396 |
| 390 } // namespace media_router | 397 } // namespace media_router |
| OLD | NEW |