Chromium Code Reviews| 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/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 sink_list_and_identity->Set("sinks", sinks_val.release()); | 134 sink_list_and_identity->Set("sinks", sinks_val.release()); |
| 135 sink_list_and_identity->SetBoolean("showEmail", show_email); | 135 sink_list_and_identity->SetBoolean("showEmail", show_email); |
| 136 sink_list_and_identity->SetBoolean("showDomain", show_domain); | 136 sink_list_and_identity->SetBoolean("showDomain", show_domain); |
| 137 return sink_list_and_identity; | 137 return sink_list_and_identity; |
| 138 } | 138 } |
| 139 | 139 |
| 140 std::unique_ptr<base::DictionaryValue> RouteToValue( | 140 std::unique_ptr<base::DictionaryValue> RouteToValue( |
| 141 const MediaRoute& route, | 141 const MediaRoute& route, |
| 142 bool can_join, | 142 bool can_join, |
| 143 const std::string& extension_id, | 143 const std::string& extension_id, |
| 144 bool off_the_record) { | 144 bool off_the_record, |
| 145 int current_cast_mode) { | |
| 145 std::unique_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); | 146 std::unique_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); |
| 146 dictionary->SetString("id", route.media_route_id()); | 147 dictionary->SetString("id", route.media_route_id()); |
| 147 dictionary->SetString("sinkId", route.media_sink_id()); | 148 dictionary->SetString("sinkId", route.media_sink_id()); |
| 148 dictionary->SetString("description", route.description()); | 149 dictionary->SetString("description", route.description()); |
| 149 dictionary->SetBoolean("isLocal", route.is_local()); | 150 dictionary->SetBoolean("isLocal", route.is_local()); |
| 150 dictionary->SetBoolean("canJoin", can_join); | 151 dictionary->SetBoolean("canJoin", can_join); |
| 152 if (current_cast_mode > 0) { | |
| 153 dictionary->SetInteger("currentCastMode", current_cast_mode); | |
| 154 } | |
| 151 | 155 |
| 152 const std::string& custom_path = route.custom_controller_path(); | 156 const std::string& custom_path = route.custom_controller_path(); |
| 153 if (!off_the_record && !custom_path.empty()) { | 157 if (!off_the_record && !custom_path.empty()) { |
| 154 std::string full_custom_controller_path = base::StringPrintf("%s://%s/%s", | 158 std::string full_custom_controller_path = base::StringPrintf("%s://%s/%s", |
| 155 extensions::kExtensionScheme, extension_id.c_str(), | 159 extensions::kExtensionScheme, extension_id.c_str(), |
| 156 custom_path.c_str()); | 160 custom_path.c_str()); |
| 157 DCHECK(GURL(full_custom_controller_path).is_valid()); | 161 DCHECK(GURL(full_custom_controller_path).is_valid()); |
| 158 dictionary->SetString("customControllerPath", | 162 dictionary->SetString("customControllerPath", |
| 159 full_custom_controller_path); | 163 full_custom_controller_path); |
| 160 } | 164 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 const std::vector<MediaSinkWithCastModes>& sinks) { | 244 const std::vector<MediaSinkWithCastModes>& sinks) { |
| 241 DVLOG(2) << "UpdateSinks"; | 245 DVLOG(2) << "UpdateSinks"; |
| 242 std::unique_ptr<base::DictionaryValue> sinks_and_identity_val( | 246 std::unique_ptr<base::DictionaryValue> sinks_and_identity_val( |
| 243 SinksAndIdentityToValue(sinks, GetAccountInfo())); | 247 SinksAndIdentityToValue(sinks, GetAccountInfo())); |
| 244 web_ui()->CallJavascriptFunction(kSetSinkListAndIdentity, | 248 web_ui()->CallJavascriptFunction(kSetSinkListAndIdentity, |
| 245 *sinks_and_identity_val); | 249 *sinks_and_identity_val); |
| 246 } | 250 } |
| 247 | 251 |
| 248 void MediaRouterWebUIMessageHandler::UpdateRoutes( | 252 void MediaRouterWebUIMessageHandler::UpdateRoutes( |
| 249 const std::vector<MediaRoute>& routes, | 253 const std::vector<MediaRoute>& routes, |
| 250 const std::vector<MediaRoute::Id>& joinable_route_ids) { | 254 const std::vector<MediaRoute::Id>& joinable_route_ids, |
| 255 const std::unordered_map<MediaRoute::Id, MediaCastMode>& | |
| 256 current_cast_modes) { | |
| 251 std::unique_ptr<base::ListValue> routes_val( | 257 std::unique_ptr<base::ListValue> routes_val( |
| 252 RoutesToValue(routes, joinable_route_ids)); | 258 RoutesToValue(routes, joinable_route_ids, current_cast_modes)); |
| 253 web_ui()->CallJavascriptFunction(kSetRouteList, *routes_val); | 259 web_ui()->CallJavascriptFunction(kSetRouteList, *routes_val); |
| 254 } | 260 } |
| 255 | 261 |
| 256 void MediaRouterWebUIMessageHandler::UpdateCastModes( | 262 void MediaRouterWebUIMessageHandler::UpdateCastModes( |
| 257 const CastModeSet& cast_modes, | 263 const CastModeSet& cast_modes, |
| 258 const std::string& source_host) { | 264 const std::string& source_host) { |
| 259 DVLOG(2) << "UpdateCastModes"; | 265 DVLOG(2) << "UpdateCastModes"; |
| 260 std::unique_ptr<base::ListValue> cast_modes_val( | 266 std::unique_ptr<base::ListValue> cast_modes_val( |
| 261 CastModesToValue(cast_modes, source_host)); | 267 CastModesToValue(cast_modes, source_host)); |
| 262 web_ui()->CallJavascriptFunction(kSetCastModeList, *cast_modes_val); | 268 web_ui()->CallJavascriptFunction(kSetCastModeList, *cast_modes_val); |
| 263 } | 269 } |
| 264 | 270 |
| 265 void MediaRouterWebUIMessageHandler::OnCreateRouteResponseReceived( | 271 void MediaRouterWebUIMessageHandler::OnCreateRouteResponseReceived( |
| 266 const MediaSink::Id& sink_id, | 272 const MediaSink::Id& sink_id, |
| 267 const MediaRoute* route) { | 273 const MediaRoute* route) { |
| 268 DVLOG(2) << "OnCreateRouteResponseReceived"; | 274 DVLOG(2) << "OnCreateRouteResponseReceived"; |
| 269 if (route) { | 275 if (route) { |
| 276 const auto& current_cast_modes = media_router_ui_->current_cast_modes(); | |
| 277 auto current_cast_mode_entry = | |
| 278 current_cast_modes.find(route->media_route_id()); | |
| 279 int current_cast_mode = current_cast_mode_entry != end(current_cast_modes) | |
|
imcheng
2016/06/06 20:48:19
nit: current_cast_modes.end()
btolsch
2016/06/06 23:46:53
Removed.
| |
| 280 ? current_cast_mode_entry->second | |
| 281 : -1; | |
| 270 std::unique_ptr<base::DictionaryValue> route_value(RouteToValue( | 282 std::unique_ptr<base::DictionaryValue> route_value(RouteToValue( |
| 271 *route, false, media_router_ui_->GetRouteProviderExtensionId(), | 283 *route, false, media_router_ui_->GetRouteProviderExtensionId(), |
| 272 off_the_record_)); | 284 off_the_record_, current_cast_mode)); |
|
imcheng
2016/06/06 20:48:19
Is the current_cast_mode value on the route respon
btolsch
2016/06/06 23:46:53
It's not used on the route response. I'll use -1
| |
| 273 web_ui()->CallJavascriptFunction( | 285 web_ui()->CallJavascriptFunction( |
| 274 kOnCreateRouteResponseReceived, | 286 kOnCreateRouteResponseReceived, |
| 275 base::StringValue(sink_id), *route_value, | 287 base::StringValue(sink_id), *route_value, |
| 276 base::FundamentalValue(route->for_display())); | 288 base::FundamentalValue(route->for_display())); |
| 277 } else { | 289 } else { |
| 278 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, | 290 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, |
| 279 base::StringValue(sink_id), | 291 base::StringValue(sink_id), |
| 280 *base::Value::CreateNullValue(), | 292 *base::Value::CreateNullValue(), |
| 281 base::FundamentalValue(false)); | 293 base::FundamentalValue(false)); |
| 282 } | 294 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 397 | 409 |
| 398 // "No Cast devices found?" Chromecast help center page. | 410 // "No Cast devices found?" Chromecast help center page. |
| 399 initial_data.SetString("deviceMissingUrl", | 411 initial_data.SetString("deviceMissingUrl", |
| 400 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); | 412 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); |
| 401 | 413 |
| 402 std::unique_ptr<base::DictionaryValue> sinks_and_identity( | 414 std::unique_ptr<base::DictionaryValue> sinks_and_identity( |
| 403 SinksAndIdentityToValue(media_router_ui_->sinks(), GetAccountInfo())); | 415 SinksAndIdentityToValue(media_router_ui_->sinks(), GetAccountInfo())); |
| 404 initial_data.Set("sinksAndIdentity", sinks_and_identity.release()); | 416 initial_data.Set("sinksAndIdentity", sinks_and_identity.release()); |
| 405 | 417 |
| 406 std::unique_ptr<base::ListValue> routes(RoutesToValue( | 418 std::unique_ptr<base::ListValue> routes(RoutesToValue( |
| 407 media_router_ui_->routes(), media_router_ui_->joinable_route_ids())); | 419 media_router_ui_->routes(), media_router_ui_->joinable_route_ids(), |
| 420 media_router_ui_->current_cast_modes())); | |
| 408 initial_data.Set("routes", routes.release()); | 421 initial_data.Set("routes", routes.release()); |
| 409 | 422 |
| 410 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes(); | 423 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes(); |
| 411 std::unique_ptr<base::ListValue> cast_modes_list(CastModesToValue( | 424 std::unique_ptr<base::ListValue> cast_modes_list(CastModesToValue( |
| 412 cast_modes, media_router_ui_->GetPresentationRequestSourceName())); | 425 cast_modes, media_router_ui_->GetPresentationRequestSourceName())); |
| 413 initial_data.Set("castModes", cast_modes_list.release()); | 426 initial_data.Set("castModes", cast_modes_list.release()); |
| 414 | 427 |
| 415 web_ui()->CallJavascriptFunction(kSetInitialData, initial_data); | 428 web_ui()->CallJavascriptFunction(kSetInitialData, initial_data); |
| 416 media_router_ui_->UIInitialized(); | 429 media_router_ui_->UIInitialized(); |
| 417 } | 430 } |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 845 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui())); | 858 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui())); |
| 846 if (signin_manager) | 859 if (signin_manager) |
| 847 return signin_manager->GetAuthenticatedAccountInfo(); | 860 return signin_manager->GetAuthenticatedAccountInfo(); |
| 848 #endif // defined(GOOGLE_CHROME_BUILD) | 861 #endif // defined(GOOGLE_CHROME_BUILD) |
| 849 | 862 |
| 850 return AccountInfo(); | 863 return AccountInfo(); |
| 851 } | 864 } |
| 852 | 865 |
| 853 std::unique_ptr<base::ListValue> MediaRouterWebUIMessageHandler::RoutesToValue( | 866 std::unique_ptr<base::ListValue> MediaRouterWebUIMessageHandler::RoutesToValue( |
| 854 const std::vector<MediaRoute>& routes, | 867 const std::vector<MediaRoute>& routes, |
| 855 const std::vector<MediaRoute::Id>& joinable_route_ids) const { | 868 const std::vector<MediaRoute::Id>& joinable_route_ids, |
| 869 const std::unordered_map<MediaRoute::Id, MediaCastMode>& current_cast_modes) | |
| 870 const { | |
| 856 std::unique_ptr<base::ListValue> value(new base::ListValue); | 871 std::unique_ptr<base::ListValue> value(new base::ListValue); |
| 857 const std::string& extension_id = | 872 const std::string& extension_id = |
| 858 media_router_ui_->GetRouteProviderExtensionId(); | 873 media_router_ui_->GetRouteProviderExtensionId(); |
| 859 | 874 |
| 860 for (const MediaRoute& route : routes) { | 875 for (const MediaRoute& route : routes) { |
| 861 bool can_join = ContainsValue(joinable_route_ids, route.media_route_id()); | 876 bool can_join = ContainsValue(joinable_route_ids, route.media_route_id()); |
| 862 std::unique_ptr<base::DictionaryValue> route_val( | 877 auto current_cast_mode_entry = |
|
apacible
2016/06/06 20:17:10
Pull out lines 877-881 (and 277-281) into a helper
btolsch
2016/06/06 23:46:53
Done. Only this instance remains in use but still
| |
| 863 RouteToValue(route, can_join, extension_id, off_the_record_)); | 878 current_cast_modes.find(route.media_route_id()); |
| 879 int current_cast_mode = current_cast_mode_entry != end(current_cast_modes) | |
| 880 ? current_cast_mode_entry->second | |
| 881 : -1; | |
| 882 std::unique_ptr<base::DictionaryValue> route_val(RouteToValue( | |
| 883 route, can_join, extension_id, off_the_record_, current_cast_mode)); | |
| 864 value->Append(route_val.release()); | 884 value->Append(route_val.release()); |
| 865 } | 885 } |
| 866 | 886 |
| 867 return value; | 887 return value; |
| 868 } | 888 } |
| 869 | 889 |
| 870 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { | 890 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { |
| 871 set_web_ui(web_ui); | 891 set_web_ui(web_ui); |
| 872 } | 892 } |
| 873 | 893 |
| 874 } // namespace media_router | 894 } // namespace media_router |
| OLD | NEW |