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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/login/ui/webui_login_display.h"
8 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
9 #include "chrome/browser/chromeos/login/lock/screen_locker.h"
10 #include "chrome/browser/chromeos/login/screens/chrome_user_selection_screen.h"
11 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
12 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
13 #include "chrome/browser/chromeos/login/ui/webui_login_view.h"
14 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
15 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/browser/ui/browser_window.h"
17 #include "chrome/grit/chromium_strings.h"
18 #include "chrome/grit/generated_resources.h"
19 #include "chromeos/ime/ime_keyboard.h"
20 #include "chromeos/ime/input_method_manager.h"
21 #include "chromeos/login/user_names.h"
22 #include "components/user_manager/user_manager.h"
23 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/views/widget/widget.h"
25 #include "ui/wm/core/user_activity_detector.h"
29 // WebUILoginDisplay, public: --------------------------------------------------
31 WebUILoginDisplay::~WebUILoginDisplay() {
33 webui_handler_->ResetSigninScreenHandlerDelegate();
34 wm::UserActivityDetector* activity_detector = ash::Shell::GetInstance()->
35 user_activity_detector();
36 if (activity_detector->HasObserver(this))
37 activity_detector->RemoveObserver(this);
40 // LoginDisplay implementation: ------------------------------------------------
42 WebUILoginDisplay::WebUILoginDisplay(LoginDisplay::Delegate* delegate)
43 : LoginDisplay(delegate, gfx::Rect()),
45 show_new_user_(false),
47 gaia_screen_(new GaiaScreen()),
48 user_selection_screen_(new ChromeUserSelectionScreen()) {
51 void WebUILoginDisplay::ClearAndEnablePassword() {
53 webui_handler_->ClearAndEnablePassword();
56 void WebUILoginDisplay::Init(const user_manager::UserList& users,
60 // Testing that the delegate has been set.
63 user_selection_screen_->Init(users, show_guest);
64 show_guest_ = show_guest;
65 show_users_ = show_users;
66 show_new_user_ = show_new_user;
68 wm::UserActivityDetector* activity_detector = ash::Shell::GetInstance()->
69 user_activity_detector();
70 if (!activity_detector->HasObserver(this))
71 activity_detector->AddObserver(this);
74 // ---- Common methods
76 // ---- User selection screen methods
78 void WebUILoginDisplay::OnBeforeUserRemoved(const std::string& username) {
79 user_selection_screen_->OnBeforeUserRemoved(username);
82 void WebUILoginDisplay::OnUserRemoved(const std::string& username) {
83 user_selection_screen_->OnUserRemoved(username);
86 void WebUILoginDisplay::OnUserImageChanged(const user_manager::User& user) {
87 user_selection_screen_->OnUserImageChanged(user);
90 void WebUILoginDisplay::HandleGetUsers() {
91 user_selection_screen_->HandleGetUsers();
94 const user_manager::UserList& WebUILoginDisplay::GetUsers() const {
95 return user_selection_screen_->GetUsers();
98 // User selection screen, screen lock API
100 void WebUILoginDisplay::SetAuthType(
101 const std::string& username,
102 ScreenlockBridge::LockHandler::AuthType auth_type) {
103 user_selection_screen_->SetAuthType(username, auth_type);
106 ScreenlockBridge::LockHandler::AuthType WebUILoginDisplay::GetAuthType(
107 const std::string& username) const {
108 return user_selection_screen_->GetAuthType(username);
111 // ---- Gaia screen methods
113 // ---- Not yet classified methods
115 void WebUILoginDisplay::OnPreferencesChanged() {
117 webui_handler_->OnPreferencesChanged();
120 void WebUILoginDisplay::SetUIEnabled(bool is_enabled) {
121 // TODO(nkostylev): Cleanup this condition,
122 // see http://crbug.com/157885 and http://crbug.com/158255.
123 // Allow this call only before user sign in or at lock screen.
124 // If this call is made after new user signs in but login screen is still
125 // around that would trigger a sign in extension refresh.
126 if (is_enabled && (!user_manager::UserManager::Get()->IsUserLoggedIn() ||
127 ScreenLocker::default_screen_locker())) {
128 ClearAndEnablePassword();
131 if (chromeos::LoginDisplayHost* host =
132 chromeos::LoginDisplayHostImpl::default_host()) {
133 if (chromeos::WebUILoginView* login_view = host->GetWebUILoginView())
134 login_view->SetUIEnabled(is_enabled);
138 void WebUILoginDisplay::ShowError(int error_msg_id,
140 HelpAppLauncher::HelpTopic help_topic_id) {
141 VLOG(1) << "Show error, error_id: " << error_msg_id
142 << ", attempts:" << login_attempts
143 << ", help_topic_id: " << help_topic_id;
147 std::string error_text;
148 switch (error_msg_id) {
149 case IDS_LOGIN_ERROR_AUTHENTICATING_HOSTED:
150 error_text = l10n_util::GetStringFUTF8(
151 error_msg_id, l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_OS_NAME));
153 case IDS_LOGIN_ERROR_CAPTIVE_PORTAL:
154 error_text = l10n_util::GetStringFUTF8(
155 error_msg_id, delegate()->GetConnectedNetworkName());
158 error_text = l10n_util::GetStringUTF8(error_msg_id);
162 // Only display hints about keyboard layout if the error is authentication-
164 if (error_msg_id != IDS_LOGIN_ERROR_WHITELIST &&
165 error_msg_id != IDS_LOGIN_ERROR_OWNER_KEY_LOST &&
166 error_msg_id != IDS_LOGIN_ERROR_OWNER_REQUIRED) {
167 // Display a warning if Caps Lock is on.
168 input_method::InputMethodManager* ime_manager =
169 input_method::InputMethodManager::Get();
170 if (ime_manager->GetImeKeyboard()->CapsLockIsEnabled()) {
171 // TODO(ivankr): use a format string instead of concatenation.
173 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_CAPS_LOCK_HINT);
176 // Display a hint to switch keyboards if there are other active input
178 if (ime_manager->GetNumActiveInputMethods() > 1) {
180 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_KEYBOARD_SWITCH_HINT);
184 std::string help_link;
185 switch (error_msg_id) {
186 case IDS_LOGIN_ERROR_AUTHENTICATING_HOSTED:
187 help_link = l10n_util::GetStringUTF8(IDS_LEARN_MORE);
190 if (login_attempts > 1)
191 help_link = l10n_util::GetStringUTF8(IDS_LEARN_MORE);
195 webui_handler_->ShowError(login_attempts, error_text, help_link,
199 void WebUILoginDisplay::ShowErrorScreen(LoginDisplay::SigninError error_id) {
200 VLOG(1) << "Show error screen, error_id: " << error_id;
203 webui_handler_->ShowErrorScreen(error_id);
206 void WebUILoginDisplay::ShowGaiaPasswordChanged(const std::string& username) {
208 webui_handler_->ShowGaiaPasswordChanged(username);
211 void WebUILoginDisplay::ShowPasswordChangedDialog(bool show_password_error) {
213 webui_handler_->ShowPasswordChangedDialog(show_password_error);
216 void WebUILoginDisplay::ShowSigninUI(const std::string& email) {
218 webui_handler_->ShowSigninUI(email);
221 // WebUILoginDisplay, NativeWindowDelegate implementation: ---------------------
222 gfx::NativeWindow WebUILoginDisplay::GetNativeWindow() const {
223 return parent_window();
226 // WebUILoginDisplay, SigninScreenHandlerDelegate implementation: --------------
227 void WebUILoginDisplay::CancelPasswordChangedFlow() {
230 delegate_->CancelPasswordChangedFlow();
233 void WebUILoginDisplay::CancelUserAdding() {
234 if (!UserAddingScreen::Get()->IsRunning()) {
235 LOG(ERROR) << "User adding screen not running.";
238 UserAddingScreen::Get()->Cancel();
241 void WebUILoginDisplay::CreateAccount() {
244 delegate_->CreateAccount();
247 void WebUILoginDisplay::CompleteLogin(const UserContext& user_context) {
250 delegate_->CompleteLogin(user_context);
253 void WebUILoginDisplay::Login(const UserContext& user_context,
254 const SigninSpecifics& specifics) {
257 delegate_->Login(user_context, specifics);
260 void WebUILoginDisplay::MigrateUserData(const std::string& old_password) {
263 delegate_->MigrateUserData(old_password);
266 void WebUILoginDisplay::LoadWallpaper(const std::string& username) {
267 WallpaperManager::Get()->SetUserWallpaperDelayed(username);
270 void WebUILoginDisplay::LoadSigninWallpaper() {
271 WallpaperManager::Get()->SetDefaultWallpaperDelayed(
272 chromeos::login::kSignInUser);
275 void WebUILoginDisplay::OnSigninScreenReady() {
277 delegate_->OnSigninScreenReady();
280 void WebUILoginDisplay::RemoveUser(const std::string& username) {
281 user_manager::UserManager::Get()->RemoveUser(username, this);
284 void WebUILoginDisplay::ResyncUserData() {
287 delegate_->ResyncUserData();
290 void WebUILoginDisplay::ShowEnterpriseEnrollmentScreen() {
292 delegate_->OnStartEnterpriseEnrollment();
295 void WebUILoginDisplay::ShowKioskEnableScreen() {
297 delegate_->OnStartKioskEnableScreen();
300 void WebUILoginDisplay::ShowKioskAutolaunchScreen() {
302 delegate_->OnStartKioskAutolaunchScreen();
305 void WebUILoginDisplay::ShowWrongHWIDScreen() {
307 delegate_->ShowWrongHWIDScreen();
310 void WebUILoginDisplay::SetWebUIHandler(
311 LoginDisplayWebUIHandler* webui_handler) {
312 webui_handler_ = webui_handler;
313 gaia_screen_->SetHandler(webui_handler_);
314 user_selection_screen_->SetHandler(webui_handler_);
317 void WebUILoginDisplay::ShowSigninScreenForCreds(
318 const std::string& username,
319 const std::string& password) {
321 webui_handler_->ShowSigninScreenForCreds(username, password);
324 bool WebUILoginDisplay::IsShowGuest() const {
328 bool WebUILoginDisplay::IsShowUsers() const {
332 bool WebUILoginDisplay::IsSigninInProgress() const {
333 return delegate_->IsSigninInProgress();
336 bool WebUILoginDisplay::IsUserSigninCompleted() const {
337 return is_signin_completed();
340 void WebUILoginDisplay::SetDisplayEmail(const std::string& email) {
342 delegate_->SetDisplayEmail(email);
345 void WebUILoginDisplay::Signout() {
346 delegate_->Signout();
349 void WebUILoginDisplay::OnUserActivity(const ui::Event* event) {
351 delegate_->ResetPublicSessionAutoLoginTimer();
355 } // namespace chromeos