| 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/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/browser_process_platform_part.h" | 17 #include "chrome/browser/browser_process_platform_part.h" |
| 18 #include "chrome/browser/chromeos/login/error_screens_histogram_helper.h" | 18 #include "chrome/browser/chromeos/login/error_screens_histogram_helper.h" |
| 19 #include "chrome/browser/chromeos/login/help_app_launcher.h" | 19 #include "chrome/browser/chromeos/login/help_app_launcher.h" |
| 20 #include "chrome/browser/chromeos/login/helper.h" |
| 20 #include "chrome/browser/chromeos/login/screens/network_error.h" | 21 #include "chrome/browser/chromeos/login/screens/network_error.h" |
| 21 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 22 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 22 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" | 23 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
| 23 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" | 24 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" |
| 24 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" | 25 #include "chrome/browser/chromeos/policy/policy_oauth2_token_fetcher.h" |
| 25 #include "chrome/browser/ui/webui/chromeos/login/oobe_screen.h" | 26 #include "chrome/browser/ui/webui/chromeos/login/oobe_screen.h" |
| 26 #include "chrome/grit/generated_resources.h" | 27 #include "chrome/grit/generated_resources.h" |
| 27 #include "chromeos/dbus/auth_policy_client.h" | 28 #include "chromeos/dbus/auth_policy_client.h" |
| 28 #include "chromeos/dbus/dbus_thread_manager.h" | 29 #include "chromeos/dbus/dbus_thread_manager.h" |
| 29 #include "chromeos/network/network_state.h" | 30 #include "chromeos/network/network_state.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 } | 101 } |
| 101 | 102 |
| 102 | 103 |
| 103 // Returns the enterprise domain after enrollment, or an empty string. | 104 // Returns the enterprise domain after enrollment, or an empty string. |
| 104 std::string GetEnterpriseDomain() { | 105 std::string GetEnterpriseDomain() { |
| 105 policy::BrowserPolicyConnectorChromeOS* connector = | 106 policy::BrowserPolicyConnectorChromeOS* connector = |
| 106 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 107 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 107 return connector->GetEnterpriseDomain(); | 108 return connector->GetEnterpriseDomain(); |
| 108 } | 109 } |
| 109 | 110 |
| 110 // Returns file descriptor of a pipe, open for reading. Pipe keeps user | |
| 111 // password, which can be read from the returned descriptor. | |
| 112 base::ScopedFD GetPasswordReadPipe(const std::string& password) { | |
| 113 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | |
| 114 int pipe_fds[2]; | |
| 115 if (!base::CreateLocalNonBlockingPipe(pipe_fds)) { | |
| 116 LOG(ERROR) << "Failed to create pipe"; | |
| 117 return base::ScopedFD(); | |
| 118 } | |
| 119 base::ScopedFD pipe_read_end(pipe_fds[0]); | |
| 120 base::ScopedFD pipe_write_end(pipe_fds[1]); | |
| 121 | |
| 122 if (!base::WriteFileDescriptor(pipe_write_end.get(), | |
| 123 password.c_str(), | |
| 124 password.size())) { | |
| 125 LOG(ERROR) << "Failed to write to pipe"; | |
| 126 return base::ScopedFD(); | |
| 127 } | |
| 128 return pipe_read_end; | |
| 129 } | |
| 130 | |
| 131 } // namespace | 111 } // namespace |
| 132 | 112 |
| 133 // EnrollmentScreenHandler, public ------------------------------ | 113 // EnrollmentScreenHandler, public ------------------------------ |
| 134 | 114 |
| 135 EnrollmentScreenHandler::EnrollmentScreenHandler( | 115 EnrollmentScreenHandler::EnrollmentScreenHandler( |
| 136 const scoped_refptr<NetworkStateInformer>& network_state_informer, | 116 const scoped_refptr<NetworkStateInformer>& network_state_informer, |
| 137 NetworkErrorModel* network_error_model) | 117 NetworkErrorModel* network_error_model) |
| 138 : BaseScreenHandler(kJsScreenPath), | 118 : BaseScreenHandler(kJsScreenPath), |
| 139 controller_(NULL), | 119 controller_(NULL), |
| 140 show_on_init_(false), | 120 show_on_init_(false), |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 DCHECK(controller_); | 527 DCHECK(controller_); |
| 548 controller_->OnLoginDone(gaia::SanitizeEmail(user), auth_code); | 528 controller_->OnLoginDone(gaia::SanitizeEmail(user), auth_code); |
| 549 } | 529 } |
| 550 | 530 |
| 551 void EnrollmentScreenHandler::HandleAdCompleteLogin( | 531 void EnrollmentScreenHandler::HandleAdCompleteLogin( |
| 552 const std::string& machine_name, | 532 const std::string& machine_name, |
| 553 const std::string& user_name, | 533 const std::string& user_name, |
| 554 const std::string& password) { | 534 const std::string& password) { |
| 555 observe_network_failure_ = false; | 535 observe_network_failure_ = false; |
| 556 DCHECK(controller_); | 536 DCHECK(controller_); |
| 557 base::PostTaskAndReplyWithResult( | 537 login::GetPipeReadEnd( |
| 558 content::BrowserThread::GetBlockingPool(), FROM_HERE, | 538 password, |
| 559 base::Bind(&GetPasswordReadPipe, password), | |
| 560 base::Bind(&EnrollmentScreenHandler::OnPasswordPipeReady, | 539 base::Bind(&EnrollmentScreenHandler::OnPasswordPipeReady, |
| 561 weak_ptr_factory_.GetWeakPtr(), machine_name, user_name)); | 540 weak_ptr_factory_.GetWeakPtr(), machine_name, user_name)); |
| 562 } | 541 } |
| 563 | 542 |
| 564 void EnrollmentScreenHandler::OnPasswordPipeReady( | 543 void EnrollmentScreenHandler::OnPasswordPipeReady( |
| 565 const std::string& machine_name, | 544 const std::string& machine_name, |
| 566 const std::string& user_name, | 545 const std::string& user_name, |
| 567 base::ScopedFD password_fd) { | 546 base::ScopedFD password_fd) { |
| 568 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 547 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 569 if (!password_fd.is_valid()) { | 548 if (!password_fd.is_valid()) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 | 634 |
| 656 ShowScreenWithData(OobeScreen::SCREEN_OOBE_ENROLLMENT, &screen_data); | 635 ShowScreenWithData(OobeScreen::SCREEN_OOBE_ENROLLMENT, &screen_data); |
| 657 if (first_show_) { | 636 if (first_show_) { |
| 658 first_show_ = false; | 637 first_show_ = false; |
| 659 UpdateStateInternal(NetworkError::ERROR_REASON_UPDATE, true); | 638 UpdateStateInternal(NetworkError::ERROR_REASON_UPDATE, true); |
| 660 } | 639 } |
| 661 histogram_helper_->OnScreenShow(); | 640 histogram_helper_->OnScreenShow(); |
| 662 } | 641 } |
| 663 | 642 |
| 664 } // namespace chromeos | 643 } // namespace chromeos |
| OLD | NEW |