OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/chromeos/login/existing_user_controller.h" | 5 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <map> | 9 #include <map> |
10 | 10 |
11 #include "app/l10n_util.h" | 11 #include "app/l10n_util.h" |
12 #include "app/resource_bundle.h" | 12 #include "app/resource_bundle.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
15 #include "base/stl_util-inl.h" | 15 #include "base/stl_util-inl.h" |
16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
17 #include "base/values.h" | |
17 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
18 #include "chrome/browser/chrome_thread.h" | 19 #include "chrome/browser/chrome_thread.h" |
19 #include "chrome/browser/chromeos/boot_times_loader.h" | 20 #include "chrome/browser/chromeos/boot_times_loader.h" |
20 #include "chrome/browser/chromeos/cros/cros_library.h" | 21 #include "chrome/browser/chromeos/cros/cros_library.h" |
21 #include "chrome/browser/chromeos/cros/login_library.h" | 22 #include "chrome/browser/chromeos/cros/login_library.h" |
22 #include "chrome/browser/chromeos/cros/network_library.h" | 23 #include "chrome/browser/chromeos/cros/network_library.h" |
24 #include "chrome/browser/chromeos/cros_settings_provider_user.h" | |
23 #include "chrome/browser/chromeos/login/authenticator.h" | 25 #include "chrome/browser/chromeos/login/authenticator.h" |
24 #include "chrome/browser/chromeos/login/background_view.h" | 26 #include "chrome/browser/chromeos/login/background_view.h" |
25 #include "chrome/browser/chromeos/login/help_app_launcher.h" | 27 #include "chrome/browser/chromeos/login/help_app_launcher.h" |
26 #include "chrome/browser/chromeos/login/helper.h" | 28 #include "chrome/browser/chromeos/login/helper.h" |
27 #include "chrome/browser/chromeos/login/login_utils.h" | 29 #include "chrome/browser/chromeos/login/login_utils.h" |
28 #include "chrome/browser/chromeos/login/message_bubble.h" | 30 #include "chrome/browser/chromeos/login/message_bubble.h" |
29 #include "chrome/browser/chromeos/login/wizard_controller.h" | 31 #include "chrome/browser/chromeos/login/wizard_controller.h" |
30 #include "chrome/browser/chromeos/wm_ipc.h" | 32 #include "chrome/browser/chromeos/wm_ipc.h" |
31 #include "chrome/browser/profile.h" | 33 #include "chrome/browser/profile.h" |
32 #include "chrome/browser/profile_manager.h" | 34 #include "chrome/browser/profile_manager.h" |
(...skipping 30 matching lines...) Expand all Loading... | |
63 ++visible_display_names[display_name]; | 65 ++visible_display_names[display_name]; |
64 } | 66 } |
65 for (size_t i = 0; i + 1 < controllers.size(); ++i) { | 67 for (size_t i = 0; i + 1 < controllers.size(); ++i) { |
66 const std::string& display_name = | 68 const std::string& display_name = |
67 controllers[i]->user().GetDisplayName(); | 69 controllers[i]->user().GetDisplayName(); |
68 bool show_tooltip = visible_display_names[display_name] > 1; | 70 bool show_tooltip = visible_display_names[display_name] > 1; |
69 controllers[i]->EnableNameTooltip(show_tooltip); | 71 controllers[i]->EnableNameTooltip(show_tooltip); |
70 } | 72 } |
71 } | 73 } |
72 | 74 |
75 // Returns true if given email is in user whitelist. | |
76 // Note this function is for display purpose only and should use | |
77 // CheckWhitelist op for the real whitelist check. | |
78 bool IsEmailInCachedWhitelist(const std::string& email) { | |
79 StringValue email_value(email); | |
80 const ListValue* whitelist = UserCrosSettingsProvider::cached_whitelist(); | |
81 for (ListValue::const_iterator i(whitelist->begin()); | |
82 i != whitelist->end(); ++i) { | |
83 if ((*i)->Equals(&email_value)) | |
84 return true; | |
85 } | |
86 return false; | |
87 } | |
88 | |
73 } // namespace | 89 } // namespace |
74 | 90 |
75 ExistingUserController* | 91 ExistingUserController* |
76 ExistingUserController::delete_scheduled_instance_ = NULL; | 92 ExistingUserController::delete_scheduled_instance_ = NULL; |
77 | 93 |
78 ExistingUserController::ExistingUserController( | 94 ExistingUserController::ExistingUserController( |
79 const std::vector<UserManager::User>& users, | 95 const std::vector<UserManager::User>& users, |
80 const gfx::Rect& background_bounds) | 96 const gfx::Rect& background_bounds) |
81 : background_bounds_(background_bounds), | 97 : background_bounds_(background_bounds), |
82 background_window_(NULL), | 98 background_window_(NULL), |
83 background_view_(NULL), | 99 background_view_(NULL), |
84 selected_view_index_(kNotSelected), | 100 selected_view_index_(kNotSelected), |
85 num_login_attempts_(0), | 101 num_login_attempts_(0), |
86 bubble_(NULL), | 102 bubble_(NULL), |
87 last_login_error_(GoogleServiceAuthError::NONE), | 103 last_login_error_(GoogleServiceAuthError::NONE), |
88 login_timed_out_(false) { | 104 login_timed_out_(false) { |
89 if (delete_scheduled_instance_) | 105 if (delete_scheduled_instance_) |
90 delete_scheduled_instance_->Delete(); | 106 delete_scheduled_instance_->Delete(); |
91 | 107 |
92 // Caclulate the max number of users from available screen size. | 108 // Caclulate the max number of users from available screen size. |
93 size_t max_users = kMaxUsers; | 109 if (UserCrosSettingsProvider::cached_show_users_on_signin()) { |
94 int screen_width = background_bounds.width(); | 110 size_t max_users = kMaxUsers; |
95 if (screen_width > 0) { | 111 int screen_width = background_bounds.width(); |
96 max_users = std::max(static_cast<size_t>(2), std::min(kMaxUsers, | 112 if (screen_width > 0) { |
97 static_cast<size_t>((screen_width - login::kUserImageSize) | 113 max_users = std::max(static_cast<size_t>(2), std::min(kMaxUsers, |
98 / (UserController::kUnselectedSize + | 114 static_cast<size_t>((screen_width - login::kUserImageSize) |
99 UserController::kPadding)))); | 115 / (UserController::kUnselectedSize + |
116 UserController::kPadding)))); | |
117 } | |
118 | |
119 size_t visible_users_count = std::min(users.size(), max_users - 1); | |
120 for (size_t i = 0; i < users.size(); ++i) { | |
121 if (controllers_.size() == visible_users_count) | |
122 break; | |
123 | |
124 // TODO(xiyuan): Clean user profile whose email is not in whitelist. | |
125 if (UserCrosSettingsProvider::cached_allow_guest() || | |
126 IsEmailInCachedWhitelist(users[i].email())) { | |
127 controllers_.push_back(new UserController(this, users[i])); | |
128 } | |
129 } | |
100 } | 130 } |
101 | 131 |
102 size_t visible_users_count = std::min(users.size(), max_users - 1); | |
103 for (size_t i = 0; i < visible_users_count; ++i) | |
104 controllers_.push_back(new UserController(this, users[i])); | |
105 | |
106 // Add the view representing the guest user last. | 132 // Add the view representing the guest user last. |
107 controllers_.push_back(new UserController(this)); | 133 controllers_.push_back(new UserController(this)); |
108 } | 134 } |
109 | 135 |
110 void ExistingUserController::Init() { | 136 void ExistingUserController::Init() { |
111 if (!background_window_) { | 137 if (!background_window_) { |
112 background_window_ = BackgroundView::CreateWindowContainingView( | 138 background_window_ = BackgroundView::CreateWindowContainingView( |
113 background_bounds_, | 139 background_bounds_, |
114 &background_view_); | 140 &background_view_); |
115 | 141 |
116 if (!WizardController::IsDeviceRegistered()) { | 142 if (!WizardController::IsDeviceRegistered()) { |
117 background_view_->SetOobeProgressBarVisible(true); | 143 background_view_->SetOobeProgressBarVisible(true); |
118 background_view_->SetOobeProgress(chromeos::BackgroundView::SIGNIN); | 144 background_view_->SetOobeProgress(chromeos::BackgroundView::SIGNIN); |
119 } else { | 145 } else { |
120 background_view_->SetGoIncognitoButtonVisible(true, this); | 146 background_view_->SetGoIncognitoButtonVisible( |
147 UserCrosSettingsProvider::cached_allow_bwsi(), this); | |
121 } | 148 } |
122 | 149 |
123 background_window_->Show(); | 150 background_window_->Show(); |
124 } | 151 } |
125 for (size_t i = 0; i < controllers_.size(); ++i) { | 152 for (size_t i = 0; i < controllers_.size(); ++i) { |
126 (controllers_[i])->Init(static_cast<int>(i), | 153 (controllers_[i])->Init(static_cast<int>(i), |
127 static_cast<int>(controllers_.size()), | 154 static_cast<int>(controllers_.size()), |
128 background_view_->IsOobeProgressBarVisible()); | 155 background_view_->IsOobeProgressBarVisible()); |
129 } | 156 } |
130 | 157 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 std::find(controllers_.begin(), controllers_.end(), source); | 230 std::find(controllers_.begin(), controllers_.end(), source); |
204 DCHECK(i != controllers_.end()); | 231 DCHECK(i != controllers_.end()); |
205 | 232 |
206 if (i == controllers_.begin() + selected_view_index_) { | 233 if (i == controllers_.begin() + selected_view_index_) { |
207 num_login_attempts_++; | 234 num_login_attempts_++; |
208 } else { | 235 } else { |
209 selected_view_index_ = i - controllers_.begin(); | 236 selected_view_index_ = i - controllers_.begin(); |
210 num_login_attempts_ = 0; | 237 num_login_attempts_ = 0; |
211 } | 238 } |
212 | 239 |
240 password_ = password; | |
241 | |
242 if (UserCrosSettingsProvider::cached_allow_guest()) { | |
243 // Starts authentication if guest login is allowed. | |
244 StartAuthentication(); | |
245 } else { | |
246 // Otherwise, do whitelist check first. | |
247 SignedSettingsHelper::Get()->StartCheckWhitelistOp( | |
248 controllers_[selected_view_index_]->user().email(), this); | |
249 } | |
250 | |
251 // Disable clicking on other windows. | |
252 SendSetLoginState(false); | |
253 } | |
254 | |
255 void ExistingUserController::OnCheckWhiteListCompleted( | |
256 bool success, const std::string& email) { | |
257 if (success) { | |
258 // Whitelist check passed, continue with authentication. | |
259 StartAuthentication(); | |
260 } else { | |
261 // Otherwise, show whitelist check error. | |
262 ShowError(IDS_LOGIN_ERROR_WHITELIST, email); | |
263 | |
264 // Reenable userview and use ClearAndEnablePassword to keep username on | |
265 // screen with the error bubble. | |
266 controllers_[selected_view_index_]->ClearAndEnablePassword(); | |
267 | |
268 // Reenable clicking on other windows. | |
269 SendSetLoginState(true); | |
270 } | |
271 } | |
272 | |
273 void ExistingUserController::StartAuthentication() { | |
213 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); | 274 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); |
214 Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile(); | 275 Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile(); |
215 ChromeThread::PostTask( | 276 ChromeThread::PostTask( |
216 ChromeThread::UI, FROM_HERE, | 277 ChromeThread::UI, FROM_HERE, |
217 NewRunnableMethod(authenticator_.get(), | 278 NewRunnableMethod(authenticator_.get(), |
218 &Authenticator::AuthenticateToLogin, | 279 &Authenticator::AuthenticateToLogin, |
219 profile, | 280 profile, |
220 controllers_[selected_view_index_]->user().email(), | 281 controllers_[selected_view_index_]->user().email(), |
221 UTF16ToUTF8(password), | 282 UTF16ToUTF8(password_), |
222 login_token_, | 283 login_token_, |
223 login_captcha_)); | 284 login_captcha_)); |
224 | 285 password_.clear(); |
225 // Disable clicking on other windows. | |
226 SendSetLoginState(false); | |
227 } | 286 } |
228 | 287 |
229 void ExistingUserController::LoginOffTheRecord() { | 288 void ExistingUserController::LoginOffTheRecord() { |
289 // Check allow_bwsi in case this call is fired from key accelerator. | |
290 if (!UserCrosSettingsProvider::cached_allow_bwsi()) | |
291 return; | |
292 | |
230 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); | 293 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); |
231 ChromeThread::PostTask( | 294 ChromeThread::PostTask( |
232 ChromeThread::UI, FROM_HERE, | 295 ChromeThread::UI, FROM_HERE, |
233 NewRunnableMethod(authenticator_.get(), | 296 NewRunnableMethod(authenticator_.get(), |
234 &Authenticator::LoginOffTheRecord)); | 297 &Authenticator::LoginOffTheRecord)); |
235 | 298 |
236 // Disable clicking on other windows. | 299 // Disable clicking on other windows. |
237 SendSetLoginState(false); | 300 SendSetLoginState(false); |
238 } | 301 } |
239 | 302 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
395 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING), | 458 ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING), |
396 error_text, | 459 error_text, |
397 help_link, | 460 help_link, |
398 this); | 461 this); |
399 } | 462 } |
400 | 463 |
401 void ExistingUserController::OnLoginSuccess(const std::string& username, | 464 void ExistingUserController::OnLoginSuccess(const std::string& username, |
402 const GaiaAuthConsumer::ClientLoginResult& credentials) { | 465 const GaiaAuthConsumer::ClientLoginResult& credentials) { |
403 | 466 |
404 AppendStartUrlToCmdline(); | 467 AppendStartUrlToCmdline(); |
405 if (selected_view_index_ + 1 == controllers_.size()) { | 468 if (selected_view_index_ + 1 == controllers_.size() && |
469 !UserManager::Get()->IsKnownUser(username)) { | |
Nikita (slow)
2010/11/03 16:58:56
Was this an intentional change? It doesn't seem th
xiyuan
2010/11/03 17:34:36
I thought it was a bug. This code path is from new
Nikita (slow)
2010/11/03 17:42:25
There were some other reports too so it's ok to le
| |
406 // For new user login don't launch browser until we pass image screen. | 470 // For new user login don't launch browser until we pass image screen. |
407 LoginUtils::Get()->EnableBrowserLaunch(false); | 471 LoginUtils::Get()->EnableBrowserLaunch(false); |
408 LoginUtils::Get()->CompleteLogin(username, credentials); | 472 LoginUtils::Get()->CompleteLogin(username, credentials); |
409 ActivateWizard(WizardController::IsDeviceRegistered() ? | 473 ActivateWizard(WizardController::IsDeviceRegistered() ? |
410 WizardController::kUserImageScreenName : | 474 WizardController::kUserImageScreenName : |
411 WizardController::kRegistrationScreenName); | 475 WizardController::kRegistrationScreenName); |
412 } else { | 476 } else { |
413 // Hide the login windows now. | 477 // Hide the login windows now. |
414 WmIpc::Message message(WM_IPC_MESSAGE_WM_HIDE_LOGIN); | 478 WmIpc::Message message(WM_IPC_MESSAGE_WM_HIDE_LOGIN); |
415 WmIpc::instance()->SendMessage(message); | 479 WmIpc::instance()->SendMessage(message); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
490 void ExistingUserController::ResyncEncryptedData() { | 554 void ExistingUserController::ResyncEncryptedData() { |
491 ChromeThread::PostTask( | 555 ChromeThread::PostTask( |
492 ChromeThread::UI, FROM_HERE, | 556 ChromeThread::UI, FROM_HERE, |
493 NewRunnableMethod(authenticator_.get(), | 557 NewRunnableMethod(authenticator_.get(), |
494 &Authenticator::ResyncEncryptedData, | 558 &Authenticator::ResyncEncryptedData, |
495 cached_credentials_)); | 559 cached_credentials_)); |
496 cached_credentials_ = GaiaAuthConsumer::ClientLoginResult(); | 560 cached_credentials_ = GaiaAuthConsumer::ClientLoginResult(); |
497 } | 561 } |
498 | 562 |
499 } // namespace chromeos | 563 } // namespace chromeos |
OLD | NEW |