| 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) { |
| 43 scoped_ptr<base::ListValue> value(new base::ListValue); | 45 scoped_ptr<base::ListValue> value(new base::ListValue); |
| 44 | 46 |
| 45 for (const MediaSinkWithCastModes& sink_with_cast_modes : sinks) { | 47 for (const MediaSinkWithCastModes& sink_with_cast_modes : sinks) { |
| 46 scoped_ptr<base::DictionaryValue> sink_val(new base::DictionaryValue); | 48 scoped_ptr<base::DictionaryValue> sink_val(new base::DictionaryValue); |
| 47 | 49 |
| 48 const MediaSink& sink = sink_with_cast_modes.sink; | 50 const MediaSink& sink = sink_with_cast_modes.sink; |
| 49 sink_val->SetString("id", sink.id()); | 51 sink_val->SetString("id", sink.id()); |
| 50 sink_val->SetString("name", sink.name()); | 52 sink_val->SetString("name", sink.name()); |
| 51 sink_val->SetInteger("iconType", sink.icon_type()); | 53 sink_val->SetInteger("iconType", sink.icon_type()); |
| 52 sink_val->SetBoolean("isLaunching", sink.is_launching()); | |
| 53 | 54 |
| 54 scoped_ptr<base::ListValue> cast_modes_val(new base::ListValue); | 55 scoped_ptr<base::ListValue> cast_modes_val(new base::ListValue); |
| 55 for (MediaCastMode cast_mode : sink_with_cast_modes.cast_modes) | 56 for (MediaCastMode cast_mode : sink_with_cast_modes.cast_modes) |
| 56 cast_modes_val->AppendInteger(cast_mode); | 57 cast_modes_val->AppendInteger(cast_mode); |
| 57 sink_val->Set("castModes", cast_modes_val.Pass()); | 58 sink_val->Set("castModes", cast_modes_val.Pass()); |
| 58 | 59 |
| 59 value->Append(sink_val.release()); | 60 value->Append(sink_val.release()); |
| 60 } | 61 } |
| 61 | 62 |
| 62 return value.Pass(); | 63 return value.Pass(); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 DVLOG(2) << "UpdateIssue"; | 213 DVLOG(2) << "UpdateIssue"; |
| 213 if (issue) { | 214 if (issue) { |
| 214 scoped_ptr<base::DictionaryValue> issue_val(IssueToValue(*issue)); | 215 scoped_ptr<base::DictionaryValue> issue_val(IssueToValue(*issue)); |
| 215 web_ui()->CallJavascriptFunction(kSetIssue, *issue_val); | 216 web_ui()->CallJavascriptFunction(kSetIssue, *issue_val); |
| 216 } else { | 217 } else { |
| 217 // Clears the issue in the WebUI. | 218 // Clears the issue in the WebUI. |
| 218 web_ui()->CallJavascriptFunction(kSetIssue); | 219 web_ui()->CallJavascriptFunction(kSetIssue); |
| 219 } | 220 } |
| 220 } | 221 } |
| 221 | 222 |
| 223 void MediaRouterWebUIMessageHandler::NotifyRouteCreationTimeout() { |
| 224 DVLOG(2) << "NotifyRouteCreationTimeout"; |
| 225 web_ui()->CallJavascriptFunction(kNotifyRouteCreationTimeout); |
| 226 } |
| 227 |
| 222 void MediaRouterWebUIMessageHandler::RegisterMessages() { | 228 void MediaRouterWebUIMessageHandler::RegisterMessages() { |
| 223 web_ui()->RegisterMessageCallback( | 229 web_ui()->RegisterMessageCallback( |
| 224 kRequestInitialData, | 230 kRequestInitialData, |
| 225 base::Bind(&MediaRouterWebUIMessageHandler::OnRequestInitialData, | 231 base::Bind(&MediaRouterWebUIMessageHandler::OnRequestInitialData, |
| 226 base::Unretained(this))); | 232 base::Unretained(this))); |
| 227 web_ui()->RegisterMessageCallback( | 233 web_ui()->RegisterMessageCallback( |
| 228 kCreateRoute, | 234 kCreateRoute, |
| 229 base::Bind(&MediaRouterWebUIMessageHandler::OnCreateRoute, | 235 base::Bind(&MediaRouterWebUIMessageHandler::OnCreateRoute, |
| 230 base::Unretained(this))); | 236 base::Unretained(this))); |
| 231 web_ui()->RegisterMessageCallback( | 237 web_ui()->RegisterMessageCallback( |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 } | 292 } |
| 287 | 293 |
| 288 if (sink_id.empty()) { | 294 if (sink_id.empty()) { |
| 289 DVLOG(1) << "Media Route UI did not respond with a " | 295 DVLOG(1) << "Media Route UI did not respond with a " |
| 290 << "valid sink ID. Aborting."; | 296 << "valid sink ID. Aborting."; |
| 291 return; | 297 return; |
| 292 } | 298 } |
| 293 | 299 |
| 294 MediaRouterUI* media_router_ui = | 300 MediaRouterUI* media_router_ui = |
| 295 static_cast<MediaRouterUI*>(web_ui()->GetController()); | 301 static_cast<MediaRouterUI*>(web_ui()->GetController()); |
| 296 if (media_router_ui->has_pending_route_request()) { | 302 if (media_router_ui->HasPendingRouteRequest()) { |
| 297 DVLOG(1) << "UI already has pending route request. Ignoring."; | 303 DVLOG(1) << "UI already has pending route request. Ignoring."; |
| 298 Issue issue( | 304 Issue issue( |
| 299 l10n_util::GetStringUTF8(IDS_MEDIA_ROUTER_ISSUE_PENDING_ROUTE), | 305 l10n_util::GetStringUTF8(IDS_MEDIA_ROUTER_ISSUE_PENDING_ROUTE), |
| 300 std::string(), IssueAction(IssueAction::TYPE_DISMISS), | 306 std::string(), IssueAction(IssueAction::TYPE_DISMISS), |
| 301 std::vector<IssueAction>(), std::string(), Issue::NOTIFICATION, | 307 std::vector<IssueAction>(), std::string(), Issue::NOTIFICATION, |
| 302 false, std::string()); | 308 false, std::string()); |
| 303 media_router_ui_->AddIssue(issue); | 309 media_router_ui_->AddIssue(issue); |
| 304 return; | 310 return; |
| 305 } | 311 } |
| 306 | 312 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 open_args->AppendString(learn_more_url); | 387 open_args->AppendString(learn_more_url); |
| 382 web_ui()->CallJavascriptFunction(kWindowOpen, *open_args); | 388 web_ui()->CallJavascriptFunction(kWindowOpen, *open_args); |
| 383 return true; | 389 return true; |
| 384 } else { | 390 } else { |
| 385 // Do nothing; no other issue action types require any other action. | 391 // Do nothing; no other issue action types require any other action. |
| 386 return true; | 392 return true; |
| 387 } | 393 } |
| 388 } | 394 } |
| 389 | 395 |
| 390 } // namespace media_router | 396 } // namespace media_router |
| OLD | NEW |