| OLD | NEW |
| 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | |
| 9 #include "base/strings/utf_string_conversions.h" | |
| 10 #include "base/values.h" | 8 #include "base/values.h" |
| 11 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/browser_shutdown.h" | |
| 13 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | |
| 14 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" | 10 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" |
| 15 #include "chrome/browser/chromeos/login/users/user_manager.h" | 11 #include "chrome/browser/chromeos/login/users/user_manager.h" |
| 16 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
| 17 #include "chrome/browser/chromeos/settings/cros_settings.h" | 12 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 18 #include "chrome/browser/io_thread.h" | |
| 19 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | 13 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
| 20 #include "chromeos/chromeos_switches.h" | 14 #include "chromeos/chromeos_switches.h" |
| 21 #include "chromeos/settings/cros_settings_names.h" | 15 #include "chromeos/settings/cros_settings_names.h" |
| 22 #include "content/public/browser/browser_thread.h" | |
| 23 #include "content/public/browser/render_frame_host.h" | |
| 24 #include "google_apis/gaia/gaia_auth_util.h" | |
| 25 #include "google_apis/gaia/gaia_switches.h" | 16 #include "google_apis/gaia/gaia_switches.h" |
| 26 #include "google_apis/gaia/gaia_urls.h" | 17 #include "google_apis/gaia/gaia_urls.h" |
| 27 #include "grit/chromium_strings.h" | 18 #include "grit/chromium_strings.h" |
| 28 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 30 | 21 |
| 31 using content::BrowserThread; | |
| 32 | |
| 33 namespace chromeos { | 22 namespace chromeos { |
| 34 | 23 |
| 35 namespace { | 24 namespace { |
| 36 | 25 |
| 37 const char kJsScreenPath[] = "login.GaiaSigninScreen"; | 26 const char kJsScreenPath[] = "login.GaiaSigninScreen"; |
| 38 | 27 |
| 39 void UpdateAuthParams(base::DictionaryValue* params, bool has_users) { | 28 void UpdateAuthParams(base::DictionaryValue* params, bool has_users) { |
| 40 CrosSettings* cros_settings = CrosSettings::Get(); | 29 CrosSettings* cros_settings = CrosSettings::Get(); |
| 41 bool allow_new_user = true; | 30 bool allow_new_user = true; |
| 42 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); | 31 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 73 | 62 |
| 74 // Now check whether we're in multi-profiles user adding scenario and | 63 // Now check whether we're in multi-profiles user adding scenario and |
| 75 // disable GAIA right panel features if that's the case. | 64 // disable GAIA right panel features if that's the case. |
| 76 if (UserAddingScreen::Get()->IsRunning()) { | 65 if (UserAddingScreen::Get()->IsRunning()) { |
| 77 params->SetBoolean("createAccount", false); | 66 params->SetBoolean("createAccount", false); |
| 78 params->SetBoolean("guestSignin", false); | 67 params->SetBoolean("guestSignin", false); |
| 79 params->SetBoolean("managedUsersEnabled", false); | 68 params->SetBoolean("managedUsersEnabled", false); |
| 80 } | 69 } |
| 81 } | 70 } |
| 82 | 71 |
| 83 void RecordSAMLScrapingVerificationResultInHistogram(bool success) { | |
| 84 UMA_HISTOGRAM_BOOLEAN("ChromeOS.SAML.Scraping.VerificationResult", success); | |
| 85 } | |
| 86 | |
| 87 // The Task posted to PostTaskAndReply in StartClearingDnsCache on the IO | |
| 88 // thread. | |
| 89 void ClearDnsCache(IOThread* io_thread) { | |
| 90 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 91 if (browser_shutdown::IsTryingToQuit()) | |
| 92 return; | |
| 93 | |
| 94 io_thread->ClearHostCache(); | |
| 95 } | |
| 96 | |
| 97 } // namespace | 72 } // namespace |
| 98 | 73 |
| 99 GaiaContext::GaiaContext() | 74 GaiaContext::GaiaContext() |
| 100 : force_reload(false), | 75 : force_reload(false), |
| 101 is_local(false), | 76 is_local(false), |
| 102 password_changed(false), | 77 password_changed(false), |
| 103 show_users(false), | 78 show_users(false), |
| 104 use_offline(false), | 79 use_offline(false), |
| 105 has_users(false) {} | 80 has_users(false) {} |
| 106 | 81 |
| 107 GaiaScreenHandler::GaiaScreenHandler( | 82 GaiaScreenHandler::GaiaScreenHandler( |
| 108 const scoped_refptr<NetworkStateInformer>& network_state_informer) | 83 const scoped_refptr<NetworkStateInformer>& network_state_informer) |
| 109 : BaseScreenHandler(kJsScreenPath), | 84 : BaseScreenHandler(kJsScreenPath), |
| 110 frame_state_(FRAME_STATE_UNKNOWN), | 85 frame_state_(FRAME_STATE_UNKNOWN), |
| 111 frame_error_(net::OK), | 86 frame_error_(net::OK), |
| 112 network_state_informer_(network_state_informer), | 87 network_state_informer_(network_state_informer), |
| 113 dns_cleared_(false), | 88 signin_screen_handler_(NULL) { |
| 114 dns_clear_task_running_(false), | |
| 115 cookies_cleared_(false), | |
| 116 focus_stolen_(false), | |
| 117 gaia_silent_load_(false), | |
| 118 using_saml_api_(false), | |
| 119 test_expects_complete_login_(false), | |
| 120 signin_screen_handler_(NULL), | |
| 121 weak_factory_(this) { | |
| 122 DCHECK(network_state_informer_.get()); | 89 DCHECK(network_state_informer_.get()); |
| 123 } | 90 } |
| 124 | 91 |
| 125 GaiaScreenHandler::~GaiaScreenHandler() { | 92 GaiaScreenHandler::~GaiaScreenHandler() {} |
| 126 } | |
| 127 | 93 |
| 128 void GaiaScreenHandler::LoadGaia(const GaiaContext& context) { | 94 void GaiaScreenHandler::LoadGaia(const GaiaContext& context) { |
| 95 LOG(WARNING) << "LoadGaia() call."; |
| 96 |
| 129 base::DictionaryValue params; | 97 base::DictionaryValue params; |
| 130 | 98 |
| 131 params.SetBoolean("forceReload", context.force_reload); | 99 params.SetBoolean("forceReload", context.force_reload); |
| 132 params.SetBoolean("isLocal", context.is_local); | 100 params.SetBoolean("isLocal", context.is_local); |
| 133 params.SetBoolean("passwordChanged", context.password_changed); | 101 params.SetBoolean("passwordChanged", context.password_changed); |
| 134 params.SetBoolean("isShowUsers", context.show_users); | 102 params.SetBoolean("isShowUsers", context.show_users); |
| 135 params.SetBoolean("useOffline", context.use_offline); | 103 params.SetBoolean("useOffline", context.use_offline); |
| 136 params.SetString("email", context.email); | 104 params.SetString("email", context.email); |
| 137 | 105 |
| 138 UpdateAuthParams(¶ms, context.has_users); | 106 UpdateAuthParams(¶ms, context.has_users); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 builder->Add("signinScreenTitle", IDS_SIGNIN_SCREEN_TITLE); | 170 builder->Add("signinScreenTitle", IDS_SIGNIN_SCREEN_TITLE); |
| 203 builder->Add("signinScreenPasswordChanged", | 171 builder->Add("signinScreenPasswordChanged", |
| 204 IDS_SIGNIN_SCREEN_PASSWORD_CHANGED); | 172 IDS_SIGNIN_SCREEN_PASSWORD_CHANGED); |
| 205 builder->Add("createAccount", IDS_CREATE_ACCOUNT_HTML); | 173 builder->Add("createAccount", IDS_CREATE_ACCOUNT_HTML); |
| 206 builder->Add("guestSignin", IDS_BROWSE_WITHOUT_SIGNING_IN_HTML); | 174 builder->Add("guestSignin", IDS_BROWSE_WITHOUT_SIGNING_IN_HTML); |
| 207 builder->Add("createLocallyManagedUser", | 175 builder->Add("createLocallyManagedUser", |
| 208 IDS_CREATE_LOCALLY_MANAGED_USER_HTML); | 176 IDS_CREATE_LOCALLY_MANAGED_USER_HTML); |
| 209 builder->Add("createManagedUserFeatureName", | 177 builder->Add("createManagedUserFeatureName", |
| 210 IDS_CREATE_LOCALLY_MANAGED_USER_FEATURE_NAME); | 178 IDS_CREATE_LOCALLY_MANAGED_USER_FEATURE_NAME); |
| 211 | 179 |
| 212 // Strings used by the SAML fatal error dialog. | 180 // Strings used by the fatal error dialog. |
| 213 builder->Add("fatalErrorMessageNoEmail", IDS_LOGIN_FATAL_ERROR_NO_EMAIL); | 181 builder->Add("fatalErrorMessageNoEmail", IDS_LOGIN_FATAL_ERROR_NO_EMAIL); |
| 214 builder->Add("fatalErrorMessageNoPassword", | 182 builder->Add("fatalErrorMessageNoPassword", |
| 215 IDS_LOGIN_FATAL_ERROR_NO_PASSWORD); | 183 IDS_LOGIN_FATAL_ERROR_NO_PASSWORD); |
| 216 builder->Add("fatalErrorMessageVerificationFailed", | 184 builder->Add("fatalErrorMessageVerificationFailed", |
| 217 IDS_LOGIN_FATAL_ERROR_PASSWORD_VERIFICATION); | 185 IDS_LOGIN_FATAL_ERROR_PASSWORD_VERIFICATION); |
| 218 builder->Add("fatalErrorMessageInsecureURL", | 186 builder->Add("fatalErrorMessageInsecureURL", |
| 219 IDS_LOGIN_FATAL_ERROR_TEXT_INSECURE_URL); | 187 IDS_LOGIN_FATAL_ERROR_TEXT_INSECURE_URL); |
| 220 builder->Add("fatalErrorInstructions", IDS_LOGIN_FATAL_ERROR_INSTRUCTIONS); | 188 builder->Add("fatalErrorInstructions", IDS_LOGIN_FATAL_ERROR_INSTRUCTIONS); |
| 221 builder->Add("fatalErrorDismissButton", IDS_OK); | 189 builder->Add("fatalErrorDismissButton", IDS_OK); |
| 222 } | 190 } |
| 223 | 191 |
| 224 void GaiaScreenHandler::Initialize() { | 192 void GaiaScreenHandler::Initialize() {} |
| 225 } | |
| 226 | 193 |
| 227 void GaiaScreenHandler::RegisterMessages() { | 194 void GaiaScreenHandler::RegisterMessages() { |
| 228 AddCallback("frameLoadingCompleted", | 195 AddCallback("frameLoadingCompleted", |
| 229 &GaiaScreenHandler::HandleFrameLoadingCompleted); | 196 &GaiaScreenHandler::HandleFrameLoadingCompleted); |
| 230 AddCallback("completeLogin", &GaiaScreenHandler::HandleCompleteLogin); | |
| 231 AddCallback("completeAuthentication", | |
| 232 &GaiaScreenHandler::HandleCompleteAuthentication); | |
| 233 AddCallback("usingSAMLAPI", &GaiaScreenHandler::HandleUsingSAMLAPI); | |
| 234 AddCallback("scrapedPasswordCount", | |
| 235 &GaiaScreenHandler::HandleScrapedPasswordCount); | |
| 236 AddCallback("scrapedPasswordVerificationFailed", | |
| 237 &GaiaScreenHandler::HandleScrapedPasswordVerificationFailed); | |
| 238 AddCallback("loginWebuiReady", &GaiaScreenHandler::HandleGaiaUIReady); | |
| 239 } | 197 } |
| 240 | 198 |
| 241 void GaiaScreenHandler::HandleFrameLoadingCompleted(int status) { | 199 void GaiaScreenHandler::HandleFrameLoadingCompleted(int status) { |
| 242 const net::Error frame_error = static_cast<net::Error>(-status); | 200 const net::Error frame_error = static_cast<net::Error>(-status); |
| 243 if (frame_error == net::ERR_ABORTED) { | 201 if (frame_error == net::ERR_ABORTED) { |
| 244 LOG(WARNING) << "Ignoring Gaia frame error: " << frame_error; | 202 LOG(WARNING) << "Ignoring Gaia frame error: " << frame_error; |
| 245 return; | 203 return; |
| 246 } | 204 } |
| 247 frame_error_ = frame_error; | 205 frame_error_ = frame_error; |
| 248 if (frame_error == net::OK) { | 206 if (frame_error == net::OK) { |
| 249 VLOG(1) << "Gaia is loaded"; | 207 VLOG(1) << "Gaia is loaded"; |
| 250 frame_state_ = FRAME_STATE_LOADED; | 208 frame_state_ = FRAME_STATE_LOADED; |
| 251 } else { | 209 } else { |
| 252 LOG(WARNING) << "Gaia frame error: " << frame_error_; | 210 LOG(WARNING) << "Gaia frame error: " << frame_error_; |
| 253 frame_state_ = FRAME_STATE_ERROR; | 211 frame_state_ = FRAME_STATE_ERROR; |
| 254 } | 212 } |
| 255 | 213 |
| 256 if (network_state_informer_->state() != NetworkStateInformer::ONLINE) | 214 if (network_state_informer_->state() != NetworkStateInformer::ONLINE) |
| 257 return; | 215 return; |
| 258 if (frame_state_ == FRAME_STATE_LOADED) | 216 if (frame_state_ == FRAME_STATE_LOADED) |
| 259 UpdateState(ErrorScreenActor::ERROR_REASON_UPDATE); | 217 UpdateState(ErrorScreenActor::ERROR_REASON_UPDATE); |
| 260 else if (frame_state_ == FRAME_STATE_ERROR) | 218 else if (frame_state_ == FRAME_STATE_ERROR) |
| 261 UpdateState(ErrorScreenActor::ERROR_REASON_FRAME_ERROR); | 219 UpdateState(ErrorScreenActor::ERROR_REASON_FRAME_ERROR); |
| 262 } | 220 } |
| 263 | 221 |
| 264 void GaiaScreenHandler::HandleCompleteAuthentication( | |
| 265 const std::string& email, | |
| 266 const std::string& password, | |
| 267 const std::string& auth_code) { | |
| 268 if (!Delegate()) | |
| 269 return; | |
| 270 Delegate()->SetDisplayEmail(gaia::SanitizeEmail(email)); | |
| 271 UserContext user_context(email); | |
| 272 user_context.SetKey(Key(password)); | |
| 273 user_context.SetAuthCode(auth_code); | |
| 274 Delegate()->CompleteLogin(user_context); | |
| 275 } | |
| 276 | |
| 277 void GaiaScreenHandler::HandleCompleteLogin(const std::string& typed_email, | |
| 278 const std::string& password, | |
| 279 bool using_saml) { | |
| 280 if (!Delegate()) | |
| 281 return; | |
| 282 | |
| 283 if (using_saml && !using_saml_api_) | |
| 284 RecordSAMLScrapingVerificationResultInHistogram(true); | |
| 285 | |
| 286 const std::string sanitized_email = gaia::SanitizeEmail(typed_email); | |
| 287 Delegate()->SetDisplayEmail(sanitized_email); | |
| 288 UserContext user_context(sanitized_email); | |
| 289 user_context.SetKey(Key(password)); | |
| 290 user_context.SetAuthFlow(using_saml | |
| 291 ? UserContext::AUTH_FLOW_GAIA_WITH_SAML | |
| 292 : UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML); | |
| 293 Delegate()->CompleteLogin(user_context); | |
| 294 | |
| 295 if (test_expects_complete_login_) { | |
| 296 VLOG(2) << "Complete test login for " << typed_email | |
| 297 << ", requested=" << test_user_; | |
| 298 | |
| 299 test_expects_complete_login_ = false; | |
| 300 test_user_.clear(); | |
| 301 test_pass_.clear(); | |
| 302 } | |
| 303 } | |
| 304 | |
| 305 void GaiaScreenHandler::HandleUsingSAMLAPI() { | |
| 306 SetSAMLPrincipalsAPIUsed(true); | |
| 307 } | |
| 308 | |
| 309 void GaiaScreenHandler::HandleScrapedPasswordCount(int password_count) { | |
| 310 SetSAMLPrincipalsAPIUsed(false); | |
| 311 // Use a histogram that has 11 buckets, one for each of the values in [0, 9] | |
| 312 // and an overflow bucket at the end. | |
| 313 UMA_HISTOGRAM_ENUMERATION( | |
| 314 "ChromeOS.SAML.Scraping.PasswordCount", std::min(password_count, 10), 11); | |
| 315 if (password_count == 0) | |
| 316 HandleScrapedPasswordVerificationFailed(); | |
| 317 } | |
| 318 | |
| 319 void GaiaScreenHandler::HandleScrapedPasswordVerificationFailed() { | |
| 320 RecordSAMLScrapingVerificationResultInHistogram(false); | |
| 321 } | |
| 322 | |
| 323 void GaiaScreenHandler::HandleGaiaUIReady() { | |
| 324 if (focus_stolen_) { | |
| 325 // Set focus to the Gaia page. | |
| 326 // TODO(altimofeev): temporary solution, until focus parameters are | |
| 327 // implemented on the Gaia side. | |
| 328 // Do this only once. Any subsequent call would relod GAIA frame. | |
| 329 focus_stolen_ = false; | |
| 330 const char code[] = | |
| 331 "if (typeof gWindowOnLoad != 'undefined') gWindowOnLoad();"; | |
| 332 content::RenderFrameHost* frame = | |
| 333 LoginDisplayHostImpl::GetGaiaAuthIframe(web_ui()->GetWebContents()); | |
| 334 frame->ExecuteJavaScript(base::ASCIIToUTF16(code)); | |
| 335 } | |
| 336 if (gaia_silent_load_) { | |
| 337 focus_stolen_ = true; | |
| 338 // Prevent focus stealing by the Gaia page. | |
| 339 // TODO(altimofeev): temporary solution, until focus parameters are | |
| 340 // implemented on the Gaia side. | |
| 341 const char code[] = | |
| 342 "var gWindowOnLoad = window.onload; " | |
| 343 "window.onload=function() {};"; | |
| 344 content::RenderFrameHost* frame = | |
| 345 LoginDisplayHostImpl::GetGaiaAuthIframe(web_ui()->GetWebContents()); | |
| 346 frame->ExecuteJavaScript(base::ASCIIToUTF16(code)); | |
| 347 | |
| 348 // As we could miss and window.onload could already be called, restore | |
| 349 // focus to current pod (see crbug/175243). | |
| 350 DCHECK(signin_screen_handler_); | |
| 351 signin_screen_handler_->RefocusCurrentPod(); | |
| 352 } | |
| 353 HandleFrameLoadingCompleted(0); | |
| 354 | |
| 355 if (test_expects_complete_login_) | |
| 356 SubmitLoginFormForTest(); | |
| 357 } | |
| 358 | |
| 359 void GaiaScreenHandler::PopulateEmail(const std::string& user_id) { | |
| 360 populated_email_ = user_id; | |
| 361 } | |
| 362 | |
| 363 void GaiaScreenHandler::PasswordChangedFor(const std::string& user_id) { | |
| 364 password_changed_for_.insert(user_id); | |
| 365 } | |
| 366 | |
| 367 void GaiaScreenHandler::StartClearingDnsCache() { | |
| 368 if (dns_clear_task_running_ || !g_browser_process->io_thread()) | |
| 369 return; | |
| 370 | |
| 371 dns_cleared_ = false; | |
| 372 BrowserThread::PostTaskAndReply( | |
| 373 BrowserThread::IO, | |
| 374 FROM_HERE, | |
| 375 base::Bind(&ClearDnsCache, g_browser_process->io_thread()), | |
| 376 base::Bind(&GaiaScreenHandler::OnDnsCleared, weak_factory_.GetWeakPtr())); | |
| 377 dns_clear_task_running_ = true; | |
| 378 } | |
| 379 | |
| 380 void GaiaScreenHandler::OnDnsCleared() { | |
| 381 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 382 dns_clear_task_running_ = false; | |
| 383 dns_cleared_ = true; | |
| 384 ShowGaiaScreenIfReady(); | |
| 385 } | |
| 386 | |
| 387 void GaiaScreenHandler::StartClearingCookies( | |
| 388 const base::Closure& on_clear_callback) { | |
| 389 cookies_cleared_ = false; | |
| 390 ProfileHelper* profile_helper = | |
| 391 g_browser_process->platform_part()->profile_helper(); | |
| 392 LOG_ASSERT(Profile::FromWebUI(web_ui()) == | |
| 393 profile_helper->GetSigninProfile()); | |
| 394 profile_helper->ClearSigninProfile( | |
| 395 base::Bind(&GaiaScreenHandler::OnCookiesCleared, | |
| 396 weak_factory_.GetWeakPtr(), | |
| 397 on_clear_callback)); | |
| 398 } | |
| 399 | |
| 400 void GaiaScreenHandler::OnCookiesCleared( | |
| 401 const base::Closure& on_clear_callback) { | |
| 402 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 403 cookies_cleared_ = true; | |
| 404 on_clear_callback.Run(); | |
| 405 } | |
| 406 | |
| 407 void GaiaScreenHandler::ShowSigninScreenForCreds(const std::string& username, | |
| 408 const std::string& password) { | |
| 409 VLOG(2) << "ShowSigninScreenForCreds for user " << username | |
| 410 << ", frame_state=" << FrameState(); | |
| 411 | |
| 412 test_user_ = username; | |
| 413 test_pass_ = password; | |
| 414 test_expects_complete_login_ = true; | |
| 415 | |
| 416 // Submit login form for test if gaia is ready. If gaia is loading, login | |
| 417 // will be attempted in HandleLoginWebuiReady after gaia is ready. Otherwise, | |
| 418 // reload gaia then follow the loading case. | |
| 419 if (FrameState() == GaiaScreenHandler::FRAME_STATE_LOADED) | |
| 420 SubmitLoginFormForTest(); | |
| 421 else if (FrameState() != GaiaScreenHandler::FRAME_STATE_LOADING) { | |
| 422 DCHECK(signin_screen_handler_); | |
| 423 signin_screen_handler_->OnShowAddUser(); | |
| 424 } | |
| 425 } | |
| 426 | |
| 427 void GaiaScreenHandler::SubmitLoginFormForTest() { | |
| 428 VLOG(2) << "Submit login form for test, user=" << test_user_; | |
| 429 | |
| 430 std::string code; | |
| 431 code += "document.getElementById('Email').value = '" + test_user_ + "';"; | |
| 432 code += "document.getElementById('Passwd').value = '" + test_pass_ + "';"; | |
| 433 code += "document.getElementById('signIn').click();"; | |
| 434 | |
| 435 content::RenderFrameHost* frame = | |
| 436 LoginDisplayHostImpl::GetGaiaAuthIframe(web_ui()->GetWebContents()); | |
| 437 frame->ExecuteJavaScript(base::ASCIIToUTF16(code)); | |
| 438 | |
| 439 // Test properties are cleared in HandleCompleteLogin because the form | |
| 440 // submission might fail and login will not be attempted after reloading | |
| 441 // if they are cleared here. | |
| 442 } | |
| 443 | |
| 444 void GaiaScreenHandler::SetSAMLPrincipalsAPIUsed(bool api_used) { | |
| 445 using_saml_api_ = api_used; | |
| 446 UMA_HISTOGRAM_BOOLEAN("ChromeOS.SAML.APIUsed", api_used); | |
| 447 } | |
| 448 | |
| 449 void GaiaScreenHandler::ShowGaia() { | |
| 450 if (gaia_silent_load_ && populated_email_.empty()) { | |
| 451 dns_cleared_ = true; | |
| 452 cookies_cleared_ = true; | |
| 453 ShowGaiaScreenIfReady(); | |
| 454 } else { | |
| 455 StartClearingDnsCache(); | |
| 456 StartClearingCookies(base::Bind(&GaiaScreenHandler::ShowGaiaScreenIfReady, | |
| 457 weak_factory_.GetWeakPtr())); | |
| 458 } | |
| 459 } | |
| 460 | |
| 461 void GaiaScreenHandler::ShowGaiaScreenIfReady() { | |
| 462 if (!dns_cleared_ || !cookies_cleared_ || !Delegate()) | |
| 463 return; | |
| 464 | |
| 465 std::string active_network_path = network_state_informer_->network_path(); | |
| 466 if (gaia_silent_load_ && | |
| 467 (network_state_informer_->state() != NetworkStateInformer::ONLINE || | |
| 468 gaia_silent_load_network_ != active_network_path)) { | |
| 469 // Network has changed. Force Gaia reload. | |
| 470 gaia_silent_load_ = false; | |
| 471 // Gaia page will be realoded, so focus isn't stolen anymore. | |
| 472 focus_stolen_ = false; | |
| 473 } | |
| 474 | |
| 475 // Note that LoadAuthExtension clears |populated_email_|. | |
| 476 if (populated_email_.empty()) | |
| 477 Delegate()->LoadSigninWallpaper(); | |
| 478 else | |
| 479 Delegate()->LoadWallpaper(populated_email_); | |
| 480 | |
| 481 // Set Least Recently Used input method for the user. | |
| 482 if (!populated_email_.empty()) | |
| 483 signin_screen_handler_->SetUserInputMethod(populated_email_); | |
| 484 | |
| 485 LoadAuthExtension(!gaia_silent_load_, false, false); | |
| 486 signin_screen_handler_->UpdateUIState( | |
| 487 SigninScreenHandler::UI_STATE_GAIA_SIGNIN, NULL); | |
| 488 | |
| 489 if (gaia_silent_load_) { | |
| 490 // The variable is assigned to false because silently loaded Gaia page was | |
| 491 // used. | |
| 492 gaia_silent_load_ = false; | |
| 493 if (focus_stolen_) | |
| 494 HandleGaiaUIReady(); | |
| 495 } | |
| 496 | |
| 497 signin_screen_handler_->UpdateState(ErrorScreenActor::ERROR_REASON_UPDATE); | |
| 498 } | |
| 499 | |
| 500 void GaiaScreenHandler::MaybePreloadAuthExtension() { | |
| 501 LOG(WARNING) << "MaybePreloadAuthExtension() call."; | |
| 502 | |
| 503 // If cookies clearing was initiated or |dns_clear_task_running_| then auth | |
| 504 // extension showing has already been initiated and preloading is senseless. | |
| 505 if (signin_screen_handler_->ShouldLoadGaia() && | |
| 506 !gaia_silent_load_ && | |
| 507 !cookies_cleared_ && | |
| 508 !dns_clear_task_running_ && | |
| 509 network_state_informer_->state() == NetworkStateInformer::ONLINE) { | |
| 510 gaia_silent_load_ = true; | |
| 511 gaia_silent_load_network_ = network_state_informer_->network_path(); | |
| 512 LoadAuthExtension(true, true, false); | |
| 513 } | |
| 514 } | |
| 515 | |
| 516 void GaiaScreenHandler::LoadAuthExtension(bool force, | |
| 517 bool silent_load, | |
| 518 bool offline) { | |
| 519 GaiaContext context; | |
| 520 context.force_reload = force; | |
| 521 context.is_local = offline; | |
| 522 context.password_changed = !populated_email_.empty() && | |
| 523 password_changed_for_.count(populated_email_); | |
| 524 context.use_offline = offline; | |
| 525 context.email = populated_email_; | |
| 526 if (Delegate()) { | |
| 527 context.show_users = Delegate()->IsShowUsers(); | |
| 528 context.has_users = !Delegate()->GetUsers().empty(); | |
| 529 } | |
| 530 | |
| 531 populated_email_.clear(); | |
| 532 | |
| 533 LoadGaia(context); | |
| 534 } | |
| 535 | |
| 536 void GaiaScreenHandler::UpdateState(ErrorScreenActor::ErrorReason reason) { | 222 void GaiaScreenHandler::UpdateState(ErrorScreenActor::ErrorReason reason) { |
| 537 if (signin_screen_handler_) | 223 if (signin_screen_handler_) |
| 538 signin_screen_handler_->UpdateState(reason); | 224 signin_screen_handler_->UpdateState(reason); |
| 539 } | 225 } |
| 540 | 226 |
| 541 SigninScreenHandlerDelegate* GaiaScreenHandler::Delegate() { | |
| 542 DCHECK(signin_screen_handler_); | |
| 543 return signin_screen_handler_->delegate_; | |
| 544 } | |
| 545 | |
| 546 void GaiaScreenHandler::SetSigninScreenHandler(SigninScreenHandler* handler) { | 227 void GaiaScreenHandler::SetSigninScreenHandler(SigninScreenHandler* handler) { |
| 547 signin_screen_handler_ = handler; | 228 signin_screen_handler_ = handler; |
| 548 } | 229 } |
| 230 |
| 549 } // namespace chromeos | 231 } // namespace chromeos |
| OLD | NEW |