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::ShowPasswordChangedDialog(bool show_password_error
,
184 const std::string
& email
) {
186 webui_handler_
->ShowPasswordChangedDialog(show_password_error
, email
);
189 void WebUILoginDisplay::ShowSigninUI(const std::string
& email
) {
191 webui_handler_
->ShowSigninUI(email
);
194 void WebUILoginDisplay::ShowWhitelistCheckFailedError() {
196 webui_handler_
->ShowWhitelistCheckFailedError();
199 // WebUILoginDisplay, NativeWindowDelegate implementation: ---------------------
200 gfx::NativeWindow
WebUILoginDisplay::GetNativeWindow() const {
201 return parent_window();
204 // WebUILoginDisplay, SigninScreenHandlerDelegate implementation: --------------
205 void WebUILoginDisplay::CancelPasswordChangedFlow() {
208 delegate_
->CancelPasswordChangedFlow();
211 void WebUILoginDisplay::CancelUserAdding() {
212 if (!UserAddingScreen::Get()->IsRunning()) {
213 LOG(ERROR
) << "User adding screen not running.";
216 UserAddingScreen::Get()->Cancel();
219 void WebUILoginDisplay::CreateAccount() {
222 delegate_
->CreateAccount();
225 void WebUILoginDisplay::CompleteLogin(const UserContext
& user_context
) {
228 delegate_
->CompleteLogin(user_context
);
231 void WebUILoginDisplay::Login(const UserContext
& user_context
,
232 const SigninSpecifics
& specifics
) {
235 delegate_
->Login(user_context
, specifics
);
238 void WebUILoginDisplay::MigrateUserData(const std::string
& old_password
) {
241 delegate_
->MigrateUserData(old_password
);
244 void WebUILoginDisplay::LoadWallpaper(const std::string
& username
) {
245 WallpaperManager::Get()->SetUserWallpaperDelayed(username
);
248 void WebUILoginDisplay::LoadSigninWallpaper() {
249 WallpaperManager::Get()->SetDefaultWallpaperDelayed(
250 chromeos::login::kSignInUser
);
253 void WebUILoginDisplay::OnSigninScreenReady() {
254 SignInScreenController::Get()->OnSigninScreenReady();
257 delegate_
->OnSigninScreenReady();
260 void WebUILoginDisplay::RemoveUser(const std::string
& user_id
) {
261 SignInScreenController::Get()->RemoveUser(user_id
);
264 void WebUILoginDisplay::ResyncUserData() {
267 delegate_
->ResyncUserData();
270 void WebUILoginDisplay::ShowEnterpriseEnrollmentScreen() {
272 delegate_
->OnStartEnterpriseEnrollment();
275 void WebUILoginDisplay::ShowEnableDebuggingScreen() {
277 delegate_
->OnStartEnableDebuggingScreen();
280 void WebUILoginDisplay::ShowKioskEnableScreen() {
282 delegate_
->OnStartKioskEnableScreen();
285 void WebUILoginDisplay::ShowKioskAutolaunchScreen() {
287 delegate_
->OnStartKioskAutolaunchScreen();
290 void WebUILoginDisplay::ShowWrongHWIDScreen() {
292 delegate_
->ShowWrongHWIDScreen();
295 void WebUILoginDisplay::SetWebUIHandler(
296 LoginDisplayWebUIHandler
* webui_handler
) {
297 webui_handler_
= webui_handler
;
298 SignInScreenController::Get()->SetWebUIHandler(webui_handler_
);
301 void WebUILoginDisplay::ShowSigninScreenForCreds(
302 const std::string
& username
,
303 const std::string
& password
) {
305 webui_handler_
->ShowSigninScreenForCreds(username
, password
);
308 bool WebUILoginDisplay::IsShowGuest() const {
312 bool WebUILoginDisplay::IsShowUsers() const {
316 bool WebUILoginDisplay::IsSigninInProgress() const {
317 return delegate_
->IsSigninInProgress();
320 bool WebUILoginDisplay::IsUserSigninCompleted() const {
321 return is_signin_completed();
324 void WebUILoginDisplay::SetDisplayEmail(const std::string
& email
) {
326 delegate_
->SetDisplayEmail(email
);
329 void WebUILoginDisplay::Signout() {
330 delegate_
->Signout();
333 void WebUILoginDisplay::OnUserActivity(const ui::Event
* event
) {
335 delegate_
->ResetPublicSessionAutoLoginTimer();
338 bool WebUILoginDisplay::IsUserWhitelisted(const std::string
& user_id
) {
341 return delegate_
->IsUserWhitelisted(user_id
);
345 } // namespace chromeos