| 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()->CallJavascriptFunctionUnsafe(kSetSinkListAndIdentity, | 248 web_ui()->CallJavascriptFunctionUnsafe(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()->CallJavascriptFunctionUnsafe(kSetRouteList, *routes_val); | 259 web_ui()->CallJavascriptFunctionUnsafe(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()->CallJavascriptFunctionUnsafe(kSetCastModeList, *cast_modes_val); | 268 web_ui()->CallJavascriptFunctionUnsafe(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 int current_cast_mode = CurrentCastModeForRouteId( |
| 277 route->media_route_id(), media_router_ui_->current_cast_modes()); |
| 270 std::unique_ptr<base::DictionaryValue> route_value(RouteToValue( | 278 std::unique_ptr<base::DictionaryValue> route_value(RouteToValue( |
| 271 *route, false, media_router_ui_->GetRouteProviderExtensionId(), | 279 *route, false, media_router_ui_->GetRouteProviderExtensionId(), |
| 272 off_the_record_)); | 280 off_the_record_, current_cast_mode)); |
| 273 web_ui()->CallJavascriptFunctionUnsafe( | 281 web_ui()->CallJavascriptFunctionUnsafe( |
| 274 kOnCreateRouteResponseReceived, base::StringValue(sink_id), | 282 kOnCreateRouteResponseReceived, base::StringValue(sink_id), |
| 275 *route_value, base::FundamentalValue(route->for_display())); | 283 *route_value, base::FundamentalValue(route->for_display())); |
| 276 } else { | 284 } else { |
| 277 web_ui()->CallJavascriptFunctionUnsafe( | 285 web_ui()->CallJavascriptFunctionUnsafe( |
| 278 kOnCreateRouteResponseReceived, base::StringValue(sink_id), | 286 kOnCreateRouteResponseReceived, base::StringValue(sink_id), |
| 279 *base::Value::CreateNullValue(), base::FundamentalValue(false)); | 287 *base::Value::CreateNullValue(), base::FundamentalValue(false)); |
| 280 } | 288 } |
| 281 } | 289 } |
| 282 | 290 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 | 404 |
| 397 // "No Cast devices found?" Chromecast help center page. | 405 // "No Cast devices found?" Chromecast help center page. |
| 398 initial_data.SetString("deviceMissingUrl", | 406 initial_data.SetString("deviceMissingUrl", |
| 399 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); | 407 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); |
| 400 | 408 |
| 401 std::unique_ptr<base::DictionaryValue> sinks_and_identity( | 409 std::unique_ptr<base::DictionaryValue> sinks_and_identity( |
| 402 SinksAndIdentityToValue(media_router_ui_->sinks(), GetAccountInfo())); | 410 SinksAndIdentityToValue(media_router_ui_->sinks(), GetAccountInfo())); |
| 403 initial_data.Set("sinksAndIdentity", sinks_and_identity.release()); | 411 initial_data.Set("sinksAndIdentity", sinks_and_identity.release()); |
| 404 | 412 |
| 405 std::unique_ptr<base::ListValue> routes(RoutesToValue( | 413 std::unique_ptr<base::ListValue> routes(RoutesToValue( |
| 406 media_router_ui_->routes(), media_router_ui_->joinable_route_ids())); | 414 media_router_ui_->routes(), media_router_ui_->joinable_route_ids(), |
| 415 media_router_ui_->current_cast_modes())); |
| 407 initial_data.Set("routes", routes.release()); | 416 initial_data.Set("routes", routes.release()); |
| 408 | 417 |
| 409 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes(); | 418 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes(); |
| 410 std::unique_ptr<base::ListValue> cast_modes_list(CastModesToValue( | 419 std::unique_ptr<base::ListValue> cast_modes_list(CastModesToValue( |
| 411 cast_modes, media_router_ui_->GetPresentationRequestSourceName())); | 420 cast_modes, media_router_ui_->GetPresentationRequestSourceName())); |
| 412 initial_data.Set("castModes", cast_modes_list.release()); | 421 initial_data.Set("castModes", cast_modes_list.release()); |
| 413 | 422 |
| 414 web_ui()->CallJavascriptFunctionUnsafe(kSetInitialData, initial_data); | 423 web_ui()->CallJavascriptFunctionUnsafe(kSetInitialData, initial_data); |
| 415 media_router_ui_->UIInitialized(); | 424 media_router_ui_->UIInitialized(); |
| 416 } | 425 } |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 #if defined(GOOGLE_CHROME_BUILD) | 852 #if defined(GOOGLE_CHROME_BUILD) |
| 844 SigninManagerBase* signin_manager = | 853 SigninManagerBase* signin_manager = |
| 845 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui())); | 854 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui())); |
| 846 if (signin_manager) | 855 if (signin_manager) |
| 847 return signin_manager->GetAuthenticatedAccountInfo(); | 856 return signin_manager->GetAuthenticatedAccountInfo(); |
| 848 #endif // defined(GOOGLE_CHROME_BUILD) | 857 #endif // defined(GOOGLE_CHROME_BUILD) |
| 849 | 858 |
| 850 return AccountInfo(); | 859 return AccountInfo(); |
| 851 } | 860 } |
| 852 | 861 |
| 862 int MediaRouterWebUIMessageHandler::CurrentCastModeForRouteId( |
| 863 const MediaRoute::Id& route_id, |
| 864 const std::unordered_map<MediaRoute::Id, MediaCastMode>& current_cast_modes) |
| 865 const { |
| 866 auto current_cast_mode_entry = current_cast_modes.find(route_id); |
| 867 int current_cast_mode = current_cast_mode_entry != current_cast_modes.end() |
| 868 ? current_cast_mode_entry->second |
| 869 : -1; |
| 870 return current_cast_mode; |
| 871 } |
| 872 |
| 853 std::unique_ptr<base::ListValue> MediaRouterWebUIMessageHandler::RoutesToValue( | 873 std::unique_ptr<base::ListValue> MediaRouterWebUIMessageHandler::RoutesToValue( |
| 854 const std::vector<MediaRoute>& routes, | 874 const std::vector<MediaRoute>& routes, |
| 855 const std::vector<MediaRoute::Id>& joinable_route_ids) const { | 875 const std::vector<MediaRoute::Id>& joinable_route_ids, |
| 876 const std::unordered_map<MediaRoute::Id, MediaCastMode>& current_cast_modes) |
| 877 const { |
| 856 std::unique_ptr<base::ListValue> value(new base::ListValue); | 878 std::unique_ptr<base::ListValue> value(new base::ListValue); |
| 857 const std::string& extension_id = | 879 const std::string& extension_id = |
| 858 media_router_ui_->GetRouteProviderExtensionId(); | 880 media_router_ui_->GetRouteProviderExtensionId(); |
| 859 | 881 |
| 860 for (const MediaRoute& route : routes) { | 882 for (const MediaRoute& route : routes) { |
| 861 bool can_join = ContainsValue(joinable_route_ids, route.media_route_id()); | 883 bool can_join = ContainsValue(joinable_route_ids, route.media_route_id()); |
| 862 std::unique_ptr<base::DictionaryValue> route_val( | 884 int current_cast_mode = CurrentCastModeForRouteId(route.media_route_id(), |
| 863 RouteToValue(route, can_join, extension_id, off_the_record_)); | 885 current_cast_modes); |
| 886 std::unique_ptr<base::DictionaryValue> route_val(RouteToValue( |
| 887 route, can_join, extension_id, off_the_record_, current_cast_mode)); |
| 864 value->Append(route_val.release()); | 888 value->Append(route_val.release()); |
| 865 } | 889 } |
| 866 | 890 |
| 867 return value; | 891 return value; |
| 868 } | 892 } |
| 869 | 893 |
| 870 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { | 894 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { |
| 871 set_web_ui(web_ui); | 895 set_web_ui(web_ui); |
| 872 } | 896 } |
| 873 | 897 |
| 874 } // namespace media_router | 898 } // namespace media_router |
| OLD | NEW |