Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: chrome/browser/ui/webui/media_router/media_router_webui_message_handler.cc

Issue 2040873002: [Media Router] Assign each route a current cast mode if possible (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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)
280 ? current_cast_mode =
281 current_cast_mode_entry->second
282 : -1;
270 std::unique_ptr<base::DictionaryValue> route_value(RouteToValue( 283 std::unique_ptr<base::DictionaryValue> route_value(RouteToValue(
271 *route, false, media_router_ui_->GetRouteProviderExtensionId(), 284 *route, false, media_router_ui_->GetRouteProviderExtensionId(),
272 off_the_record_)); 285 off_the_record_, current_cast_mode));
273 web_ui()->CallJavascriptFunction( 286 web_ui()->CallJavascriptFunction(
274 kOnCreateRouteResponseReceived, 287 kOnCreateRouteResponseReceived,
275 base::StringValue(sink_id), *route_value, 288 base::StringValue(sink_id), *route_value,
276 base::FundamentalValue(route->for_display())); 289 base::FundamentalValue(route->for_display()));
277 } else { 290 } else {
278 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived, 291 web_ui()->CallJavascriptFunction(kOnCreateRouteResponseReceived,
279 base::StringValue(sink_id), 292 base::StringValue(sink_id),
280 *base::Value::CreateNullValue(), 293 *base::Value::CreateNullValue(),
281 base::FundamentalValue(false)); 294 base::FundamentalValue(false));
282 } 295 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 410
398 // "No Cast devices found?" Chromecast help center page. 411 // "No Cast devices found?" Chromecast help center page.
399 initial_data.SetString("deviceMissingUrl", 412 initial_data.SetString("deviceMissingUrl",
400 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); 413 base::StringPrintf(kHelpPageUrlPrefix, 3249268));
401 414
402 std::unique_ptr<base::DictionaryValue> sinks_and_identity( 415 std::unique_ptr<base::DictionaryValue> sinks_and_identity(
403 SinksAndIdentityToValue(media_router_ui_->sinks(), GetAccountInfo())); 416 SinksAndIdentityToValue(media_router_ui_->sinks(), GetAccountInfo()));
404 initial_data.Set("sinksAndIdentity", sinks_and_identity.release()); 417 initial_data.Set("sinksAndIdentity", sinks_and_identity.release());
405 418
406 std::unique_ptr<base::ListValue> routes(RoutesToValue( 419 std::unique_ptr<base::ListValue> routes(RoutesToValue(
407 media_router_ui_->routes(), media_router_ui_->joinable_route_ids())); 420 media_router_ui_->routes(), media_router_ui_->joinable_route_ids(),
421 media_router_ui_->current_cast_modes()));
408 initial_data.Set("routes", routes.release()); 422 initial_data.Set("routes", routes.release());
409 423
410 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes(); 424 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes();
411 std::unique_ptr<base::ListValue> cast_modes_list(CastModesToValue( 425 std::unique_ptr<base::ListValue> cast_modes_list(CastModesToValue(
412 cast_modes, media_router_ui_->GetPresentationRequestSourceName())); 426 cast_modes, media_router_ui_->GetPresentationRequestSourceName()));
413 initial_data.Set("castModes", cast_modes_list.release()); 427 initial_data.Set("castModes", cast_modes_list.release());
414 428
415 web_ui()->CallJavascriptFunction(kSetInitialData, initial_data); 429 web_ui()->CallJavascriptFunction(kSetInitialData, initial_data);
416 media_router_ui_->UIInitialized(); 430 media_router_ui_->UIInitialized();
417 } 431 }
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui())); 859 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui()));
846 if (signin_manager) 860 if (signin_manager)
847 return signin_manager->GetAuthenticatedAccountInfo(); 861 return signin_manager->GetAuthenticatedAccountInfo();
848 #endif // defined(GOOGLE_CHROME_BUILD) 862 #endif // defined(GOOGLE_CHROME_BUILD)
849 863
850 return AccountInfo(); 864 return AccountInfo();
851 } 865 }
852 866
853 std::unique_ptr<base::ListValue> MediaRouterWebUIMessageHandler::RoutesToValue( 867 std::unique_ptr<base::ListValue> MediaRouterWebUIMessageHandler::RoutesToValue(
854 const std::vector<MediaRoute>& routes, 868 const std::vector<MediaRoute>& routes,
855 const std::vector<MediaRoute::Id>& joinable_route_ids) const { 869 const std::vector<MediaRoute::Id>& joinable_route_ids,
870 const std::unordered_map<MediaRoute::Id, MediaCastMode>& current_cast_modes)
871 const {
856 std::unique_ptr<base::ListValue> value(new base::ListValue); 872 std::unique_ptr<base::ListValue> value(new base::ListValue);
857 const std::string& extension_id = 873 const std::string& extension_id =
858 media_router_ui_->GetRouteProviderExtensionId(); 874 media_router_ui_->GetRouteProviderExtensionId();
859 875
860 for (const MediaRoute& route : routes) { 876 for (const MediaRoute& route : routes) {
861 bool can_join = ContainsValue(joinable_route_ids, route.media_route_id()); 877 bool can_join = ContainsValue(joinable_route_ids, route.media_route_id());
862 std::unique_ptr<base::DictionaryValue> route_val( 878 auto current_cast_mode_entry =
863 RouteToValue(route, can_join, extension_id, off_the_record_)); 879 current_cast_modes.find(route.media_route_id());
880 int current_cast_mode = current_cast_mode_entry != end(current_cast_modes)
881 ? current_cast_mode =
882 current_cast_mode_entry->second
883 : -1;
884 std::unique_ptr<base::DictionaryValue> route_val(RouteToValue(
885 route, can_join, extension_id, off_the_record_, current_cast_mode));
864 value->Append(route_val.release()); 886 value->Append(route_val.release());
865 } 887 }
866 888
867 return value; 889 return value;
868 } 890 }
869 891
870 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { 892 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) {
871 set_web_ui(web_ui); 893 set_web_ui(web_ui);
872 } 894 }
873 895
874 } // namespace media_router 896 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698