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/ui/login_display_host_impl.h"
11 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
12 #include "chrome/browser/chromeos/login/ui/webui_login_view.h"
13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/browser/ui/browser_window.h"
15 #include "chrome/grit/chromium_strings.h"
16 #include "chrome/grit/generated_resources.h"
17 #include "chromeos/ime/ime_keyboard.h"
18 #include "chromeos/ime/input_method_manager.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/l10n/l10n_util.h"
23 #include "ui/views/widget/widget.h"
24 #include "ui/wm/core/user_activity_detector.h"
26 #if !defined(USE_ATHENA)
27 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
32 // WebUILoginDisplay, public: --------------------------------------------------
34 WebUILoginDisplay::~WebUILoginDisplay() {
36 webui_handler_->ResetSigninScreenHandlerDelegate();
37 wm::UserActivityDetector* activity_detector = wm::UserActivityDetector::Get();
38 if (activity_detector->HasObserver(this))
39 activity_detector->RemoveObserver(this);
42 // LoginDisplay implementation: ------------------------------------------------
44 WebUILoginDisplay::WebUILoginDisplay(LoginDisplay::Delegate* delegate)
45 : LoginDisplay(delegate, gfx::Rect()),
47 show_new_user_(false),
49 gaia_screen_(new GaiaScreen()),
50 user_selection_screen_(new ChromeUserSelectionScreen()) {
53 void WebUILoginDisplay::ClearAndEnablePassword() {
55 webui_handler_->ClearAndEnablePassword();
58 void WebUILoginDisplay::Init(const user_manager::UserList& users,
62 // Testing that the delegate has been set.
65 user_selection_screen_->Init(users, show_guest);
66 show_guest_ = show_guest;
67 show_users_ = show_users;
68 show_new_user_ = show_new_user;
70 wm::UserActivityDetector* activity_detector = wm::UserActivityDetector::Get();
71 if (!activity_detector->HasObserver(this))
72 activity_detector->AddObserver(this);
75 // ---- Common methods
77 // ---- User selection screen methods
79 void WebUILoginDisplay::OnBeforeUserRemoved(const std::string& username) {
80 user_selection_screen_->OnBeforeUserRemoved(username);
83 void WebUILoginDisplay::OnUserRemoved(const std::string& username) {
84 user_selection_screen_->OnUserRemoved(username);
87 void WebUILoginDisplay::OnUserImageChanged(const user_manager::User& user) {
88 user_selection_screen_->OnUserImageChanged(user);
91 void WebUILoginDisplay::HandleGetUsers() {
92 user_selection_screen_->HandleGetUsers();
95 const user_manager::UserList& WebUILoginDisplay::GetUsers() const {
96 return user_selection_screen_->GetUsers();
99 // User selection screen, screen lock API
101 void WebUILoginDisplay::SetAuthType(
102 const std::string& username,
103 ScreenlockBridge::LockHandler::AuthType auth_type) {
104 user_selection_screen_->SetAuthType(username, auth_type);
107 ScreenlockBridge::LockHandler::AuthType WebUILoginDisplay::GetAuthType(
108 const std::string& username) const {
109 return user_selection_screen_->GetAuthType(username);
112 // ---- Gaia screen methods
114 // ---- Not yet classified methods
116 void WebUILoginDisplay::OnPreferencesChanged() {
118 webui_handler_->OnPreferencesChanged();
121 void WebUILoginDisplay::SetUIEnabled(bool is_enabled) {
122 // TODO(nkostylev): Cleanup this condition,
123 // see http://crbug.com/157885 and http://crbug.com/158255.
124 // Allow this call only before user sign in or at lock screen.
125 // If this call is made after new user signs in but login screen is still
126 // around that would trigger a sign in extension refresh.
127 if (is_enabled && (!user_manager::UserManager::Get()->IsUserLoggedIn() ||
128 ScreenLocker::default_screen_locker())) {
129 ClearAndEnablePassword();
132 if (chromeos::LoginDisplayHost* host =
133 chromeos::LoginDisplayHostImpl::default_host()) {
134 if (chromeos::WebUILoginView* login_view = host->GetWebUILoginView())
135 login_view->SetUIEnabled(is_enabled);
139 void WebUILoginDisplay::ShowError(int error_msg_id,
141 HelpAppLauncher::HelpTopic help_topic_id) {
142 VLOG(1) << "Show error, error_id: " << error_msg_id
143 << ", attempts:" << login_attempts
144 << ", help_topic_id: " << help_topic_id;
148 std::string error_text;
149 switch (error_msg_id) {
150 case IDS_LOGIN_ERROR_AUTHENTICATING_HOSTED:
151 error_text = l10n_util::GetStringFUTF8(
152 error_msg_id, l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_OS_NAME));
154 case IDS_LOGIN_ERROR_CAPTIVE_PORTAL:
155 error_text = l10n_util::GetStringFUTF8(
156 error_msg_id, delegate()->GetConnectedNetworkName());
159 error_text = l10n_util::GetStringUTF8(error_msg_id);
163 // Only display hints about keyboard layout if the error is authentication-
165 if (error_msg_id != IDS_LOGIN_ERROR_WHITELIST &&
166 error_msg_id != IDS_LOGIN_ERROR_OWNER_KEY_LOST &&
167 error_msg_id != IDS_LOGIN_ERROR_OWNER_REQUIRED) {
168 // Display a warning if Caps Lock is on.
169 input_method::InputMethodManager* ime_manager =
170 input_method::InputMethodManager::Get();
171 if (ime_manager->GetImeKeyboard()->CapsLockIsEnabled()) {
172 // TODO(ivankr): use a format string instead of concatenation.
174 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_CAPS_LOCK_HINT);
177 // Display a hint to switch keyboards if there are other active input
179 if (ime_manager->GetActiveIMEState()->GetNumActiveInputMethods() > 1) {
181 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_KEYBOARD_SWITCH_HINT);
185 std::string help_link;
186 switch (error_msg_id) {
187 case IDS_LOGIN_ERROR_AUTHENTICATING_HOSTED:
188 help_link = l10n_util::GetStringUTF8(IDS_LEARN_MORE);
191 if (login_attempts > 1)
192 help_link = l10n_util::GetStringUTF8(IDS_LEARN_MORE);
196 webui_handler_->ShowError(login_attempts, error_text, help_link,
200 void WebUILoginDisplay::ShowErrorScreen(LoginDisplay::SigninError error_id) {
201 VLOG(1) << "Show error screen, error_id: " << error_id;
204 webui_handler_->ShowErrorScreen(error_id);
207 void WebUILoginDisplay::ShowGaiaPasswordChanged(const std::string& username) {
209 webui_handler_->ShowGaiaPasswordChanged(username);
212 void WebUILoginDisplay::ShowPasswordChangedDialog(bool show_password_error) {
214 webui_handler_->ShowPasswordChangedDialog(show_password_error);
217 void WebUILoginDisplay::ShowSigninUI(const std::string& email) {
219 webui_handler_->ShowSigninUI(email);
222 // WebUILoginDisplay, NativeWindowDelegate implementation: ---------------------
223 gfx::NativeWindow WebUILoginDisplay::GetNativeWindow() const {
224 return parent_window();
227 // WebUILoginDisplay, SigninScreenHandlerDelegate implementation: --------------
228 void WebUILoginDisplay::CancelPasswordChangedFlow() {
231 delegate_->CancelPasswordChangedFlow();
234 void WebUILoginDisplay::CancelUserAdding() {
235 if (!UserAddingScreen::Get()->IsRunning()) {
236 LOG(ERROR) << "User adding screen not running.";
239 UserAddingScreen::Get()->Cancel();
242 void WebUILoginDisplay::CreateAccount() {
245 delegate_->CreateAccount();
248 void WebUILoginDisplay::CompleteLogin(const UserContext& user_context) {
251 delegate_->CompleteLogin(user_context);
254 void WebUILoginDisplay::Login(const UserContext& user_context,
255 const SigninSpecifics& specifics) {
258 delegate_->Login(user_context, specifics);
261 void WebUILoginDisplay::MigrateUserData(const std::string& old_password) {
264 delegate_->MigrateUserData(old_password);
267 void WebUILoginDisplay::LoadWallpaper(const std::string& username) {
268 #if !defined(USE_ATHENA)
269 WallpaperManager::Get()->SetUserWallpaperDelayed(username);
273 void WebUILoginDisplay::LoadSigninWallpaper() {
274 #if !defined(USE_ATHENA)
275 WallpaperManager::Get()->SetDefaultWallpaperDelayed(
276 chromeos::login::kSignInUser);
280 void WebUILoginDisplay::OnSigninScreenReady() {
282 delegate_->OnSigninScreenReady();
285 void WebUILoginDisplay::RemoveUser(const std::string& username) {
286 user_manager::UserManager::Get()->RemoveUser(username, this);
289 void WebUILoginDisplay::ResyncUserData() {
292 delegate_->ResyncUserData();
295 void WebUILoginDisplay::ShowEnterpriseEnrollmentScreen() {
297 delegate_->OnStartEnterpriseEnrollment();
300 void WebUILoginDisplay::ShowKioskEnableScreen() {
302 delegate_->OnStartKioskEnableScreen();
305 void WebUILoginDisplay::ShowKioskAutolaunchScreen() {
307 delegate_->OnStartKioskAutolaunchScreen();
310 void WebUILoginDisplay::ShowWrongHWIDScreen() {
312 delegate_->ShowWrongHWIDScreen();
315 void WebUILoginDisplay::SetWebUIHandler(
316 LoginDisplayWebUIHandler* webui_handler) {
317 webui_handler_ = webui_handler;
318 gaia_screen_->SetHandler(webui_handler_);
319 user_selection_screen_->SetHandler(webui_handler_);
322 void WebUILoginDisplay::ShowSigninScreenForCreds(
323 const std::string& username,
324 const std::string& password) {
326 webui_handler_->ShowSigninScreenForCreds(username, password);
329 bool WebUILoginDisplay::IsShowGuest() const {
333 bool WebUILoginDisplay::IsShowUsers() const {
337 bool WebUILoginDisplay::IsSigninInProgress() const {
338 return delegate_->IsSigninInProgress();
341 bool WebUILoginDisplay::IsUserSigninCompleted() const {
342 return is_signin_completed();
345 void WebUILoginDisplay::SetDisplayEmail(const std::string& email) {
347 delegate_->SetDisplayEmail(email);
350 void WebUILoginDisplay::Signout() {
351 delegate_->Signout();
354 void WebUILoginDisplay::OnUserActivity(const ui::Event* event) {
356 delegate_->ResetPublicSessionAutoLoginTimer();
360 } // namespace chromeos