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"
7 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
8 #include "chrome/browser/chromeos/login/lock/screen_locker.h"
9 #include "chrome/browser/chromeos/login/screens/chrome_user_selection_screen.h"
10 #include "chrome/browser/chromeos/login/signin_screen_controller.h"
11 #include "chrome/browser/chromeos/login/startup_utils.h"
12 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
13 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
14 #include "chrome/browser/chromeos/login/ui/webui_login_view.h"
15 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
16 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/browser/ui/browser_window.h"
18 #include "chrome/grit/chromium_strings.h"
19 #include "chrome/grit/generated_resources.h"
20 #include "chromeos/login/user_names.h"
21 #include "components/user_manager/user_manager.h"
22 #include "grit/components_strings.h"
23 #include "ui/base/ime/chromeos/ime_keyboard.h"
24 #include "ui/base/ime/chromeos/input_method_manager.h"
25 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/base/user_activity/user_activity_detector.h"
27 #include "ui/views/widget/widget.h"
31 // WebUILoginDisplay, public: --------------------------------------------------
33 WebUILoginDisplay::~WebUILoginDisplay() {
35 webui_handler_
->ResetSigninScreenHandlerDelegate();
36 ui::UserActivityDetector
* activity_detector
= ui::UserActivityDetector::Get();
37 if (activity_detector
->HasObserver(this))
38 activity_detector
->RemoveObserver(this);
41 // LoginDisplay implementation: ------------------------------------------------
43 WebUILoginDisplay::WebUILoginDisplay(LoginDisplay::Delegate
* delegate
)
44 : LoginDisplay(delegate
, gfx::Rect()),
46 show_new_user_(false),
47 webui_handler_(NULL
) {
50 void WebUILoginDisplay::ClearAndEnablePassword() {
52 webui_handler_
->ClearAndEnablePassword();
55 void WebUILoginDisplay::Init(const user_manager::UserList
& users
,
59 // Testing that the delegate has been set.
61 SignInScreenController::Get()->Init(users
, show_guest
);
62 show_guest_
= show_guest
;
63 show_users_
= show_users
;
64 show_new_user_
= show_new_user
;
66 ui::UserActivityDetector
* activity_detector
= ui::UserActivityDetector::Get();
67 if (!activity_detector
->HasObserver(this))
68 activity_detector
->AddObserver(this);
71 // ---- Common methods
73 // ---- User selection screen methods
75 void WebUILoginDisplay::HandleGetUsers() {
76 SignInScreenController::Get()->SendUserList();
79 const user_manager::UserList
& WebUILoginDisplay::GetUsers() const {
80 return SignInScreenController::Get()->GetUsers();
83 void WebUILoginDisplay::CheckUserStatus(const std::string
& user_id
) {
84 SignInScreenController::Get()->CheckUserStatus(user_id
);
87 // ---- Gaia screen methods
89 // ---- Not yet classified methods
91 void WebUILoginDisplay::OnPreferencesChanged() {
93 webui_handler_
->OnPreferencesChanged();
96 void WebUILoginDisplay::SetUIEnabled(bool is_enabled
) {
97 // TODO(nkostylev): Cleanup this condition,
98 // see http://crbug.com/157885 and http://crbug.com/158255.
99 // Allow this call only before user sign in or at lock screen.
100 // If this call is made after new user signs in but login screen is still
101 // around that would trigger a sign in extension refresh.
102 if (is_enabled
&& (!user_manager::UserManager::Get()->IsUserLoggedIn() ||
103 ScreenLocker::default_screen_locker())) {
104 ClearAndEnablePassword();
107 if (chromeos::LoginDisplayHost
* host
=
108 chromeos::LoginDisplayHostImpl::default_host()) {
109 if (chromeos::WebUILoginView
* login_view
= host
->GetWebUILoginView())
110 login_view
->SetUIEnabled(is_enabled
);
114 void WebUILoginDisplay::ShowError(int error_msg_id
,
116 HelpAppLauncher::HelpTopic help_topic_id
) {
117 VLOG(1) << "Show error, error_id: " << error_msg_id
118 << ", attempts:" << login_attempts
119 << ", help_topic_id: " << help_topic_id
;
123 std::string error_text
;
124 switch (error_msg_id
) {
125 case IDS_LOGIN_ERROR_AUTHENTICATING_HOSTED
:
126 error_text
= l10n_util::GetStringFUTF8(
127 error_msg_id
, l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_OS_NAME
));
129 case IDS_LOGIN_ERROR_CAPTIVE_PORTAL
:
130 error_text
= l10n_util::GetStringFUTF8(
131 error_msg_id
, delegate()->GetConnectedNetworkName());
134 error_text
= l10n_util::GetStringUTF8(error_msg_id
);
138 // Only display hints about keyboard layout if the error is authentication-
140 if (error_msg_id
!= IDS_LOGIN_ERROR_WHITELIST
&&
141 error_msg_id
!= IDS_ENTERPRISE_LOGIN_ERROR_WHITELIST
&&
142 error_msg_id
!= IDS_LOGIN_ERROR_OWNER_KEY_LOST
&&
143 error_msg_id
!= IDS_LOGIN_ERROR_OWNER_REQUIRED
) {
144 // Display a warning if Caps Lock is on.
145 input_method::InputMethodManager
* ime_manager
=
146 input_method::InputMethodManager::Get();
147 if (ime_manager
->GetImeKeyboard()->CapsLockIsEnabled()) {
148 // TODO(ivankr): use a format string instead of concatenation.
150 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_CAPS_LOCK_HINT
);
153 // Display a hint to switch keyboards if there are other active input
155 if (ime_manager
->GetActiveIMEState()->GetNumActiveInputMethods() > 1) {
157 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_KEYBOARD_SWITCH_HINT
);
161 std::string help_link
;
162 switch (error_msg_id
) {
163 case IDS_LOGIN_ERROR_AUTHENTICATING_HOSTED
:
164 help_link
= l10n_util::GetStringUTF8(IDS_LEARN_MORE
);
167 if (login_attempts
> 1)
168 help_link
= l10n_util::GetStringUTF8(IDS_LEARN_MORE
);
172 webui_handler_
->ShowError(login_attempts
, error_text
, help_link
,
176 void WebUILoginDisplay::ShowErrorScreen(LoginDisplay::SigninError error_id
) {
177 VLOG(1) << "Show error screen, error_id: " << error_id
;
180 webui_handler_
->ShowErrorScreen(error_id
);
183 void WebUILoginDisplay::ShowGaiaPasswordChanged(const std::string
& username
) {
185 webui_handler_
->ShowGaiaPasswordChanged(username
);
188 void WebUILoginDisplay::ShowPasswordChangedDialog(bool show_password_error
,
189 const std::string
& email
) {
191 webui_handler_
->ShowPasswordChangedDialog(show_password_error
, email
);
194 void WebUILoginDisplay::ShowSigninUI(const std::string
& email
) {
196 webui_handler_
->ShowSigninUI(email
);
199 void WebUILoginDisplay::ShowWhitelistCheckFailedError() {
201 webui_handler_
->ShowWhitelistCheckFailedError();
204 // WebUILoginDisplay, NativeWindowDelegate implementation: ---------------------
205 gfx::NativeWindow
WebUILoginDisplay::GetNativeWindow() const {
206 return parent_window();
209 // WebUILoginDisplay, SigninScreenHandlerDelegate implementation: --------------
210 void WebUILoginDisplay::CancelPasswordChangedFlow() {
213 delegate_
->CancelPasswordChangedFlow();
216 void WebUILoginDisplay::CancelUserAdding() {
217 if (!UserAddingScreen::Get()->IsRunning()) {
218 LOG(ERROR
) << "User adding screen not running.";
221 UserAddingScreen::Get()->Cancel();
224 void WebUILoginDisplay::CreateAccount() {
227 delegate_
->CreateAccount();
230 void WebUILoginDisplay::CompleteLogin(const UserContext
& user_context
) {
233 delegate_
->CompleteLogin(user_context
);
236 void WebUILoginDisplay::Login(const UserContext
& user_context
,
237 const SigninSpecifics
& specifics
) {
240 delegate_
->Login(user_context
, specifics
);
243 void WebUILoginDisplay::MigrateUserData(const std::string
& old_password
) {
246 delegate_
->MigrateUserData(old_password
);
249 void WebUILoginDisplay::LoadWallpaper(const std::string
& username
) {
250 WallpaperManager::Get()->SetUserWallpaperDelayed(username
);
253 void WebUILoginDisplay::LoadSigninWallpaper() {
254 WallpaperManager::Get()->SetDefaultWallpaperDelayed(
255 chromeos::login::kSignInUser
);
258 void WebUILoginDisplay::OnSigninScreenReady() {
259 SignInScreenController::Get()->OnSigninScreenReady();
262 delegate_
->OnSigninScreenReady();
265 void WebUILoginDisplay::RemoveUser(const std::string
& user_id
) {
266 SignInScreenController::Get()->RemoveUser(user_id
);
269 void WebUILoginDisplay::ResyncUserData() {
272 delegate_
->ResyncUserData();
275 void WebUILoginDisplay::ShowEnterpriseEnrollmentScreen() {
277 delegate_
->OnStartEnterpriseEnrollment();
280 void WebUILoginDisplay::ShowEnableDebuggingScreen() {
282 delegate_
->OnStartEnableDebuggingScreen();
285 void WebUILoginDisplay::ShowKioskEnableScreen() {
287 delegate_
->OnStartKioskEnableScreen();
290 void WebUILoginDisplay::ShowKioskAutolaunchScreen() {
292 delegate_
->OnStartKioskAutolaunchScreen();
295 void WebUILoginDisplay::ShowWrongHWIDScreen() {
297 delegate_
->ShowWrongHWIDScreen();
300 void WebUILoginDisplay::SetWebUIHandler(
301 LoginDisplayWebUIHandler
* webui_handler
) {
302 webui_handler_
= webui_handler
;
303 SignInScreenController::Get()->SetWebUIHandler(webui_handler_
);
306 void WebUILoginDisplay::ShowSigninScreenForCreds(
307 const std::string
& username
,
308 const std::string
& password
) {
310 webui_handler_
->ShowSigninScreenForCreds(username
, password
);
313 bool WebUILoginDisplay::IsShowGuest() const {
317 bool WebUILoginDisplay::IsShowUsers() const {
321 bool WebUILoginDisplay::IsSigninInProgress() const {
322 return delegate_
->IsSigninInProgress();
325 bool WebUILoginDisplay::IsUserSigninCompleted() const {
326 return is_signin_completed();
329 void WebUILoginDisplay::SetDisplayEmail(const std::string
& email
) {
331 delegate_
->SetDisplayEmail(email
);
334 void WebUILoginDisplay::Signout() {
335 delegate_
->Signout();
338 void WebUILoginDisplay::OnUserActivity(const ui::Event
* event
) {
340 delegate_
->ResetPublicSessionAutoLoginTimer();
343 bool WebUILoginDisplay::IsUserWhitelisted(const std::string
& user_id
) {
346 return delegate_
->IsUserWhitelisted(user_id
);
350 } // namespace chromeos