| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ui/webui_login_display.h" | 5 #include "chrome/browser/chromeos/login/ui/webui_login_display.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 8 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 9 #include "chrome/browser/chromeos/login/lock/screen_locker.h" | 9 #include "chrome/browser/chromeos/login/lock/screen_locker.h" |
| 10 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" | 10 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 if (activity_detector->HasObserver(this)) | 39 if (activity_detector->HasObserver(this)) |
| 40 activity_detector->RemoveObserver(this); | 40 activity_detector->RemoveObserver(this); |
| 41 } | 41 } |
| 42 | 42 |
| 43 // LoginDisplay implementation: ------------------------------------------------ | 43 // LoginDisplay implementation: ------------------------------------------------ |
| 44 | 44 |
| 45 WebUILoginDisplay::WebUILoginDisplay(LoginDisplay::Delegate* delegate) | 45 WebUILoginDisplay::WebUILoginDisplay(LoginDisplay::Delegate* delegate) |
| 46 : LoginDisplay(delegate, gfx::Rect()), | 46 : LoginDisplay(delegate, gfx::Rect()), |
| 47 show_guest_(false), | 47 show_guest_(false), |
| 48 show_new_user_(false), | 48 show_new_user_(false), |
| 49 webui_handler_(NULL) { | 49 webui_handler_(NULL), |
| 50 gaia_screen_(new GaiaScreen()), |
| 51 user_selection_screen_(new UserSelectionScreen()) { |
| 50 } | 52 } |
| 51 | 53 |
| 52 void WebUILoginDisplay::ClearAndEnablePassword() { | 54 void WebUILoginDisplay::ClearAndEnablePassword() { |
| 53 if (webui_handler_) | 55 if (webui_handler_) |
| 54 webui_handler_->ClearAndEnablePassword(); | 56 webui_handler_->ClearAndEnablePassword(); |
| 55 } | 57 } |
| 56 | 58 |
| 57 void WebUILoginDisplay::Init(const UserList& users, | 59 void WebUILoginDisplay::Init(const UserList& users, |
| 58 bool show_guest, | 60 bool show_guest, |
| 59 bool show_users, | 61 bool show_users, |
| 60 bool show_new_user) { | 62 bool show_new_user) { |
| 61 // Testing that the delegate has been set. | 63 // Testing that the delegate has been set. |
| 62 DCHECK(delegate_); | 64 DCHECK(delegate_); |
| 63 | 65 |
| 64 users_ = users; | 66 user_selection_screen_->Init(users); |
| 65 show_guest_ = show_guest; | 67 show_guest_ = show_guest; |
| 66 show_users_ = show_users; | 68 show_users_ = show_users; |
| 67 show_new_user_ = show_new_user; | 69 show_new_user_ = show_new_user; |
| 68 | 70 |
| 69 wm::UserActivityDetector* activity_detector = ash::Shell::GetInstance()-> | 71 wm::UserActivityDetector* activity_detector = ash::Shell::GetInstance()-> |
| 70 user_activity_detector(); | 72 user_activity_detector(); |
| 71 if (!activity_detector->HasObserver(this)) | 73 if (!activity_detector->HasObserver(this)) |
| 72 activity_detector->AddObserver(this); | 74 activity_detector->AddObserver(this); |
| 73 } | 75 } |
| 74 | 76 |
| 75 void WebUILoginDisplay::OnPreferencesChanged() { | 77 // ---- Common methods |
| 76 if (webui_handler_) | 78 |
| 77 webui_handler_->OnPreferencesChanged(); | 79 // ---- User selection screen methods |
| 80 |
| 81 void WebUILoginDisplay::OnBeforeUserRemoved(const std::string& username) { |
| 82 user_selection_screen_->OnBeforeUserRemoved(username); |
| 78 } | 83 } |
| 79 | 84 |
| 80 void WebUILoginDisplay::OnBeforeUserRemoved(const std::string& username) { | 85 void WebUILoginDisplay::OnUserRemoved(const std::string& username) { |
| 81 for (UserList::iterator it = users_.begin(); it != users_.end(); ++it) { | 86 user_selection_screen_->OnUserRemoved(username); |
| 82 if ((*it)->email() == username) { | |
| 83 users_.erase(it); | |
| 84 break; | |
| 85 } | |
| 86 } | |
| 87 } | 87 } |
| 88 | 88 |
| 89 void WebUILoginDisplay::OnUserImageChanged(const User& user) { | 89 void WebUILoginDisplay::OnUserImageChanged(const User& user) { |
| 90 if (webui_handler_) | 90 user_selection_screen_->OnUserImageChanged(user); |
| 91 webui_handler_->OnUserImageChanged(user); | |
| 92 } | 91 } |
| 93 | 92 |
| 94 void WebUILoginDisplay::OnUserRemoved(const std::string& username) { | 93 void WebUILoginDisplay::ShowUserPodButton(const std::string& username, |
| 95 if (webui_handler_) | 94 const std::string& iconURL, |
| 96 webui_handler_->OnUserRemoved(username); | 95 const base::Closure& click_callback) { |
| 96 user_selection_screen_->ShowUserPodButton(username, iconURL, click_callback); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void WebUILoginDisplay::OnFadeOut() { | 99 void WebUILoginDisplay::HideUserPodButton(const std::string& username) { |
| 100 user_selection_screen_->HideUserPodButton(username); |
| 100 } | 101 } |
| 101 | 102 |
| 102 void WebUILoginDisplay::OnLoginSuccess(const std::string& username) { | 103 // User selection screen, screen lock API |
| 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 | 104 |
| 129 void WebUILoginDisplay::ShowBannerMessage(const std::string& message) { | 105 void WebUILoginDisplay::ShowBannerMessage(const std::string& message) { |
| 130 if (!webui_handler_) | 106 if (!webui_handler_) |
| 131 return; | 107 return; |
| 132 webui_handler_->ShowBannerMessage(message); | 108 webui_handler_->ShowBannerMessage(message); |
| 133 } | 109 } |
| 134 | 110 |
| 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 | 111 |
| 150 void WebUILoginDisplay::SetAuthType(const std::string& username, | 112 void WebUILoginDisplay::SetAuthType(const std::string& username, |
| 151 AuthType auth_type, | 113 AuthType auth_type, |
| 152 const std::string& initial_value) { | 114 const std::string& initial_value) { |
| 153 if (!webui_handler_) | 115 if (!webui_handler_) |
| 154 return; | 116 return; |
| 155 webui_handler_->SetAuthType(username, auth_type, initial_value); | 117 webui_handler_->SetAuthType(username, auth_type, initial_value); |
| 156 } | 118 } |
| 157 | 119 |
| 158 LoginDisplay::AuthType WebUILoginDisplay::GetAuthType( | 120 LoginDisplay::AuthType WebUILoginDisplay::GetAuthType( |
| 159 const std::string& username) const { | 121 const std::string& username) const { |
| 160 // Return default auth type if WebUI hander is not ready. | 122 // Return default auth type if WebUI hander is not ready. |
| 161 if (!webui_handler_) | 123 if (!webui_handler_) |
| 162 return OFFLINE_PASSWORD; | 124 return OFFLINE_PASSWORD; |
| 163 return webui_handler_->GetAuthType(username); | 125 return webui_handler_->GetAuthType(username); |
| 164 } | 126 } |
| 165 | 127 |
| 128 const UserList& WebUILoginDisplay::GetUsers() const { |
| 129 return user_selection_screen_->GetUsers(); |
| 130 } |
| 131 |
| 132 // ---- Gaia screen methods |
| 133 |
| 134 // ---- Not yet classified methods |
| 135 |
| 136 void WebUILoginDisplay::OnPreferencesChanged() { |
| 137 if (webui_handler_) |
| 138 webui_handler_->OnPreferencesChanged(); |
| 139 } |
| 140 |
| 141 void WebUILoginDisplay::SetUIEnabled(bool is_enabled) { |
| 142 // TODO(nkostylev): Cleanup this condition, |
| 143 // see http://crbug.com/157885 and http://crbug.com/158255. |
| 144 // Allow this call only before user sign in or at lock screen. |
| 145 // If this call is made after new user signs in but login screen is still |
| 146 // around that would trigger a sign in extension refresh. |
| 147 if (is_enabled && (!UserManager::Get()->IsUserLoggedIn() || |
| 148 ScreenLocker::default_screen_locker())) { |
| 149 ClearAndEnablePassword(); |
| 150 } |
| 151 |
| 152 if (chromeos::LoginDisplayHost* host = |
| 153 chromeos::LoginDisplayHostImpl::default_host()) { |
| 154 if (chromeos::WebUILoginView* login_view = host->GetWebUILoginView()) |
| 155 login_view->SetUIEnabled(is_enabled); |
| 156 } |
| 157 } |
| 158 |
| 166 void WebUILoginDisplay::ShowError(int error_msg_id, | 159 void WebUILoginDisplay::ShowError(int error_msg_id, |
| 167 int login_attempts, | 160 int login_attempts, |
| 168 HelpAppLauncher::HelpTopic help_topic_id) { | 161 HelpAppLauncher::HelpTopic help_topic_id) { |
| 169 VLOG(1) << "Show error, error_id: " << error_msg_id | 162 VLOG(1) << "Show error, error_id: " << error_msg_id |
| 170 << ", attempts:" << login_attempts | 163 << ", attempts:" << login_attempts |
| 171 << ", help_topic_id: " << help_topic_id; | 164 << ", help_topic_id: " << help_topic_id; |
| 172 if (!webui_handler_) | 165 if (!webui_handler_) |
| 173 return; | 166 return; |
| 174 | 167 |
| 175 std::string error_text; | 168 std::string error_text; |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 } | 345 } |
| 353 | 346 |
| 354 void WebUILoginDisplay::ShowWrongHWIDScreen() { | 347 void WebUILoginDisplay::ShowWrongHWIDScreen() { |
| 355 if (delegate_) | 348 if (delegate_) |
| 356 delegate_->ShowWrongHWIDScreen(); | 349 delegate_->ShowWrongHWIDScreen(); |
| 357 } | 350 } |
| 358 | 351 |
| 359 void WebUILoginDisplay::SetWebUIHandler( | 352 void WebUILoginDisplay::SetWebUIHandler( |
| 360 LoginDisplayWebUIHandler* webui_handler) { | 353 LoginDisplayWebUIHandler* webui_handler) { |
| 361 webui_handler_ = webui_handler; | 354 webui_handler_ = webui_handler; |
| 355 gaia_screen_->SetHandler(webui_handler_); |
| 356 user_selection_screen_->SetHandler(webui_handler_); |
| 362 } | 357 } |
| 363 | 358 |
| 364 void WebUILoginDisplay::ShowSigninScreenForCreds( | 359 void WebUILoginDisplay::ShowSigninScreenForCreds( |
| 365 const std::string& username, | 360 const std::string& username, |
| 366 const std::string& password) { | 361 const std::string& password) { |
| 367 if (webui_handler_) | 362 if (webui_handler_) |
| 368 webui_handler_->ShowSigninScreenForCreds(username, password); | 363 webui_handler_->ShowSigninScreenForCreds(username, password); |
| 369 } | 364 } |
| 370 | 365 |
| 371 const UserList& WebUILoginDisplay::GetUsers() const { | |
| 372 return users_; | |
| 373 } | |
| 374 | |
| 375 bool WebUILoginDisplay::IsShowGuest() const { | 366 bool WebUILoginDisplay::IsShowGuest() const { |
| 376 return show_guest_; | 367 return show_guest_; |
| 377 } | 368 } |
| 378 | 369 |
| 379 bool WebUILoginDisplay::IsShowUsers() const { | 370 bool WebUILoginDisplay::IsShowUsers() const { |
| 380 return show_users_; | 371 return show_users_; |
| 381 } | 372 } |
| 382 | 373 |
| 383 bool WebUILoginDisplay::IsShowNewUser() const { | 374 bool WebUILoginDisplay::IsShowNewUser() const { |
| 384 return show_new_user_; | 375 return show_new_user_; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 base::TimeDelta::FromSeconds(kPasswordClearTimeoutSec), this, | 411 base::TimeDelta::FromSeconds(kPasswordClearTimeoutSec), this, |
| 421 &WebUILoginDisplay::OnPasswordClearTimerExpired); | 412 &WebUILoginDisplay::OnPasswordClearTimerExpired); |
| 422 } | 413 } |
| 423 | 414 |
| 424 void WebUILoginDisplay::OnPasswordClearTimerExpired() { | 415 void WebUILoginDisplay::OnPasswordClearTimerExpired() { |
| 425 if (webui_handler_) | 416 if (webui_handler_) |
| 426 webui_handler_->ClearUserPodPassword(); | 417 webui_handler_->ClearUserPodPassword(); |
| 427 } | 418 } |
| 428 | 419 |
| 429 } // namespace chromeos | 420 } // namespace chromeos |
| OLD | NEW |