| 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 ScreelockBridge to SignInScreenBridge, as this is not | |
| 25 // used solely for the lock screen anymore. | |
| 26 class ScreenlockBridge { | |
| 27 public: | |
| 28 class Observer { | |
| 29 public: | |
| 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; | |
| 36 protected: | |
| 37 virtual ~Observer() {} | |
| 38 }; | |
| 39 | |
| 40 // Class containing parameters describing the custom icon that should be | |
| 41 // shown on a user's screen lock pod next to the input field. | |
| 42 class UserPodCustomIconOptions { | |
| 43 public: | |
| 44 UserPodCustomIconOptions(); | |
| 45 ~UserPodCustomIconOptions(); | |
| 46 | |
| 47 // Converts parameters to a dictionary values that can be sent to the | |
| 48 // screenlock web UI. | |
| 49 scoped_ptr<base::DictionaryValue> ToDictionaryValue() const; | |
| 50 | |
| 51 // Sets the icon as chrome://theme resource URL. | |
| 52 void SetIconAsResourceURL(const std::string& url); | |
| 53 | |
| 54 // Sets the icon size. If not called, the icon will not be visible. | |
| 55 // For animated icon, this should be set to a single frame size, not the | |
| 56 // animation resource size. | |
| 57 void SetSize(size_t icon_width, size_t icon_height); | |
| 58 | |
| 59 // If the icon is supposed to be animated, sets the animation parameters. | |
| 60 // If set, it expects that the resource set using |SetIconAsResourceURL| | |
| 61 // method contains horizontally arranged ordered list of animation frames. | |
| 62 // Note that the icon size set in |SetSize| should be a single frame size. | |
| 63 // |resource_width|: Total animation resource width. | |
| 64 // |frame_length_ms|: Time for which a single animation frame is shown. | |
| 65 void SetAnimation(size_t resource_width, size_t frame_length_ms); | |
| 66 | |
| 67 // Sets the icon opacity. The values should be in <0, 100] interval, which | |
| 68 // will get scaled into <0, 1] interval. The default value is 100. | |
| 69 void SetOpacity(size_t opacity); | |
| 70 | |
| 71 // Sets the icon tooltip. If |autoshow| is set the tooltip is automatically | |
| 72 // shown with the icon. | |
| 73 void SetTooltip(const base::string16& tooltip, bool autoshow); | |
| 74 | |
| 75 // If hardlock on click is set, clicking the icon in the screenlock will | |
| 76 // go to state where password is required for unlock. | |
| 77 void SetHardlockOnClick(); | |
| 78 | |
| 79 private: | |
| 80 std::string icon_resource_url_; | |
| 81 | |
| 82 size_t width_; | |
| 83 size_t height_; | |
| 84 | |
| 85 bool animation_set_; | |
| 86 size_t animation_resource_width_; | |
| 87 size_t animation_frame_length_ms_; | |
| 88 | |
| 89 // The opacity should be in <0, 100] range. | |
| 90 size_t opacity_; | |
| 91 | |
| 92 base::string16 tooltip_; | |
| 93 bool autoshow_tooltip_; | |
| 94 | |
| 95 bool hardlock_on_click_; | |
| 96 | |
| 97 DISALLOW_COPY_AND_ASSIGN(UserPodCustomIconOptions); | |
| 98 }; | |
| 99 | |
| 100 class LockHandler { | |
| 101 public: | |
| 102 // Supported authentication types. Keep in sync with the enum in | |
| 103 // user_pod_row.js. | |
| 104 enum AuthType { | |
| 105 OFFLINE_PASSWORD = 0, | |
| 106 ONLINE_SIGN_IN = 1, | |
| 107 NUMERIC_PIN = 2, | |
| 108 USER_CLICK = 3, | |
| 109 EXPAND_THEN_USER_CLICK = 4, | |
| 110 FORCE_OFFLINE_PASSWORD = 5 | |
| 111 }; | |
| 112 | |
| 113 // Displays |message| in a banner on the lock screen. | |
| 114 virtual void ShowBannerMessage(const base::string16& message) = 0; | |
| 115 | |
| 116 // Shows a custom icon in the user pod on the lock screen. | |
| 117 virtual void ShowUserPodCustomIcon( | |
| 118 const std::string& user_email, | |
| 119 const UserPodCustomIconOptions& icon) = 0; | |
| 120 | |
| 121 // Hides the custom icon in user pod for a user. | |
| 122 virtual void HideUserPodCustomIcon(const std::string& user_email) = 0; | |
| 123 | |
| 124 // (Re)enable lock screen UI. | |
| 125 virtual void EnableInput() = 0; | |
| 126 | |
| 127 // Set the authentication type to be used on the lock screen. | |
| 128 virtual void SetAuthType(const std::string& user_email, | |
| 129 AuthType auth_type, | |
| 130 const base::string16& auth_value) = 0; | |
| 131 | |
| 132 // Returns the authentication type used for a user. | |
| 133 virtual AuthType GetAuthType(const std::string& user_email) const = 0; | |
| 134 | |
| 135 // Unlock from easy unlock app for a user. | |
| 136 virtual void Unlock(const std::string& user_email) = 0; | |
| 137 | |
| 138 // Attempts to login the user using an easy unlock key. | |
| 139 virtual void AttemptUserClickLogin(const std::string& user_email, | |
| 140 const std::string& secret, | |
| 141 const std::string& key_label) = 0; | |
| 142 | |
| 143 protected: | |
| 144 virtual ~LockHandler() {} | |
| 145 }; | |
| 146 | |
| 147 static ScreenlockBridge* Get(); | |
| 148 static std::string GetAuthenticatedUserEmail(Profile* profile); | |
| 149 | |
| 150 void SetLockHandler(LockHandler* lock_handler); | |
| 151 void SetFocusedUser(const std::string& user_id); | |
| 152 | |
| 153 bool IsLocked() const; | |
| 154 void Lock(Profile* profile); | |
| 155 void Unlock(Profile* profile); | |
| 156 | |
| 157 void AddObserver(Observer* observer); | |
| 158 void RemoveObserver(Observer* observer); | |
| 159 | |
| 160 LockHandler* lock_handler() { return lock_handler_; } | |
| 161 | |
| 162 std::string focused_user_id() const { return focused_user_id_; } | |
| 163 | |
| 164 private: | |
| 165 friend struct base::DefaultLazyInstanceTraits<ScreenlockBridge>; | |
| 166 friend struct base::DefaultDeleter<ScreenlockBridge>; | |
| 167 | |
| 168 ScreenlockBridge(); | |
| 169 ~ScreenlockBridge(); | |
| 170 | |
| 171 LockHandler* lock_handler_; // Not owned | |
| 172 // The last focused user's id. | |
| 173 std::string focused_user_id_; | |
| 174 ObserverList<Observer, true> observers_; | |
| 175 | |
| 176 DISALLOW_COPY_AND_ASSIGN(ScreenlockBridge); | |
| 177 }; | |
| 178 | |
| 179 #endif // CHROME_BROWSER_SIGNIN_SCREENLOCK_BRIDGE_H_ | |
| OLD | NEW |