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/callback.h"
     12 #include "base/strings/string16.h"
     13 #include "chrome/browser/chromeos/login/help_app_launcher.h"
     14 #include "chrome/browser/chromeos/login/remove_user_delegate.h"
     15 #include "chrome/browser/chromeos/login/user.h"
     16 #include "chrome/browser/chromeos/login/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 
     21 namespace chromeos {
     22 
     23 // TODO(nkostylev): Extract interface, create a BaseLoginDisplay class.
     24 // An abstract class that defines login UI implementation.
     25 class LoginDisplay : public RemoveUserDelegate {
     26  public:
     27   // Sign in error IDs that require detailed error screen and not just
     28   // a simple error bubble.
     29   enum SigninError {
     30     // Shown in case of critical TPM error.
     31     TPM_ERROR,
     32   };
     33 
     34   class Delegate {
     35    public:
     36     // Cancels current password changed flow.
     37     virtual void CancelPasswordChangedFlow() = 0;
     38 
     39     // Create new Google account.
     40     virtual void CreateAccount() = 0;
     41 
     42     // Complete sign process with specified |user_context|.
     43     // Used for new users authenticated through an extension.
     44     virtual void CompleteLogin(const UserContext& user_context) = 0;
     45 
     46     // Returns name of the currently connected network.
     47     virtual base::string16 GetConnectedNetworkName() = 0;
     48 
     49     // Returns true if sign in is in progress.
     50     virtual bool IsSigninInProgress() const = 0;
     51 
     52     // Sign in using |username| and |password| specified.
     53     // Used for known users only.
     54     virtual void Login(const UserContext& user_context) = 0;
     55 
     56     // Sign in as a retail mode user.
     57     virtual void LoginAsRetailModeUser() = 0;
     58 
     59     // Sign in into guest session.
     60     virtual void LoginAsGuest() = 0;
     61 
     62     // Decrypt cryptohome using user provided |old_password|
     63     // and migrate to new password.
     64     virtual void MigrateUserData(const std::string& old_password) = 0;
     65 
     66     // Sign in into the public account identified by |username|.
     67     virtual void LoginAsPublicAccount(const std::string& username) = 0;
     68 
     69     // Login to kiosk mode for app with |app_id|.
     70     virtual void LoginAsKioskApp(const std::string& app_id) = 0;
     71 
     72     // Notify the delegate when the sign-in UI is finished loading.
     73     virtual void OnSigninScreenReady() = 0;
     74 
     75     // Called when existing user pod is selected in the UI.
     76     virtual void OnUserSelected(const std::string& username) = 0;
     77 
     78     // Called when the user requests enterprise enrollment.
     79     virtual void OnStartEnterpriseEnrollment() = 0;
     80 
     81     // Called when the user requests kiosk enable screen.
     82     virtual void OnStartKioskEnableScreen() = 0;
     83 
     84     // Called when the user requests device reset.
     85     virtual void OnStartDeviceReset() = 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   // After this call login display should be ready to be smoothly destroyed
    135   // (e.g. hide throbber, etc.).
    136   virtual void OnFadeOut() = 0;
    137 
    138   // Called when user is successfully authenticated.
    139   virtual void OnLoginSuccess(const std::string& username) = 0;
    140 
    141   // Changes enabled state of the UI.
    142   virtual void SetUIEnabled(bool is_enabled) = 0;
    143 
    144   // Selects user entry with specified |index|.
    145   // Does nothing if current user is already selected.
    146   virtual void SelectPod(int index) = 0;
    147 
    148   // Displays a banner on the login screen containing |message|.
    149   virtual void ShowBannerMessage(const std::string& message) = 0;
    150 
    151   // Shows a button with an icon inside the user pod of |username|.
    152   virtual void ShowUserPodButton(const std::string& username,
    153                                  const std::string& iconURL,
    154                                  const base::Closure& click_callback) = 0;
    155 
    156   // Displays simple error bubble with |error_msg_id| specified.
    157   // |login_attempts| shows number of login attempts made by current user.
    158   // |help_topic_id| is additional help topic that is presented as link.
    159   virtual void ShowError(int error_msg_id,
    160                          int login_attempts,
    161                          HelpAppLauncher::HelpTopic help_topic_id) = 0;
    162 
    163   // Displays detailed error screen for error with ID |error_id|.
    164   virtual void ShowErrorScreen(LoginDisplay::SigninError error_id) = 0;
    165 
    166   // Proceed with Gaia flow because password has changed.
    167   virtual void ShowGaiaPasswordChanged(const std::string& username) = 0;
    168 
    169   // Show password changed dialog. If |show_password_error| is not null
    170   // user already tried to enter old password but it turned out to be incorrect.
    171   virtual void ShowPasswordChangedDialog(bool show_password_error) = 0;
    172 
    173   // Shows signin UI with specified email.
    174   virtual void ShowSigninUI(const std::string& email) = 0;
    175 
    176   gfx::Rect background_bounds() const { return background_bounds_; }
    177   void set_background_bounds(const gfx::Rect background_bounds){
    178     background_bounds_ = background_bounds;
    179   }
    180 
    181   Delegate* delegate() { return delegate_; }
    182   void set_delegate(Delegate* delegate) { delegate_ = delegate; }
    183 
    184   gfx::NativeWindow parent_window() const { return parent_window_; }
    185   void set_parent_window(gfx::NativeWindow window) { parent_window_ = window; }
    186 
    187   bool is_signin_completed() const { return is_signin_completed_; }
    188   void set_signin_completed(bool value) { is_signin_completed_ = value; }
    189 
    190   int width() const { return background_bounds_.width(); }
    191 
    192  protected:
    193   // Login UI delegate (controller).
    194   Delegate* delegate_;
    195 
    196   // Parent window, might be used to create dialog windows.
    197   gfx::NativeWindow parent_window_;
    198 
    199   // Bounds of the login UI background.
    200   gfx::Rect background_bounds_;
    201 
    202   // True if signin for user has completed.
    203   // TODO(nkostylev): Find a better place to store this state
    204   // in redesigned login stack.
    205   // Login stack (and this object) will be recreated for next user sign in.
    206   bool is_signin_completed_;
    207 
    208   DISALLOW_COPY_AND_ASSIGN(LoginDisplay);
    209 };
    210 
    211 }  // namespace chromeos
    212 
    213 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_DISPLAY_H_
    214