ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chrome / browser / chromeos / login / ui / webui_login_display.cc
blob2e96623f1c75847ace8c57ee7f850380316d3a0c
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"
28 namespace chromeos {
30 // WebUILoginDisplay, public: --------------------------------------------------
32 WebUILoginDisplay::~WebUILoginDisplay() {
33 if (webui_handler_)
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()),
44 show_guest_(false),
45 show_new_user_(false),
46 webui_handler_(NULL) {
49 void WebUILoginDisplay::ClearAndEnablePassword() {
50 if (webui_handler_)
51 webui_handler_->ClearAndEnablePassword();
54 void WebUILoginDisplay::Init(const user_manager::UserList& users,
55 bool show_guest,
56 bool show_users,
57 bool show_new_user) {
58 // Testing that the delegate has been set.
59 DCHECK(delegate_);
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() {
87 if (webui_handler_)
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,
110 int login_attempts,
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;
115 if (!webui_handler_)
116 return;
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));
123 break;
124 case IDS_LOGIN_ERROR_CAPTIVE_PORTAL:
125 error_text = l10n_util::GetStringFUTF8(
126 error_msg_id, delegate()->GetConnectedNetworkName());
127 break;
128 default:
129 error_text = l10n_util::GetStringUTF8(error_msg_id);
130 break;
133 // Only display hints about keyboard layout if the error is authentication-
134 // related.
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.
144 error_text += "\n" +
145 l10n_util::GetStringUTF8(IDS_LOGIN_ERROR_CAPS_LOCK_HINT);
148 // Display a hint to switch keyboards if there are other active input
149 // methods.
150 if (ime_manager->GetActiveIMEState()->GetNumActiveInputMethods() > 1) {
151 error_text += "\n" +
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);
160 break;
161 default:
162 if (login_attempts > 1)
163 help_link = l10n_util::GetStringUTF8(IDS_LEARN_MORE);
164 break;
167 webui_handler_->ShowError(login_attempts, error_text, help_link,
168 help_topic_id);
171 void WebUILoginDisplay::ShowErrorScreen(LoginDisplay::SigninError error_id) {
172 VLOG(1) << "Show error screen, error_id: " << error_id;
173 if (!webui_handler_)
174 return;
175 webui_handler_->ShowErrorScreen(error_id);
178 void WebUILoginDisplay::ShowGaiaPasswordChanged(const std::string& username) {
179 if (webui_handler_)
180 webui_handler_->ShowGaiaPasswordChanged(username);
183 void WebUILoginDisplay::ShowPasswordChangedDialog(bool show_password_error) {
184 if (webui_handler_)
185 webui_handler_->ShowPasswordChangedDialog(show_password_error);
188 void WebUILoginDisplay::ShowSigninUI(const std::string& email) {
189 if (webui_handler_)
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() {
200 DCHECK(delegate_);
201 if (delegate_)
202 delegate_->CancelPasswordChangedFlow();
205 void WebUILoginDisplay::CancelUserAdding() {
206 if (!UserAddingScreen::Get()->IsRunning()) {
207 LOG(ERROR) << "User adding screen not running.";
208 return;
210 UserAddingScreen::Get()->Cancel();
213 void WebUILoginDisplay::CreateAccount() {
214 DCHECK(delegate_);
215 if (delegate_)
216 delegate_->CreateAccount();
219 void WebUILoginDisplay::CompleteLogin(const UserContext& user_context) {
220 DCHECK(delegate_);
221 if (delegate_)
222 delegate_->CompleteLogin(user_context);
225 void WebUILoginDisplay::Login(const UserContext& user_context,
226 const SigninSpecifics& specifics) {
227 DCHECK(delegate_);
228 if (delegate_)
229 delegate_->Login(user_context, specifics);
232 void WebUILoginDisplay::MigrateUserData(const std::string& old_password) {
233 DCHECK(delegate_);
234 if (delegate_)
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();
250 if (delegate_)
251 delegate_->OnSigninScreenReady();
254 void WebUILoginDisplay::RemoveUser(const std::string& user_id) {
255 SignInScreenController::Get()->RemoveUser(user_id);
258 void WebUILoginDisplay::ResyncUserData() {
259 DCHECK(delegate_);
260 if (delegate_)
261 delegate_->ResyncUserData();
264 void WebUILoginDisplay::ShowEnterpriseEnrollmentScreen() {
265 if (delegate_)
266 delegate_->OnStartEnterpriseEnrollment();
269 void WebUILoginDisplay::ShowEnableDebuggingScreen() {
270 if (delegate_)
271 delegate_->OnStartEnableDebuggingScreen();
274 void WebUILoginDisplay::ShowKioskEnableScreen() {
275 if (delegate_)
276 delegate_->OnStartKioskEnableScreen();
279 void WebUILoginDisplay::ShowKioskAutolaunchScreen() {
280 if (delegate_)
281 delegate_->OnStartKioskAutolaunchScreen();
284 void WebUILoginDisplay::ShowWrongHWIDScreen() {
285 if (delegate_)
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) {
298 if (webui_handler_)
299 webui_handler_->ShowSigninScreenForCreds(username, password);
302 bool WebUILoginDisplay::IsShowGuest() const {
303 return show_guest_;
306 bool WebUILoginDisplay::IsShowUsers() const {
307 return show_users_;
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) {
319 if (delegate_)
320 delegate_->SetDisplayEmail(email);
323 void WebUILoginDisplay::Signout() {
324 delegate_->Signout();
327 void WebUILoginDisplay::OnUserActivity(const ui::Event* event) {
328 if (delegate_)
329 delegate_->ResetPublicSessionAutoLoginTimer();
333 } // namespace chromeos