File: screenlock_bridge.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (191 lines) | stat: -rw-r--r-- 6,377 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_PROXIMITY_AUTH_SCREENLOCK_BRIDGE_H_
#define COMPONENTS_PROXIMITY_AUTH_SCREENLOCK_BRIDGE_H_

#include <memory>
#include <string>

#include "base/lazy_instance.h"
#include "base/macros.h"
#include "base/observer_list.h"
#include "base/strings/string16.h"
#include "base/values.h"
#include "components/signin/core/account_id/account_id.h"

namespace proximity_auth {

// ScreenlockBridge brings together the screenLockPrivate API and underlying
// support. On ChromeOS, it delegates calls to the ScreenLocker. On other
// platforms, it delegates calls to UserManagerUI (and friends).
// TODO(tbarzic): Rename ScreenlockBridge to SignInScreenBridge, as this is not
// used solely for the lock screen anymore.
class ScreenlockBridge {
 public:
  // User pod icons supported by lock screen / signin screen UI.
  enum UserPodCustomIcon {
    USER_POD_CUSTOM_ICON_NONE,
    USER_POD_CUSTOM_ICON_HARDLOCKED,
    USER_POD_CUSTOM_ICON_LOCKED,
    USER_POD_CUSTOM_ICON_LOCKED_TO_BE_ACTIVATED,
    // TODO(isherman): The "locked with proximity hint" icon is currently the
    // same as the "locked" icon. It's treated as a separate case to allow an
    // easy asset swap without changing the code, in case we decide to use a
    // different icon for this case. If we definitely decide against that, then
    // this enum entry should be removed.
    USER_POD_CUSTOM_ICON_LOCKED_WITH_PROXIMITY_HINT,
    USER_POD_CUSTOM_ICON_UNLOCKED,
    USER_POD_CUSTOM_ICON_SPINNER
  };

  // Class containing parameters describing the custom icon that should be
  // shown on a user's screen lock pod next to the input field.
  class UserPodCustomIconOptions {
   public:
    UserPodCustomIconOptions();
    ~UserPodCustomIconOptions();

    // Converts parameters to a dictionary values that can be sent to the
    // screenlock web UI.
    std::unique_ptr<base::DictionaryValue> ToDictionaryValue() const;

    // Sets the icon that should be shown in the UI.
    void SetIcon(UserPodCustomIcon icon);

    // Sets the icon tooltip. If |autoshow| is set the tooltip is automatically
    // shown with the icon.
    void SetTooltip(const base::string16& tooltip, bool autoshow);

    // Sets the accessibility label of the icon. If this attribute is not
    // provided, then the tooltip will be used.
    void SetAriaLabel(const base::string16& aria_label);

    // If hardlock on click is set, clicking the icon in the screenlock will
    // go to state where password is required for unlock.
    void SetHardlockOnClick();

    // If the current lock screen is a trial run to introduce users to Easy
    // Unlock, the icon will record metrics upon click.
    void SetTrialRun();

   private:
    UserPodCustomIcon icon_;

    base::string16 tooltip_;
    bool autoshow_tooltip_;

    base::string16 aria_label_;

    bool hardlock_on_click_;

    bool is_trial_run_;

    DISALLOW_COPY_AND_ASSIGN(UserPodCustomIconOptions);
  };

  class LockHandler {
   public:
    // Supported authentication types. Keep in sync with the enum in
    // user_pod_row.js.
    enum AuthType {
      OFFLINE_PASSWORD = 0,
      ONLINE_SIGN_IN = 1,
      NUMERIC_PIN = 2,
      USER_CLICK = 3,
      EXPAND_THEN_USER_CLICK = 4,
      FORCE_OFFLINE_PASSWORD = 5
    };

    enum ScreenType { SIGNIN_SCREEN = 0, LOCK_SCREEN = 1, OTHER_SCREEN = 2 };

    // Displays |message| in a banner on the lock screen.
    virtual void ShowBannerMessage(const base::string16& message) = 0;

    // Shows a custom icon in the user pod on the lock screen.
    virtual void ShowUserPodCustomIcon(
        const AccountId& account_id,
        const UserPodCustomIconOptions& icon) = 0;

    // Hides the custom icon in user pod for a user.
    virtual void HideUserPodCustomIcon(const AccountId& account_id) = 0;

    // (Re)enable lock screen UI.
    virtual void EnableInput() = 0;

    // Set the authentication type to be used on the lock screen.
    virtual void SetAuthType(const AccountId& account_id,
                             AuthType auth_type,
                             const base::string16& auth_value) = 0;

    // Returns the authentication type used for a user.
    virtual AuthType GetAuthType(const AccountId& account_id) const = 0;

    // Returns the type of the screen -- a signin or a lock screen.
    virtual ScreenType GetScreenType() const = 0;

    // Unlocks from easy unlock app for a user.
    virtual void Unlock(const AccountId& account_id) = 0;

    // Attempts to login the user using an easy unlock key.
    virtual void AttemptEasySignin(const AccountId& account_id,
                                   const std::string& secret,
                                   const std::string& key_label) = 0;

   protected:
    virtual ~LockHandler() {}
  };

  class Observer {
   public:
    // Invoked after the screen is locked.
    virtual void OnScreenDidLock(LockHandler::ScreenType screen_type) = 0;

    // Invoked after the screen lock is dismissed.
    virtual void OnScreenDidUnlock(LockHandler::ScreenType screen_type) = 0;

    // Invoked when the user focused on the lock screen changes.
    virtual void OnFocusedUserChanged(const AccountId& account_id) = 0;

   protected:
    virtual ~Observer() {}
  };

  static ScreenlockBridge* Get();

  void SetLockHandler(LockHandler* lock_handler);
  void SetFocusedUser(const AccountId& account_id);

  bool IsLocked() const;
  void Lock();

  // Unlocks the screen for the authenticated user with the given |user_id|.
  void Unlock(const AccountId& account_id);

  void AddObserver(Observer* observer);
  void RemoveObserver(Observer* observer);

  LockHandler* lock_handler() { return lock_handler_; }

  const AccountId& focused_account_id() const { return focused_account_id_; }

 private:
  friend struct base::DefaultLazyInstanceTraits<ScreenlockBridge>;
  friend std::default_delete<ScreenlockBridge>;

  ScreenlockBridge();
  ~ScreenlockBridge();

  LockHandler* lock_handler_;  // Not owned

  // The last focused user's id.
  AccountId focused_account_id_;
  base::ObserverList<Observer, true> observers_;

  DISALLOW_COPY_AND_ASSIGN(ScreenlockBridge);
};

}  // namespace proximity_auth

#endif  // COMPONENTS_PROXIMITY_AUTH_SCREENLOCK_BRIDGE_H_