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_
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"
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
{
32 // |client| is not owned and must outlive this object.
33 explicit ScreenlockBridge(ProximityAuthClient
* client
);
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
{
56 UserPodCustomIconOptions();
57 ~UserPodCustomIconOptions();
59 // Converts parameters to a dictionary values that can be sent to the
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.
83 UserPodCustomIcon icon_
;
85 base::string16 tooltip_
;
86 bool autoshow_tooltip_
;
88 base::string16 aria_label_
;
90 bool hardlock_on_click_
;
94 DISALLOW_COPY_AND_ASSIGN(UserPodCustomIconOptions
);
99 // Supported authentication types. Keep in sync with the enum in
102 OFFLINE_PASSWORD
= 0,
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
,
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;
146 virtual ~LockHandler() {}
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;
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_
; }
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_