| 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" |
| 11 #include "chrome/browser/ui/webui/media_router/media_router_ui.h" | 11 #include "chrome/browser/ui/webui/media_router/media_router_ui.h" |
| 12 | 12 |
| 13 namespace media_router { | 13 namespace media_router { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 const char kHelpPageUrlPrefix[] = | 17 const char kHelpPageUrlPrefix[] = |
| 18 "https://support.google.com/chromecast/answer/%d"; | 18 "https://support.google.com/chromecast/answer/%d"; |
| 19 | 19 |
| 20 // Message names. | 20 // Message names. |
| 21 const char kRequestInitialData[] = "requestInitialData"; | 21 const char kRequestInitialData[] = "requestInitialData"; |
| 22 const char kCreateRoute[] = "requestRoute"; | 22 const char kCreateRoute[] = "requestRoute"; |
| 23 const char kActOnIssue[] = "actOnIssue"; | 23 const char kActOnIssue[] = "actOnIssue"; |
| 24 const char kCloseRoute[] = "closeRoute"; | 24 const char kCloseRoute[] = "closeRoute"; |
| 25 const char kCloseDialog[] = "closeDialog"; | 25 const char kCloseDialog[] = "closeDialog"; |
| 26 | 26 |
| 27 // JS function names. | 27 // JS function names. |
| 28 const char kSetInitialData[] = "media_router.ui.setInitialData"; | 28 const char kSetInitialData[] = "media_router.ui.setInitialData"; |
| 29 const char kAddRoute[] = "media_router.ui.addRoute"; | 29 const char kOnCreateRouteResponseReceived[] = |
| 30 "media_router.ui.onCreateRouteResponseReceived"; |
| 30 const char kSetIssue[] = "media_router.ui.setIssue"; | 31 const char kSetIssue[] = "media_router.ui.setIssue"; |
| 31 const char kSetSinkList[] = "media_router.ui.setSinkList"; | 32 const char kSetSinkList[] = "media_router.ui.setSinkList"; |
| 32 const char kSetRouteList[] = "media_router.ui.setRouteList"; | 33 const char kSetRouteList[] = "media_router.ui.setRouteList"; |
| 33 const char kSetCastModeList[] = "media_router.ui.setCastModeList"; | 34 const char kSetCastModeList[] = "media_router.ui.setCastModeList"; |
| 34 const char kWindowOpen[] = "window.open"; | 35 const char kWindowOpen[] = "window.open"; |
| 35 | 36 |
| 36 scoped_ptr<base::ListValue> SinksToValue( | 37 scoped_ptr<base::ListValue> SinksToValue( |
| 37 const std::vector<MediaSinkWithCastModes>& sinks) { | 38 const std::vector<MediaSinkWithCastModes>& sinks) { |
| 38 scoped_ptr<base::ListValue> value(new base::ListValue); | 39 scoped_ptr<base::ListValue> value(new base::ListValue); |
| 39 | 40 |
| 40 for (const MediaSinkWithCastModes& sink_with_cast_modes : sinks) { | 41 for (const MediaSinkWithCastModes& sink_with_cast_modes : sinks) { |
| 41 scoped_ptr<base::DictionaryValue> sink_val(new base::DictionaryValue); | 42 scoped_ptr<base::DictionaryValue> sink_val(new base::DictionaryValue); |
| 42 | 43 |
| 43 const MediaSink& sink = sink_with_cast_modes.sink; | 44 const MediaSink& sink = sink_with_cast_modes.sink; |
| 44 sink_val->SetString("id", sink.id()); | 45 sink_val->SetString("id", sink.id()); |
| 45 sink_val->SetString("name", sink.name()); | 46 sink_val->SetString("name", sink.name()); |
| 47 sink_val->SetBoolean("isLaunching", sink.is_launching()); |
| 46 | 48 |
| 47 scoped_ptr<base::ListValue> cast_modes_val(new base::ListValue); | 49 scoped_ptr<base::ListValue> cast_modes_val(new base::ListValue); |
| 48 for (MediaCastMode cast_mode : sink_with_cast_modes.cast_modes) | 50 for (MediaCastMode cast_mode : sink_with_cast_modes.cast_modes) |
| 49 cast_modes_val->AppendInteger(cast_mode); | 51 cast_modes_val->AppendInteger(cast_mode); |
| 50 sink_val->Set("castModes", cast_modes_val.Pass()); | 52 sink_val->Set("castModes", cast_modes_val.Pass()); |
| 51 | 53 |
| 52 value->Append(sink_val.release()); | 54 value->Append(sink_val.release()); |
| 53 } | 55 } |
| 54 | 56 |
| 55 return value.Pass(); | 57 return value.Pass(); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 | 166 |
| 165 void MediaRouterWebUIMessageHandler::UpdateCastModes( | 167 void MediaRouterWebUIMessageHandler::UpdateCastModes( |
| 166 const CastModeSet& cast_modes, | 168 const CastModeSet& cast_modes, |
| 167 const std::string& source_host) { | 169 const std::string& source_host) { |
| 168 DVLOG(2) << "UpdateCastModes"; | 170 DVLOG(2) << "UpdateCastModes"; |
| 169 scoped_ptr<base::ListValue> cast_modes_val( | 171 scoped_ptr<base::ListValue> cast_modes_val( |
| 170 CastModesToValue(cast_modes, source_host)); | 172 CastModesToValue(cast_modes, source_host)); |
| 171 web_ui()->CallJavascriptFunction(kSetCastModeList, *cast_modes_val); | 173 web_ui()->CallJavascriptFunction(kSetCastModeList, *cast_modes_val); |
| 172 } | 174 } |
| 173 | 175 |
| 174 void MediaRouterWebUIMessageHandler::AddRoute(const MediaRoute& route) { | 176 void MediaRouterWebUIMessageHandler::OnCreateRouteResponseReceived( |
| 175 DVLOG(2) << "AddRoute"; | 177 const MediaSink::Id& sink_id, |
| 176 scoped_ptr<base::DictionaryValue> route_value(RouteToValue(route)); | 178 const MediaRoute* route) { |
| 177 web_ui()->CallJavascriptFunction(kAddRoute, *route_value); | 179 DVLOG(2) << "OnCreateRouteResponseReceived"; |
| 180 if (route) { |
| 181 scoped_ptr<base::DictionaryValue> route_value(RouteToValue(*route)); |
| 182 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, |
| 183 base::StringValue(sink_id), *route_value); |
| 184 } else { |
| 185 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, |
| 186 base::StringValue(sink_id), |
| 187 *base::Value::CreateNullValue()); |
| 188 } |
| 178 } | 189 } |
| 179 | 190 |
| 180 void MediaRouterWebUIMessageHandler::UpdateIssue(const Issue* issue) { | 191 void MediaRouterWebUIMessageHandler::UpdateIssue(const Issue* issue) { |
| 181 DVLOG(2) << "UpdateIssue"; | 192 DVLOG(2) << "UpdateIssue"; |
| 182 if (issue) { | 193 if (issue) { |
| 183 scoped_ptr<base::DictionaryValue> issue_val(IssueToValue(*issue)); | 194 scoped_ptr<base::DictionaryValue> issue_val(IssueToValue(*issue)); |
| 184 web_ui()->CallJavascriptFunction(kSetIssue, *issue_val); | 195 web_ui()->CallJavascriptFunction(kSetIssue, *issue_val); |
| 185 } else { | 196 } else { |
| 186 // Clears the issue in the WebUI. | 197 // Clears the issue in the WebUI. |
| 187 web_ui()->CallJavascriptFunction(kSetIssue); | 198 web_ui()->CallJavascriptFunction(kSetIssue); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 } | 360 } |
| 350 | 361 |
| 351 MediaRouterUI* MediaRouterWebUIMessageHandler::GetMediaRouterUI() { | 362 MediaRouterUI* MediaRouterWebUIMessageHandler::GetMediaRouterUI() { |
| 352 MediaRouterUI* media_router_ui = | 363 MediaRouterUI* media_router_ui = |
| 353 static_cast<MediaRouterUI*>(web_ui()->GetController()); | 364 static_cast<MediaRouterUI*>(web_ui()->GetController()); |
| 354 DCHECK(media_router_ui); | 365 DCHECK(media_router_ui); |
| 355 return media_router_ui; | 366 return media_router_ui; |
| 356 } | 367 } |
| 357 | 368 |
| 358 } // namespace media_router | 369 } // namespace media_router |
| OLD | NEW |