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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 const char kReportTimeToClickSink[] = "reportTimeToClickSink"; | 57 const char kReportTimeToClickSink[] = "reportTimeToClickSink"; |
| 58 const char kReportTimeToInitialActionClose[] = "reportTimeToInitialActionClose"; | 58 const char kReportTimeToInitialActionClose[] = "reportTimeToInitialActionClose"; |
| 59 const char kOnInitialDataReceived[] = "onInitialDataReceived"; | 59 const char kOnInitialDataReceived[] = "onInitialDataReceived"; |
| 60 | 60 |
| 61 // JS function names. | 61 // JS function names. |
| 62 const char kSetInitialData[] = "media_router.ui.setInitialData"; | 62 const char kSetInitialData[] = "media_router.ui.setInitialData"; |
| 63 const char kOnCreateRouteResponseReceived[] = | 63 const char kOnCreateRouteResponseReceived[] = |
| 64 "media_router.ui.onCreateRouteResponseReceived"; | 64 "media_router.ui.onCreateRouteResponseReceived"; |
| 65 const char kSetFirstRunFlowData[] = "media_router.ui.setFirstRunFlowData"; | 65 const char kSetFirstRunFlowData[] = "media_router.ui.setFirstRunFlowData"; |
| 66 const char kSetIssue[] = "media_router.ui.setIssue"; | 66 const char kSetIssue[] = "media_router.ui.setIssue"; |
| 67 const char kSetSinkList[] = "media_router.ui.setSinkList"; | 67 const char kSetSinkListAndIdentity[] = "media_router.ui.setSinkListAndIdentity"; |
| 68 const char kSetRouteList[] = "media_router.ui.setRouteList"; | 68 const char kSetRouteList[] = "media_router.ui.setRouteList"; |
| 69 const char kSetCastModeList[] = "media_router.ui.setCastModeList"; | 69 const char kSetCastModeList[] = "media_router.ui.setCastModeList"; |
| 70 const char kUpdateMaxHeight[] = "media_router.ui.updateMaxHeight"; | 70 const char kUpdateMaxHeight[] = "media_router.ui.updateMaxHeight"; |
| 71 const char kWindowOpen[] = "window.open"; | 71 const char kWindowOpen[] = "window.open"; |
| 72 | 72 |
| 73 scoped_ptr<base::ListValue> SinksToValue( | 73 scoped_ptr<base::DictionaryValue> SinksAndIdentityToValue( |
| 74 const std::vector<MediaSinkWithCastModes>& sinks) { | 74 const std::vector<MediaSinkWithCastModes>& sinks, |
| 75 scoped_ptr<base::ListValue> value(new base::ListValue); | 75 Profile* profile) { |
| 76 | |
|
apacible
2016/02/23 21:51:01
nit: remove newline.
amp
2016/02/24 00:29:23
Done.
| |
| 77 scoped_ptr<base::DictionaryValue> sink_list_and_identity( | |
| 78 new base::DictionaryValue); | |
| 79 | |
| 80 std::string user_domain; | |
| 81 #if defined(GOOGLE_CHROME_BUILD) | |
| 82 SigninManagerBase* signin_manager = | |
| 83 SigninManagerFactory::GetForProfile(profile); | |
| 84 AccountInfo account_info = signin_manager->GetAuthenticatedAccountInfo(); | |
| 85 LOG(ERROR) << "Signin_manager valid: " << account_info.IsValid(); | |
| 86 if (account_info.IsValid()) { | |
| 87 user_domain = account_info.hosted_domain; | |
| 88 sink_list_and_identity->SetString("userEmail", account_info.email); | |
| 89 sink_list_and_identity->SetString("userDomain", user_domain); | |
| 90 } | |
| 91 #endif // defined(GOOGLE_CHROME_BUILD) | |
| 92 | |
| 93 scoped_ptr<base::ListValue> sinks_val(new base::ListValue); | |
|
apacible
2016/02/23 21:51:01
nit organizational suggestion: move this right bel
amp
2016/02/24 00:29:23
Done.
| |
| 94 bool show_email = false; | |
| 95 bool show_domain = false; | |
| 76 | 96 |
| 77 for (const MediaSinkWithCastModes& sink_with_cast_modes : sinks) { | 97 for (const MediaSinkWithCastModes& sink_with_cast_modes : sinks) { |
| 78 scoped_ptr<base::DictionaryValue> sink_val(new base::DictionaryValue); | 98 scoped_ptr<base::DictionaryValue> sink_val(new base::DictionaryValue); |
| 79 | 99 |
| 80 const MediaSink& sink = sink_with_cast_modes.sink; | 100 const MediaSink& sink = sink_with_cast_modes.sink; |
| 81 sink_val->SetString("id", sink.id()); | 101 sink_val->SetString("id", sink.id()); |
| 82 sink_val->SetString("name", sink.name()); | 102 sink_val->SetString("name", sink.name()); |
| 83 sink_val->SetInteger("iconType", sink.icon_type()); | 103 sink_val->SetInteger("iconType", sink.icon_type()); |
| 84 if (!sink.description().empty()) | 104 if (!sink.description().empty()) |
| 85 sink_val->SetString("description", sink.description()); | 105 sink_val->SetString("description", sink.description()); |
| 86 if (!sink.domain().empty()) | 106 |
| 87 sink_val->SetString("domain", sink.domain()); | 107 if (!user_domain.empty() && !sink.domain().empty()) { |
| 108 std::string domain = sink.domain(); | |
| 109 // Convert default domains to user domain | |
| 110 if (sink.domain() == "default") { | |
|
apacible
2016/02/23 21:51:01
if (sink.domain() == "default" &&
user_domain
amp
2016/02/24 00:29:23
I don't think that will work. If the user domain
| |
| 111 domain = user_domain; | |
| 112 if (domain == "NO_HOSTED_DOMAIN") { | |
| 113 // Default domain will be empty for non-dasher accounts. | |
| 114 domain.clear(); | |
| 115 } | |
| 116 } | |
| 117 | |
| 118 sink_val->SetString("domain", domain); | |
| 119 | |
| 120 show_email = true; | |
| 121 if (!domain.empty() && domain != user_domain) | |
| 122 show_domain = true; | |
| 123 } | |
| 88 | 124 |
| 89 int cast_mode_bits = 0; | 125 int cast_mode_bits = 0; |
| 90 for (MediaCastMode cast_mode : sink_with_cast_modes.cast_modes) | 126 for (MediaCastMode cast_mode : sink_with_cast_modes.cast_modes) |
| 91 cast_mode_bits |= cast_mode; | 127 cast_mode_bits |= cast_mode; |
| 92 | 128 |
| 93 sink_val->SetInteger("castModes", cast_mode_bits); | 129 sink_val->SetInteger("castModes", cast_mode_bits); |
| 94 value->Append(sink_val.release()); | 130 sinks_val->Append(sink_val.release()); |
| 95 } | 131 } |
| 96 | 132 |
| 97 return value; | 133 sink_list_and_identity->Set("sinks", sinks_val.release()); |
| 134 sink_list_and_identity->SetBoolean("showEmail", show_email); | |
| 135 sink_list_and_identity->SetBoolean("showDomain", show_domain); | |
| 136 return sink_list_and_identity; | |
| 98 } | 137 } |
| 99 | 138 |
| 100 scoped_ptr<base::DictionaryValue> RouteToValue( | 139 scoped_ptr<base::DictionaryValue> RouteToValue( |
| 101 const MediaRoute& route, bool canJoin, const std::string& extension_id) { | 140 const MediaRoute& route, bool canJoin, const std::string& extension_id) { |
| 102 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); | 141 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); |
| 103 dictionary->SetString("id", route.media_route_id()); | 142 dictionary->SetString("id", route.media_route_id()); |
| 104 dictionary->SetString("sinkId", route.media_sink_id()); | 143 dictionary->SetString("sinkId", route.media_sink_id()); |
| 105 dictionary->SetString("description", route.description()); | 144 dictionary->SetString("description", route.description()); |
| 106 dictionary->SetBoolean("isLocal", route.is_local()); | 145 dictionary->SetBoolean("isLocal", route.is_local()); |
| 107 dictionary->SetBoolean("canJoin", canJoin); | 146 dictionary->SetBoolean("canJoin", canJoin); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 media_router_ui_(media_router_ui) { | 240 media_router_ui_(media_router_ui) { |
| 202 DCHECK(media_router_ui_); | 241 DCHECK(media_router_ui_); |
| 203 } | 242 } |
| 204 | 243 |
| 205 MediaRouterWebUIMessageHandler::~MediaRouterWebUIMessageHandler() { | 244 MediaRouterWebUIMessageHandler::~MediaRouterWebUIMessageHandler() { |
| 206 } | 245 } |
| 207 | 246 |
| 208 void MediaRouterWebUIMessageHandler::UpdateSinks( | 247 void MediaRouterWebUIMessageHandler::UpdateSinks( |
| 209 const std::vector<MediaSinkWithCastModes>& sinks) { | 248 const std::vector<MediaSinkWithCastModes>& sinks) { |
| 210 DVLOG(2) << "UpdateSinks"; | 249 DVLOG(2) << "UpdateSinks"; |
| 211 scoped_ptr<base::ListValue> sinks_val(SinksToValue(sinks)); | 250 scoped_ptr<base::DictionaryValue> sinks_and_identity_val( |
| 212 web_ui()->CallJavascriptFunction(kSetSinkList, *sinks_val); | 251 SinksAndIdentityToValue(sinks, Profile::FromWebUI(web_ui()))); |
| 252 web_ui()->CallJavascriptFunction( | |
| 253 kSetSinkListAndIdentity, *sinks_and_identity_val); | |
| 213 } | 254 } |
| 214 | 255 |
| 215 void MediaRouterWebUIMessageHandler::UpdateRoutes( | 256 void MediaRouterWebUIMessageHandler::UpdateRoutes( |
| 216 const std::vector<MediaRoute>& routes, | 257 const std::vector<MediaRoute>& routes, |
| 217 const std::vector<MediaRoute::Id>& joinable_route_ids) { | 258 const std::vector<MediaRoute::Id>& joinable_route_ids) { |
| 218 scoped_ptr<base::ListValue> routes_val(RoutesToValue(routes, | 259 scoped_ptr<base::ListValue> routes_val(RoutesToValue(routes, |
| 219 joinable_route_ids, | 260 joinable_route_ids, |
| 220 media_router_ui_->GetRouteProviderExtensionId())); | 261 media_router_ui_->GetRouteProviderExtensionId())); |
| 221 web_ui()->CallJavascriptFunction(kSetRouteList, *routes_val); | 262 web_ui()->CallJavascriptFunction(kSetRouteList, *routes_val); |
| 222 } | 263 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 void MediaRouterWebUIMessageHandler::OnRequestInitialData( | 377 void MediaRouterWebUIMessageHandler::OnRequestInitialData( |
| 337 const base::ListValue* args) { | 378 const base::ListValue* args) { |
| 338 DVLOG(1) << "OnRequestInitialData"; | 379 DVLOG(1) << "OnRequestInitialData"; |
| 339 media_router_ui_->OnUIInitiallyLoaded(); | 380 media_router_ui_->OnUIInitiallyLoaded(); |
| 340 base::DictionaryValue initial_data; | 381 base::DictionaryValue initial_data; |
| 341 | 382 |
| 342 // "No Cast devices found?" Chromecast help center page. | 383 // "No Cast devices found?" Chromecast help center page. |
| 343 initial_data.SetString("deviceMissingUrl", | 384 initial_data.SetString("deviceMissingUrl", |
| 344 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); | 385 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); |
| 345 | 386 |
| 346 scoped_ptr<base::ListValue> sinks(SinksToValue(media_router_ui_->sinks())); | 387 scoped_ptr<base::DictionaryValue> sinks_and_identity(SinksAndIdentityToValue( |
| 347 initial_data.Set("sinks", sinks.release()); | 388 media_router_ui_->sinks(), Profile::FromWebUI(web_ui()))); |
| 389 initial_data.Set("sinksAndIdentity", sinks_and_identity.release()); | |
| 348 | 390 |
| 349 scoped_ptr<base::ListValue> routes(RoutesToValue(media_router_ui_->routes(), | 391 scoped_ptr<base::ListValue> routes(RoutesToValue(media_router_ui_->routes(), |
| 350 media_router_ui_->joinable_route_ids(), | 392 media_router_ui_->joinable_route_ids(), |
| 351 media_router_ui_->GetRouteProviderExtensionId())); | 393 media_router_ui_->GetRouteProviderExtensionId())); |
| 352 initial_data.Set("routes", routes.release()); | 394 initial_data.Set("routes", routes.release()); |
| 353 | 395 |
| 354 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes(); | 396 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes(); |
| 355 scoped_ptr<base::ListValue> cast_modes_list( | 397 scoped_ptr<base::ListValue> cast_modes_list( |
| 356 CastModesToValue(cast_modes, | 398 CastModesToValue(cast_modes, |
| 357 media_router_ui_->GetPresentationRequestSourceName())); | 399 media_router_ui_->GetPresentationRequestSourceName())); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 | 462 |
| 421 #if defined(GOOGLE_CHROME_BUILD) | 463 #if defined(GOOGLE_CHROME_BUILD) |
| 422 bool enabled_cloud_services = false; | 464 bool enabled_cloud_services = false; |
| 423 // Do not set the relevant cloud services prefs if the user was not shown | 465 // Do not set the relevant cloud services prefs if the user was not shown |
| 424 // the cloud services prompt. | 466 // the cloud services prompt. |
| 425 if (!args->GetBoolean(0, &enabled_cloud_services)) { | 467 if (!args->GetBoolean(0, &enabled_cloud_services)) { |
| 426 DVLOG(1) << "User was not shown the enable cloud services prompt."; | 468 DVLOG(1) << "User was not shown the enable cloud services prompt."; |
| 427 return; | 469 return; |
| 428 } | 470 } |
| 429 | 471 |
| 430 Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean( | 472 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 473 pref_service->SetBoolean( | |
| 431 prefs::kMediaRouterEnableCloudServices, enabled_cloud_services); | 474 prefs::kMediaRouterEnableCloudServices, enabled_cloud_services); |
| 432 Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean( | 475 pref_service->SetBoolean(prefs::kMediaRouterCloudServicesPrefSet, true); |
| 433 prefs::kMediaRouterCloudServicesPrefSet, true); | |
| 434 #endif // defined(GOOGLE_CHROME_BUILD) | 476 #endif // defined(GOOGLE_CHROME_BUILD) |
| 435 } | 477 } |
| 436 | 478 |
| 437 void MediaRouterWebUIMessageHandler::OnActOnIssue( | 479 void MediaRouterWebUIMessageHandler::OnActOnIssue( |
| 438 const base::ListValue* args) { | 480 const base::ListValue* args) { |
| 439 DVLOG(1) << "OnActOnIssue"; | 481 DVLOG(1) << "OnActOnIssue"; |
| 440 const base::DictionaryValue* args_dict = nullptr; | 482 const base::DictionaryValue* args_dict = nullptr; |
| 441 Issue::Id issue_id; | 483 Issue::Id issue_id; |
| 442 int action_type_num = -1; | 484 int action_type_num = -1; |
| 443 if (!args->GetDictionary(0, &args_dict) || | 485 if (!args->GetDictionary(0, &args_dict) || |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 718 first_run_flow_acknowledged); | 760 first_run_flow_acknowledged); |
| 719 first_run_flow_data.SetBoolean("showFirstRunFlowCloudPref", show_cloud_pref); | 761 first_run_flow_data.SetBoolean("showFirstRunFlowCloudPref", show_cloud_pref); |
| 720 web_ui()->CallJavascriptFunction(kSetFirstRunFlowData, first_run_flow_data); | 762 web_ui()->CallJavascriptFunction(kSetFirstRunFlowData, first_run_flow_data); |
| 721 } | 763 } |
| 722 | 764 |
| 723 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { | 765 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { |
| 724 set_web_ui(web_ui); | 766 set_web_ui(web_ui); |
| 725 } | 767 } |
| 726 | 768 |
| 727 } // namespace media_router | 769 } // namespace media_router |
| OLD | NEW |