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

Side by Side Diff: chrome/browser/ui/webui/chromeos/login/gaia_screen_handler.cc

Issue 1138143002: Pass Device ID in the oauth2/token request. Keep Device ID in local state on Chrome OS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final version. Created 5 years, 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/chromeos/login/gaia_screen_handler.h" 5 #include "chrome/browser/ui/webui/chromeos/login/gaia_screen_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/guid.h" 8 #include "base/guid.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 } 146 }
147 147
148 } // namespace 148 } // namespace
149 149
150 GaiaContext::GaiaContext() 150 GaiaContext::GaiaContext()
151 : force_reload(false), 151 : force_reload(false),
152 is_local(false), 152 is_local(false),
153 password_changed(false), 153 password_changed(false),
154 show_users(false), 154 show_users(false),
155 use_offline(false), 155 use_offline(false),
156 has_users(false), 156 has_users(false) {
157 session_is_ephemeral(false) {
158 } 157 }
159 158
160 GaiaScreenHandler::GaiaScreenHandler( 159 GaiaScreenHandler::GaiaScreenHandler(
161 CoreOobeActor* core_oobe_actor, 160 CoreOobeActor* core_oobe_actor,
162 const scoped_refptr<NetworkStateInformer>& network_state_informer, 161 const scoped_refptr<NetworkStateInformer>& network_state_informer,
163 policy::ConsumerManagementService* consumer_management) 162 policy::ConsumerManagementService* consumer_management)
164 : BaseScreenHandler(kJsScreenPath), 163 : BaseScreenHandler(kJsScreenPath),
165 frame_state_(FRAME_STATE_UNKNOWN), 164 frame_state_(FRAME_STATE_UNKNOWN),
166 frame_error_(net::OK), 165 frame_error_(net::OK),
167 network_state_informer_(network_state_informer), 166 network_state_informer_(network_state_informer),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 210
212 params.SetBoolean("forceReload", context.force_reload); 211 params.SetBoolean("forceReload", context.force_reload);
213 params.SetBoolean("isLocal", context.is_local); 212 params.SetBoolean("isLocal", context.is_local);
214 params.SetBoolean("passwordChanged", context.password_changed); 213 params.SetBoolean("passwordChanged", context.password_changed);
215 params.SetBoolean("isShowUsers", context.show_users); 214 params.SetBoolean("isShowUsers", context.show_users);
216 params.SetBoolean("useOffline", context.use_offline); 215 params.SetBoolean("useOffline", context.use_offline);
217 params.SetString("gaiaId", context.gaia_id); 216 params.SetString("gaiaId", context.gaia_id);
218 params.SetString("email", context.email); 217 params.SetString("email", context.email);
219 params.SetBoolean("isEnrollingConsumerManagement", 218 params.SetBoolean("isEnrollingConsumerManagement",
220 is_enrolling_consumer_management); 219 is_enrolling_consumer_management);
221 if (StartupUtils::IsWebviewSigninEnabled()) {
222 params.SetString("deviceId", context.device_id);
223 params.SetBoolean("sessionIsEphemeral", context.session_is_ephemeral);
224 }
225 220
226 UpdateAuthParams(&params, 221 UpdateAuthParams(&params,
227 context.has_users, 222 context.has_users,
228 is_enrolling_consumer_management); 223 is_enrolling_consumer_management);
229 224
230 if (!context.use_offline) { 225 if (!context.use_offline) {
231 const std::string app_locale = g_browser_process->GetApplicationLocale(); 226 const std::string app_locale = g_browser_process->GetApplicationLocale();
232 if (!app_locale.empty()) 227 if (!app_locale.empty())
233 params.SetString("hl", app_locale); 228 params.SetString("hl", app_locale);
234 } else { 229 } else {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 params.SetString("clientId", 326 params.SetString("clientId",
332 GaiaUrls::GetInstance()->oauth2_chrome_client_id()); 327 GaiaUrls::GetInstance()->oauth2_chrome_client_id());
333 } 328 }
334 329
335 frame_state_ = FRAME_STATE_LOADING; 330 frame_state_ = FRAME_STATE_LOADING;
336 CallJS("loadAuthExtension", params); 331 CallJS("loadAuthExtension", params);
337 } 332 }
338 333
339 void GaiaScreenHandler::UpdateGaia(const GaiaContext& context) { 334 void GaiaScreenHandler::UpdateGaia(const GaiaContext& context) {
340 base::DictionaryValue params; 335 base::DictionaryValue params;
341 if (StartupUtils::IsWebviewSigninEnabled()) {
342 params.SetString("deviceId", context.device_id);
343 }
344 UpdateAuthParams(&params, context.has_users, 336 UpdateAuthParams(&params, context.has_users,
345 context.is_enrolling_consumer_management); 337 context.is_enrolling_consumer_management);
346 CallJS("updateAuthExtension", params); 338 CallJS("updateAuthExtension", params);
347 } 339 }
348 340
349 void GaiaScreenHandler::ReloadGaia(bool force_reload) { 341 void GaiaScreenHandler::ReloadGaia(bool force_reload) {
350 if (frame_state_ == FRAME_STATE_LOADING && !force_reload) { 342 if (frame_state_ == FRAME_STATE_LOADING && !force_reload) {
351 VLOG(1) << "Skipping reloading of Gaia since gaia is loading."; 343 VLOG(1) << "Skipping reloading of Gaia since gaia is loading.";
352 return; 344 return;
353 } 345 }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 NetworkError::ERROR_REASON_FRAME_ERROR; 488 NetworkError::ERROR_REASON_FRAME_ERROR;
497 frame_state_ = FRAME_STATE_ERROR; 489 frame_state_ = FRAME_STATE_ERROR;
498 UpdateState(error_reason); 490 UpdateState(error_reason);
499 } 491 }
500 492
501 void GaiaScreenHandler::HandleCompleteAuthentication( 493 void GaiaScreenHandler::HandleCompleteAuthentication(
502 const std::string& gaia_id, 494 const std::string& gaia_id,
503 const std::string& email, 495 const std::string& email,
504 const std::string& password, 496 const std::string& password,
505 const std::string& auth_code, 497 const std::string& auth_code,
506 bool using_saml, 498 bool using_saml) {
507 const std::string& device_id) {
508 if (!Delegate()) 499 if (!Delegate())
509 return; 500 return;
510 501
511 RecordGAIAFlowTypeHistogram(); 502 RecordGAIAFlowTypeHistogram();
512 503
513 DCHECK(!email.empty()); 504 DCHECK(!email.empty());
514 DCHECK(!gaia_id.empty()); 505 DCHECK(!gaia_id.empty());
515 const std::string sanitized_email = gaia::SanitizeEmail(email); 506 const std::string sanitized_email = gaia::SanitizeEmail(email);
516 Delegate()->SetDisplayEmail(sanitized_email); 507 Delegate()->SetDisplayEmail(sanitized_email);
517 UserContext user_context(sanitized_email); 508 UserContext user_context(sanitized_email);
518 user_context.SetGaiaID(gaia_id); 509 user_context.SetGaiaID(gaia_id);
519 user_context.SetKey(Key(password)); 510 user_context.SetKey(Key(password));
520 user_context.SetAuthCode(auth_code); 511 user_context.SetAuthCode(auth_code);
521 user_context.SetAuthFlow(using_saml 512 user_context.SetAuthFlow(using_saml
522 ? UserContext::AUTH_FLOW_GAIA_WITH_SAML 513 ? UserContext::AUTH_FLOW_GAIA_WITH_SAML
523 : UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); 514 : UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML);
524 user_context.SetDeviceId(device_id);
525 Delegate()->CompleteLogin(user_context); 515 Delegate()->CompleteLogin(user_context);
526 } 516 }
527 517
528 void GaiaScreenHandler::HandleCompleteAuthenticationAuthCodeOnly( 518 void GaiaScreenHandler::HandleCompleteAuthenticationAuthCodeOnly(
529 const std::string& auth_code) { 519 const std::string& auth_code) {
530 if (!Delegate()) 520 if (!Delegate())
531 return; 521 return;
532 522
533 RecordGAIAFlowTypeHistogram(); 523 RecordGAIAFlowTypeHistogram();
534 524
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 585
596 void GaiaScreenHandler::HandleToggleEasyBootstrap() { 586 void GaiaScreenHandler::HandleToggleEasyBootstrap() {
597 use_easy_bootstrap_ = !use_easy_bootstrap_; 587 use_easy_bootstrap_ = !use_easy_bootstrap_;
598 const bool kForceReload = true; 588 const bool kForceReload = true;
599 const bool kSilentLoad = true; 589 const bool kSilentLoad = true;
600 const bool kNoOfflineUI = false; 590 const bool kNoOfflineUI = false;
601 LoadAuthExtension(kForceReload, kSilentLoad, kNoOfflineUI); 591 LoadAuthExtension(kForceReload, kSilentLoad, kNoOfflineUI);
602 } 592 }
603 593
604 void GaiaScreenHandler::HandleAttemptLogin(const std::string& email) { 594 void GaiaScreenHandler::HandleAttemptLogin(const std::string& email) {
605 std::string device_id = 595 // Kept for future use.
achuithb 2015/05/12 23:25:01 What does this comment mean?
dzhioev (left Google) 2015/05/13 00:25:18 I believe we are going to make whitelist checking
606 user_manager::UserManager::Get()->GetKnownUserDeviceId(
607 gaia::CanonicalizeEmail(gaia::SanitizeEmail(email)));
608
609 if (!device_id.empty() && StartupUtils::IsWebviewSigninEnabled()) {
610 base::DictionaryValue params;
611 params.SetString("deviceId", device_id);
612 CallJS("updateDeviceId", params);
613 } else {
614 // Mark current temporary device Id as used.
615 temporary_device_id_ = std::string();
616 }
617 } 596 }
618 597
619 void GaiaScreenHandler::HandleGaiaUIReady() { 598 void GaiaScreenHandler::HandleGaiaUIReady() {
620 if (focus_stolen_) { 599 if (focus_stolen_) {
621 // Set focus to the Gaia page. 600 // Set focus to the Gaia page.
622 // TODO(altimofeev): temporary solution, until focus parameters are 601 // TODO(altimofeev): temporary solution, until focus parameters are
623 // implemented on the Gaia side. 602 // implemented on the Gaia side.
624 // Do this only once. Any subsequent call would relod GAIA frame. 603 // Do this only once. Any subsequent call would relod GAIA frame.
625 focus_stolen_ = false; 604 focus_stolen_ = false;
626 const char code[] = 605 const char code[] =
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 930
952 std::string gaia_id; 931 std::string gaia_id;
953 if (user_manager::UserManager::Get()->FindGaiaID(context.email, &gaia_id)) 932 if (user_manager::UserManager::Get()->FindGaiaID(context.email, &gaia_id))
954 context.gaia_id = gaia_id; 933 context.gaia_id = gaia_id;
955 934
956 if (Delegate()) { 935 if (Delegate()) {
957 context.show_users = Delegate()->IsShowUsers(); 936 context.show_users = Delegate()->IsShowUsers();
958 context.has_users = !Delegate()->GetUsers().empty(); 937 context.has_users = !Delegate()->GetUsers().empty();
959 } 938 }
960 939
961 if (!context.email.empty()) {
962 context.device_id = user_manager::UserManager::Get()->GetKnownUserDeviceId(
963 gaia::CanonicalizeEmail(context.email));
964 }
965
966 if (context.device_id.empty())
967 context.device_id = GetTemporaryDeviceId();
968
969 context.session_is_ephemeral =
970 ChromeUserManager::Get()->AreEphemeralUsersEnabled();
971
972 populated_email_.clear(); 940 populated_email_.clear();
973 941
974 LoadGaia(context); 942 LoadGaia(context);
975 } 943 }
976 944
977 void GaiaScreenHandler::UpdateState(NetworkError::ErrorReason reason) { 945 void GaiaScreenHandler::UpdateState(NetworkError::ErrorReason reason) {
978 if (signin_screen_handler_) 946 if (signin_screen_handler_)
979 signin_screen_handler_->UpdateState(reason); 947 signin_screen_handler_->UpdateState(reason);
980 } 948 }
981 949
982 SigninScreenHandlerDelegate* GaiaScreenHandler::Delegate() { 950 SigninScreenHandlerDelegate* GaiaScreenHandler::Delegate() {
983 DCHECK(signin_screen_handler_); 951 DCHECK(signin_screen_handler_);
984 return signin_screen_handler_->delegate_; 952 return signin_screen_handler_->delegate_;
985 } 953 }
986 954
987 void GaiaScreenHandler::SetSigninScreenHandler(SigninScreenHandler* handler) { 955 void GaiaScreenHandler::SetSigninScreenHandler(SigninScreenHandler* handler) {
988 signin_screen_handler_ = handler; 956 signin_screen_handler_ = handler;
989 } 957 }
990 958
991 std::string GaiaScreenHandler::GetTemporaryDeviceId() {
992 if (temporary_device_id_.empty())
993 temporary_device_id_ = base::GenerateGUID();
994
995 DCHECK(!temporary_device_id_.empty());
996 return temporary_device_id_;
997 }
998
999 } // namespace chromeos 959 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698