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

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

Issue 1680743006: [Media Router] Show user email in header if cloud sink is present. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Overhauled implementation to use observers and fire events as well as push down logic into native m… Created 4 years, 10 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 const char kReportSinkCount[] = "reportSinkCount"; 56 const char kReportSinkCount[] = "reportSinkCount";
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 kSetIssue[] = "media_router.ui.setIssue"; 65 const char kSetIssue[] = "media_router.ui.setIssue";
66 const char kSetSinkList[] = "media_router.ui.setSinkList"; 66 const char kSetSinkListAndIdentityVisibility[] =
67 "media_router.ui.setSinkListAndIdentityVisibility";
67 const char kSetRouteList[] = "media_router.ui.setRouteList"; 68 const char kSetRouteList[] = "media_router.ui.setRouteList";
68 const char kSetCastModeList[] = "media_router.ui.setCastModeList"; 69 const char kSetCastModeList[] = "media_router.ui.setCastModeList";
69 const char kUpdateMaxHeight[] = "media_router.ui.updateMaxHeight"; 70 const char kUpdateMaxHeight[] = "media_router.ui.updateMaxHeight";
70 const char kWindowOpen[] = "window.open"; 71 const char kWindowOpen[] = "window.open";
71 72
72 scoped_ptr<base::ListValue> SinksToValue( 73 scoped_ptr<base::DictionaryValue> SinksToValue(
73 const std::vector<MediaSinkWithCastModes>& sinks) { 74 const std::vector<MediaSinkWithCastModes>& sinks) {
75
76 Profile* profile = Profile::FromWebUI(web_ui());
77 SigninManagerBase* signin_manager =
78 SigninManagerFactory::GetForProfile(profile);
79 std::string userDomain =
80 signin_manager->GetAuthenticatedAccountInfo().hosted_domain;
81
82 scoped_ptr<base::DictionaryValue> sink_list_and_identity(
83 new base::DictionaryValue);
74 scoped_ptr<base::ListValue> value(new base::ListValue); 84 scoped_ptr<base::ListValue> value(new base::ListValue);
85 int identityVisibility = 0;
75 86
76 for (const MediaSinkWithCastModes& sink_with_cast_modes : sinks) { 87 for (const MediaSinkWithCastModes& sink_with_cast_modes : sinks) {
77 scoped_ptr<base::DictionaryValue> sink_val(new base::DictionaryValue); 88 scoped_ptr<base::DictionaryValue> sink_val(new base::DictionaryValue);
78 89
79 const MediaSink& sink = sink_with_cast_modes.sink; 90 const MediaSink& sink = sink_with_cast_modes.sink;
80 sink_val->SetString("id", sink.id()); 91 sink_val->SetString("id", sink.id());
81 sink_val->SetString("name", sink.name()); 92 sink_val->SetString("name", sink.name());
82 sink_val->SetInteger("iconType", sink.icon_type()); 93 sink_val->SetInteger("iconType", sink.icon_type());
83 if (!sink.description().empty()) 94 if (!sink.description().empty())
84 sink_val->SetString("description", sink.description()); 95 sink_val->SetString("description", sink.description());
85 if (!sink.domain().empty()) 96 if (!sink.domain().empty()) {
86 sink_val->SetString("domain", sink.domain()); 97 std::string domain = sink.domain();
98 // Convert default domains to user domain
99 if (sink.domain() == "default")
100 domain = userDomain;
101
102 sink_val->SetString("domain", domain);
103
104 // Don't reset visibliity to 1 if it was already 2
apacible 2016/02/13 08:13:02 nit: "visibility" misspelled
amp 2016/02/16 22:19:12 Done.
105 if (identityVisibility == 0)
apacible 2016/02/13 08:13:02 Declare identity visibility options as enums here
amp 2016/02/16 22:19:12 Done. I declared a local enum to this class but d
106 identityVisibility = 1;
107 if (domain != userDomain)
108 identityVisibility = 2;
109 }
87 110
88 int cast_mode_bits = 0; 111 int cast_mode_bits = 0;
89 for (MediaCastMode cast_mode : sink_with_cast_modes.cast_modes) 112 for (MediaCastMode cast_mode : sink_with_cast_modes.cast_modes)
90 cast_mode_bits |= cast_mode; 113 cast_mode_bits |= cast_mode;
91 114
92 sink_val->SetInteger("castModes", cast_mode_bits); 115 sink_val->SetInteger("castModes", cast_mode_bits);
93 value->Append(sink_val.release()); 116 value->Append(sink_val.release());
94 } 117 }
95 118
96 return value; 119 sink_list_and_identity->Set("sinks", sinks);
120 sink_list_and_identity->SetInteger("identityVisibility",
121 identityVisibility);
122 return sink_list_and_identity;
97 } 123 }
98 124
99 scoped_ptr<base::DictionaryValue> RouteToValue( 125 scoped_ptr<base::DictionaryValue> RouteToValue(
100 const MediaRoute& route, bool canJoin, const std::string& extension_id) { 126 const MediaRoute& route, bool canJoin, const std::string& extension_id) {
101 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue); 127 scoped_ptr<base::DictionaryValue> dictionary(new base::DictionaryValue);
102 dictionary->SetString("id", route.media_route_id()); 128 dictionary->SetString("id", route.media_route_id());
103 dictionary->SetString("sinkId", route.media_sink_id()); 129 dictionary->SetString("sinkId", route.media_sink_id());
104 dictionary->SetString("description", route.description()); 130 dictionary->SetString("description", route.description());
105 dictionary->SetBoolean("isLocal", route.is_local()); 131 dictionary->SetBoolean("isLocal", route.is_local());
106 dictionary->SetBoolean("canJoin", canJoin); 132 dictionary->SetBoolean("canJoin", canJoin);
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 media_router_ui_(media_router_ui) { 226 media_router_ui_(media_router_ui) {
201 DCHECK(media_router_ui_); 227 DCHECK(media_router_ui_);
202 } 228 }
203 229
204 MediaRouterWebUIMessageHandler::~MediaRouterWebUIMessageHandler() { 230 MediaRouterWebUIMessageHandler::~MediaRouterWebUIMessageHandler() {
205 } 231 }
206 232
207 void MediaRouterWebUIMessageHandler::UpdateSinks( 233 void MediaRouterWebUIMessageHandler::UpdateSinks(
208 const std::vector<MediaSinkWithCastModes>& sinks) { 234 const std::vector<MediaSinkWithCastModes>& sinks) {
209 DVLOG(2) << "UpdateSinks"; 235 DVLOG(2) << "UpdateSinks";
210 scoped_ptr<base::ListValue> sinks_val(SinksToValue(sinks)); 236 scoped_ptr<base::DictionaryValue> sinks_val(SinksToValue(sinks));
211 web_ui()->CallJavascriptFunction(kSetSinkList, *sinks_val); 237 web_ui()->CallJavascriptFunction(
238 kSetSinkListAndIdentityVisibility, *sinks_val);
212 } 239 }
213 240
214 void MediaRouterWebUIMessageHandler::UpdateRoutes( 241 void MediaRouterWebUIMessageHandler::UpdateRoutes(
215 const std::vector<MediaRoute>& routes, 242 const std::vector<MediaRoute>& routes,
216 const std::vector<MediaRoute::Id>& joinable_route_ids) { 243 const std::vector<MediaRoute::Id>& joinable_route_ids) {
217 scoped_ptr<base::ListValue> routes_val(RoutesToValue(routes, 244 scoped_ptr<base::ListValue> routes_val(RoutesToValue(routes,
218 joinable_route_ids, 245 joinable_route_ids,
219 media_router_ui_->GetRouteProviderExtensionId())); 246 media_router_ui_->GetRouteProviderExtensionId()));
220 web_ui()->CallJavascriptFunction(kSetRouteList, *routes_val); 247 web_ui()->CallJavascriptFunction(kSetRouteList, *routes_val);
221 } 248 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 // "Casting to a Hangout from Chrome" Chromecast help center page. 369 // "Casting to a Hangout from Chrome" Chromecast help center page.
343 initial_data.SetString("firstRunFlowCloudPrefLearnMoreUrl", 370 initial_data.SetString("firstRunFlowCloudPrefLearnMoreUrl",
344 base::StringPrintf(kHelpPageUrlPrefix, 6320939)); 371 base::StringPrintf(kHelpPageUrlPrefix, 6320939));
345 #endif // defined(GOOGLE_CHROME_BUILD) 372 #endif // defined(GOOGLE_CHROME_BUILD)
346 // General Chromecast learn more page. 373 // General Chromecast learn more page.
347 initial_data.SetString("firstRunFlowLearnMoreUrl", kCastLearnMorePageUrl); 374 initial_data.SetString("firstRunFlowLearnMoreUrl", kCastLearnMorePageUrl);
348 // "No Cast devices found?" Chromecast help center page. 375 // "No Cast devices found?" Chromecast help center page.
349 initial_data.SetString("deviceMissingUrl", 376 initial_data.SetString("deviceMissingUrl",
350 base::StringPrintf(kHelpPageUrlPrefix, 3249268)); 377 base::StringPrintf(kHelpPageUrlPrefix, 3249268));
351 378
352 scoped_ptr<base::ListValue> sinks(SinksToValue(media_router_ui_->sinks())); 379 scoped_ptr<base::DictionaryValue> sinks_with_identity(SinksToValue(
353 initial_data.Set("sinks", sinks.release()); 380 media_router_ui_->sinks()));
381 const base::ListValue* sinks_val = nullptr;
382 sinks_with_identity->GetList("sinks", &sinks_val);
383 int identity_visibility = -1;
384 sinks_with_identity->GetInteger("identityVisibility", &identity_visibility);
385 initial_data.Set("sinks", &sinks_val);
386 initial_data.SetInteger("identityVisibility", identity_visibility);
354 387
355 scoped_ptr<base::ListValue> routes(RoutesToValue(media_router_ui_->routes(), 388 scoped_ptr<base::ListValue> routes(RoutesToValue(media_router_ui_->routes(),
356 media_router_ui_->joinable_route_ids(), 389 media_router_ui_->joinable_route_ids(),
357 media_router_ui_->GetRouteProviderExtensionId())); 390 media_router_ui_->GetRouteProviderExtensionId()));
358 initial_data.Set("routes", routes.release()); 391 initial_data.Set("routes", routes.release());
359 392
360 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes(); 393 const std::set<MediaCastMode> cast_modes = media_router_ui_->cast_modes();
361 scoped_ptr<base::ListValue> cast_modes_list( 394 scoped_ptr<base::ListValue> cast_modes_list(
362 CastModesToValue(cast_modes, 395 CastModesToValue(cast_modes,
363 media_router_ui_->GetPresentationRequestSourceName())); 396 media_router_ui_->GetPresentationRequestSourceName()));
364 initial_data.Set("castModes", cast_modes_list.release()); 397 initial_data.Set("castModes", cast_modes_list.release());
365 398
366 Profile* profile = Profile::FromWebUI(web_ui()); 399 Profile* profile = Profile::FromWebUI(web_ui());
367 400
368 bool first_run_flow_acknowledged = 401 bool first_run_flow_acknowledged =
369 profile->GetPrefs()->GetBoolean( 402 profile->GetPrefs()->GetBoolean(
370 prefs::kMediaRouterFirstRunFlowAcknowledged); 403 prefs::kMediaRouterFirstRunFlowAcknowledged);
371 initial_data.SetBoolean("wasFirstRunFlowAcknowledged", 404 initial_data.SetBoolean("wasFirstRunFlowAcknowledged",
372 first_run_flow_acknowledged); 405 first_run_flow_acknowledged);
373 bool show_cloud_pref = false; 406 bool show_cloud_pref = false;
374 #if defined(GOOGLE_CHROME_BUILD) 407 #if defined(GOOGLE_CHROME_BUILD)
375 // Cloud services preference is shown if user is logged in and has sync 408 // Cloud services preference is shown if user is logged in and has sync
376 // enabled. If the user enables sync after acknowledging the first run flow, 409 // enabled. If the user enables sync after acknowledging the first run flow,
377 // this is treated as the user opting into Google services, including cloud 410 // this is treated as the user opting into Google services, including cloud
378 // services, if the browser is a Chrome branded build. 411 // services, if the browser is a Chrome branded build.
412 SigninManagerBase* signin_manager =
413 SigninManagerFactory::GetForProfile(profile);
379 if (!profile->GetPrefs()->GetBoolean( 414 if (!profile->GetPrefs()->GetBoolean(
380 prefs::kMediaRouterCloudServicesPrefSet) && 415 prefs::kMediaRouterCloudServicesPrefSet) &&
381 profile->IsSyncAllowed()) { 416 profile->IsSyncAllowed()) {
382 SigninManagerBase* signin_manager =
383 SigninManagerFactory::GetForProfile(profile);
384 show_cloud_pref = signin_manager && signin_manager->IsAuthenticated() && 417 show_cloud_pref = signin_manager && signin_manager->IsAuthenticated() &&
385 ProfileSyncServiceFactory::GetForProfile(profile)->IsSyncActive(); 418 ProfileSyncServiceFactory::GetForProfile(profile)->IsSyncActive();
386 } 419 }
420 initial_data.SetString("userEmail",
421 signin_manager->GetAuthenticatedAccountInfo().email);
422 initial_data.SetString("userDomain",
423 signin_manager->GetAuthenticatedAccountInfo().hosted_domain);
387 #endif // defined(GOOGLE_CHROME_BUILD) 424 #endif // defined(GOOGLE_CHROME_BUILD)
388 initial_data.SetBoolean("showFirstRunFlowCloudPref", show_cloud_pref); 425 initial_data.SetBoolean("showFirstRunFlowCloudPref", show_cloud_pref);
389 426
390 web_ui()->CallJavascriptFunction(kSetInitialData, initial_data); 427 web_ui()->CallJavascriptFunction(kSetInitialData, initial_data);
391 media_router_ui_->UIInitialized(); 428 media_router_ui_->UIInitialized();
392 } 429 }
393 430
394 void MediaRouterWebUIMessageHandler::OnCreateRoute( 431 void MediaRouterWebUIMessageHandler::OnCreateRoute(
395 const base::ListValue* args) { 432 const base::ListValue* args) {
396 DVLOG(1) << "OnCreateRoute"; 433 DVLOG(1) << "OnCreateRoute";
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 // Do nothing; no other issue action types require any other action. 730 // Do nothing; no other issue action types require any other action.
694 return true; 731 return true;
695 } 732 }
696 } 733 }
697 734
698 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) { 735 void MediaRouterWebUIMessageHandler::SetWebUIForTest(content::WebUI* web_ui) {
699 set_web_ui(web_ui); 736 set_web_ui(web_ui);
700 } 737 }
701 738
702 } // namespace media_router 739 } // namespace media_router
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698