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 CHROME_BROWSER_SIGNIN_SCREENLOCK_BRIDGE_H_
6 #define CHROME_BROWSER_SIGNIN_SCREENLOCK_BRIDGE_H_
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"
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 {
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;
37 virtual ~Observer() {}
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
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 {
53 UserPodCustomIconOptions();
54 ~UserPodCustomIconOptions();
56 // Converts parameters to a dictionary values that can be sent to the
58 scoped_ptr<base::DictionaryValue> ToDictionaryValue() const;
60 // Sets the icon that should be shown in the UI.
61 void SetIcon(UserPodCustomIcon icon);
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);
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);
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();
76 UserPodCustomIcon icon_;
78 base::string16 tooltip_;
79 bool autoshow_tooltip_;
81 base::string16 aria_label_;
83 bool hardlock_on_click_;
85 DISALLOW_COPY_AND_ASSIGN(UserPodCustomIconOptions);
90 // Supported authentication types. Keep in sync with the enum in
97 EXPAND_THEN_USER_CLICK = 4,
98 FORCE_OFFLINE_PASSWORD = 5
101 // Displays |message| in a banner on the lock screen.
102 virtual void ShowBannerMessage(const base::string16& message) = 0;
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;
109 // Hides the custom icon in user pod for a user.
110 virtual void HideUserPodCustomIcon(const std::string& user_email) = 0;
112 // (Re)enable lock screen UI.
113 virtual void EnableInput() = 0;
115 // Set the authentication type to be used on the lock screen.
116 virtual void SetAuthType(const std::string& user_email,
118 const base::string16& auth_value) = 0;
120 // Returns the authentication type used for a user.
121 virtual AuthType GetAuthType(const std::string& user_email) const = 0;
123 // Unlock from easy unlock app for a user.
124 virtual void Unlock(const std::string& user_email) = 0;
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;
132 virtual ~LockHandler() {}
135 static ScreenlockBridge* Get();
136 static std::string GetAuthenticatedUserEmail(Profile* profile);
138 void SetLockHandler(LockHandler* lock_handler);
139 void SetFocusedUser(const std::string& user_id);
141 bool IsLocked() const;
142 void Lock(Profile* profile);
143 void Unlock(Profile* profile);
145 void AddObserver(Observer* observer);
146 void RemoveObserver(Observer* observer);
148 LockHandler* lock_handler() { return lock_handler_; }
150 std::string focused_user_id() const { return focused_user_id_; }
153 friend struct base::DefaultLazyInstanceTraits<ScreenlockBridge>;
154 friend struct base::DefaultDeleter<ScreenlockBridge>;
159 LockHandler* lock_handler_; // Not owned
160 // The last focused user's id.
161 std::string focused_user_id_;
162 ObserverList<Observer, true> observers_;
164 DISALLOW_COPY_AND_ASSIGN(ScreenlockBridge);
167 #endif // CHROME_BROWSER_SIGNIN_SCREENLOCK_BRIDGE_H_