| 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 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 DCHECK(controller_); | 532 DCHECK(controller_); |
| 553 controller_->OnLoginDone(gaia::SanitizeEmail(user), auth_code); | 533 controller_->OnLoginDone(gaia::SanitizeEmail(user), auth_code); |
| 554 } | 534 } |
| 555 | 535 |
| 556 void EnrollmentScreenHandler::HandleAdCompleteLogin( | 536 void EnrollmentScreenHandler::HandleAdCompleteLogin( |
| 557 const std::string& machine_name, | 537 const std::string& machine_name, |
| 558 const std::string& user_name, | 538 const std::string& user_name, |
| 559 const std::string& password) { | 539 const std::string& password) { |
| 560 observe_network_failure_ = false; | 540 observe_network_failure_ = false; |
| 561 DCHECK(controller_); | 541 DCHECK(controller_); |
| 562 base::PostTaskAndReplyWithResult( | 542 login::GetPipeReadEnd( |
| 563 content::BrowserThread::GetBlockingPool(), FROM_HERE, | 543 password, |
| 564 base::Bind(&GetPasswordReadPipe, password), | |
| 565 base::Bind(&EnrollmentScreenHandler::OnPasswordPipeReady, | 544 base::Bind(&EnrollmentScreenHandler::OnPasswordPipeReady, |
| 566 weak_ptr_factory_.GetWeakPtr(), machine_name, user_name)); | 545 weak_ptr_factory_.GetWeakPtr(), machine_name, user_name)); |
| 567 } | 546 } |
| 568 | 547 |
| 569 void EnrollmentScreenHandler::OnPasswordPipeReady( | 548 void EnrollmentScreenHandler::OnPasswordPipeReady( |
| 570 const std::string& machine_name, | 549 const std::string& machine_name, |
| 571 const std::string& user_name, | 550 const std::string& user_name, |
| 572 base::ScopedFD password_fd) { | 551 base::ScopedFD password_fd) { |
| 573 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 552 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 574 if (!password_fd.is_valid()) { | 553 if (!password_fd.is_valid()) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 | 639 |
| 661 ShowScreenWithData(OobeScreen::SCREEN_OOBE_ENROLLMENT, &screen_data); | 640 ShowScreenWithData(OobeScreen::SCREEN_OOBE_ENROLLMENT, &screen_data); |
| 662 if (first_show_) { | 641 if (first_show_) { |
| 663 first_show_ = false; | 642 first_show_ = false; |
| 664 UpdateStateInternal(NetworkError::ERROR_REASON_UPDATE, true); | 643 UpdateStateInternal(NetworkError::ERROR_REASON_UPDATE, true); |
| 665 } | 644 } |
| 666 histogram_helper_->OnScreenShow(); | 645 histogram_helper_->OnScreenShow(); |
| 667 } | 646 } |
| 668 | 647 |
| 669 } // namespace chromeos | 648 } // namespace chromeos |
| OLD | NEW |