OLD | NEW |
| (Empty) |
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 // User pod icons supported by lock screen / signin screen UI. | |
29 enum UserPodCustomIcon { | |
30 USER_POD_CUSTOM_ICON_NONE, | |
31 USER_POD_CUSTOM_ICON_HARDLOCKED, | |
32 USER_POD_CUSTOM_ICON_LOCKED, | |
33 USER_POD_CUSTOM_ICON_LOCKED_TO_BE_ACTIVATED, | |
34 // TODO(isherman): The "locked with proximity hint" icon is currently the | |
35 // same as the "locked" icon. It's treated as a separate case to allow an | |
36 // easy asset swap without changing the code, in case we decide to use a | |
37 // different icon for this case. If we definitely decide against that, then | |
38 // this enum entry should be removed. | |
39 USER_POD_CUSTOM_ICON_LOCKED_WITH_PROXIMITY_HINT, | |
40 USER_POD_CUSTOM_ICON_UNLOCKED, | |
41 USER_POD_CUSTOM_ICON_SPINNER | |
42 }; | |
43 | |
44 // Class containing parameters describing the custom icon that should be | |
45 // shown on a user's screen lock pod next to the input field. | |
46 class UserPodCustomIconOptions { | |
47 public: | |
48 UserPodCustomIconOptions(); | |
49 ~UserPodCustomIconOptions(); | |
50 | |
51 // Converts parameters to a dictionary values that can be sent to the | |
52 // screenlock web UI. | |
53 scoped_ptr<base::DictionaryValue> ToDictionaryValue() const; | |
54 | |
55 // Sets the icon that should be shown in the UI. | |
56 void SetIcon(UserPodCustomIcon icon); | |
57 | |
58 // Sets the icon tooltip. If |autoshow| is set the tooltip is automatically | |
59 // shown with the icon. | |
60 void SetTooltip(const base::string16& tooltip, bool autoshow); | |
61 | |
62 // Sets the accessibility label of the icon. If this attribute is not | |
63 // provided, then the tooltip will be used. | |
64 void SetAriaLabel(const base::string16& aria_label); | |
65 | |
66 // If hardlock on click is set, clicking the icon in the screenlock will | |
67 // go to state where password is required for unlock. | |
68 void SetHardlockOnClick(); | |
69 | |
70 // If the current lock screen is a trial run to introduce users to Easy | |
71 // Unlock, the icon will record metrics upon click. | |
72 void SetTrialRun(); | |
73 | |
74 private: | |
75 UserPodCustomIcon icon_; | |
76 | |
77 base::string16 tooltip_; | |
78 bool autoshow_tooltip_; | |
79 | |
80 base::string16 aria_label_; | |
81 | |
82 bool hardlock_on_click_; | |
83 | |
84 bool is_trial_run_; | |
85 | |
86 DISALLOW_COPY_AND_ASSIGN(UserPodCustomIconOptions); | |
87 }; | |
88 | |
89 class LockHandler { | |
90 public: | |
91 // Supported authentication types. Keep in sync with the enum in | |
92 // user_pod_row.js. | |
93 enum AuthType { | |
94 OFFLINE_PASSWORD = 0, | |
95 ONLINE_SIGN_IN = 1, | |
96 NUMERIC_PIN = 2, | |
97 USER_CLICK = 3, | |
98 EXPAND_THEN_USER_CLICK = 4, | |
99 FORCE_OFFLINE_PASSWORD = 5 | |
100 }; | |
101 | |
102 enum ScreenType { | |
103 SIGNIN_SCREEN = 0, | |
104 LOCK_SCREEN = 1, | |
105 OTHER_SCREEN = 2 | |
106 }; | |
107 | |
108 // Displays |message| in a banner on the lock screen. | |
109 virtual void ShowBannerMessage(const base::string16& message) = 0; | |
110 | |
111 // Shows a custom icon in the user pod on the lock screen. | |
112 virtual void ShowUserPodCustomIcon( | |
113 const std::string& user_email, | |
114 const UserPodCustomIconOptions& icon) = 0; | |
115 | |
116 // Hides the custom icon in user pod for a user. | |
117 virtual void HideUserPodCustomIcon(const std::string& user_email) = 0; | |
118 | |
119 // (Re)enable lock screen UI. | |
120 virtual void EnableInput() = 0; | |
121 | |
122 // Set the authentication type to be used on the lock screen. | |
123 virtual void SetAuthType(const std::string& user_email, | |
124 AuthType auth_type, | |
125 const base::string16& auth_value) = 0; | |
126 | |
127 // Returns the authentication type used for a user. | |
128 virtual AuthType GetAuthType(const std::string& user_email) const = 0; | |
129 | |
130 // Returns the type of the screen -- a signin or a lock screen. | |
131 virtual ScreenType GetScreenType() const = 0; | |
132 | |
133 // Unlock from easy unlock app for a user. | |
134 virtual void Unlock(const std::string& user_email) = 0; | |
135 | |
136 // Attempts to login the user using an easy unlock key. | |
137 virtual void AttemptEasySignin(const std::string& user_email, | |
138 const std::string& secret, | |
139 const std::string& key_label) = 0; | |
140 | |
141 protected: | |
142 virtual ~LockHandler() {} | |
143 }; | |
144 | |
145 class Observer { | |
146 public: | |
147 // Invoked after the screen is locked. | |
148 virtual void OnScreenDidLock(LockHandler::ScreenType screen_type) = 0; | |
149 | |
150 // Invoked after the screen lock is dismissed. | |
151 virtual void OnScreenDidUnlock(LockHandler::ScreenType screen_type) = 0; | |
152 | |
153 // Invoked when the user focused on the lock screen changes. | |
154 virtual void OnFocusedUserChanged(const std::string& user_id) = 0; | |
155 | |
156 protected: | |
157 virtual ~Observer() {} | |
158 }; | |
159 | |
160 static ScreenlockBridge* Get(); | |
161 static std::string GetAuthenticatedUserEmail(const Profile* profile); | |
162 | |
163 void SetLockHandler(LockHandler* lock_handler); | |
164 void SetFocusedUser(const std::string& user_id); | |
165 | |
166 bool IsLocked() const; | |
167 void Lock(Profile* profile); | |
168 void Unlock(Profile* profile); | |
169 | |
170 void AddObserver(Observer* observer); | |
171 void RemoveObserver(Observer* observer); | |
172 | |
173 LockHandler* lock_handler() { return lock_handler_; } | |
174 | |
175 std::string focused_user_id() const { return focused_user_id_; } | |
176 | |
177 private: | |
178 friend struct base::DefaultLazyInstanceTraits<ScreenlockBridge>; | |
179 friend struct base::DefaultDeleter<ScreenlockBridge>; | |
180 | |
181 ScreenlockBridge(); | |
182 ~ScreenlockBridge(); | |
183 | |
184 LockHandler* lock_handler_; // Not owned | |
185 // The last focused user's id. | |
186 std::string focused_user_id_; | |
187 ObserverList<Observer, true> observers_; | |
188 | |
189 DISALLOW_COPY_AND_ASSIGN(ScreenlockBridge); | |
190 }; | |
191 | |
192 #endif // CHROME_BROWSER_SIGNIN_SCREENLOCK_BRIDGE_H_ | |
OLD | NEW |