Move Webstore URL concepts to //extensions and out
[chromium-blink-merge.git] / chrome / browser / signin / screenlock_bridge.h
blob379f447488d743b9624c3dd5efd569a0e82c03db
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_
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"
19 class Profile;
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 class ScreenlockBridge {
25 public:
26 class Observer {
27 public:
28 // Invoked after the screen is locked.
29 virtual void OnScreenDidLock() = 0;
30 // Invoked after the screen lock is dismissed.
31 virtual void OnScreenDidUnlock() = 0;
32 protected:
33 virtual ~Observer() {}
36 // Class containing parameters describing the custom icon that should be
37 // shown on a user's screen lock pod next to the input field.
38 class UserPodCustomIconOptions {
39 public:
40 UserPodCustomIconOptions();
41 ~UserPodCustomIconOptions();
43 // Converts parameters to a dictionary values that can be sent to the
44 // screenlock web UI.
45 scoped_ptr<base::DictionaryValue> ToDictionaryValue() const;
47 // Sets the icon as chrome://theme resource URL.
48 void SetIconAsResourceURL(const std::string& url);
50 // Sets the icon size. If not called, the icon will not be visible.
51 // For animated icon, this should be set to a single frame size, not the
52 // animation resource size.
53 void SetSize(size_t icon_width, size_t icon_height);
55 // If the icon is supposed to be animated, sets the animation parameters.
56 // If set, it expects that the resource set using |SetIconAsResourceURL|
57 // method contains horizontally arranged ordered list of animation frames.
58 // Note that the icon size set in |SetSize| should be a single frame size.
59 // |resource_width|: Total animation resource width.
60 // |frame_length_ms|: Time for which a single animation frame is shown.
61 void SetAnimation(size_t resource_width, size_t frame_length_ms);
63 // Sets the icon opacity. The values should be in <0, 100] interval, which
64 // will get scaled into <0, 1] interval. The default value is 100.
65 void SetOpacity(size_t opacity);
67 // Sets the icon tooltip. If |autoshow| is set the tooltip is automatically
68 // shown with the icon.
69 void SetTooltip(const base::string16& tooltip, bool autoshow);
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();
75 private:
76 std::string icon_resource_url_;
78 size_t width_;
79 size_t height_;
81 bool animation_set_;
82 size_t animation_resource_width_;
83 size_t animation_frame_length_ms_;
85 // The opacity should be in <0, 100] range.
86 size_t opacity_;
88 base::string16 tooltip_;
89 bool autoshow_tooltip_;
91 bool hardlock_on_click_;
93 DISALLOW_COPY_AND_ASSIGN(UserPodCustomIconOptions);
96 class LockHandler {
97 public:
98 // Supported authentication types. Keep in sync with the enum in
99 // user_pod_row.js.
100 enum AuthType {
101 OFFLINE_PASSWORD = 0,
102 ONLINE_SIGN_IN = 1,
103 NUMERIC_PIN = 2,
104 USER_CLICK = 3,
105 EXPAND_THEN_USER_CLICK = 4,
106 FORCE_OFFLINE_PASSWORD = 5
109 // Displays |message| in a banner on the lock screen.
110 virtual void ShowBannerMessage(const base::string16& message) = 0;
112 // Shows a custom icon in the user pod on the lock screen.
113 virtual void ShowUserPodCustomIcon(
114 const std::string& user_email,
115 const UserPodCustomIconOptions& icon) = 0;
117 // Hides the custom icon in user pod for a user.
118 virtual void HideUserPodCustomIcon(const std::string& user_email) = 0;
120 // (Re)enable lock screen UI.
121 virtual void EnableInput() = 0;
123 // Set the authentication type to be used on the lock screen.
124 virtual void SetAuthType(const std::string& user_email,
125 AuthType auth_type,
126 const base::string16& auth_value) = 0;
128 // Returns the authentication type used for a user.
129 virtual AuthType GetAuthType(const std::string& user_email) const = 0;
131 // Unlock from easy unlock app for a user.
132 virtual void Unlock(const std::string& user_email) = 0;
134 protected:
135 virtual ~LockHandler() {}
138 static ScreenlockBridge* Get();
139 static std::string GetAuthenticatedUserEmail(Profile* profile);
141 void SetLockHandler(LockHandler* lock_handler);
143 bool IsLocked() const;
144 void Lock(Profile* profile);
145 void Unlock(Profile* profile);
147 void AddObserver(Observer* observer);
148 void RemoveObserver(Observer* observer);
150 LockHandler* lock_handler() { return lock_handler_; }
152 private:
153 friend struct base::DefaultLazyInstanceTraits<ScreenlockBridge>;
154 friend struct base::DefaultDeleter<ScreenlockBridge>;
156 ScreenlockBridge();
157 ~ScreenlockBridge();
159 LockHandler* lock_handler_; // Not owned
160 ObserverList<Observer, true> observers_;
162 DISALLOW_COPY_AND_ASSIGN(ScreenlockBridge);
165 #endif // CHROME_BROWSER_SIGNIN_SCREENLOCK_BRIDGE_H_