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