Clean up extension confirmation prompts and make them consistent between Views and...
[chromium-blink-merge.git] / components / proximity_auth / screenlock_bridge.h
blobf9a47a45fcd10f9d0e62b6ec5366a2b269054a13
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.
5 #ifndef COMPONENTS_PROXIMITY_AUTH_SCREENLOCK_BRIDGE_H_
6 #define COMPONENTS_PROXIMITY_AUTH_SCREENLOCK_BRIDGE_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/observer_list.h"
14 #include "base/strings/string16.h"
15 #include "base/values.h"
17 namespace content {
18 class BrowserContext;
19 } // namespace content
21 namespace proximity_auth {
23 class ProximityAuthClient;
25 // ScreenlockBridge brings together the screenLockPrivate API and underlying
26 // support. On ChromeOS, it delegates calls to the ScreenLocker. On other
27 // platforms, it delegates calls to UserManagerUI (and friends).
28 // TODO(tbarzic): Rename ScreenlockBridge to SignInScreenBridge, as this is not
29 // used solely for the lock screen anymore.
30 class ScreenlockBridge {
31 public:
32 // |client| is not owned and must outlive this object.
33 explicit ScreenlockBridge(ProximityAuthClient* client);
34 ~ScreenlockBridge();
36 // User pod icons supported by lock screen / signin screen UI.
37 enum UserPodCustomIcon {
38 USER_POD_CUSTOM_ICON_NONE,
39 USER_POD_CUSTOM_ICON_HARDLOCKED,
40 USER_POD_CUSTOM_ICON_LOCKED,
41 USER_POD_CUSTOM_ICON_LOCKED_TO_BE_ACTIVATED,
42 // TODO(isherman): The "locked with proximity hint" icon is currently the
43 // same as the "locked" icon. It's treated as a separate case to allow an
44 // easy asset swap without changing the code, in case we decide to use a
45 // different icon for this case. If we definitely decide against that, then
46 // this enum entry should be removed.
47 USER_POD_CUSTOM_ICON_LOCKED_WITH_PROXIMITY_HINT,
48 USER_POD_CUSTOM_ICON_UNLOCKED,
49 USER_POD_CUSTOM_ICON_SPINNER
52 // Class containing parameters describing the custom icon that should be
53 // shown on a user's screen lock pod next to the input field.
54 class UserPodCustomIconOptions {
55 public:
56 UserPodCustomIconOptions();
57 ~UserPodCustomIconOptions();
59 // Converts parameters to a dictionary values that can be sent to the
60 // screenlock web UI.
61 scoped_ptr<base::DictionaryValue> ToDictionaryValue() const;
63 // Sets the icon that should be shown in the UI.
64 void SetIcon(UserPodCustomIcon icon);
66 // Sets the icon tooltip. If |autoshow| is set the tooltip is automatically
67 // shown with the icon.
68 void SetTooltip(const base::string16& tooltip, bool autoshow);
70 // Sets the accessibility label of the icon. If this attribute is not
71 // provided, then the tooltip will be used.
72 void SetAriaLabel(const base::string16& aria_label);
74 // If hardlock on click is set, clicking the icon in the screenlock will
75 // go to state where password is required for unlock.
76 void SetHardlockOnClick();
78 // If the current lock screen is a trial run to introduce users to Easy
79 // Unlock, the icon will record metrics upon click.
80 void SetTrialRun();
82 private:
83 UserPodCustomIcon icon_;
85 base::string16 tooltip_;
86 bool autoshow_tooltip_;
88 base::string16 aria_label_;
90 bool hardlock_on_click_;
92 bool is_trial_run_;
94 DISALLOW_COPY_AND_ASSIGN(UserPodCustomIconOptions);
97 class LockHandler {
98 public:
99 // Supported authentication types. Keep in sync with the enum in
100 // user_pod_row.js.
101 enum AuthType {
102 OFFLINE_PASSWORD = 0,
103 ONLINE_SIGN_IN = 1,
104 NUMERIC_PIN = 2,
105 USER_CLICK = 3,
106 EXPAND_THEN_USER_CLICK = 4,
107 FORCE_OFFLINE_PASSWORD = 5
110 enum ScreenType { SIGNIN_SCREEN = 0, LOCK_SCREEN = 1, OTHER_SCREEN = 2 };
112 // Displays |message| in a banner on the lock screen.
113 virtual void ShowBannerMessage(const base::string16& message) = 0;
115 // Shows a custom icon in the user pod on the lock screen.
116 virtual void ShowUserPodCustomIcon(
117 const std::string& user_email,
118 const UserPodCustomIconOptions& icon) = 0;
120 // Hides the custom icon in user pod for a user.
121 virtual void HideUserPodCustomIcon(const std::string& user_email) = 0;
123 // (Re)enable lock screen UI.
124 virtual void EnableInput() = 0;
126 // Set the authentication type to be used on the lock screen.
127 virtual void SetAuthType(const std::string& user_email,
128 AuthType auth_type,
129 const base::string16& auth_value) = 0;
131 // Returns the authentication type used for a user.
132 virtual AuthType GetAuthType(const std::string& user_email) const = 0;
134 // Returns the type of the screen -- a signin or a lock screen.
135 virtual ScreenType GetScreenType() const = 0;
137 // Unlocks from easy unlock app for a user.
138 virtual void Unlock(const std::string& user_email) = 0;
140 // Attempts to login the user using an easy unlock key.
141 virtual void AttemptEasySignin(const std::string& user_email,
142 const std::string& secret,
143 const std::string& key_label) = 0;
145 protected:
146 virtual ~LockHandler() {}
149 class Observer {
150 public:
151 // Invoked after the screen is locked.
152 virtual void OnScreenDidLock(LockHandler::ScreenType screen_type) = 0;
154 // Invoked after the screen lock is dismissed.
155 virtual void OnScreenDidUnlock(LockHandler::ScreenType screen_type) = 0;
157 // Invoked when the user focused on the lock screen changes.
158 virtual void OnFocusedUserChanged(const std::string& user_id) = 0;
160 protected:
161 virtual ~Observer() {}
164 void SetLockHandler(LockHandler* lock_handler);
165 void SetFocusedUser(const std::string& user_id);
167 bool IsLocked() const;
168 void Lock(content::BrowserContext* browser_context);
169 void Unlock(content::BrowserContext* browser_context);
171 void AddObserver(Observer* observer);
172 void RemoveObserver(Observer* observer);
174 LockHandler* lock_handler() { return lock_handler_; }
176 std::string focused_user_id() const { return focused_user_id_; }
178 private:
179 ProximityAuthClient* client_; // Not owned. Must outlive this object.
180 LockHandler* lock_handler_; // Not owned
181 // The last focused user's id.
182 std::string focused_user_id_;
183 base::ObserverList<Observer, true> observers_;
185 DISALLOW_COPY_AND_ASSIGN(ScreenlockBridge);
188 } // namespace proximity_auth
190 #endif // COMPONENTS_PROXIMITY_AUTH_SCREENLOCK_BRIDGE_H_