login_display.h revision cedac228d2dd51db4b79ea1e72c7f249408ee061
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.
4
5#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_UI_LOGIN_DISPLAY_H_
6#define CHROME_BROWSER_CHROMEOS_LOGIN_UI_LOGIN_DISPLAY_H_
7
8#include <string>
9#include <vector>
10
11#include "base/callback.h"
12#include "base/strings/string16.h"
13#include "chrome/browser/chromeos/login/help_app_launcher.h"
14#include "chrome/browser/chromeos/login/users/remove_user_delegate.h"
15#include "chrome/browser/chromeos/login/users/user.h"
16#include "chrome/browser/chromeos/login/users/user_manager.h"
17#include "ui/gfx/image/image.h"
18#include "ui/gfx/native_widget_types.h"
19#include "ui/gfx/rect.h"
20
21namespace chromeos {
22
23class UserContext;
24
25// TODO(nkostylev): Extract interface, create a BaseLoginDisplay class.
26// An abstract class that defines login UI implementation.
27class LoginDisplay : public RemoveUserDelegate {
28 public:
29  // Sign in error IDs that require detailed error screen and not just
30  // a simple error bubble.
31  enum SigninError {
32    // Shown in case of critical TPM error.
33    TPM_ERROR,
34  };
35
36  class Delegate {
37   public:
38    // Cancels current password changed flow.
39    virtual void CancelPasswordChangedFlow() = 0;
40
41    // Create new Google account.
42    virtual void CreateAccount() = 0;
43
44    // Complete sign process with specified |user_context|.
45    // Used for new users authenticated through an extension.
46    virtual void CompleteLogin(const UserContext& user_context) = 0;
47
48    // Returns name of the currently connected network.
49    virtual base::string16 GetConnectedNetworkName() = 0;
50
51    // Returns true if sign in is in progress.
52    virtual bool IsSigninInProgress() const = 0;
53
54    // Sign in using |username| and |password| specified.
55    // Used for known users only.
56    virtual void Login(const UserContext& user_context) = 0;
57
58    // Sign in as a retail mode user.
59    virtual void LoginAsRetailModeUser() = 0;
60
61    // Sign in into guest session.
62    virtual void LoginAsGuest() = 0;
63
64    // Decrypt cryptohome using user provided |old_password|
65    // and migrate to new password.
66    virtual void MigrateUserData(const std::string& old_password) = 0;
67
68    // Sign in into the public account identified by |username|.
69    virtual void LoginAsPublicAccount(const std::string& username) = 0;
70
71    // Login to kiosk mode for app with |app_id|.
72    virtual void LoginAsKioskApp(const std::string& app_id,
73                                 bool diagnostic_mode) = 0;
74
75    // Notify the delegate when the sign-in UI is finished loading.
76    virtual void OnSigninScreenReady() = 0;
77
78    // Called when existing user pod is selected in the UI.
79    virtual void OnUserSelected(const std::string& username) = 0;
80
81    // Called when the user requests enterprise enrollment.
82    virtual void OnStartEnterpriseEnrollment() = 0;
83
84    // Called when the user requests kiosk enable screen.
85    virtual void OnStartKioskEnableScreen() = 0;
86
87    // Called when the owner permission for kiosk app auto launch is requested.
88    virtual void OnStartKioskAutolaunchScreen() = 0;
89
90    // Shows wrong HWID screen.
91    virtual void ShowWrongHWIDScreen() = 0;
92
93    // Restarts the public-session auto-login timer if it is running.
94    virtual void ResetPublicSessionAutoLoginTimer() = 0;
95
96    // Ignore password change, remove existing cryptohome and
97    // force full sync of user data.
98    virtual void ResyncUserData() = 0;
99
100    // Sets the displayed email for the next login attempt with |CompleteLogin|.
101    // If it succeeds, user's displayed email value will be updated to |email|.
102    virtual void SetDisplayEmail(const std::string& email) = 0;
103
104    // Sign out the currently signed in user.
105    // Used when the lock screen is being displayed.
106    virtual void Signout() = 0;
107
108   protected:
109    virtual ~Delegate();
110  };
111
112  // |background_bounds| determines the bounds of login UI background.
113  LoginDisplay(Delegate* delegate, const gfx::Rect& background_bounds);
114  virtual ~LoginDisplay();
115
116  // Clears and enables fields on user pod or GAIA frame.
117  virtual void ClearAndEnablePassword() = 0;
118
119  // Initializes login UI with the user pods based on list of known users and
120  // guest, new user pods if those are enabled.
121  virtual void Init(const UserList& users,
122                    bool show_guest,
123                    bool show_users,
124                    bool show_new_user) = 0;
125
126  // Notifies the login UI that the preferences defining how to visualize it to
127  // the user have changed and it needs to refresh.
128  virtual void OnPreferencesChanged() = 0;
129
130  // Called when user image has been changed.
131  // |user| contains updated user.
132  virtual void OnUserImageChanged(const User& user) = 0;
133
134  // Changes enabled state of the UI.
135  virtual void SetUIEnabled(bool is_enabled) = 0;
136
137  // Displays simple error bubble with |error_msg_id| specified.
138  // |login_attempts| shows number of login attempts made by current user.
139  // |help_topic_id| is additional help topic that is presented as link.
140  virtual void ShowError(int error_msg_id,
141                         int login_attempts,
142                         HelpAppLauncher::HelpTopic help_topic_id) = 0;
143
144  // Displays detailed error screen for error with ID |error_id|.
145  virtual void ShowErrorScreen(LoginDisplay::SigninError error_id) = 0;
146
147  // Proceed with Gaia flow because password has changed.
148  virtual void ShowGaiaPasswordChanged(const std::string& username) = 0;
149
150  // Show password changed dialog. If |show_password_error| is not null
151  // user already tried to enter old password but it turned out to be incorrect.
152  virtual void ShowPasswordChangedDialog(bool show_password_error) = 0;
153
154  // Shows signin UI with specified email.
155  virtual void ShowSigninUI(const std::string& email) = 0;
156
157  gfx::Rect background_bounds() const { return background_bounds_; }
158  void set_background_bounds(const gfx::Rect& background_bounds) {
159    background_bounds_ = background_bounds;
160  }
161
162  Delegate* delegate() { return delegate_; }
163  void set_delegate(Delegate* delegate) { delegate_ = delegate; }
164
165  gfx::NativeWindow parent_window() const { return parent_window_; }
166  void set_parent_window(gfx::NativeWindow window) { parent_window_ = window; }
167
168  bool is_signin_completed() const { return is_signin_completed_; }
169  void set_signin_completed(bool value) { is_signin_completed_ = value; }
170
171  int width() const { return background_bounds_.width(); }
172
173 protected:
174  // Login UI delegate (controller).
175  Delegate* delegate_;
176
177  // Parent window, might be used to create dialog windows.
178  gfx::NativeWindow parent_window_;
179
180  // Bounds of the login UI background.
181  gfx::Rect background_bounds_;
182
183  // True if signin for user has completed.
184  // TODO(nkostylev): Find a better place to store this state
185  // in redesigned login stack.
186  // Login stack (and this object) will be recreated for next user sign in.
187  bool is_signin_completed_;
188
189  DISALLOW_COPY_AND_ASSIGN(LoginDisplay);
190};
191
192}  // namespace chromeos
193
194#endif  // CHROME_BROWSER_CHROMEOS_LOGIN_UI_LOGIN_DISPLAY_H_
195