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