Home | History | Annotate | Download | only in signin
      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_SIGNIN_SCREENLOCK_BRIDGE_H_
      6 #define CHROME_BROWSER_SIGNIN_SCREENLOCK_BRIDGE_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/lazy_instance.h"
     12 #include "base/macros.h"
     13 #include "base/memory/scoped_ptr.h"
     14 #include "base/observer_list.h"
     15 #include "base/strings/string16.h"
     16 #include "base/values.h"
     17 
     18 
     19 class Profile;
     20 
     21 // ScreenlockBridge brings together the screenLockPrivate API and underlying
     22 // support. On ChromeOS, it delegates calls to the ScreenLocker. On other
     23 // platforms, it delegates calls to UserManagerUI (and friends).
     24 // TODO(tbarzic): Rename ScreenlockBridge to SignInScreenBridge, as this is not
     25 // used solely for the lock screen anymore.
     26 class ScreenlockBridge {
     27  public:
     28   class Observer {
     29    public:
     30     // Invoked after the screen is locked.
     31     virtual void OnScreenDidLock() = 0;
     32     // Invoked after the screen lock is dismissed.
     33     virtual void OnScreenDidUnlock() = 0;
     34     // Invoked when the user focused on the lock screen changes.
     35     virtual void OnFocusedUserChanged(const std::string& user_id) = 0;
     36    protected:
     37     virtual ~Observer() {}
     38   };
     39 
     40   // User pod icons supported by lock screen / signin screen UI.
     41   enum UserPodCustomIcon {
     42     USER_POD_CUSTOM_ICON_NONE,
     43     USER_POD_CUSTOM_ICON_HARDLOCKED,
     44     USER_POD_CUSTOM_ICON_LOCKED,
     45     USER_POD_CUSTOM_ICON_UNLOCKED,
     46     USER_POD_CUSTOM_ICON_SPINNER
     47   };
     48 
     49   // Class containing parameters describing the custom icon that should be
     50   // shown on a user's screen lock pod next to the input field.
     51   class UserPodCustomIconOptions {
     52    public:
     53     UserPodCustomIconOptions();
     54     ~UserPodCustomIconOptions();
     55 
     56     // Converts parameters to a dictionary values that can be sent to the
     57     // screenlock web UI.
     58     scoped_ptr<base::DictionaryValue> ToDictionaryValue() const;
     59 
     60     // Sets the icon that should be shown in the UI.
     61     void SetIcon(UserPodCustomIcon icon);
     62 
     63     // Sets the icon tooltip. If |autoshow| is set the tooltip is automatically
     64     // shown with the icon.
     65     void SetTooltip(const base::string16& tooltip, bool autoshow);
     66 
     67     // Sets the accessiblity label of the icon. If this attribute is not
     68     // provided, then the tooltip will be used.
     69     void SetAriaLabel(const base::string16& aria_label);
     70 
     71     // If hardlock on click is set, clicking the icon in the screenlock will
     72     // go to state where password is required for unlock.
     73     void SetHardlockOnClick();
     74 
     75    private:
     76     UserPodCustomIcon icon_;
     77 
     78     base::string16 tooltip_;
     79     bool autoshow_tooltip_;
     80 
     81     base::string16 aria_label_;
     82 
     83     bool hardlock_on_click_;
     84 
     85     DISALLOW_COPY_AND_ASSIGN(UserPodCustomIconOptions);
     86   };
     87 
     88   class LockHandler {
     89    public:
     90     // Supported authentication types. Keep in sync with the enum in
     91     // user_pod_row.js.
     92     enum AuthType {
     93       OFFLINE_PASSWORD = 0,
     94       ONLINE_SIGN_IN = 1,
     95       NUMERIC_PIN = 2,
     96       USER_CLICK = 3,
     97       EXPAND_THEN_USER_CLICK = 4,
     98       FORCE_OFFLINE_PASSWORD = 5
     99     };
    100 
    101     // Displays |message| in a banner on the lock screen.
    102     virtual void ShowBannerMessage(const base::string16& message) = 0;
    103 
    104     // Shows a custom icon in the user pod on the lock screen.
    105     virtual void ShowUserPodCustomIcon(
    106         const std::string& user_email,
    107         const UserPodCustomIconOptions& icon) = 0;
    108 
    109     // Hides the custom icon in user pod for a user.
    110     virtual void HideUserPodCustomIcon(const std::string& user_email) = 0;
    111 
    112     // (Re)enable lock screen UI.
    113     virtual void EnableInput() = 0;
    114 
    115     // Set the authentication type to be used on the lock screen.
    116     virtual void SetAuthType(const std::string& user_email,
    117                              AuthType auth_type,
    118                              const base::string16& auth_value) = 0;
    119 
    120     // Returns the authentication type used for a user.
    121     virtual AuthType GetAuthType(const std::string& user_email) const = 0;
    122 
    123     // Unlock from easy unlock app for a user.
    124     virtual void Unlock(const std::string& user_email) = 0;
    125 
    126     // Attempts to login the user using an easy unlock key.
    127     virtual void AttemptEasySignin(const std::string& user_email,
    128                                    const std::string& secret,
    129                                    const std::string& key_label) = 0;
    130 
    131    protected:
    132     virtual ~LockHandler() {}
    133   };
    134 
    135   static ScreenlockBridge* Get();
    136   static std::string GetAuthenticatedUserEmail(Profile* profile);
    137 
    138   void SetLockHandler(LockHandler* lock_handler);
    139   void SetFocusedUser(const std::string& user_id);
    140 
    141   bool IsLocked() const;
    142   void Lock(Profile* profile);
    143   void Unlock(Profile* profile);
    144 
    145   void AddObserver(Observer* observer);
    146   void RemoveObserver(Observer* observer);
    147 
    148   LockHandler* lock_handler() { return lock_handler_; }
    149 
    150   std::string focused_user_id() const { return focused_user_id_; }
    151 
    152  private:
    153   friend struct base::DefaultLazyInstanceTraits<ScreenlockBridge>;
    154   friend struct base::DefaultDeleter<ScreenlockBridge>;
    155 
    156   ScreenlockBridge();
    157   ~ScreenlockBridge();
    158 
    159   LockHandler* lock_handler_;  // Not owned
    160   // The last focused user's id.
    161   std::string focused_user_id_;
    162   ObserverList<Observer, true> observers_;
    163 
    164   DISALLOW_COPY_AND_ASSIGN(ScreenlockBridge);
    165 };
    166 
    167 #endif  // CHROME_BROWSER_SIGNIN_SCREENLOCK_BRIDGE_H_
    168