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 const AccountInfo& account_info) { |
| 76 scoped_ptr<base::DictionaryValue> sink_list_and_identity( |
| 77 new base::DictionaryValue); |
| 78 bool show_email = false; |
| 79 bool show_domain = false; |
| 80 std::string user_domain; |
| 81 if (account_info.IsValid()) { |
| 82 user_domain = account_info.hosted_domain; |
| 83 sink_list_and_identity->SetString("userEmail", account_info.email); |
| 84 sink_list_and_identity->SetString("userDomain", user_domain); |
| 85 } |
| 86 |
| 87 scoped_ptr<base::ListValue> sinks_val(new base::ListValue); |
76 | 88 |
77 for (const MediaSinkWithCastModes& sink_with_cast_modes : sinks) { | 89 for (const MediaSinkWithCastModes& sink_with_cast_modes : sinks) { |
78 scoped_ptr<base::DictionaryValue> sink_val(new base::DictionaryValue); | 90 scoped_ptr<base::DictionaryValue> sink_val(new base::DictionaryValue); |
79 | 91 |
80 const MediaSink& sink = sink_with_cast_modes.sink; | 92 const MediaSink& sink = sink_with_cast_modes.sink; |
81 sink_val->SetString("id", sink.id()); | 93 sink_val->SetString("id", sink.id()); |
82 sink_val->SetString("name", sink.name()); | 94 sink_val->SetString("name", sink.name()); |
83 sink_val->SetInteger("iconType", sink.icon_type()); | 95 sink_val->SetInteger("iconType", sink.icon_type()); |
84 if (!sink.description().empty()) | 96 if (!sink.description().empty()) |
85 sink_val->SetString("description", sink.description()); | 97 sink_val->SetString("description", sink.description()); |
86 if (!sink.domain().empty()) | 98 |
87 sink_val->SetString("domain", sink.domain()); | 99 if (!user_domain.empty() && !sink.domain().empty()) { |
| 100 std::string domain = sink.domain(); |
| 101 // Convert default domains to user domain |
| 102 if (sink.domain() == "default") { |
| 103 domain = user_domain; |
| 104 if (domain == "NO_HOSTED_DOMAIN") { |
| 105 // Default domain will be empty for non-dasher accounts. |
| 106 domain.clear(); |
| 107 } |
| 108 } |
| 109 |
| 110 sink_val->SetString("domain", domain); |
| 111 |
| 112 show_email = true; |
| 113 if (!domain.empty() && domain != user_domain) |
| 114 show_domain = true; |
| 115 } |
88 | 116 |
89 int cast_mode_bits = 0; | 117 int cast_mode_bits = 0; |
90 for (MediaCastMode cast_mode : sink_with_cast_modes.cast_modes) | 118 for (MediaCastMode cast_mode : sink_with_cast_modes.cast_modes) |
91 cast_mode_bits |= cast_mode; | 119 cast_mode_bits |= cast_mode; |
92 | 120 |
93 sink_val->SetInteger("castModes", cast_mode_bits); | 121 sink_val->SetInteger("castModes", cast_mode_bits); |
94 value->Append(sink_val.release()); | 122 sinks_val->Append(sink_val.release()); |
95 } | 123 } |
96 | 124 |
97 return value; | 125 sink_list_and_identity->Set("sinks", sinks_val.release()); |
| 126 sink_list_and_identity->SetBoolean("showEmail", show_email); |
| 127 sink_list_and_identity->SetBoolean("showDomain", show_domain); |
| 128 return sink_list_and_identity; |
98 } | 129 } |
99 | 130 |
100 scoped_ptr<base::DictionaryValue> RouteToValue( | 131 scoped_ptr<base::DictionaryValue> RouteToValue( |
101 const MediaRoute& route, bool canJoin, const std::string& extension_id) { | 132 const MediaRoute& route, bool canJoin, const std::string& extension_id) { |
102 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); | 133 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); |
103 dictionary->SetString("id", route.media_route_id()); | 134 dictionary->SetString("id", route.media_route_id()); |
104 dictionary->SetString("sinkId", route.media_sink_id()); | 135 dictionary->SetString("sinkId", route.media_sink_id()); |
105 dictionary->SetString("description", route.description()); | 136 dictionary->SetString("description", route.description()); |
106 dictionary->SetBoolean("isLocal", route.is_local()); | 137 dictionary->SetBoolean("isLocal", route.is_local()); |
107 dictionary->SetBoolean("canJoin", canJoin); | 138 dictionary->SetBoolean("canJoin", canJoin); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 media_router_ui_(media_router_ui) { | 232 media_router_ui_(media_router_ui) { |
202 DCHECK(media_router_ui_); | 233 DCHECK(media_router_ui_); |
203 } | 234 } |
204 | 235 |
205 MediaRouterWebUIMessageHandler::~MediaRouterWebUIMessageHandler() { | 236 MediaRouterWebUIMessageHandler::~MediaRouterWebUIMessageHandler() { |
206 } | 237 } |
207 | 238 |
208 void MediaRouterWebUIMessageHandler::UpdateSinks( | 239 void MediaRouterWebUIMessageHandler::UpdateSinks( |
209 const std::vector<MediaSinkWithCastModes>& sinks) { | 240 const std::vector<MediaSinkWithCastModes>& sinks) { |
210 DVLOG(2) << "UpdateSinks"; | 241 DVLOG(2) << "UpdateSinks"; |
211 scoped_ptr<base::ListValue> sinks_val(SinksToValue(sinks)); | 242 scoped_ptr<base::DictionaryValue> sinks_and_identity_val( |
212 web_ui()->CallJavascriptFunction(kSetSinkList, *sinks_val); | 243 SinksAndIdentityToValue(sinks, GetAccountInfo())); |
| 244 web_ui()->CallJavascriptFunction(kSetSinkListAndIdentity, |
| 245 *sinks_and_identity_val); |
213 } | 246 } |
214 | 247 |
215 void MediaRouterWebUIMessageHandler::UpdateRoutes( | 248 void MediaRouterWebUIMessageHandler::UpdateRoutes( |
216 const std::vector<MediaRoute>& routes, | 249 const std::vector<MediaRoute>& routes, |
217 const std::vector<MediaRoute::Id>& joinable_route_ids) { | 250 const std::vector<MediaRoute::Id>& joinable_route_ids) { |
218 scoped_ptr<base::ListValue> routes_val(RoutesToValue(routes, | 251 scoped_ptr<base::ListValue> routes_val(RoutesToValue(routes, |
219 joinable_route_ids, | 252 joinable_route_ids, |
220 media_router_ui_->GetRouteProviderExtensionId())); | 253 media_router_ui_->GetRouteProviderExtensionId())); |
221 web_ui()->CallJavascriptFunction(kSetRouteList, *routes_val); | 254 web_ui()->CallJavascriptFunction(kSetRouteList, *routes_val); |
222 } | 255 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 void MediaRouterWebUIMessageHandler::OnRequestInitialData( | 369 void MediaRouterWebUIMessageHandler::OnRequestInitialData( |
337 const base::ListValue* args) { | 370 const base::ListValue* args) { |
338 DVLOG(1) << "OnRequestInitialData"; | 371 DVLOG(1) << "OnRequestInitialData"; |
339 media_router_ui_->OnUIInitiallyLoaded(); | 372 media_router_ui_->OnUIInitiallyLoaded(); |
340 base::DictionaryValue initial_data; | 373 base::DictionaryValue initial_data; |
341 | 374 |
342 // "No Cast devices found?" Chromecast help center page. | 375 // "No Cast devices found?" Chromecast help center page. |
343 initial_data.SetString("deviceMissingUrl", | 376 initial_data.SetString("deviceMissingUrl", |
344 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); | 377 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); |
345 | 378 |
346 scoped_ptr<base::ListValue> sinks(SinksToValue(media_router_ui_->sinks())); | 379 scoped_ptr<base::DictionaryValue> sinks_and_identity( |
347 initial_data.Set("sinks", sinks.release()); | 380 SinksAndIdentityToValue(media_router_ui_->sinks(), GetAccountInfo())); |
| 381 initial_data.Set("sinksAndIdentity", sinks_and_identity.release()); |
348 | 382 |
349 scoped_ptr<base::ListValue> routes(RoutesToValue(media_router_ui_->routes(), | 383 scoped_ptr<base::ListValue> routes(RoutesToValue(media_router_ui_->routes(), |
350 media_router_ui_->joinable_route_ids(), | 384 media_router_ui_->joinable_route_ids(), |
351 media_router_ui_->GetRouteProviderExtensionId())); | 385 media_router_ui_->GetRouteProviderExtensionId())); |
352 initial_data.Set("routes", routes.release()); | 386 initial_data.Set("routes", routes.release()); |
353 | 387 |
354 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes(); | 388 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes(); |
355 scoped_ptr<base::ListValue> cast_modes_list( | 389 scoped_ptr<base::ListValue> cast_modes_list( |
356 CastModesToValue(cast_modes, | 390 CastModesToValue(cast_modes, |
357 media_router_ui_->GetPresentationRequestSourceName())); | 391 media_router_ui_->GetPresentationRequestSourceName())); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 | 454 |
421 #if defined(GOOGLE_CHROME_BUILD) | 455 #if defined(GOOGLE_CHROME_BUILD) |
422 bool enabled_cloud_services = false; | 456 bool enabled_cloud_services = false; |
423 // Do not set the relevant cloud services prefs if the user was not shown | 457 // Do not set the relevant cloud services prefs if the user was not shown |
424 // the cloud services prompt. | 458 // the cloud services prompt. |
425 if (!args->GetBoolean(0, &enabled_cloud_services)) { | 459 if (!args->GetBoolean(0, &enabled_cloud_services)) { |
426 DVLOG(1) << "User was not shown the enable cloud services prompt."; | 460 DVLOG(1) << "User was not shown the enable cloud services prompt."; |
427 return; | 461 return; |
428 } | 462 } |
429 | 463 |
430 Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean( | 464 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
431 prefs::kMediaRouterEnableCloudServices, enabled_cloud_services); | 465 pref_service->SetBoolean(prefs::kMediaRouterEnableCloudServices, |
432 Profile::FromWebUI(web_ui())->GetPrefs()->SetBoolean( | 466 enabled_cloud_services); |
433 prefs::kMediaRouterCloudServicesPrefSet, true); | 467 pref_service->SetBoolean(prefs::kMediaRouterCloudServicesPrefSet, true); |
434 #endif // defined(GOOGLE_CHROME_BUILD) | 468 #endif // defined(GOOGLE_CHROME_BUILD) |
435 } | 469 } |
436 | 470 |
437 void MediaRouterWebUIMessageHandler::OnActOnIssue( | 471 void MediaRouterWebUIMessageHandler::OnActOnIssue( |
438 const base::ListValue* args) { | 472 const base::ListValue* args) { |
439 DVLOG(1) << "OnActOnIssue"; | 473 DVLOG(1) << "OnActOnIssue"; |
440 const base::DictionaryValue* args_dict = nullptr; | 474 const base::DictionaryValue* args_dict = nullptr; |
441 Issue::Id issue_id; | 475 Issue::Id issue_id; |
442 int action_type_num = -1; | 476 int action_type_num = -1; |
443 if (!args->GetDictionary(0, &args_dict) || | 477 if (!args->GetDictionary(0, &args_dict) || |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 | 747 |
714 // General Chromecast learn more page. | 748 // General Chromecast learn more page. |
715 first_run_flow_data.SetString("firstRunFlowLearnMoreUrl", | 749 first_run_flow_data.SetString("firstRunFlowLearnMoreUrl", |
716 kCastLearnMorePageUrl); | 750 kCastLearnMorePageUrl); |
717 first_run_flow_data.SetBoolean("wasFirstRunFlowAcknowledged", | 751 first_run_flow_data.SetBoolean("wasFirstRunFlowAcknowledged", |
718 first_run_flow_acknowledged); | 752 first_run_flow_acknowledged); |
719 first_run_flow_data.SetBoolean("showFirstRunFlowCloudPref", show_cloud_pref); | 753 first_run_flow_data.SetBoolean("showFirstRunFlowCloudPref", show_cloud_pref); |
720 web_ui()->CallJavascriptFunction(kSetFirstRunFlowData, first_run_flow_data); | 754 web_ui()->CallJavascriptFunction(kSetFirstRunFlowData, first_run_flow_data); |
721 } | 755 } |
722 | 756 |
| 757 AccountInfo MediaRouterWebUIMessageHandler::GetAccountInfo() { |
| 758 #if defined(GOOGLE_CHROME_BUILD) |
| 759 SigninManagerBase* signin_manager = |
| 760 SigninManagerFactory::GetForProfile(Profile::FromWebUI(web_ui())); |
| 761 return signin_manager->GetAuthenticatedAccountInfo(); |
| 762 #else |
| 763 return AccountInfo(); |
| 764 #endif // defined(GOOGLE_CHROME_BUILD) |
| 765 } |
| 766 |
723 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { | 767 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { |
724 set_web_ui(web_ui); | 768 set_web_ui(web_ui); |
725 } | 769 } |
726 | 770 |
727 } // namespace media_router | 771 } // namespace media_router |
OLD | NEW |