| 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 "ash/common/system/chromeos/devicetype_utils.h" | 7 #include "ash/common/system/chromeos/devicetype_utils.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/guid.h" | 10 #include "base/guid.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/task_scheduler/post_task.h" | 15 #include "base/task_scheduler/post_task.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/browser_shutdown.h" | 18 #include "chrome/browser/browser_shutdown.h" |
| 19 #include "chrome/browser/chromeos/input_method/input_method_util.h" | 19 #include "chrome/browser/chromeos/input_method/input_method_util.h" |
| 20 #include "chrome/browser/chromeos/language_preferences.h" | 20 #include "chrome/browser/chromeos/language_preferences.h" |
| 21 #include "chrome/browser/chromeos/login/helper.h" | |
| 22 #include "chrome/browser/chromeos/login/screens/network_error.h" | 21 #include "chrome/browser/chromeos/login/screens/network_error.h" |
| 23 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" | 22 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" |
| 24 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" | 23 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
| 25 #include "chrome/browser/chromeos/net/network_portal_detector_impl.h" | 24 #include "chrome/browser/chromeos/net/network_portal_detector_impl.h" |
| 26 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 25 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 27 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 26 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
| 28 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 27 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 29 #include "chrome/browser/chromeos/settings/cros_settings.h" | 28 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 30 #include "chrome/browser/io_thread.h" | 29 #include "chrome/browser/io_thread.h" |
| 31 #include "chrome/browser/ui/webui/chromeos/login/enrollment_screen_handler.h" | 30 #include "chrome/browser/ui/webui/chromeos/login/enrollment_screen_handler.h" |
| 32 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | 31 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" |
| 33 #include "chrome/browser/ui/webui/signin/signin_utils.h" | 32 #include "chrome/browser/ui/webui/signin/signin_utils.h" |
| 34 #include "chrome/common/channel_info.h" | 33 #include "chrome/common/channel_info.h" |
| 35 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
| 36 #include "chrome/grit/generated_resources.h" | 35 #include "chrome/grit/generated_resources.h" |
| 37 #include "chromeos/chromeos_switches.h" | 36 #include "chromeos/chromeos_switches.h" |
| 38 #include "chromeos/dbus/auth_policy_client.h" | 37 #include "chromeos/login/auth/authpolicy_login_helper.h" |
| 39 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 40 #include "chromeos/login/auth/user_context.h" | 38 #include "chromeos/login/auth/user_context.h" |
| 41 #include "chromeos/settings/cros_settings_names.h" | 39 #include "chromeos/settings/cros_settings_names.h" |
| 42 #include "chromeos/system/devicetype.h" | 40 #include "chromeos/system/devicetype.h" |
| 43 #include "chromeos/system/version_loader.h" | 41 #include "chromeos/system/version_loader.h" |
| 44 #include "components/login/localized_values_builder.h" | 42 #include "components/login/localized_values_builder.h" |
| 45 #include "components/prefs/pref_service.h" | 43 #include "components/prefs/pref_service.h" |
| 46 #include "components/strings/grit/components_strings.h" | 44 #include "components/strings/grit/components_strings.h" |
| 47 #include "components/user_manager/known_user.h" | 45 #include "components/user_manager/known_user.h" |
| 48 #include "components/user_manager/user_manager.h" | 46 #include "components/user_manager/user_manager.h" |
| 49 #include "components/version_info/version_info.h" | 47 #include "components/version_info/version_info.h" |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 params.SetString("gaiaId", context.gaia_id); | 285 params.SetString("gaiaId", context.gaia_id); |
| 288 params.SetBoolean("readOnlyEmail", true); | 286 params.SetBoolean("readOnlyEmail", true); |
| 289 params.SetString("email", context.email); | 287 params.SetString("email", context.email); |
| 290 params.SetString("gapsCookie", context.gaps_cookie); | 288 params.SetString("gapsCookie", context.gaps_cookie); |
| 291 | 289 |
| 292 UpdateAuthParams(¶ms, IsRestrictiveProxy()); | 290 UpdateAuthParams(¶ms, IsRestrictiveProxy()); |
| 293 | 291 |
| 294 GaiaScreenMode screen_mode = GetGaiaScreenMode(context.email, | 292 GaiaScreenMode screen_mode = GetGaiaScreenMode(context.email, |
| 295 context.use_offline); | 293 context.use_offline); |
| 296 params.SetInteger("screenMode", screen_mode); | 294 params.SetInteger("screenMode", screen_mode); |
| 295 |
| 296 if (screen_mode == GAIA_SCREEN_MODE_AD && !authpolicy_login_helper_) |
| 297 authpolicy_login_helper_ = base::MakeUnique<AuthPolicyLoginHelper>(); |
| 298 |
| 297 if (screen_mode != GAIA_SCREEN_MODE_OFFLINE) { | 299 if (screen_mode != GAIA_SCREEN_MODE_OFFLINE) { |
| 298 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 300 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
| 299 if (!app_locale.empty()) | 301 if (!app_locale.empty()) |
| 300 params.SetString("hl", app_locale); | 302 params.SetString("hl", app_locale); |
| 301 } | 303 } |
| 302 | 304 |
| 303 std::string realm(GetRealm()); | 305 std::string realm(GetRealm()); |
| 304 if (!realm.empty()) { | 306 if (!realm.empty()) { |
| 305 params.SetString("realm", realm); | 307 params.SetString("realm", realm); |
| 306 } | 308 } |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 &GaiaScreenHandler::HandleToggleEasyBootstrap); | 444 &GaiaScreenHandler::HandleToggleEasyBootstrap); |
| 443 AddCallback("identifierEntered", &GaiaScreenHandler::HandleIdentifierEntered); | 445 AddCallback("identifierEntered", &GaiaScreenHandler::HandleIdentifierEntered); |
| 444 AddCallback("updateOfflineLogin", | 446 AddCallback("updateOfflineLogin", |
| 445 &GaiaScreenHandler::set_offline_login_is_active); | 447 &GaiaScreenHandler::set_offline_login_is_active); |
| 446 AddCallback("authExtensionLoaded", | 448 AddCallback("authExtensionLoaded", |
| 447 &GaiaScreenHandler::HandleAuthExtensionLoaded); | 449 &GaiaScreenHandler::HandleAuthExtensionLoaded); |
| 448 AddCallback("completeAdAuthentication", | 450 AddCallback("completeAdAuthentication", |
| 449 &GaiaScreenHandler::HandleCompleteAdAuthentication); | 451 &GaiaScreenHandler::HandleCompleteAdAuthentication); |
| 450 AddCallback("completeAdPasswordChange", | 452 AddCallback("completeAdPasswordChange", |
| 451 &GaiaScreenHandler::HandleCompleteAdPasswordChange); | 453 &GaiaScreenHandler::HandleCompleteAdPasswordChange); |
| 454 AddCallback("cancelAdAuthentication", |
| 455 &GaiaScreenHandler::HandleCancelActiveDirectoryAuth); |
| 452 } | 456 } |
| 453 | 457 |
| 454 void GaiaScreenHandler::OnPortalDetectionCompleted( | 458 void GaiaScreenHandler::OnPortalDetectionCompleted( |
| 455 const NetworkState* network, | 459 const NetworkState* network, |
| 456 const NetworkPortalDetector::CaptivePortalState& state) { | 460 const NetworkPortalDetector::CaptivePortalState& state) { |
| 457 VLOG(1) << "OnPortalDetectionCompleted " | 461 VLOG(1) << "OnPortalDetectionCompleted " |
| 458 << NetworkPortalDetector::CaptivePortalStatusString(state.status); | 462 << NetworkPortalDetector::CaptivePortalStatusString(state.status); |
| 459 | 463 |
| 460 const NetworkPortalDetector::CaptivePortalStatus previous_status = | 464 const NetworkPortalDetector::CaptivePortalStatus previous_status = |
| 461 captive_portal_status_; | 465 captive_portal_status_; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 DLOG(WARNING) << "Unhandled error code: " << error; | 589 DLOG(WARNING) << "Unhandled error code: " << error; |
| 586 LoadAuthExtension(true, false /* offline */); | 590 LoadAuthExtension(true, false /* offline */); |
| 587 } | 591 } |
| 588 } | 592 } |
| 589 | 593 |
| 590 void GaiaScreenHandler::HandleCompleteAdAuthentication( | 594 void GaiaScreenHandler::HandleCompleteAdAuthentication( |
| 591 const std::string& username, | 595 const std::string& username, |
| 592 const std::string& password) { | 596 const std::string& password) { |
| 593 Delegate()->SetDisplayEmail(username); | 597 Delegate()->SetDisplayEmail(username); |
| 594 set_populated_email(username); | 598 set_populated_email(username); |
| 595 | 599 DCHECK(authpolicy_login_helper_); |
| 596 login::GetPipeReadEnd( | 600 authpolicy_login_helper_->AuthenticateUser( |
| 597 password, | 601 username, password, |
| 598 base::Bind(&GaiaScreenHandler::OnPasswordPipeReady, | 602 base::BindOnce(&GaiaScreenHandler::DoAdAuth, weak_factory_.GetWeakPtr(), |
| 599 weak_factory_.GetWeakPtr(), username, Key(password))); | 603 username, Key(password))); |
| 600 } | 604 } |
| 601 | 605 |
| 602 void GaiaScreenHandler::HandleCompleteAdPasswordChange( | 606 void GaiaScreenHandler::HandleCompleteAdPasswordChange( |
| 603 const std::string& username, | 607 const std::string& username, |
| 604 const std::string& old_password, | 608 const std::string& old_password, |
| 605 const std::string& new_password) { | 609 const std::string& new_password) { |
| 606 Delegate()->SetDisplayEmail(username); | 610 Delegate()->SetDisplayEmail(username); |
| 607 set_populated_email(username); | 611 set_populated_email(username); |
| 608 | 612 |
| 609 login::GetPipeReadEnd( | 613 DCHECK(authpolicy_login_helper_); |
| 610 old_password + "\n" + new_password + "\n" + new_password, | 614 authpolicy_login_helper_->AuthenticateUser( |
| 611 base::Bind(&GaiaScreenHandler::OnPasswordPipeReady, | 615 username, old_password + "\n" + new_password + "\n" + new_password, |
| 612 weak_factory_.GetWeakPtr(), username, Key(new_password))); | 616 base::Bind(&GaiaScreenHandler::DoAdAuth, weak_factory_.GetWeakPtr(), |
| 617 username, Key(new_password))); |
| 613 } | 618 } |
| 614 | 619 |
| 615 void GaiaScreenHandler::OnPasswordPipeReady(const std::string& username, | 620 void GaiaScreenHandler::HandleCancelActiveDirectoryAuth() { |
| 616 const Key& key, | 621 DCHECK(authpolicy_login_helper_); |
| 617 base::ScopedFD password_fd) { | 622 authpolicy_login_helper_->CancelRequestsAndRestart(); |
| 618 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 619 if (!password_fd.is_valid()) { | |
| 620 DLOG(ERROR) << "Got invalid password_fd"; | |
| 621 return; | |
| 622 } | |
| 623 chromeos::AuthPolicyClient* client = | |
| 624 chromeos::DBusThreadManager::Get()->GetAuthPolicyClient(); | |
| 625 client->AuthenticateUser( | |
| 626 username, password_fd.get(), | |
| 627 base::Bind(&GaiaScreenHandler::DoAdAuth, weak_factory_.GetWeakPtr(), | |
| 628 username, key)); | |
| 629 } | 623 } |
| 630 | 624 |
| 631 void GaiaScreenHandler::HandleCompleteAuthentication( | 625 void GaiaScreenHandler::HandleCompleteAuthentication( |
| 632 const std::string& gaia_id, | 626 const std::string& gaia_id, |
| 633 const std::string& email, | 627 const std::string& email, |
| 634 const std::string& password, | 628 const std::string& password, |
| 635 const std::string& auth_code, | 629 const std::string& auth_code, |
| 636 bool using_saml, | 630 bool using_saml, |
| 637 const std::string& gaps_cookie) { | 631 const std::string& gaps_cookie) { |
| 638 if (!Delegate()) | 632 if (!Delegate()) |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 SigninScreenHandlerDelegate* GaiaScreenHandler::Delegate() { | 969 SigninScreenHandlerDelegate* GaiaScreenHandler::Delegate() { |
| 976 return signin_screen_handler_->delegate_; | 970 return signin_screen_handler_->delegate_; |
| 977 } | 971 } |
| 978 | 972 |
| 979 bool GaiaScreenHandler::IsRestrictiveProxy() const { | 973 bool GaiaScreenHandler::IsRestrictiveProxy() const { |
| 980 return !disable_restrictive_proxy_check_for_test_ && | 974 return !disable_restrictive_proxy_check_for_test_ && |
| 981 !IsOnline(captive_portal_status_); | 975 !IsOnline(captive_portal_status_); |
| 982 } | 976 } |
| 983 | 977 |
| 984 } // namespace chromeos | 978 } // namespace chromeos |
| OLD | NEW |