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

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

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

Powered by Google App Engine
This is Rietveld 408576698