| 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 | 9 |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/browser/chromeos/login/background_view.h" | 21 #include "chrome/browser/chromeos/login/background_view.h" |
| 22 #include "chrome/browser/chromeos/login/login_utils.h" | 22 #include "chrome/browser/chromeos/login/login_utils.h" |
| 23 #include "chrome/browser/chromeos/login/message_bubble.h" | 23 #include "chrome/browser/chromeos/login/message_bubble.h" |
| 24 #include "chrome/browser/chromeos/login/wizard_controller.h" | 24 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 25 #include "chrome/browser/chromeos/wm_ipc.h" | 25 #include "chrome/browser/chromeos/wm_ipc.h" |
| 26 #include "chrome/browser/profile.h" | 26 #include "chrome/browser/profile.h" |
| 27 #include "chrome/browser/profile_manager.h" | 27 #include "chrome/browser/profile_manager.h" |
| 28 #include "grit/theme_resources.h" | 28 #include "grit/theme_resources.h" |
| 29 #include "views/screen.h" | 29 #include "views/screen.h" |
| 30 #include "views/widget/widget.h" | 30 #include "views/widget/widget.h" |
| 31 #include "views/widget/widget_gtk.h" |
| 32 #include "views/window/window.h" |
| 31 | 33 |
| 32 namespace chromeos { | 34 namespace chromeos { |
| 33 | 35 |
| 34 namespace { | 36 namespace { |
| 35 | 37 |
| 36 // Max number of users we'll show. The true max is the min of this and the | 38 // Max number of users we'll show. The true max is the min of this and the |
| 37 // number of windows that fit on the screen. | 39 // number of windows that fit on the screen. |
| 38 const size_t kMaxUsers = 6; | 40 const size_t kMaxUsers = 6; |
| 39 | 41 |
| 40 // Used to indicate no user has been selected. | 42 // Used to indicate no user has been selected. |
| 41 const size_t kNotSelected = -1; | 43 const size_t kNotSelected = -1; |
| 42 | 44 |
| 45 // ClientLogin response parameters. |
| 46 const char kError[] = "Error="; |
| 47 const char kCaptchaError[] = "CaptchaRequired"; |
| 48 const char kCaptchaUrlParam[] = "CaptchaUrl="; |
| 49 const char kCaptchaTokenParam[] = "CaptchaToken="; |
| 50 const char kParamSuffix[] = "\n"; |
| 51 |
| 52 // URL prefix for CAPTCHA image. |
| 53 const char kCaptchaUrlPrefix[] = "http://www.google.com/accounts/"; |
| 54 |
| 43 } // namespace | 55 } // namespace |
| 44 | 56 |
| 45 ExistingUserController::ExistingUserController( | 57 ExistingUserController::ExistingUserController( |
| 46 const std::vector<UserManager::User>& users, | 58 const std::vector<UserManager::User>& users, |
| 47 const gfx::Rect& background_bounds) | 59 const gfx::Rect& background_bounds) |
| 48 : background_bounds_(background_bounds), | 60 : background_bounds_(background_bounds), |
| 49 background_window_(NULL), | 61 background_window_(NULL), |
| 50 background_view_(NULL), | 62 background_view_(NULL), |
| 51 selected_view_index_(kNotSelected), | 63 selected_view_index_(kNotSelected), |
| 52 bubble_(NULL) { | 64 bubble_(NULL) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 selected_view_index_ = i - controllers_.begin(); | 134 selected_view_index_ = i - controllers_.begin(); |
| 123 | 135 |
| 124 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); | 136 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); |
| 125 Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile(); | 137 Profile* profile = g_browser_process->profile_manager()->GetDefaultProfile(); |
| 126 ChromeThread::PostTask( | 138 ChromeThread::PostTask( |
| 127 ChromeThread::FILE, FROM_HERE, | 139 ChromeThread::FILE, FROM_HERE, |
| 128 NewRunnableMethod(authenticator_.get(), | 140 NewRunnableMethod(authenticator_.get(), |
| 129 &Authenticator::AuthenticateToLogin, | 141 &Authenticator::AuthenticateToLogin, |
| 130 profile, | 142 profile, |
| 131 controllers_[selected_view_index_]->user().email(), | 143 controllers_[selected_view_index_]->user().email(), |
| 132 UTF16ToUTF8(password))); | 144 UTF16ToUTF8(password), |
| 145 login_token_, |
| 146 login_captcha_)); |
| 133 | 147 |
| 134 // Disable clicking on other windows. | 148 // Disable clicking on other windows. |
| 135 SendSetLoginState(false); | 149 SendSetLoginState(false); |
| 136 } | 150 } |
| 137 | 151 |
| 138 void ExistingUserController::LoginOffTheRecord() { | 152 void ExistingUserController::LoginOffTheRecord() { |
| 139 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); | 153 authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); |
| 140 ChromeThread::PostTask( | 154 ChromeThread::PostTask( |
| 141 ChromeThread::UI, FROM_HERE, | 155 ChromeThread::UI, FROM_HERE, |
| 142 NewRunnableMethod(authenticator_.get(), | 156 NewRunnableMethod(authenticator_.get(), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 153 } | 167 } |
| 154 | 168 |
| 155 void ExistingUserController::OnUserSelected(UserController* source) { | 169 void ExistingUserController::OnUserSelected(UserController* source) { |
| 156 std::vector<UserController*>::const_iterator i = | 170 std::vector<UserController*>::const_iterator i = |
| 157 std::find(controllers_.begin(), controllers_.end(), source); | 171 std::find(controllers_.begin(), controllers_.end(), source); |
| 158 DCHECK(i != controllers_.end()); | 172 DCHECK(i != controllers_.end()); |
| 159 size_t new_selected_index = i - controllers_.begin(); | 173 size_t new_selected_index = i - controllers_.begin(); |
| 160 if (new_selected_index != selected_view_index_ && | 174 if (new_selected_index != selected_view_index_ && |
| 161 selected_view_index_ != kNotSelected) { | 175 selected_view_index_ != kNotSelected) { |
| 162 controllers_[selected_view_index_]->ClearAndEnablePassword(); | 176 controllers_[selected_view_index_]->ClearAndEnablePassword(); |
| 177 ClearCaptchaState(); |
| 163 } | 178 } |
| 164 selected_view_index_ = new_selected_index; | 179 selected_view_index_ = new_selected_index; |
| 165 } | 180 } |
| 166 | 181 |
| 167 void ExistingUserController::ActivateWizard(const std::string& screen_name) { | 182 void ExistingUserController::ActivateWizard(const std::string& screen_name) { |
| 168 // WizardController takes care of deleting itself when done. | 183 // WizardController takes care of deleting itself when done. |
| 169 WizardController* controller = new WizardController(); | 184 WizardController* controller = new WizardController(); |
| 170 controller->Init(screen_name, background_bounds_, false); | 185 controller->Init(screen_name, background_bounds_, false); |
| 171 controller->Show(); | 186 controller->Show(); |
| 172 | 187 |
| 173 // Give the background window to the controller. | 188 // Give the background window to the controller. |
| 174 controller->OwnBackground(background_window_, background_view_); | 189 controller->OwnBackground(background_window_, background_view_); |
| 175 background_window_ = NULL; | 190 background_window_ = NULL; |
| 176 | 191 |
| 177 // And schedule us for deletion. We delay for a second as the window manager | 192 // And schedule us for deletion. We delay for a second as the window manager |
| 178 // is doing an animation with our windows. | 193 // is doing an animation with our windows. |
| 179 delete_timer_.Start(base::TimeDelta::FromSeconds(1), this, | 194 delete_timer_.Start(base::TimeDelta::FromSeconds(1), this, |
| 180 &ExistingUserController::Delete); | 195 &ExistingUserController::Delete); |
| 181 } | 196 } |
| 182 | 197 |
| 183 void ExistingUserController::OnLoginFailure(const std::string& error) { | 198 void ExistingUserController::OnLoginFailure(const std::string& error) { |
| 184 LOG(INFO) << "OnLoginFailure"; | 199 LOG(INFO) << "OnLoginFailure"; |
| 200 ClearCaptchaState(); |
| 185 | 201 |
| 186 // Check networking after trying to login in case user is | 202 // Check networking after trying to login in case user is |
| 187 // cached locally or the local admin account. | 203 // cached locally or the local admin account. |
| 188 NetworkLibrary* network = CrosLibrary::Get()->GetNetworkLibrary(); | 204 NetworkLibrary* network = CrosLibrary::Get()->GetNetworkLibrary(); |
| 189 if (!network || !CrosLibrary::Get()->EnsureLoaded()) { | 205 if (!network || !CrosLibrary::Get()->EnsureLoaded()) { |
| 190 ShowError(IDS_LOGIN_ERROR_NO_NETWORK_LIBRARY, error); | 206 ShowError(IDS_LOGIN_ERROR_NO_NETWORK_LIBRARY, error); |
| 191 } else if (!network->Connected()) { | 207 } else if (!network->Connected()) { |
| 192 ShowError(IDS_LOGIN_ERROR_OFFLINE_FAILED_NETWORK_NOT_CONNECTED, error); | 208 ShowError(IDS_LOGIN_ERROR_OFFLINE_FAILED_NETWORK_NOT_CONNECTED, error); |
| 193 } else { | 209 } else { |
| 194 ShowError(IDS_LOGIN_ERROR_AUTHENTICATING, error); | 210 std::string error_code = LoginUtils::ExtractClientLoginParam(error, |
| 211 kError, |
| 212 kParamSuffix); |
| 213 std::string captcha_url; |
| 214 if (error_code == kCaptchaError) |
| 215 captcha_url = LoginUtils::ExtractClientLoginParam(error, |
| 216 kCaptchaUrlParam, |
| 217 kParamSuffix); |
| 218 if (captcha_url.empty()) { |
| 219 ShowError(IDS_LOGIN_ERROR_AUTHENTICATING, error); |
| 220 } else { |
| 221 // Save token for next login retry. |
| 222 login_token_ = LoginUtils::ExtractClientLoginParam(error, |
| 223 kCaptchaTokenParam, |
| 224 kParamSuffix); |
| 225 gfx::NativeWindow parent = GTK_WINDOW( |
| 226 static_cast<views::WidgetGtk*>(background_window_)->GetNativeView()); |
| 227 CaptchaView* view = |
| 228 new CaptchaView(GURL(kCaptchaUrlPrefix + captcha_url)); |
| 229 view->set_delegate(this); |
| 230 views::Window* window = views::Window::CreateChromeWindow(parent, |
| 231 gfx::Rect(), |
| 232 view); |
| 233 window->SetIsAlwaysOnTop(true); |
| 234 window->Show(); |
| 235 } |
| 195 } | 236 } |
| 196 | 237 |
| 197 controllers_[selected_view_index_]->ClearAndEnablePassword(); | 238 controllers_[selected_view_index_]->ClearAndEnablePassword(); |
| 198 | 239 |
| 199 // Reenable clicking on other windows. | 240 // Reenable clicking on other windows. |
| 200 SendSetLoginState(true); | 241 SendSetLoginState(true); |
| 201 } | 242 } |
| 202 | 243 |
| 244 void ExistingUserController::ClearCaptchaState() { |
| 245 login_token_.clear(); |
| 246 login_captcha_.clear(); |
| 247 } |
| 248 |
| 203 void ExistingUserController::ShowError(int error_id, | 249 void ExistingUserController::ShowError(int error_id, |
| 204 const std::string& details) { | 250 const std::string& details) { |
| 205 ClearErrors(); | 251 ClearErrors(); |
| 206 std::wstring error_text = l10n_util::GetString(error_id); | 252 std::wstring error_text = l10n_util::GetString(error_id); |
| 207 if (!details.empty()) | 253 if (!details.empty()) |
| 208 error_text += L"\n" + ASCIIToWide(details); | 254 error_text += L"\n" + ASCIIToWide(details); |
| 209 bubble_ = MessageBubble::Show( | 255 bubble_ = MessageBubble::Show( |
| 210 controllers_[selected_view_index_]->controls_window(), | 256 controllers_[selected_view_index_]->controls_window(), |
| 211 controllers_[selected_view_index_]->GetScreenBounds(), | 257 controllers_[selected_view_index_]->GetScreenBounds(), |
| 212 BubbleBorder::BOTTOM_LEFT, | 258 BubbleBorder::BOTTOM_LEFT, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 231 LoginUtils::Get()->CompleteLogin(username, credentials); | 277 LoginUtils::Get()->CompleteLogin(username, credentials); |
| 232 // Delay deletion as we're on the stack. | 278 // Delay deletion as we're on the stack. |
| 233 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 279 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
| 234 } | 280 } |
| 235 } | 281 } |
| 236 | 282 |
| 237 void ExistingUserController::OnOffTheRecordLoginSuccess() { | 283 void ExistingUserController::OnOffTheRecordLoginSuccess() { |
| 238 LoginUtils::Get()->CompleteOffTheRecordLogin(); | 284 LoginUtils::Get()->CompleteOffTheRecordLogin(); |
| 239 } | 285 } |
| 240 | 286 |
| 287 void ExistingUserController::OnCaptchaEntered(const std::string& captcha) { |
| 288 login_captcha_ = captcha; |
| 289 } |
| 290 |
| 241 } // namespace chromeos | 291 } // namespace chromeos |
| OLD | NEW |