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/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/login/user_names.h"
20 #include "components/user_manager/user_manager.h"
21 #include "grit/components_strings.h"
22 #include "ui/base/ime/chromeos/ime_keyboard.h"
23 #include "ui/base/ime/chromeos/input_method_manager.h"
24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/user_activity/user_activity_detector.h"
26 #include "ui/views/widget/widget.h"
30 // WebUILoginDisplay, public: --------------------------------------------------
32 WebUILoginDisplay::~WebUILoginDisplay() {
34 webui_handler_
->ResetSigninScreenHandlerDelegate();
35 ui::UserActivityDetector
* activity_detector
= ui::UserActivityDetector::Get();
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),
46 webui_handler_(NULL
) {
49 void WebUILoginDisplay::ClearAndEnablePassword() {
51 webui_handler_
->ClearAndEnablePassword();
54 void WebUILoginDisplay::Init(const user_manager::UserList
& users
,
58 // Testing that the delegate has been set.
60 SignInScreenController::Get()->Init(users
, show_guest
);
61 show_guest_
= show_guest
;
62 show_users_
= show_users
;
63 show_new_user_
= show_new_user
;
65 ui::UserActivityDetector
* activity_detector
= ui::UserActivityDetector::Get();
66 if (!activity_detector
->HasObserver(this))
67 activity_detector
->AddObserver(this);
70 // ---- Common methods
72 // ---- User selection screen methods
74 void WebUILoginDisplay::HandleGetUsers() {
75 SignInScreenController::Get()->SendUserList();
78 const user_manager::UserList
& WebUILoginDisplay::GetUsers() const {
79 return SignInScreenController::Get()->GetUsers();
82 // ---- Gaia screen methods
84 // ---- Not yet classified methods
86 void WebUILoginDisplay::OnPreferencesChanged() {
88 webui_handler_
->OnPreferencesChanged();
91 void WebUILoginDisplay::SetUIEnabled(bool is_enabled
) {
92 // TODO(nkostylev): Cleanup this condition,
93 // see http://crbug.com/157885 and http://crbug.com/158255.
94 // Allow this call only before user sign in or at lock screen.
95 // If this call is made after new user signs in but login screen is still
96 // around that would trigger a sign in extension refresh.
97 if (is_enabled
&& (!user_manager::UserManager::Get()->IsUserLoggedIn() ||
98 ScreenLocker::default_screen_locker())) {
99 ClearAndEnablePassword();
102 if (chromeos::LoginDisplayHost
* host
=
103 chromeos::LoginDisplayHostImpl::default_host()) {
104 if (chromeos::WebUILoginView
* login_view
= host
->GetWebUILoginView())
105 login_view
->SetUIEnabled(is_enabled
);
109 void WebUILoginDisplay::ShowError(int error_msg_id
,
111 HelpAppLauncher::HelpTopic help_topic_id
) {
112 VLOG(1) << "Show error, error_id: " << error_msg_id
113 << ", attempts:" << login_attempts
114 << ", help_topic_id: " << help_topic_id
;
118 std::string error_text
;
119 switch (error_msg_id
) {
120 case IDS_LOGIN_ERROR_AUTHENTICATING_HOSTED
:
121 error_text
= l10n_util::GetStringFUTF8(
122 error_msg_id
, l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_OS_NAME
));
124 case IDS_LOGIN_ERROR_CAPTIVE_PORTAL
:
125 error_text
= l10n_util::GetStringFUTF8(
126 error_msg_id
, delegate()->GetConnectedNetworkName());
129 error_text
= l10n_util::GetStringUTF8(error_msg_id
);
133 // Only display hints about keyboard layout if the error is authentication-
135 if (error_msg_id
!= IDS_LOGIN_ERROR_WHITELIST
&&
136 error_msg_id
!= IDS_ENTERPRISE_LOGIN_ERROR_WHITELIST
&&
137 error_msg_id
!= IDS_LOGIN_ERROR_OWNER_KEY_LOST
&&
138 error_msg_id
!= IDS_LOGIN_ERROR_OWNER_REQUIRED
) {
139 // Display a warning if Caps Lock is on.
140 input_method::InputMethodManager
* ime_manager
=
141 input_method::InputMethodManager::Get();
142 if (ime_manager
->GetImeKeyboard()->CapsLockIsEnabled()) {
143 // TODO(ivankr): use a format string instead of concatenation.
145 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_CAPS_LOCK_HINT
);
148 // Display a hint to switch keyboards if there are other active input
150 if (ime_manager
->GetActiveIMEState()->GetNumActiveInputMethods() > 1) {
152 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_KEYBOARD_SWITCH_HINT
);
156 std::string help_link
;
157 switch (error_msg_id
) {
158 case IDS_LOGIN_ERROR_AUTHENTICATING_HOSTED
:
159 help_link
= l10n_util::GetStringUTF8(IDS_LEARN_MORE
);
162 if (login_attempts
> 1)
163 help_link
= l10n_util::GetStringUTF8(IDS_LEARN_MORE
);
167 webui_handler_
->ShowError(login_attempts
, error_text
, help_link
,
171 void WebUILoginDisplay::ShowErrorScreen(LoginDisplay::SigninError error_id
) {
172 VLOG(1) << "Show error screen, error_id: " << error_id
;
175 webui_handler_
->ShowErrorScreen(error_id
);
178 void WebUILoginDisplay::ShowGaiaPasswordChanged(const std::string
& username
) {
180 webui_handler_
->ShowGaiaPasswordChanged(username
);
183 void WebUILoginDisplay::ShowPasswordChangedDialog(bool show_password_error
) {
185 webui_handler_
->ShowPasswordChangedDialog(show_password_error
);
188 void WebUILoginDisplay::ShowSigninUI(const std::string
& email
) {
190 webui_handler_
->ShowSigninUI(email
);
193 // WebUILoginDisplay, NativeWindowDelegate implementation: ---------------------
194 gfx::NativeWindow
WebUILoginDisplay::GetNativeWindow() const {
195 return parent_window();
198 // WebUILoginDisplay, SigninScreenHandlerDelegate implementation: --------------
199 void WebUILoginDisplay::CancelPasswordChangedFlow() {
202 delegate_
->CancelPasswordChangedFlow();
205 void WebUILoginDisplay::CancelUserAdding() {
206 if (!UserAddingScreen::Get()->IsRunning()) {
207 LOG(ERROR
) << "User adding screen not running.";
210 UserAddingScreen::Get()->Cancel();
213 void WebUILoginDisplay::CreateAccount() {
216 delegate_
->CreateAccount();
219 void WebUILoginDisplay::CompleteLogin(const UserContext
& user_context
) {
222 delegate_
->CompleteLogin(user_context
);
225 void WebUILoginDisplay::Login(const UserContext
& user_context
,
226 const SigninSpecifics
& specifics
) {
229 delegate_
->Login(user_context
, specifics
);
232 void WebUILoginDisplay::MigrateUserData(const std::string
& old_password
) {
235 delegate_
->MigrateUserData(old_password
);
238 void WebUILoginDisplay::LoadWallpaper(const std::string
& username
) {
239 WallpaperManager::Get()->SetUserWallpaperDelayed(username
);
242 void WebUILoginDisplay::LoadSigninWallpaper() {
243 WallpaperManager::Get()->SetDefaultWallpaperDelayed(
244 chromeos::login::kSignInUser
);
247 void WebUILoginDisplay::OnSigninScreenReady() {
248 SignInScreenController::Get()->OnSigninScreenReady();
251 delegate_
->OnSigninScreenReady();
254 void WebUILoginDisplay::RemoveUser(const std::string
& user_id
) {
255 SignInScreenController::Get()->RemoveUser(user_id
);
258 void WebUILoginDisplay::ResyncUserData() {
261 delegate_
->ResyncUserData();
264 void WebUILoginDisplay::ShowEnterpriseEnrollmentScreen() {
266 delegate_
->OnStartEnterpriseEnrollment();
269 void WebUILoginDisplay::ShowEnableDebuggingScreen() {
271 delegate_
->OnStartEnableDebuggingScreen();
274 void WebUILoginDisplay::ShowKioskEnableScreen() {
276 delegate_
->OnStartKioskEnableScreen();
279 void WebUILoginDisplay::ShowKioskAutolaunchScreen() {
281 delegate_
->OnStartKioskAutolaunchScreen();
284 void WebUILoginDisplay::ShowWrongHWIDScreen() {
286 delegate_
->ShowWrongHWIDScreen();
289 void WebUILoginDisplay::SetWebUIHandler(
290 LoginDisplayWebUIHandler
* webui_handler
) {
291 webui_handler_
= webui_handler
;
292 SignInScreenController::Get()->SetWebUIHandler(webui_handler_
);
295 void WebUILoginDisplay::ShowSigninScreenForCreds(
296 const std::string
& username
,
297 const std::string
& password
) {
299 webui_handler_
->ShowSigninScreenForCreds(username
, password
);
302 bool WebUILoginDisplay::IsShowGuest() const {
306 bool WebUILoginDisplay::IsShowUsers() const {
310 bool WebUILoginDisplay::IsSigninInProgress() const {
311 return delegate_
->IsSigninInProgress();
314 bool WebUILoginDisplay::IsUserSigninCompleted() const {
315 return is_signin_completed();
318 void WebUILoginDisplay::SetDisplayEmail(const std::string
& email
) {
320 delegate_
->SetDisplayEmail(email
);
323 void WebUILoginDisplay::Signout() {
324 delegate_
->Signout();
327 void WebUILoginDisplay::OnUserActivity(const ui::Event
* event
) {
329 delegate_
->ResetPublicSessionAutoLoginTimer();
333 } // namespace chromeos