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 | |
| 77 scoped_ptr<base::DictionaryValue> sink_list_and_identity( | |
| 78 new base::DictionaryValue); | |
| 79 | |
| 80 #if defined(GOOGLE_CHROME_BUILD) | |
| 81 SigninManagerBase* signin_manager = | |
| 82 SigninManagerFactory::GetForProfile(profile); | |
| 83 std::string user_domain = | |
| 84 signin_manager->GetAuthenticatedAccountInfo().hosted_domain; | |
|
imcheng
2016/02/17 00:51:08
the documentation says GetAuthenticatedAccountInfo
imcheng
2016/02/17 00:51:08
nit: store the result of signin_manager->GetAuthen
amp
2016/02/17 02:11:37
Done.
amp
2016/02/17 02:11:37
Done. It should now, I'll make sure to have tests
| |
| 85 sink_list_and_identity->SetString("userEmail", | |
| 86 signin_manager->GetAuthenticatedAccountInfo().email); | |
| 87 sink_list_and_identity->SetString("userDomain", user_domain); | |
| 88 #endif // defined(GOOGLE_CHROME_BUILD) | |
| 89 | |
| 90 scoped_ptr<base::ListValue> sinks_val(new base::ListValue); | |
| 91 MediaRouterWebUIMessageHandler::IdentityVisibility identityVisibility = | |
| 92 MediaRouterWebUIMessageHandler::IdentityVisibility::HIDDEN; | |
| 76 | 93 |
| 77 for (const MediaSinkWithCastModes& sink_with_cast_modes : sinks) { | 94 for (const MediaSinkWithCastModes& sink_with_cast_modes : sinks) { |
| 78 scoped_ptr<base::DictionaryValue> sink_val(new base::DictionaryValue); | 95 scoped_ptr<base::DictionaryValue> sink_val(new base::DictionaryValue); |
| 79 | 96 |
| 80 const MediaSink& sink = sink_with_cast_modes.sink; | 97 const MediaSink& sink = sink_with_cast_modes.sink; |
| 81 sink_val->SetString("id", sink.id()); | 98 sink_val->SetString("id", sink.id()); |
| 82 sink_val->SetString("name", sink.name()); | 99 sink_val->SetString("name", sink.name()); |
| 83 sink_val->SetInteger("iconType", sink.icon_type()); | 100 sink_val->SetInteger("iconType", sink.icon_type()); |
| 84 if (!sink.description().empty()) | 101 if (!sink.description().empty()) |
| 85 sink_val->SetString("description", sink.description()); | 102 sink_val->SetString("description", sink.description()); |
| 86 if (!sink.domain().empty()) | 103 #if defined(GOOGLE_CHROME_BUILD) |
|
imcheng
2016/02/17 00:51:08
Personally I think the logic to determine whether
amp
2016/02/17 02:11:37
With the change to the check on the account info s
| |
| 87 sink_val->SetString("domain", sink.domain()); | 104 if (!sink.domain().empty()) { |
| 105 std::string domain = sink.domain(); | |
| 106 // Convert default domains to user domain | |
| 107 if (sink.domain() == "default") | |
| 108 domain = user_domain; | |
| 109 | |
| 110 sink_val->SetString("domain", domain); | |
| 111 | |
| 112 // Don't reset visibility to SHOW_EMAIL if it was already SHOW_DOMAIN | |
| 113 if (identityVisibility == | |
| 114 MediaRouterWebUIMessageHandler::IdentityVisibility::HIDDEN) | |
|
imcheng
2016/02/17 00:51:08
nit: need some braces for these if statements.
amp
2016/02/17 02:11:37
With the removal of the visibility enum's these be
imcheng
2016/02/18 18:58:54
I find adding braces help readability for single s
amp
2016/02/20 02:00:55
Acknowledged.
| |
| 115 identityVisibility = | |
| 116 MediaRouterWebUIMessageHandler::IdentityVisibility::SHOW_EMAIL; | |
| 117 if (domain != user_domain) | |
| 118 identityVisibility = | |
| 119 MediaRouterWebUIMessageHandler::IdentityVisibility::SHOW_DOMAIN; | |
| 120 } | |
| 121 #endif // defined(GOOGLE_CHROME_BUILD) | |
| 88 | 122 |
| 89 int cast_mode_bits = 0; | 123 int cast_mode_bits = 0; |
| 90 for (MediaCastMode cast_mode : sink_with_cast_modes.cast_modes) | 124 for (MediaCastMode cast_mode : sink_with_cast_modes.cast_modes) |
| 91 cast_mode_bits |= cast_mode; | 125 cast_mode_bits |= cast_mode; |
| 92 | 126 |
| 93 sink_val->SetInteger("castModes", cast_mode_bits); | 127 sink_val->SetInteger("castModes", cast_mode_bits); |
| 94 value->Append(sink_val.release()); | 128 sinks_val->Append(sink_val.release()); |
| 95 } | 129 } |
| 96 | 130 |
| 97 return value; | 131 sink_list_and_identity->Set("sinks", sinks_val.release()); |
| 132 | |
| 133 sink_list_and_identity->SetBoolean("showEmail", | |
| 134 identityVisibility != | |
| 135 MediaRouterWebUIMessageHandler::IdentityVisibility::HIDDEN); | |
| 136 sink_list_and_identity->SetBoolean("showDomain", | |
| 137 identityVisibility == | |
| 138 MediaRouterWebUIMessageHandler::IdentityVisibility::SHOW_DOMAIN); | |
| 139 return sink_list_and_identity; | |
| 98 } | 140 } |
| 99 | 141 |
| 100 scoped_ptr<base::DictionaryValue> RouteToValue( | 142 scoped_ptr<base::DictionaryValue> RouteToValue( |
| 101 const MediaRoute& route, bool canJoin, const std::string& extension_id) { | 143 const MediaRoute& route, bool canJoin, const std::string& extension_id) { |
| 102 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); | 144 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); |
| 103 dictionary->SetString("id", route.media_route_id()); | 145 dictionary->SetString("id", route.media_route_id()); |
| 104 dictionary->SetString("sinkId", route.media_sink_id()); | 146 dictionary->SetString("sinkId", route.media_sink_id()); |
| 105 dictionary->SetString("description", route.description()); | 147 dictionary->SetString("description", route.description()); |
| 106 dictionary->SetBoolean("isLocal", route.is_local()); | 148 dictionary->SetBoolean("isLocal", route.is_local()); |
| 107 dictionary->SetBoolean("canJoin", canJoin); | 149 dictionary->SetBoolean("canJoin", canJoin); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 media_router_ui_(media_router_ui) { | 243 media_router_ui_(media_router_ui) { |
| 202 DCHECK(media_router_ui_); | 244 DCHECK(media_router_ui_); |
| 203 } | 245 } |
| 204 | 246 |
| 205 MediaRouterWebUIMessageHandler::~MediaRouterWebUIMessageHandler() { | 247 MediaRouterWebUIMessageHandler::~MediaRouterWebUIMessageHandler() { |
| 206 } | 248 } |
| 207 | 249 |
| 208 void MediaRouterWebUIMessageHandler::UpdateSinks( | 250 void MediaRouterWebUIMessageHandler::UpdateSinks( |
| 209 const std::vector<MediaSinkWithCastModes>& sinks) { | 251 const std::vector<MediaSinkWithCastModes>& sinks) { |
| 210 DVLOG(2) << "UpdateSinks"; | 252 DVLOG(2) << "UpdateSinks"; |
| 211 scoped_ptr<base::ListValue> sinks_val(SinksToValue(sinks)); | 253 Profile* profile = Profile::FromWebUI(web_ui()); |
| 212 web_ui()->CallJavascriptFunction(kSetSinkList, *sinks_val); | 254 scoped_ptr<base::DictionaryValue> sinks_and_identity_val( |
| 255 SinksAndIdentityToValue(sinks, profile)); | |
| 256 web_ui()->CallJavascriptFunction( | |
| 257 kSetSinkListAndIdentity, *sinks_and_identity_val); | |
| 213 } | 258 } |
| 214 | 259 |
| 215 void MediaRouterWebUIMessageHandler::UpdateRoutes( | 260 void MediaRouterWebUIMessageHandler::UpdateRoutes( |
| 216 const std::vector<MediaRoute>& routes, | 261 const std::vector<MediaRoute>& routes, |
| 217 const std::vector<MediaRoute::Id>& joinable_route_ids) { | 262 const std::vector<MediaRoute::Id>& joinable_route_ids) { |
| 218 scoped_ptr<base::ListValue> routes_val(RoutesToValue(routes, | 263 scoped_ptr<base::ListValue> routes_val(RoutesToValue(routes, |
| 219 joinable_route_ids, | 264 joinable_route_ids, |
| 220 media_router_ui_->GetRouteProviderExtensionId())); | 265 media_router_ui_->GetRouteProviderExtensionId())); |
| 221 web_ui()->CallJavascriptFunction(kSetRouteList, *routes_val); | 266 web_ui()->CallJavascriptFunction(kSetRouteList, *routes_val); |
| 222 } | 267 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 void MediaRouterWebUIMessageHandler::OnRequestInitialData( | 381 void MediaRouterWebUIMessageHandler::OnRequestInitialData( |
| 337 const base::ListValue* args) { | 382 const base::ListValue* args) { |
| 338 DVLOG(1) << "OnRequestInitialData"; | 383 DVLOG(1) << "OnRequestInitialData"; |
| 339 media_router_ui_->OnUIInitiallyLoaded(); | 384 media_router_ui_->OnUIInitiallyLoaded(); |
| 340 base::DictionaryValue initial_data; | 385 base::DictionaryValue initial_data; |
| 341 | 386 |
| 342 // "No Cast devices found?" Chromecast help center page. | 387 // "No Cast devices found?" Chromecast help center page. |
| 343 initial_data.SetString("deviceMissingUrl", | 388 initial_data.SetString("deviceMissingUrl", |
| 344 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); | 389 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); |
| 345 | 390 |
| 346 scoped_ptr<base::ListValue> sinks(SinksToValue(media_router_ui_->sinks())); | 391 Profile* profile = Profile::FromWebUI(web_ui()); |
| 347 initial_data.Set("sinks", sinks.release()); | 392 scoped_ptr<base::DictionaryValue> sinks_and_identity(SinksAndIdentityToValue( |
| 393 media_router_ui_->sinks(), profile)); | |
|
imcheng
2016/02/17 00:51:08
nit: inline profile.
amp
2016/02/17 02:11:37
Done.
| |
| 394 initial_data.Set("sinksAndIdentity", sinks_and_identity.release()); | |
| 348 | 395 |
| 349 scoped_ptr<base::ListValue> routes(RoutesToValue(media_router_ui_->routes(), | 396 scoped_ptr<base::ListValue> routes(RoutesToValue(media_router_ui_->routes(), |
| 350 media_router_ui_->joinable_route_ids(), | 397 media_router_ui_->joinable_route_ids(), |
| 351 media_router_ui_->GetRouteProviderExtensionId())); | 398 media_router_ui_->GetRouteProviderExtensionId())); |
| 352 initial_data.Set("routes", routes.release()); | 399 initial_data.Set("routes", routes.release()); |
| 353 | 400 |
| 354 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes(); | 401 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes(); |
| 355 scoped_ptr<base::ListValue> cast_modes_list( | 402 scoped_ptr<base::ListValue> cast_modes_list( |
| 356 CastModesToValue(cast_modes, | 403 CastModesToValue(cast_modes, |
| 357 media_router_ui_->GetPresentationRequestSourceName())); | 404 media_router_ui_->GetPresentationRequestSourceName())); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 sink_id, static_cast<MediaCastMode>(cast_mode_num))) { | 455 sink_id, static_cast<MediaCastMode>(cast_mode_num))) { |
| 409 // TODO(imcheng): Need to add an issue if failed to initiate a CreateRoute | 456 // TODO(imcheng): Need to add an issue if failed to initiate a CreateRoute |
| 410 // request. | 457 // request. |
| 411 DVLOG(1) << "Error initiating route request."; | 458 DVLOG(1) << "Error initiating route request."; |
| 412 } | 459 } |
| 413 } | 460 } |
| 414 | 461 |
| 415 void MediaRouterWebUIMessageHandler::OnAcknowledgeFirstRunFlow( | 462 void MediaRouterWebUIMessageHandler::OnAcknowledgeFirstRunFlow( |
| 416 const base::ListValue* args) { | 463 const base::ListValue* args) { |
| 417 DVLOG(1) << "OnAcknowledgeFirstRunFlow"; | 464 DVLOG(1) << "OnAcknowledgeFirstRunFlow"; |
| 418 Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean( | 465 Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean( |
|
imcheng
2016/02/17 00:51:08
nit: extract PrefService* into a local variable.
amp
2016/02/17 02:11:37
I'll get to this if I can. Did these lines show u
imcheng
2016/02/18 18:58:54
No these lines are not affected by your change. J
amp
2016/02/20 02:00:55
Done.
| |
| 419 prefs::kMediaRouterFirstRunFlowAcknowledged, true); | 466 prefs::kMediaRouterFirstRunFlowAcknowledged, true); |
| 420 | 467 |
| 421 #if defined(GOOGLE_CHROME_BUILD) | 468 #if defined(GOOGLE_CHROME_BUILD) |
| 422 bool enabled_cloud_services = false; | 469 bool enabled_cloud_services = false; |
| 423 // Do not set the relevant cloud services prefs if the user was not shown | 470 // Do not set the relevant cloud services prefs if the user was not shown |
| 424 // the cloud services prompt. | 471 // the cloud services prompt. |
| 425 if (!args->GetBoolean(0, &enabled_cloud_services)) { | 472 if (!args->GetBoolean(0, &enabled_cloud_services)) { |
| 426 DVLOG(1) << "User was not shown the enable cloud services prompt."; | 473 DVLOG(1) << "User was not shown the enable cloud services prompt."; |
| 427 return; | 474 return; |
| 428 } | 475 } |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 718 first_run_flow_acknowledged); | 765 first_run_flow_acknowledged); |
| 719 first_run_flow_data.SetBoolean("showFirstRunFlowCloudPref", show_cloud_pref); | 766 first_run_flow_data.SetBoolean("showFirstRunFlowCloudPref", show_cloud_pref); |
| 720 web_ui()->CallJavascriptFunction(kSetFirstRunFlowData, first_run_flow_data); | 767 web_ui()->CallJavascriptFunction(kSetFirstRunFlowData, first_run_flow_data); |
| 721 } | 768 } |
| 722 | 769 |
| 723 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { | 770 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { |
| 724 set_web_ui(web_ui); | 771 set_web_ui(web_ui); |
| 725 } | 772 } |
| 726 | 773 |
| 727 } // namespace media_router | 774 } // namespace media_router |
| OLD | NEW |