mandoline: Reland "Sandbox mojo:browser and mojo:omnibox."
[chromium-blink-merge.git] / components / proximity_auth / screenlock_bridge.h
blob9b4739298c9ad066d3b997af13784ddeab941b6b
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/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"
18 namespace proximity_auth {
20 // ScreenlockBridge brings together the screenLockPrivate API and underlying
21 // support. On ChromeOS, it delegates calls to the ScreenLocker. On other
22 // platforms, it delegates calls to UserManagerUI (and friends).
23 // TODO(tbarzic): Rename ScreenlockBridge to SignInScreenBridge, as this is not
24 // used solely for the lock screen anymore.
25 class ScreenlockBridge {
26 public:
27 // User pod icons supported by lock screen / signin screen UI.
28 enum UserPodCustomIcon {
29 USER_POD_CUSTOM_ICON_NONE,
30 USER_POD_CUSTOM_ICON_HARDLOCKED,
31 USER_POD_CUSTOM_ICON_LOCKED,
32 USER_POD_CUSTOM_ICON_LOCKED_TO_BE_ACTIVATED,
33 // TODO(isherman): The "locked with proximity hint" icon is currently the
34 // same as the "locked" icon. It's treated as a separate case to allow an
35 // easy asset swap without changing the code, in case we decide to use a
36 // different icon for this case. If we definitely decide against that, then
37 // this enum entry should be removed.
38 USER_POD_CUSTOM_ICON_LOCKED_WITH_PROXIMITY_HINT,
39 USER_POD_CUSTOM_ICON_UNLOCKED,
40 USER_POD_CUSTOM_ICON_SPINNER
43 // Class containing parameters describing the custom icon that should be
44 // shown on a user's screen lock pod next to the input field.
45 class UserPodCustomIconOptions {
46 public:
47 UserPodCustomIconOptions();
48 ~UserPodCustomIconOptions();
50 // Converts parameters to a dictionary values that can be sent to the
51 // screenlock web UI.
52 scoped_ptr<base::DictionaryValue> ToDictionaryValue() const;
54 // Sets the icon that should be shown in the UI.
55 void SetIcon(UserPodCustomIcon icon);
57 // Sets the icon tooltip. If |autoshow| is set the tooltip is automatically
58 // shown with the icon.
59 void SetTooltip(const base::string16& tooltip, bool autoshow);
61 // Sets the accessibility label of the icon. If this attribute is not
62 // provided, then the tooltip will be used.
63 void SetAriaLabel(const base::string16& aria_label);
65 // If hardlock on click is set, clicking the icon in the screenlock will
66 // go to state where password is required for unlock.
67 void SetHardlockOnClick();
69 // If the current lock screen is a trial run to introduce users to Easy
70 // Unlock, the icon will record metrics upon click.
71 void SetTrialRun();
73 private:
74 UserPodCustomIcon icon_;
76 base::string16 tooltip_;
77 bool autoshow_tooltip_;
79 base::string16 aria_label_;
81 bool hardlock_on_click_;
83 bool is_trial_run_;
85 DISALLOW_COPY_AND_ASSIGN(UserPodCustomIconOptions);
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
101 enum ScreenType { SIGNIN_SCREEN = 0, LOCK_SCREEN = 1, OTHER_SCREEN = 2 };
103 // Displays |message| in a banner on the lock screen.
104 virtual void ShowBannerMessage(const base::string16& message) = 0;
106 // Shows a custom icon in the user pod on the lock screen.
107 virtual void ShowUserPodCustomIcon(
108 const std::string& user_email,
109 const UserPodCustomIconOptions& icon) = 0;
111 // Hides the custom icon in user pod for a user.
112 virtual void HideUserPodCustomIcon(const std::string& user_email) = 0;
114 // (Re)enable lock screen UI.
115 virtual void EnableInput() = 0;
117 // Set the authentication type to be used on the lock screen.
118 virtual void SetAuthType(const std::string& user_email,
119 AuthType auth_type,
120 const base::string16& auth_value) = 0;
122 // Returns the authentication type used for a user.
123 virtual AuthType GetAuthType(const std::string& user_email) const = 0;
125 // Returns the type of the screen -- a signin or a lock screen.
126 virtual ScreenType GetScreenType() const = 0;
128 // Unlocks from easy unlock app for a user.
129 virtual void Unlock(const std::string& user_email) = 0;
131 // Attempts to login the user using an easy unlock key.
132 virtual void AttemptEasySignin(const std::string& user_email,
133 const std::string& secret,
134 const std::string& key_label) = 0;
136 protected:
137 virtual ~LockHandler() {}
140 class Observer {
141 public:
142 // Invoked after the screen is locked.
143 virtual void OnScreenDidLock(LockHandler::ScreenType screen_type) = 0;
145 // Invoked after the screen lock is dismissed.
146 virtual void OnScreenDidUnlock(LockHandler::ScreenType screen_type) = 0;
148 // Invoked when the user focused on the lock screen changes.
149 virtual void OnFocusedUserChanged(const std::string& user_id) = 0;
151 protected:
152 virtual ~Observer() {}
155 static ScreenlockBridge* Get();
157 void SetLockHandler(LockHandler* lock_handler);
158 void SetFocusedUser(const std::string& user_id);
160 bool IsLocked() const;
161 void Lock();
163 // Unlocks the screen for the authenticated user with the given |user_email|.
164 void Unlock(const std::string& user_email);
166 void AddObserver(Observer* observer);
167 void RemoveObserver(Observer* observer);
169 LockHandler* lock_handler() { return lock_handler_; }
171 std::string focused_user_id() const { return focused_user_id_; }
173 private:
174 friend struct base::DefaultLazyInstanceTraits<ScreenlockBridge>;
175 friend struct base::DefaultDeleter<ScreenlockBridge>;
177 ScreenlockBridge();
178 ~ScreenlockBridge();
180 LockHandler* lock_handler_; // Not owned
182 // The last focused user's id.
183 std::string focused_user_id_;
184 base::ObserverList<Observer, true> observers_;
186 DISALLOW_COPY_AND_ASSIGN(ScreenlockBridge);
189 } // namespace proximity_auth
191 #endif // COMPONENTS_PROXIMITY_AUTH_SCREENLOCK_BRIDGE_H_