Upstream version 10.38.208.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / signin / screenlock_bridge.h
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 namespace gfx {
19 class Image;
20 }
21
22 class Profile;
23
24 // ScreenlockBridge brings together the screenLockPrivate API and underlying
25 // support. On ChromeOS, it delegates calls to the ScreenLocker. On other
26 // platforms, it delegates calls to UserManagerUI (and friends).
27 class ScreenlockBridge {
28  public:
29   class Observer {
30    public:
31     // Invoked after the screen is locked.
32     virtual void OnScreenDidLock() = 0;
33     // Invoked after the screen lock is dismissed.
34     virtual void OnScreenDidUnlock() = 0;
35    protected:
36     virtual ~Observer() {}
37   };
38
39   // Class containing parameters describing the custom icon that should be
40   // shown on a user's screen lock pod next to the input field.
41   class UserPodCustomIconOptions {
42    public:
43     UserPodCustomIconOptions();
44     ~UserPodCustomIconOptions();
45
46     // Converts parameters to a dictionary values that can be sent to the
47     // screenlock web UI.
48     scoped_ptr<base::DictionaryValue> ToDictionaryValue() const;
49
50     // Sets the icon as chrome://theme resource URL.
51     void SetIconAsResourceURL(const std::string& url);
52
53     // Sets the icon as a gfx::Image. The image will be converted to set of data
54     // URLs for each icon representation. Use |SetIconAsResourceURL| instead of
55     // this.
56     // TODO(tbarzic): Remove this one once easy unlock app stops using
57     // screenlockPrivate.showCustomIcon.
58     void SetIconAsImage(const gfx::Image& image);
59
60     // Sets the icon size. Has to be called if |SetIconAsResourceURL| was used
61     // to set the icon. For animated icon, this should be set to a single frame
62     // size, not the animation resource size.
63     void SetSize(size_t icon_width, size_t icon_height);
64
65     // If the icon is supposed to be animated, sets the animation parameters.
66     // If set, it expects that the resource set using |SetIcon*| methods
67     // contains horizontally arranged ordered list of animation frames.
68     // Note that the icon size set in |SetSize| should be a single frame size.
69     // |resource_width|: Total animation resource width.
70     // |frame_length_ms|: Time for which a single animation frame is shown.
71     void SetAnimation(size_t resource_width, size_t frame_length_ms);
72
73     // Sets the icon opacity. The values should be in <0, 100] interval, which
74     // will get scaled into <0, 1] interval. The default value is 100.
75     void SetOpacity(size_t opacity);
76
77     // Sets the icon tooltip. If |autoshow| is set the tooltip is automatically
78     // shown with the icon.
79     void SetTooltip(const base::string16& tooltip, bool autoshow);
80
81     // If hardlock on click is set, clicking the icon in the screenlock will
82     // go to state where password is required for unlock.
83     void SetHardlockOnClick();
84
85    private:
86     std::string icon_resource_url_;
87     scoped_ptr<gfx::Image> icon_image_;
88
89     size_t width_;
90     size_t height_;
91
92     bool animation_set_;
93     size_t animation_resource_width_;
94     size_t animation_frame_length_ms_;
95
96     // The opacity should be in <0, 100] range.
97     size_t opacity_;
98
99     base::string16 tooltip_;
100     bool autoshow_tooltip_;
101
102     bool hardlock_on_click_;
103
104     DISALLOW_COPY_AND_ASSIGN(UserPodCustomIconOptions);
105   };
106
107   class LockHandler {
108    public:
109     // Supported authentication types. Keep in sync with the enum in
110     // user_pod_row.js.
111     enum AuthType {
112       OFFLINE_PASSWORD = 0,
113       ONLINE_SIGN_IN = 1,
114       NUMERIC_PIN = 2,
115       USER_CLICK = 3,
116       EXPAND_THEN_USER_CLICK = 4,
117       FORCE_OFFLINE_PASSWORD = 5
118     };
119
120     // Displays |message| in a banner on the lock screen.
121     virtual void ShowBannerMessage(const base::string16& message) = 0;
122
123     // Shows a custom icon in the user pod on the lock screen.
124     virtual void ShowUserPodCustomIcon(
125         const std::string& user_email,
126         const UserPodCustomIconOptions& icon) = 0;
127
128     // Hides the custom icon in user pod for a user.
129     virtual void HideUserPodCustomIcon(const std::string& user_email) = 0;
130
131     // (Re)enable lock screen UI.
132     virtual void EnableInput() = 0;
133
134     // Set the authentication type to be used on the lock screen.
135     virtual void SetAuthType(const std::string& user_email,
136                              AuthType auth_type,
137                              const base::string16& auth_value) = 0;
138
139     // Returns the authentication type used for a user.
140     virtual AuthType GetAuthType(const std::string& user_email) const = 0;
141
142     // Unlock from easy unlock app for a user.
143     virtual void Unlock(const std::string& user_email) = 0;
144
145    protected:
146     virtual ~LockHandler() {}
147   };
148
149   static ScreenlockBridge* Get();
150   static std::string GetAuthenticatedUserEmail(Profile* profile);
151
152   void SetLockHandler(LockHandler* lock_handler);
153
154   bool IsLocked() const;
155   void Lock(Profile* profile);
156   void Unlock(Profile* profile);
157
158   void AddObserver(Observer* observer);
159   void RemoveObserver(Observer* observer);
160
161   LockHandler* lock_handler() { return lock_handler_; }
162
163  private:
164   friend struct base::DefaultLazyInstanceTraits<ScreenlockBridge>;
165   friend struct base::DefaultDeleter<ScreenlockBridge>;
166
167   ScreenlockBridge();
168   ~ScreenlockBridge();
169
170   LockHandler* lock_handler_;  // Not owned
171   ObserverList<Observer, true> observers_;
172
173   DISALLOW_COPY_AND_ASSIGN(ScreenlockBridge);
174 };
175
176 #endif  // CHROME_BROWSER_SIGNIN_SCREENLOCK_BRIDGE_H_