1 // Copyright (c) 2013 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 #ifndef CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_SIGNIN_SCREEN_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_SIGNIN_SCREEN_HANDLER_H_
12 #include "base/basictypes.h"
13 #include "base/callback.h"
14 #include "base/compiler_specific.h"
15 #include "base/containers/hash_tables.h"
16 #include "base/memory/ref_counted.h"
17 #include "base/memory/scoped_ptr.h"
18 #include "base/memory/weak_ptr.h"
19 #include "chrome/browser/chromeos/login/screens/network_error_model.h"
20 #include "chrome/browser/chromeos/login/signin_specifics.h"
21 #include "chrome/browser/chromeos/login/ui/login_display.h"
22 #include "chrome/browser/chromeos/settings/cros_settings.h"
23 #include "chrome/browser/ui/webui/chromeos/login/base_screen_handler.h"
24 #include "chrome/browser/ui/webui/chromeos/login/network_state_informer.h"
25 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
26 #include "chrome/browser/ui/webui/chromeos/touch_view_controller_delegate.h"
27 #include "chromeos/network/portal_detector/network_portal_detector.h"
28 #include "components/proximity_auth/screenlock_bridge.h"
29 #include "components/user_manager/user_manager.h"
30 #include "content/public/browser/notification_observer.h"
31 #include "content/public/browser/notification_registrar.h"
32 #include "content/public/browser/web_ui.h"
33 #include "net/base/net_errors.h"
34 #include "ui/base/ime/chromeos/ime_keyboard.h"
35 #include "ui/base/ime/chromeos/input_method_manager.h"
36 #include "ui/events/event_handler.h"
38 class EasyUnlockService
;
41 class DictionaryValue
;
47 class CaptivePortalWindowProxy
;
49 class ErrorScreensHistogramHelper
;
50 class GaiaScreenHandler
;
51 class NativeWindowDelegate
;
52 class SupervisedUserCreationScreenHandler
;
56 // Helper class to pass initial parameters to the login screen.
57 class LoginScreenContext
{
60 explicit LoginScreenContext(const base::ListValue
* args
);
62 void set_email(const std::string
& email
) { email_
= email
; }
63 const std::string
& email() const { return email_
; }
65 void set_oobe_ui(bool oobe_ui
) { oobe_ui_
= oobe_ui
; }
66 bool oobe_ui() const { return oobe_ui_
; }
75 // An interface for WebUILoginDisplay to call SigninScreenHandler.
76 class LoginDisplayWebUIHandler
{
78 virtual void ClearAndEnablePassword() = 0;
79 virtual void ClearUserPodPassword() = 0;
80 virtual void OnUserRemoved(const std::string
& username
) = 0;
81 virtual void OnUserImageChanged(const user_manager::User
& user
) = 0;
82 virtual void OnPreferencesChanged() = 0;
83 virtual void ResetSigninScreenHandlerDelegate() = 0;
84 virtual void ShowError(int login_attempts
,
85 const std::string
& error_text
,
86 const std::string
& help_link_text
,
87 HelpAppLauncher::HelpTopic help_topic_id
) = 0;
88 virtual void ShowErrorScreen(LoginDisplay::SigninError error_id
) = 0;
89 virtual void ShowSigninUI(const std::string
& email
) = 0;
90 virtual void ShowPasswordChangedDialog(bool show_password_error
,
91 const std::string
& email
) = 0;
92 // Show sign-in screen for the given credentials.
93 virtual void ShowSigninScreenForCreds(const std::string
& username
,
94 const std::string
& password
) = 0;
95 virtual void ShowWhitelistCheckFailedError() = 0;
96 virtual void LoadUsers(const base::ListValue
& users_list
,
99 virtual ~LoginDisplayWebUIHandler() {}
102 // An interface for SigninScreenHandler to call WebUILoginDisplay.
103 class SigninScreenHandlerDelegate
{
105 // --------------- Password change flow methods.
106 // Cancels current password changed flow.
107 virtual void CancelPasswordChangedFlow() = 0;
109 // Decrypt cryptohome using user provided |old_password|
110 // and migrate to new password.
111 virtual void MigrateUserData(const std::string
& old_password
) = 0;
113 // Ignore password change, remove existing cryptohome and
114 // force full sync of user data.
115 virtual void ResyncUserData() = 0;
117 // --------------- Sign in/out methods.
118 // Sign in using username and password specified as a part of |user_context|.
119 // Used for both known and new users.
120 virtual void Login(const UserContext
& user_context
,
121 const SigninSpecifics
& specifics
) = 0;
123 // Sign in as guest to create a new Google account.
124 virtual void CreateAccount() = 0;
126 // Returns true if sign in is in progress.
127 virtual bool IsSigninInProgress() const = 0;
129 // Signs out if the screen is currently locked.
130 virtual void Signout() = 0;
132 // --------------- Account creation methods.
133 // Confirms sign up by provided credentials in |user_context|.
134 // Used for new user login via GAIA extension.
135 virtual void CompleteLogin(const UserContext
& user_context
) = 0;
137 // --------------- Shared with login display methods.
138 // Notify the delegate when the sign-in UI is finished loading.
139 virtual void OnSigninScreenReady() = 0;
141 // Shows Enterprise Enrollment screen.
142 virtual void ShowEnterpriseEnrollmentScreen() = 0;
144 // Shows Enable Developer Features screen.
145 virtual void ShowEnableDebuggingScreen() = 0;
147 // Shows Kiosk Enable screen.
148 virtual void ShowKioskEnableScreen() = 0;
150 // Shows Reset screen.
151 virtual void ShowKioskAutolaunchScreen() = 0;
153 // Show wrong hwid screen.
154 virtual void ShowWrongHWIDScreen() = 0;
156 // Sets the displayed email for the next login attempt. If it succeeds,
157 // user's displayed email value will be updated to |email|.
158 virtual void SetDisplayEmail(const std::string
& email
) = 0;
160 // --------------- Rest of the methods.
161 // Cancels user adding.
162 virtual void CancelUserAdding() = 0;
164 // Load wallpaper for given |username|.
165 virtual void LoadWallpaper(const std::string
& username
) = 0;
167 // Loads the default sign-in wallpaper.
168 virtual void LoadSigninWallpaper() = 0;
170 // Attempts to remove given user.
171 virtual void RemoveUser(const std::string
& username
) = 0;
173 // Let the delegate know about the handler it is supposed to be using.
174 virtual void SetWebUIHandler(LoginDisplayWebUIHandler
* webui_handler
) = 0;
176 // Returns users list to be shown.
177 virtual const user_manager::UserList
& GetUsers() const = 0;
179 // Whether login as guest is available.
180 virtual bool IsShowGuest() const = 0;
182 // Weather to show the user pods or only GAIA sign in.
183 // Public sessions are always shown.
184 virtual bool IsShowUsers() const = 0;
186 // Whether user sign in has completed.
187 virtual bool IsUserSigninCompleted() const = 0;
189 // Request to (re)load user list.
190 virtual void HandleGetUsers() = 0;
192 // Runs an OAuth token validation check for user.
193 virtual void CheckUserStatus(const std::string
& user_id
) = 0;
195 // Returns true if user is allowed to log in by domain policy.
196 virtual bool IsUserWhitelisted(const std::string
& user_id
) = 0;
199 virtual ~SigninScreenHandlerDelegate() {}
202 // A class that handles the WebUI hooks in sign-in screen in OobeDisplay
204 class SigninScreenHandler
205 : public BaseScreenHandler
,
206 public LoginDisplayWebUIHandler
,
207 public content::NotificationObserver
,
208 public NetworkStateInformer::NetworkStateInformerObserver
,
209 public input_method::ImeKeyboard::Observer
,
210 public TouchViewControllerDelegate::Observer
,
211 public OobeUI::Observer
{
214 const scoped_refptr
<NetworkStateInformer
>& network_state_informer
,
215 NetworkErrorModel
* network_error_model
,
216 CoreOobeActor
* core_oobe_actor
,
217 GaiaScreenHandler
* gaia_screen_handler
);
218 ~SigninScreenHandler() override
;
220 static std::string
GetUserLRUInputMethod(const std::string
& username
);
222 // Update current input method (namely keyboard layout) in the given IME state
223 // to LRU by this user.
224 static void SetUserInputMethod(
225 const std::string
& username
,
226 input_method::InputMethodManager::State
* ime_state
);
228 // Shows the sign in screen.
229 void Show(const LoginScreenContext
& context
);
231 // Sets delegate to be used by the handler. It is guaranteed that valid
232 // delegate is set before Show() method will be called.
233 void SetDelegate(SigninScreenHandlerDelegate
* delegate
);
235 void SetNativeWindowDelegate(NativeWindowDelegate
* native_window_delegate
);
237 // NetworkStateInformer::NetworkStateInformerObserver implementation:
238 void OnNetworkReady() override
;
239 void UpdateState(NetworkError::ErrorReason reason
) override
;
241 // Required Local State preferences.
242 static void RegisterPrefs(PrefRegistrySimple
* registry
);
244 // OobeUI::Observer implemetation.
245 void OnCurrentScreenChanged(OobeUI::Screen current_screen
,
246 OobeUI::Screen new_screen
) override
;
248 void SetFocusPODCallbackForTesting(base::Closure callback
);
250 // To avoid spurious error messages on flaky networks, the offline message is
251 // only shown if the network is offline for a threshold number of seconds.
252 // This method reduces the threshold to zero, allowing the offline message to
253 // show instantaneously in tests.
254 void ZeroOfflineTimeoutForTesting();
258 UI_STATE_UNKNOWN
= 0,
259 UI_STATE_GAIA_SIGNIN
,
260 UI_STATE_ACCOUNT_PICKER
,
263 friend class GaiaScreenHandler
;
264 friend class ReportDnsCacheClearedOnUIThread
;
265 friend class SupervisedUserCreationScreenHandler
;
269 // Updates current UI of the signin screen according to |ui_state|
270 // argument. Optionally it can pass screen initialization data via
271 // |params| argument.
272 void UpdateUIState(UIState ui_state
, base::DictionaryValue
* params
);
274 void UpdateStateInternal(NetworkError::ErrorReason reason
, bool force_update
);
275 void SetupAndShowOfflineMessage(NetworkStateInformer::State state
,
276 NetworkError::ErrorReason reason
);
277 void HideOfflineMessage(NetworkStateInformer::State state
,
278 NetworkError::ErrorReason reason
);
279 void ReloadGaia(bool force_reload
);
281 // BaseScreenHandler implementation:
282 void DeclareLocalizedValues(
283 ::login::LocalizedValuesBuilder
* builder
) override
;
284 void Initialize() override
;
285 gfx::NativeWindow
GetNativeWindow() override
;
287 // WebUIMessageHandler implementation:
288 void RegisterMessages() override
;
290 // LoginDisplayWebUIHandler implementation:
291 void ClearAndEnablePassword() override
;
292 void ClearUserPodPassword() override
;
293 void OnUserRemoved(const std::string
& username
) override
;
294 void OnUserImageChanged(const user_manager::User
& user
) override
;
295 void OnPreferencesChanged() override
;
296 void ResetSigninScreenHandlerDelegate() override
;
297 void ShowError(int login_attempts
,
298 const std::string
& error_text
,
299 const std::string
& help_link_text
,
300 HelpAppLauncher::HelpTopic help_topic_id
) override
;
301 void ShowSigninUI(const std::string
& email
) override
;
302 void ShowPasswordChangedDialog(bool show_password_error
,
303 const std::string
& email
) override
;
304 void ShowErrorScreen(LoginDisplay::SigninError error_id
) override
;
305 void ShowSigninScreenForCreds(const std::string
& username
,
306 const std::string
& password
) override
;
307 void ShowWhitelistCheckFailedError() override
;
308 void LoadUsers(const base::ListValue
& users_list
, bool show_guest
) override
;
310 // content::NotificationObserver implementation:
311 void Observe(int type
,
312 const content::NotificationSource
& source
,
313 const content::NotificationDetails
& details
) override
;
315 // TouchViewControllerDelegate::Observer implementation:
316 void OnMaximizeModeStarted() override
;
317 void OnMaximizeModeEnded() override
;
319 // Updates authentication extension. Called when device settings that affect
320 // sign-in (allow BWSI and allow whitelist) are changed.
321 void UserSettingsChanged();
322 void UpdateAddButtonStatus();
324 // Restore input focus to current user pod.
325 void RefocusCurrentPod();
327 // WebUI message handlers.
328 void HandleGetUsers();
329 void HandleAuthenticateUser(const std::string
& username
,
330 const std::string
& password
);
331 void HandleAttemptUnlock(const std::string
& username
);
332 void HandleLaunchIncognito();
333 void HandleLaunchPublicSession(const std::string
& user_id
,
334 const std::string
& locale
,
335 const std::string
& input_method
);
336 void HandleOfflineLogin(const base::ListValue
* args
);
337 void HandleShutdownSystem();
338 void HandleLoadWallpaper(const std::string
& email
);
339 void HandleRebootSystem();
340 void HandleRemoveUser(const std::string
& email
);
341 void HandleShowAddUser(const base::ListValue
* args
);
342 void HandleToggleEnrollmentScreen();
343 void HandleToggleEnableDebuggingScreen();
344 void HandleToggleKioskEnableScreen();
345 void HandleToggleResetScreen();
346 void HandleToggleKioskAutolaunchScreen();
347 void HandleCreateAccount();
348 void HandleAccountPickerReady();
349 void HandleWallpaperReady();
350 void HandleSignOutUser();
351 void HandleOpenProxySettings();
352 void HandleLoginVisible(const std::string
& source
);
353 void HandleCancelPasswordChangedFlow(const std::string
& user_id
);
354 void HandleCancelUserAdding();
355 void HandleMigrateUserData(const std::string
& password
);
356 void HandleResyncUserData();
357 void HandleLoginUIStateChanged(const std::string
& source
, bool active
);
358 void HandleUnlockOnLoginSuccess();
359 void HandleLoginScreenUpdate();
360 void HandleShowLoadingTimeoutError();
361 void HandleUpdateOfflineLogin(bool offline_login_active
);
362 void HandleShowSupervisedUserCreationScreen();
363 void HandleFocusPod(const std::string
& user_id
);
364 void HandleHardlockPod(const std::string
& user_id
);
365 void HandleLaunchKioskApp(const std::string
& app_id
, bool diagnostic_mode
);
366 void HandleGetPublicSessionKeyboardLayouts(const std::string
& user_id
,
367 const std::string
& locale
);
368 void HandleCancelConsumerManagementEnrollment();
369 void HandleGetTouchViewState();
370 void HandleLogRemoveUserWarningShown();
371 void HandleFirstIncorrectPasswordAttempt(const std::string
& email
);
372 void HandleMaxIncorrectPasswordAttempts(const std::string
& email
);
374 // Sends the list of |keyboard_layouts| available for the |locale| that is
375 // currently selected for the public session identified by |user_id|.
376 void SendPublicSessionKeyboardLayouts(
377 const std::string
& user_id
,
378 const std::string
& locale
,
379 scoped_ptr
<base::ListValue
> keyboard_layouts
);
382 // (i) log in is restricted to some user list,
383 // (ii) all users in the restricted list are present.
384 bool AllWhitelistedUsersPresent();
386 // Cancels password changed flow - switches back to login screen.
387 // Called as a callback after cookies are cleared.
388 void CancelPasswordChangedFlowInternal();
390 // Returns current visible screen.
391 OobeUI::Screen
GetCurrentScreen() const;
393 // Returns true if current visible screen is the Gaia sign-in page.
394 bool IsGaiaVisible() const;
396 // Returns true if current visible screen is the error screen over
397 // Gaia sign-in page.
398 bool IsGaiaHiddenByError() const;
400 // Returns true if current screen is the error screen over signin
402 bool IsSigninScreenHiddenByError() const;
404 // Returns true if guest signin is allowed.
405 bool IsGuestSigninAllowed() const;
407 // Returns true if offline login is allowed.
408 bool IsOfflineLoginAllowed() const;
410 bool ShouldLoadGaia() const;
413 void OnShowAddUser();
415 net::Error
FrameError() const;
417 // input_method::ImeKeyboard::Observer implementation:
418 void OnCapsLockChanged(bool enabled
) override
;
420 // Returns OobeUI object of NULL.
421 OobeUI
* GetOobeUI() const;
423 // Gets the easy unlock service associated with the user. Can return NULL if
424 // user cannot be found, or there is not associated service.
425 EasyUnlockService
* GetEasyUnlockServiceForUser(
426 const std::string
& username
) const;
428 // Current UI state of the signin screen.
429 UIState ui_state_
= UI_STATE_UNKNOWN
;
431 // A delegate that glues this handler with backend LoginDisplay.
432 SigninScreenHandlerDelegate
* delegate_
= nullptr;
434 // A delegate used to get gfx::NativeWindow.
435 NativeWindowDelegate
* native_window_delegate_
= nullptr;
437 // Whether screen should be shown right after initialization.
438 bool show_on_init_
= false;
440 // Keeps whether screen should be shown for OOBE.
441 bool oobe_ui_
= false;
443 // Is account picker being shown for the first time.
444 bool is_account_picker_showing_first_time_
= false;
446 // Network state informer used to keep signin screen up.
447 scoped_refptr
<NetworkStateInformer
> network_state_informer_
;
449 // Set to true once |LOGIN_WEBUI_VISIBLE| notification is observed.
450 bool webui_visible_
= false;
451 bool preferences_changed_delayed_
= false;
453 NetworkErrorModel
* network_error_model_
;
454 CoreOobeActor
* core_oobe_actor_
;
456 bool offline_login_active_
= false;
457 NetworkStateInformer::State last_network_state_
=
458 NetworkStateInformer::UNKNOWN
;
460 base::CancelableClosure update_state_closure_
;
461 base::CancelableClosure connecting_closure_
;
463 content::NotificationRegistrar registrar_
;
465 // Whether there is an auth UI pending. This flag is set on receiving
466 // NOTIFICATION_AUTH_NEEDED and reset on either NOTIFICATION_AUTH_SUPPLIED or
467 // NOTIFICATION_AUTH_CANCELLED.
468 bool has_pending_auth_ui_
= false;
470 // Used for pending GAIA reloads.
471 NetworkError::ErrorReason gaia_reload_reason_
=
472 NetworkError::ERROR_REASON_NONE
;
474 bool caps_lock_enabled_
;
477 // TODO(antrim@): remove this dependency.
478 GaiaScreenHandler
* gaia_screen_handler_
;
480 // Maximized mode controller delegate.
481 scoped_ptr
<TouchViewControllerDelegate
> max_mode_delegate_
;
483 // Whether consumer management enrollment is in progress.
484 bool is_enrolling_consumer_management_
= false;
486 // Input Method Engine state used at signin screen.
487 scoped_refptr
<input_method::InputMethodManager::State
> ime_state_
;
489 // This callback captures "focusPod finished" event for tests.
490 base::Closure test_focus_pod_callback_
;
492 // True if SigninScreenHandler has already been added to OobeUI observers.
493 bool oobe_ui_observer_added_
= false;
495 bool zero_offline_timeout_for_test_
= false;
497 scoped_ptr
<ErrorScreensHistogramHelper
> histogram_helper_
;
499 base::WeakPtrFactory
<SigninScreenHandler
> weak_factory_
;
501 DISALLOW_COPY_AND_ASSIGN(SigninScreenHandler
);
504 } // namespace chromeos
506 #endif // CHROME_BROWSER_UI_WEBUI_CHROMEOS_LOGIN_SIGNIN_SCREEN_HANDLER_H_