| 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" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/browser_shutdown.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" | 13 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" |
| 15 #include "chrome/browser/chromeos/login/users/user_manager.h" | 14 #include "chrome/browser/chromeos/login/users/user_manager.h" |
| 16 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 15 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 17 #include "chrome/browser/chromeos/settings/cros_settings.h" | 16 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 18 #include "chrome/browser/io_thread.h" | 17 #include "chrome/browser/io_thread.h" |
| 19 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | 18 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
| 19 #include "chrome/browser/ui/webui/signin/inline_login_ui.h" |
| 20 #include "chromeos/chromeos_switches.h" | 20 #include "chromeos/chromeos_switches.h" |
| 21 #include "chromeos/settings/cros_settings_names.h" | 21 #include "chromeos/settings/cros_settings_names.h" |
| 22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 23 #include "content/public/browser/render_frame_host.h" | 23 #include "content/public/browser/render_frame_host.h" |
| 24 #include "google_apis/gaia/gaia_auth_util.h" | 24 #include "google_apis/gaia/gaia_auth_util.h" |
| 25 #include "google_apis/gaia/gaia_switches.h" | 25 #include "google_apis/gaia/gaia_switches.h" |
| 26 #include "google_apis/gaia/gaia_urls.h" | 26 #include "google_apis/gaia/gaia_urls.h" |
| 27 #include "grit/chromium_strings.h" | 27 #include "grit/chromium_strings.h" |
| 28 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
| 30 | 30 |
| 31 using content::BrowserThread; | 31 using content::BrowserThread; |
| 32 | 32 |
| 33 namespace chromeos { | 33 namespace chromeos { |
| 34 | 34 |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 const char kJsScreenPath[] = "login.GaiaSigninScreen"; | 37 const char kJsScreenPath[] = "login.GaiaSigninScreen"; |
| 38 const char kAuthIframeParentName[] = "signin-frame"; |
| 39 const char kAuthIframeParentOrigin[] = |
| 40 "chrome-extension://mfffpogegjflfpflabcdkioaeobkgjik/"; |
| 38 | 41 |
| 39 void UpdateAuthParams(base::DictionaryValue* params, bool has_users) { | 42 void UpdateAuthParams(base::DictionaryValue* params, bool has_users) { |
| 40 CrosSettings* cros_settings = CrosSettings::Get(); | 43 CrosSettings* cros_settings = CrosSettings::Get(); |
| 41 bool allow_new_user = true; | 44 bool allow_new_user = true; |
| 42 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); | 45 cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); |
| 43 bool allow_guest = true; | 46 bool allow_guest = true; |
| 44 cros_settings->GetBoolean(kAccountsPrefAllowGuest, &allow_guest); | 47 cros_settings->GetBoolean(kAccountsPrefAllowGuest, &allow_guest); |
| 45 // Account creation depends on Guest sign-in (http://crosbug.com/24570). | 48 // Account creation depends on Guest sign-in (http://crosbug.com/24570). |
| 46 params->SetBoolean("createAccount", allow_new_user && allow_guest); | 49 params->SetBoolean("createAccount", allow_new_user && allow_guest); |
| 47 params->SetBoolean("guestSignin", allow_guest); | 50 params->SetBoolean("guestSignin", allow_guest); |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 | 324 |
| 322 void GaiaScreenHandler::HandleGaiaUIReady() { | 325 void GaiaScreenHandler::HandleGaiaUIReady() { |
| 323 if (focus_stolen_) { | 326 if (focus_stolen_) { |
| 324 // Set focus to the Gaia page. | 327 // Set focus to the Gaia page. |
| 325 // TODO(altimofeev): temporary solution, until focus parameters are | 328 // TODO(altimofeev): temporary solution, until focus parameters are |
| 326 // implemented on the Gaia side. | 329 // implemented on the Gaia side. |
| 327 // Do this only once. Any subsequent call would relod GAIA frame. | 330 // Do this only once. Any subsequent call would relod GAIA frame. |
| 328 focus_stolen_ = false; | 331 focus_stolen_ = false; |
| 329 const char code[] = | 332 const char code[] = |
| 330 "if (typeof gWindowOnLoad != 'undefined') gWindowOnLoad();"; | 333 "if (typeof gWindowOnLoad != 'undefined') gWindowOnLoad();"; |
| 331 content::RenderFrameHost* frame = | 334 content::RenderFrameHost* frame = InlineLoginUI::GetAuthIframe( |
| 332 LoginDisplayHostImpl::GetGaiaAuthIframe(web_ui()->GetWebContents()); | 335 web_ui()->GetWebContents(), |
| 336 GURL(kAuthIframeParentOrigin), |
| 337 kAuthIframeParentName); |
| 333 frame->ExecuteJavaScript(base::ASCIIToUTF16(code)); | 338 frame->ExecuteJavaScript(base::ASCIIToUTF16(code)); |
| 334 } | 339 } |
| 335 if (gaia_silent_load_) { | 340 if (gaia_silent_load_) { |
| 336 focus_stolen_ = true; | 341 focus_stolen_ = true; |
| 337 // Prevent focus stealing by the Gaia page. | 342 // Prevent focus stealing by the Gaia page. |
| 338 // TODO(altimofeev): temporary solution, until focus parameters are | 343 // TODO(altimofeev): temporary solution, until focus parameters are |
| 339 // implemented on the Gaia side. | 344 // implemented on the Gaia side. |
| 340 const char code[] = | 345 const char code[] = |
| 341 "var gWindowOnLoad = window.onload; " | 346 "var gWindowOnLoad = window.onload; " |
| 342 "window.onload=function() {};"; | 347 "window.onload=function() {};"; |
| 343 content::RenderFrameHost* frame = | 348 content::RenderFrameHost* frame = InlineLoginUI::GetAuthIframe( |
| 344 LoginDisplayHostImpl::GetGaiaAuthIframe(web_ui()->GetWebContents()); | 349 web_ui()->GetWebContents(), |
| 350 GURL(kAuthIframeParentOrigin), |
| 351 kAuthIframeParentName); |
| 345 frame->ExecuteJavaScript(base::ASCIIToUTF16(code)); | 352 frame->ExecuteJavaScript(base::ASCIIToUTF16(code)); |
| 346 | 353 |
| 347 // As we could miss and window.onload could already be called, restore | 354 // As we could miss and window.onload could already be called, restore |
| 348 // focus to current pod (see crbug/175243). | 355 // focus to current pod (see crbug/175243). |
| 349 DCHECK(signin_screen_handler_); | 356 DCHECK(signin_screen_handler_); |
| 350 signin_screen_handler_->RefocusCurrentPod(); | 357 signin_screen_handler_->RefocusCurrentPod(); |
| 351 } | 358 } |
| 352 HandleFrameLoadingCompleted(0); | 359 HandleFrameLoadingCompleted(0); |
| 353 | 360 |
| 354 if (test_expects_complete_login_) | 361 if (test_expects_complete_login_) |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 } | 430 } |
| 424 | 431 |
| 425 void GaiaScreenHandler::SubmitLoginFormForTest() { | 432 void GaiaScreenHandler::SubmitLoginFormForTest() { |
| 426 VLOG(2) << "Submit login form for test, user=" << test_user_; | 433 VLOG(2) << "Submit login form for test, user=" << test_user_; |
| 427 | 434 |
| 428 std::string code; | 435 std::string code; |
| 429 code += "document.getElementById('Email').value = '" + test_user_ + "';"; | 436 code += "document.getElementById('Email').value = '" + test_user_ + "';"; |
| 430 code += "document.getElementById('Passwd').value = '" + test_pass_ + "';"; | 437 code += "document.getElementById('Passwd').value = '" + test_pass_ + "';"; |
| 431 code += "document.getElementById('signIn').click();"; | 438 code += "document.getElementById('signIn').click();"; |
| 432 | 439 |
| 433 content::RenderFrameHost* frame = | 440 content::RenderFrameHost* frame = InlineLoginUI::GetAuthIframe( |
| 434 LoginDisplayHostImpl::GetGaiaAuthIframe(web_ui()->GetWebContents()); | 441 web_ui()->GetWebContents(), |
| 442 GURL(kAuthIframeParentOrigin), |
| 443 kAuthIframeParentName); |
| 435 frame->ExecuteJavaScript(base::ASCIIToUTF16(code)); | 444 frame->ExecuteJavaScript(base::ASCIIToUTF16(code)); |
| 436 | 445 |
| 437 // Test properties are cleared in HandleCompleteLogin because the form | 446 // Test properties are cleared in HandleCompleteLogin because the form |
| 438 // submission might fail and login will not be attempted after reloading | 447 // submission might fail and login will not be attempted after reloading |
| 439 // if they are cleared here. | 448 // if they are cleared here. |
| 440 } | 449 } |
| 441 | 450 |
| 442 void GaiaScreenHandler::SetSAMLPrincipalsAPIUsed(bool api_used) { | 451 void GaiaScreenHandler::SetSAMLPrincipalsAPIUsed(bool api_used) { |
| 443 using_saml_api_ = api_used; | 452 using_saml_api_ = api_used; |
| 444 UMA_HISTOGRAM_BOOLEAN("ChromeOS.SAML.APIUsed", api_used); | 453 UMA_HISTOGRAM_BOOLEAN("ChromeOS.SAML.APIUsed", api_used); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 | 547 |
| 539 SigninScreenHandlerDelegate* GaiaScreenHandler::Delegate() { | 548 SigninScreenHandlerDelegate* GaiaScreenHandler::Delegate() { |
| 540 DCHECK(signin_screen_handler_); | 549 DCHECK(signin_screen_handler_); |
| 541 return signin_screen_handler_->delegate_; | 550 return signin_screen_handler_->delegate_; |
| 542 } | 551 } |
| 543 | 552 |
| 544 void GaiaScreenHandler::SetSigninScreenHandler(SigninScreenHandler* handler) { | 553 void GaiaScreenHandler::SetSigninScreenHandler(SigninScreenHandler* handler) { |
| 545 signin_screen_handler_ = handler; | 554 signin_screen_handler_ = handler; |
| 546 } | 555 } |
| 547 } // namespace chromeos | 556 } // namespace chromeos |
| OLD | NEW |