| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/login/webui_login_display.h" | |
| 6 | |
| 7 #include "ash/shell.h" | |
| 8 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | |
| 9 #include "chrome/browser/chromeos/login/login_display_host_impl.h" | |
| 10 #include "chrome/browser/chromeos/login/screen_locker.h" | |
| 11 #include "chrome/browser/chromeos/login/user_adding_screen.h" | |
| 12 #include "chrome/browser/chromeos/login/wallpaper_manager.h" | |
| 13 #include "chrome/browser/chromeos/login/webui_login_view.h" | |
| 14 #include "chrome/browser/profiles/profile_manager.h" | |
| 15 #include "chrome/browser/ui/browser_window.h" | |
| 16 #include "chromeos/ime/ime_keyboard.h" | |
| 17 #include "chromeos/ime/input_method_manager.h" | |
| 18 #include "grit/chromium_strings.h" | |
| 19 #include "grit/generated_resources.h" | |
| 20 #include "ui/base/l10n/l10n_util.h" | |
| 21 #include "ui/views/widget/widget.h" | |
| 22 #include "ui/wm/core/user_activity_detector.h" | |
| 23 | |
| 24 namespace chromeos { | |
| 25 | |
| 26 namespace { | |
| 27 | |
| 28 const int kPasswordClearTimeoutSec = 60; | |
| 29 | |
| 30 } | |
| 31 | |
| 32 // WebUILoginDisplay, public: -------------------------------------------------- | |
| 33 | |
| 34 WebUILoginDisplay::~WebUILoginDisplay() { | |
| 35 if (webui_handler_) | |
| 36 webui_handler_->ResetSigninScreenHandlerDelegate(); | |
| 37 wm::UserActivityDetector* activity_detector = ash::Shell::GetInstance()-> | |
| 38 user_activity_detector(); | |
| 39 if (activity_detector->HasObserver(this)) | |
| 40 activity_detector->RemoveObserver(this); | |
| 41 } | |
| 42 | |
| 43 // LoginDisplay implementation: ------------------------------------------------ | |
| 44 | |
| 45 WebUILoginDisplay::WebUILoginDisplay(LoginDisplay::Delegate* delegate) | |
| 46 : LoginDisplay(delegate, gfx::Rect()), | |
| 47 show_guest_(false), | |
| 48 show_new_user_(false), | |
| 49 webui_handler_(NULL) { | |
| 50 } | |
| 51 | |
| 52 void WebUILoginDisplay::ClearAndEnablePassword() { | |
| 53 if (webui_handler_) | |
| 54 webui_handler_->ClearAndEnablePassword(); | |
| 55 } | |
| 56 | |
| 57 void WebUILoginDisplay::Init(const UserList& users, | |
| 58 bool show_guest, | |
| 59 bool show_users, | |
| 60 bool show_new_user) { | |
| 61 // Testing that the delegate has been set. | |
| 62 DCHECK(delegate_); | |
| 63 | |
| 64 users_ = users; | |
| 65 show_guest_ = show_guest; | |
| 66 show_users_ = show_users; | |
| 67 show_new_user_ = show_new_user; | |
| 68 | |
| 69 wm::UserActivityDetector* activity_detector = ash::Shell::GetInstance()-> | |
| 70 user_activity_detector(); | |
| 71 if (!activity_detector->HasObserver(this)) | |
| 72 activity_detector->AddObserver(this); | |
| 73 } | |
| 74 | |
| 75 void WebUILoginDisplay::OnPreferencesChanged() { | |
| 76 if (webui_handler_) | |
| 77 webui_handler_->OnPreferencesChanged(); | |
| 78 } | |
| 79 | |
| 80 void WebUILoginDisplay::OnBeforeUserRemoved(const std::string& username) { | |
| 81 for (UserList::iterator it = users_.begin(); it != users_.end(); ++it) { | |
| 82 if ((*it)->email() == username) { | |
| 83 users_.erase(it); | |
| 84 break; | |
| 85 } | |
| 86 } | |
| 87 } | |
| 88 | |
| 89 void WebUILoginDisplay::OnUserImageChanged(const User& user) { | |
| 90 if (webui_handler_) | |
| 91 webui_handler_->OnUserImageChanged(user); | |
| 92 } | |
| 93 | |
| 94 void WebUILoginDisplay::OnUserRemoved(const std::string& username) { | |
| 95 if (webui_handler_) | |
| 96 webui_handler_->OnUserRemoved(username); | |
| 97 } | |
| 98 | |
| 99 void WebUILoginDisplay::OnFadeOut() { | |
| 100 } | |
| 101 | |
| 102 void WebUILoginDisplay::OnLoginSuccess(const std::string& username) { | |
| 103 if (webui_handler_) | |
| 104 webui_handler_->OnLoginSuccess(username); | |
| 105 } | |
| 106 | |
| 107 void WebUILoginDisplay::SetUIEnabled(bool is_enabled) { | |
| 108 // TODO(nkostylev): Cleanup this condition, | |
| 109 // see http://crbug.com/157885 and http://crbug.com/158255. | |
| 110 // Allow this call only before user sign in or at lock screen. | |
| 111 // If this call is made after new user signs in but login screen is still | |
| 112 // around that would trigger a sign in extension refresh. | |
| 113 if (is_enabled && | |
| 114 (!UserManager::Get()->IsUserLoggedIn() || | |
| 115 ScreenLocker::default_screen_locker())) { | |
| 116 ClearAndEnablePassword(); | |
| 117 } | |
| 118 | |
| 119 if (chromeos::LoginDisplayHost* host = | |
| 120 chromeos::LoginDisplayHostImpl::default_host()) { | |
| 121 if (chromeos::WebUILoginView* login_view = host->GetWebUILoginView()) | |
| 122 login_view->SetUIEnabled(is_enabled); | |
| 123 } | |
| 124 } | |
| 125 | |
| 126 void WebUILoginDisplay::SelectPod(int index) { | |
| 127 } | |
| 128 | |
| 129 void WebUILoginDisplay::ShowBannerMessage(const std::string& message) { | |
| 130 if (!webui_handler_) | |
| 131 return; | |
| 132 webui_handler_->ShowBannerMessage(message); | |
| 133 } | |
| 134 | |
| 135 void WebUILoginDisplay::ShowUserPodButton( | |
| 136 const std::string& username, | |
| 137 const std::string& iconURL, | |
| 138 const base::Closure& click_callback) { | |
| 139 if (!webui_handler_) | |
| 140 return; | |
| 141 webui_handler_->ShowUserPodButton(username, iconURL, click_callback); | |
| 142 } | |
| 143 | |
| 144 void WebUILoginDisplay::HideUserPodButton(const std::string& username) { | |
| 145 if (!webui_handler_) | |
| 146 return; | |
| 147 webui_handler_->HideUserPodButton(username); | |
| 148 } | |
| 149 | |
| 150 void WebUILoginDisplay::SetAuthType(const std::string& username, | |
| 151 AuthType auth_type, | |
| 152 const std::string& initial_value) { | |
| 153 if (!webui_handler_) | |
| 154 return; | |
| 155 webui_handler_->SetAuthType(username, auth_type, initial_value); | |
| 156 } | |
| 157 | |
| 158 LoginDisplay::AuthType WebUILoginDisplay::GetAuthType( | |
| 159 const std::string& username) const { | |
| 160 // Return default auth type if WebUI hander is not ready. | |
| 161 if (!webui_handler_) | |
| 162 return OFFLINE_PASSWORD; | |
| 163 return webui_handler_->GetAuthType(username); | |
| 164 } | |
| 165 | |
| 166 void WebUILoginDisplay::ShowError(int error_msg_id, | |
| 167 int login_attempts, | |
| 168 HelpAppLauncher::HelpTopic help_topic_id) { | |
| 169 VLOG(1) << "Show error, error_id: " << error_msg_id | |
| 170 << ", attempts:" << login_attempts | |
| 171 << ", help_topic_id: " << help_topic_id; | |
| 172 if (!webui_handler_) | |
| 173 return; | |
| 174 | |
| 175 std::string error_text; | |
| 176 switch (error_msg_id) { | |
| 177 case IDS_LOGIN_ERROR_AUTHENTICATING_HOSTED: | |
| 178 error_text = l10n_util::GetStringFUTF8( | |
| 179 error_msg_id, l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_OS_NAME)); | |
| 180 break; | |
| 181 case IDS_LOGIN_ERROR_CAPTIVE_PORTAL: | |
| 182 error_text = l10n_util::GetStringFUTF8( | |
| 183 error_msg_id, delegate()->GetConnectedNetworkName()); | |
| 184 break; | |
| 185 default: | |
| 186 error_text = l10n_util::GetStringUTF8(error_msg_id); | |
| 187 break; | |
| 188 } | |
| 189 | |
| 190 // Only display hints about keyboard layout if the error is authentication- | |
| 191 // related. | |
| 192 if (error_msg_id != IDS_LOGIN_ERROR_WHITELIST && | |
| 193 error_msg_id != IDS_LOGIN_ERROR_OWNER_KEY_LOST && | |
| 194 error_msg_id != IDS_LOGIN_ERROR_OWNER_REQUIRED) { | |
| 195 // Display a warning if Caps Lock is on. | |
| 196 input_method::InputMethodManager* ime_manager = | |
| 197 input_method::InputMethodManager::Get(); | |
| 198 if (ime_manager->GetImeKeyboard()->CapsLockIsEnabled()) { | |
| 199 // TODO(ivankr): use a format string instead of concatenation. | |
| 200 error_text += "\n" + | |
| 201 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_CAPS_LOCK_HINT); | |
| 202 } | |
| 203 | |
| 204 // Display a hint to switch keyboards if there are other active input | |
| 205 // methods. | |
| 206 if (ime_manager->GetNumActiveInputMethods() > 1) { | |
| 207 error_text += "\n" + | |
| 208 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_KEYBOARD_SWITCH_HINT); | |
| 209 } | |
| 210 } | |
| 211 | |
| 212 std::string help_link; | |
| 213 switch (error_msg_id) { | |
| 214 case IDS_LOGIN_ERROR_AUTHENTICATING_HOSTED: | |
| 215 help_link = l10n_util::GetStringUTF8(IDS_LEARN_MORE); | |
| 216 break; | |
| 217 default: | |
| 218 if (login_attempts > 1) | |
| 219 help_link = l10n_util::GetStringUTF8(IDS_LEARN_MORE); | |
| 220 break; | |
| 221 } | |
| 222 | |
| 223 webui_handler_->ShowError(login_attempts, error_text, help_link, | |
| 224 help_topic_id); | |
| 225 } | |
| 226 | |
| 227 void WebUILoginDisplay::ShowErrorScreen(LoginDisplay::SigninError error_id) { | |
| 228 VLOG(1) << "Show error screen, error_id: " << error_id; | |
| 229 if (!webui_handler_) | |
| 230 return; | |
| 231 webui_handler_->ShowErrorScreen(error_id); | |
| 232 } | |
| 233 | |
| 234 void WebUILoginDisplay::ShowGaiaPasswordChanged(const std::string& username) { | |
| 235 if (webui_handler_) | |
| 236 webui_handler_->ShowGaiaPasswordChanged(username); | |
| 237 } | |
| 238 | |
| 239 void WebUILoginDisplay::ShowPasswordChangedDialog(bool show_password_error) { | |
| 240 if (webui_handler_) | |
| 241 webui_handler_->ShowPasswordChangedDialog(show_password_error); | |
| 242 } | |
| 243 | |
| 244 void WebUILoginDisplay::ShowSigninUI(const std::string& email) { | |
| 245 if (webui_handler_) | |
| 246 webui_handler_->ShowSigninUI(email); | |
| 247 } | |
| 248 | |
| 249 void WebUILoginDisplay::ShowControlBar(bool show) { | |
| 250 if (webui_handler_) | |
| 251 webui_handler_->ShowControlBar(show); | |
| 252 } | |
| 253 | |
| 254 // WebUILoginDisplay, NativeWindowDelegate implementation: --------------------- | |
| 255 gfx::NativeWindow WebUILoginDisplay::GetNativeWindow() const { | |
| 256 return parent_window(); | |
| 257 } | |
| 258 | |
| 259 // WebUILoginDisplay, SigninScreenHandlerDelegate implementation: -------------- | |
| 260 void WebUILoginDisplay::CancelPasswordChangedFlow() { | |
| 261 DCHECK(delegate_); | |
| 262 if (delegate_) | |
| 263 delegate_->CancelPasswordChangedFlow(); | |
| 264 } | |
| 265 | |
| 266 void WebUILoginDisplay::CancelUserAdding() { | |
| 267 if (!UserAddingScreen::Get()->IsRunning()) { | |
| 268 LOG(ERROR) << "User adding screen not running."; | |
| 269 return; | |
| 270 } | |
| 271 UserAddingScreen::Get()->Cancel(); | |
| 272 } | |
| 273 | |
| 274 void WebUILoginDisplay::CreateAccount() { | |
| 275 DCHECK(delegate_); | |
| 276 if (delegate_) | |
| 277 delegate_->CreateAccount(); | |
| 278 } | |
| 279 | |
| 280 void WebUILoginDisplay::CompleteLogin(const UserContext& user_context) { | |
| 281 DCHECK(delegate_); | |
| 282 if (delegate_) | |
| 283 delegate_->CompleteLogin(user_context); | |
| 284 } | |
| 285 | |
| 286 void WebUILoginDisplay::Login(const UserContext& user_context) { | |
| 287 DCHECK(delegate_); | |
| 288 if (delegate_) | |
| 289 delegate_->Login(user_context); | |
| 290 } | |
| 291 | |
| 292 void WebUILoginDisplay::LoginAsRetailModeUser() { | |
| 293 DCHECK(delegate_); | |
| 294 if (delegate_) | |
| 295 delegate_->LoginAsRetailModeUser(); | |
| 296 } | |
| 297 | |
| 298 void WebUILoginDisplay::LoginAsGuest() { | |
| 299 DCHECK(delegate_); | |
| 300 if (delegate_) | |
| 301 delegate_->LoginAsGuest(); | |
| 302 } | |
| 303 | |
| 304 void WebUILoginDisplay::LoginAsPublicAccount(const std::string& username) { | |
| 305 DCHECK(delegate_); | |
| 306 if (delegate_) | |
| 307 delegate_->LoginAsPublicAccount(username); | |
| 308 } | |
| 309 | |
| 310 void WebUILoginDisplay::MigrateUserData(const std::string& old_password) { | |
| 311 DCHECK(delegate_); | |
| 312 if (delegate_) | |
| 313 delegate_->MigrateUserData(old_password); | |
| 314 } | |
| 315 | |
| 316 void WebUILoginDisplay::LoadWallpaper(const std::string& username) { | |
| 317 WallpaperManager::Get()->SetUserWallpaperDelayed(username); | |
| 318 } | |
| 319 | |
| 320 void WebUILoginDisplay::LoadSigninWallpaper() { | |
| 321 WallpaperManager::Get()->SetDefaultWallpaperDelayed(UserManager::kSignInUser); | |
| 322 } | |
| 323 | |
| 324 void WebUILoginDisplay::OnSigninScreenReady() { | |
| 325 if (delegate_) | |
| 326 delegate_->OnSigninScreenReady(); | |
| 327 } | |
| 328 | |
| 329 void WebUILoginDisplay::RemoveUser(const std::string& username) { | |
| 330 UserManager::Get()->RemoveUser(username, this); | |
| 331 } | |
| 332 | |
| 333 void WebUILoginDisplay::ResyncUserData() { | |
| 334 DCHECK(delegate_); | |
| 335 if (delegate_) | |
| 336 delegate_->ResyncUserData(); | |
| 337 } | |
| 338 | |
| 339 void WebUILoginDisplay::ShowEnterpriseEnrollmentScreen() { | |
| 340 if (delegate_) | |
| 341 delegate_->OnStartEnterpriseEnrollment(); | |
| 342 } | |
| 343 | |
| 344 void WebUILoginDisplay::ShowKioskEnableScreen() { | |
| 345 if (delegate_) | |
| 346 delegate_->OnStartKioskEnableScreen(); | |
| 347 } | |
| 348 | |
| 349 void WebUILoginDisplay::ShowKioskAutolaunchScreen() { | |
| 350 if (delegate_) | |
| 351 delegate_->OnStartKioskAutolaunchScreen(); | |
| 352 } | |
| 353 | |
| 354 void WebUILoginDisplay::ShowWrongHWIDScreen() { | |
| 355 if (delegate_) | |
| 356 delegate_->ShowWrongHWIDScreen(); | |
| 357 } | |
| 358 | |
| 359 void WebUILoginDisplay::SetWebUIHandler( | |
| 360 LoginDisplayWebUIHandler* webui_handler) { | |
| 361 webui_handler_ = webui_handler; | |
| 362 } | |
| 363 | |
| 364 void WebUILoginDisplay::ShowSigninScreenForCreds( | |
| 365 const std::string& username, | |
| 366 const std::string& password) { | |
| 367 if (webui_handler_) | |
| 368 webui_handler_->ShowSigninScreenForCreds(username, password); | |
| 369 } | |
| 370 | |
| 371 const UserList& WebUILoginDisplay::GetUsers() const { | |
| 372 return users_; | |
| 373 } | |
| 374 | |
| 375 bool WebUILoginDisplay::IsShowGuest() const { | |
| 376 return show_guest_; | |
| 377 } | |
| 378 | |
| 379 bool WebUILoginDisplay::IsShowUsers() const { | |
| 380 return show_users_; | |
| 381 } | |
| 382 | |
| 383 bool WebUILoginDisplay::IsShowNewUser() const { | |
| 384 return show_new_user_; | |
| 385 } | |
| 386 | |
| 387 bool WebUILoginDisplay::IsSigninInProgress() const { | |
| 388 return delegate_->IsSigninInProgress(); | |
| 389 } | |
| 390 | |
| 391 bool WebUILoginDisplay::IsUserSigninCompleted() const { | |
| 392 return is_signin_completed(); | |
| 393 } | |
| 394 | |
| 395 void WebUILoginDisplay::SetDisplayEmail(const std::string& email) { | |
| 396 if (delegate_) | |
| 397 delegate_->SetDisplayEmail(email); | |
| 398 } | |
| 399 | |
| 400 void WebUILoginDisplay::Signout() { | |
| 401 delegate_->Signout(); | |
| 402 } | |
| 403 | |
| 404 void WebUILoginDisplay::LoginAsKioskApp(const std::string& app_id, | |
| 405 bool diagnostic_mode) { | |
| 406 delegate_->LoginAsKioskApp(app_id, diagnostic_mode); | |
| 407 } | |
| 408 | |
| 409 void WebUILoginDisplay::OnUserActivity(const ui::Event* event) { | |
| 410 if (!password_clear_timer_.IsRunning()) | |
| 411 StartPasswordClearTimer(); | |
| 412 password_clear_timer_.Reset(); | |
| 413 if (delegate_) | |
| 414 delegate_->ResetPublicSessionAutoLoginTimer(); | |
| 415 } | |
| 416 | |
| 417 void WebUILoginDisplay::StartPasswordClearTimer() { | |
| 418 DCHECK(!password_clear_timer_.IsRunning()); | |
| 419 password_clear_timer_.Start(FROM_HERE, | |
| 420 base::TimeDelta::FromSeconds(kPasswordClearTimeoutSec), this, | |
| 421 &WebUILoginDisplay::OnPasswordClearTimerExpired); | |
| 422 } | |
| 423 | |
| 424 void WebUILoginDisplay::OnPasswordClearTimerExpired() { | |
| 425 if (webui_handler_) | |
| 426 webui_handler_->ClearUserPodPassword(); | |
| 427 } | |
| 428 | |
| 429 } // namespace chromeos | |
| OLD | NEW |