| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/enrollment_screen_handler.h" | 5 #include "chrome/browser/ui/webui/chromeos/login/enrollment_screen_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/common/system/chromeos/devicetype_utils.h" | 9 #include "ash/common/system/chromeos/devicetype_utils.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/browser_process_platform_part.h" | 18 #include "chrome/browser/browser_process_platform_part.h" |
| 18 #include "chrome/browser/chromeos/login/error_screens_histogram_helper.h" | 19 #include "chrome/browser/chromeos/login/error_screens_histogram_helper.h" |
| 19 #include "chrome/browser/chromeos/login/help_app_launcher.h" | 20 #include "chrome/browser/chromeos/login/help_app_launcher.h" |
| 20 #include "chrome/browser/chromeos/login/helper.h" | |
| 21 #include "chrome/browser/chromeos/login/oobe_screen.h" | 21 #include "chrome/browser/chromeos/login/oobe_screen.h" |
| 22 #include "chrome/browser/chromeos/login/screens/network_error.h" | 22 #include "chrome/browser/chromeos/login/screens/network_error.h" |
| 23 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 23 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 24 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" | 24 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
| 25 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" | 25 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" |
| 26 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" | 26 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" |
| 27 #include "chrome/grit/generated_resources.h" | 27 #include "chrome/grit/generated_resources.h" |
| 28 #include "chromeos/dbus/auth_policy_client.h" | 28 #include "chromeos/login/auth/authpolicy_login_helper.h" |
| 29 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 30 #include "chromeos/network/network_state.h" | 29 #include "chromeos/network/network_state.h" |
| 31 #include "chromeos/network/network_state_handler.h" | 30 #include "chromeos/network/network_state_handler.h" |
| 32 #include "components/login/localized_values_builder.h" | 31 #include "components/login/localized_values_builder.h" |
| 33 #include "components/policy/core/browser/cloud/message_util.h" | 32 #include "components/policy/core/browser/cloud/message_util.h" |
| 34 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
| 35 #include "google_apis/gaia/gaia_auth_util.h" | 34 #include "google_apis/gaia/gaia_auth_util.h" |
| 36 #include "google_apis/gaia/gaia_urls.h" | 35 #include "google_apis/gaia/gaia_urls.h" |
| 37 #include "google_apis/gaia/google_service_auth_error.h" | 36 #include "google_apis/gaia/google_service_auth_error.h" |
| 38 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
| 39 | 38 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 void EnrollmentScreenHandler::Hide() { | 172 void EnrollmentScreenHandler::Hide() { |
| 174 } | 173 } |
| 175 | 174 |
| 176 void EnrollmentScreenHandler::ShowSigninScreen() { | 175 void EnrollmentScreenHandler::ShowSigninScreen() { |
| 177 observe_network_failure_ = true; | 176 observe_network_failure_ = true; |
| 178 ShowStep(kEnrollmentStepSignin); | 177 ShowStep(kEnrollmentStepSignin); |
| 179 } | 178 } |
| 180 | 179 |
| 181 void EnrollmentScreenHandler::ShowAdJoin() { | 180 void EnrollmentScreenHandler::ShowAdJoin() { |
| 182 observe_network_failure_ = false; | 181 observe_network_failure_ = false; |
| 182 if (!authpolicy_login_helper_) |
| 183 authpolicy_login_helper_ = base::MakeUnique<AuthPolicyLoginHelper>(); |
| 183 ShowStep(kEnrollmentStepAdJoin); | 184 ShowStep(kEnrollmentStepAdJoin); |
| 184 } | 185 } |
| 185 | 186 |
| 186 void EnrollmentScreenHandler::ShowAttributePromptScreen( | 187 void EnrollmentScreenHandler::ShowAttributePromptScreen( |
| 187 const std::string& asset_id, | 188 const std::string& asset_id, |
| 188 const std::string& location) { | 189 const std::string& location) { |
| 189 CallJS("showAttributePromptStep", asset_id, location); | 190 CallJS("showAttributePromptStep", asset_id, location); |
| 190 } | 191 } |
| 191 | 192 |
| 192 void EnrollmentScreenHandler::ShowEnrollmentSpinnerScreen() { | 193 void EnrollmentScreenHandler::ShowEnrollmentSpinnerScreen() { |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 } | 509 } |
| 509 | 510 |
| 510 // EnrollmentScreenHandler, private ----------------------------- | 511 // EnrollmentScreenHandler, private ----------------------------- |
| 511 void EnrollmentScreenHandler::HandleToggleFakeEnrollment() { | 512 void EnrollmentScreenHandler::HandleToggleFakeEnrollment() { |
| 512 policy::PolicyOAuth2TokenFetcher::UseFakeTokensForTesting(); | 513 policy::PolicyOAuth2TokenFetcher::UseFakeTokensForTesting(); |
| 513 } | 514 } |
| 514 | 515 |
| 515 void EnrollmentScreenHandler::HandleClose(const std::string& reason) { | 516 void EnrollmentScreenHandler::HandleClose(const std::string& reason) { |
| 516 DCHECK(controller_); | 517 DCHECK(controller_); |
| 517 | 518 |
| 518 if (reason == "cancel") | 519 if (reason == "cancel") { |
| 520 if (authpolicy_login_helper_) |
| 521 authpolicy_login_helper_->CancelRequestsAndRestart(); |
| 519 controller_->OnCancel(); | 522 controller_->OnCancel(); |
| 520 else if (reason == "done") | 523 } else if (reason == "done") { |
| 521 controller_->OnConfirmationClosed(); | 524 controller_->OnConfirmationClosed(); |
| 522 else | 525 } else { |
| 523 NOTREACHED(); | 526 NOTREACHED(); |
| 527 } |
| 524 } | 528 } |
| 525 | 529 |
| 526 void EnrollmentScreenHandler::HandleCompleteLogin( | 530 void EnrollmentScreenHandler::HandleCompleteLogin( |
| 527 const std::string& user, | 531 const std::string& user, |
| 528 const std::string& auth_code) { | 532 const std::string& auth_code) { |
| 529 observe_network_failure_ = false; | 533 observe_network_failure_ = false; |
| 530 DCHECK(controller_); | 534 DCHECK(controller_); |
| 531 controller_->OnLoginDone(gaia::SanitizeEmail(user), auth_code); | 535 controller_->OnLoginDone(gaia::SanitizeEmail(user), auth_code); |
| 532 } | 536 } |
| 533 | 537 |
| 534 void EnrollmentScreenHandler::HandleAdCompleteLogin( | 538 void EnrollmentScreenHandler::HandleAdCompleteLogin( |
| 535 const std::string& machine_name, | 539 const std::string& machine_name, |
| 536 const std::string& user_name, | 540 const std::string& user_name, |
| 537 const std::string& password) { | 541 const std::string& password) { |
| 538 observe_network_failure_ = false; | 542 observe_network_failure_ = false; |
| 539 DCHECK(controller_); | 543 DCHECK(controller_); |
| 540 login::GetPipeReadEnd( | 544 DCHECK(authpolicy_login_helper_); |
| 541 password, | 545 authpolicy_login_helper_->JoinAdDomain( |
| 542 base::Bind(&EnrollmentScreenHandler::OnPasswordPipeReady, | 546 machine_name, user_name, password, |
| 543 weak_ptr_factory_.GetWeakPtr(), machine_name, user_name)); | 547 base::BindOnce(&EnrollmentScreenHandler::HandleAdDomainJoin, |
| 544 } | 548 weak_ptr_factory_.GetWeakPtr(), machine_name, user_name)); |
| 545 | |
| 546 void EnrollmentScreenHandler::OnPasswordPipeReady( | |
| 547 const std::string& machine_name, | |
| 548 const std::string& user_name, | |
| 549 base::ScopedFD password_fd) { | |
| 550 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 551 if (!password_fd.is_valid()) { | |
| 552 DLOG(ERROR) << "Got invalid password_fd"; | |
| 553 return; | |
| 554 } | |
| 555 chromeos::AuthPolicyClient* client = | |
| 556 chromeos::DBusThreadManager::Get()->GetAuthPolicyClient(); | |
| 557 | |
| 558 client->JoinAdDomain(machine_name, | |
| 559 user_name, | |
| 560 password_fd.get(), | |
| 561 base::Bind(&EnrollmentScreenHandler::HandleAdDomainJoin, | |
| 562 weak_ptr_factory_.GetWeakPtr(), | |
| 563 machine_name, | |
| 564 user_name)); | |
| 565 } | 549 } |
| 566 | 550 |
| 567 void EnrollmentScreenHandler::HandleAdDomainJoin( | 551 void EnrollmentScreenHandler::HandleAdDomainJoin( |
| 568 const std::string& machine_name, | 552 const std::string& machine_name, |
| 569 const std::string& user_name, | 553 const std::string& user_name, |
| 570 authpolicy::ErrorType code) { | 554 authpolicy::ErrorType code) { |
| 571 switch (code) { | 555 switch (code) { |
| 572 case authpolicy::ERROR_NONE: | 556 case authpolicy::ERROR_NONE: |
| 573 ShowEnrollmentSpinnerScreen(); | 557 ShowEnrollmentSpinnerScreen(); |
| 574 controller_->OnAdJoined(gaia::ExtractDomainName(user_name)); | 558 controller_->OnAdJoined(gaia::ExtractDomainName(user_name)); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 | 670 |
| 687 ShowScreenWithData(OobeScreen::SCREEN_OOBE_ENROLLMENT, &screen_data); | 671 ShowScreenWithData(OobeScreen::SCREEN_OOBE_ENROLLMENT, &screen_data); |
| 688 if (first_show_) { | 672 if (first_show_) { |
| 689 first_show_ = false; | 673 first_show_ = false; |
| 690 UpdateStateInternal(NetworkError::ERROR_REASON_UPDATE, true); | 674 UpdateStateInternal(NetworkError::ERROR_REASON_UPDATE, true); |
| 691 } | 675 } |
| 692 histogram_helper_->OnScreenShow(); | 676 histogram_helper_->OnScreenShow(); |
| 693 } | 677 } |
| 694 | 678 |
| 695 } // namespace chromeos | 679 } // namespace chromeos |
| OLD | NEW |