summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/extensions/screenlock_private_api.h
blob: 3aa43ef77b2d240597d59e4dbc13b5ea11645b9b (plain)
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
// Copyright 2013 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 CHROME_BROWSER_CHROMEOS_EXTENSIONS_SCREENLOCK_PRIVATE_API_H_
#define CHROME_BROWSER_CHROMEOS_EXTENSIONS_SCREENLOCK_PRIVATE_API_H_

#include "chrome/browser/chromeos/login/login_display.h"
#include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
#include "chrome/browser/extensions/chrome_extension_function.h"
#include "chromeos/dbus/session_manager_client.h"

namespace extensions {

class ScreenlockPrivateGetLockedFunction : public ChromeAsyncExtensionFunction {
 public:
  DECLARE_EXTENSION_FUNCTION("screenlockPrivate.getLocked",
                             SCREENLOCKPRIVATE_GETLOCKED)
  ScreenlockPrivateGetLockedFunction();
  virtual bool RunImpl() OVERRIDE;
 private:
  virtual ~ScreenlockPrivateGetLockedFunction();
  DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateGetLockedFunction);
};

class ScreenlockPrivateSetLockedFunction : public ChromeAsyncExtensionFunction {
 public:
  DECLARE_EXTENSION_FUNCTION("screenlockPrivate.setLocked",
                             SCREENLOCKPRIVATE_SETLOCKED)
  ScreenlockPrivateSetLockedFunction();
  virtual bool RunImpl() OVERRIDE;
 private:
  virtual ~ScreenlockPrivateSetLockedFunction();
  DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateSetLockedFunction);
};

class ScreenlockPrivateShowMessageFunction
    : public ChromeAsyncExtensionFunction {
 public:
  DECLARE_EXTENSION_FUNCTION("screenlockPrivate.showMessage",
                             SCREENLOCKPRIVATE_SHOWMESSAGE)
  ScreenlockPrivateShowMessageFunction();
  virtual bool RunImpl() OVERRIDE;
 private:
  virtual ~ScreenlockPrivateShowMessageFunction();
  DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateShowMessageFunction );
};

class ScreenlockPrivateShowButtonFunction
    : public ChromeAsyncExtensionFunction {
 public:
  DECLARE_EXTENSION_FUNCTION("screenlockPrivate.showButton",
                             SCREENLOCKPRIVATE_SHOWBUTTON)
  ScreenlockPrivateShowButtonFunction();
  virtual bool RunImpl() OVERRIDE;
 private:
  virtual ~ScreenlockPrivateShowButtonFunction();
  void OnImageLoaded(const gfx::Image& image);
  DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateShowButtonFunction);
};

class ScreenlockPrivateHideButtonFunction
    : public ChromeAsyncExtensionFunction {
 public:
  DECLARE_EXTENSION_FUNCTION("screenlockPrivate.hideButton",
                             SCREENLOCKPRIVATE_HIDEBUTTON)
  ScreenlockPrivateHideButtonFunction();
  virtual bool RunImpl() OVERRIDE;

 private:
  virtual ~ScreenlockPrivateHideButtonFunction();
  void OnImageLoaded(const gfx::Image& image);
  DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateHideButtonFunction);
};

class ScreenlockPrivateSetAuthTypeFunction
    : public ChromeAsyncExtensionFunction {
 public:
  DECLARE_EXTENSION_FUNCTION("screenlockPrivate.setAuthType",
                             SCREENLOCKPRIVATE_SETAUTHTYPE)
  ScreenlockPrivateSetAuthTypeFunction();
  virtual bool RunImpl() OVERRIDE;

 private:
  virtual ~ScreenlockPrivateSetAuthTypeFunction();
  DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateSetAuthTypeFunction);
};

class ScreenlockPrivateGetAuthTypeFunction
    : public ChromeAsyncExtensionFunction {
 public:
  DECLARE_EXTENSION_FUNCTION("screenlockPrivate.getAuthType",
                             SCREENLOCKPRIVATE_GETAUTHTYPE)
  ScreenlockPrivateGetAuthTypeFunction();
  virtual bool RunImpl() OVERRIDE;

 private:
  virtual ~ScreenlockPrivateGetAuthTypeFunction();
  DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateGetAuthTypeFunction);
};

class ScreenlockPrivateAcceptAuthAttemptFunction
    : public ChromeAsyncExtensionFunction {
 public:
  DECLARE_EXTENSION_FUNCTION("screenlockPrivate.acceptAuthAttempt",
                             SCREENLOCKPRIVATE_ACCEPTAUTHATTEMPT)
  ScreenlockPrivateAcceptAuthAttemptFunction();
  virtual bool RunImpl() OVERRIDE;

 private:
  virtual ~ScreenlockPrivateAcceptAuthAttemptFunction();
  DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateAcceptAuthAttemptFunction);
};

class ScreenlockPrivateEventRouter
    : public extensions::ProfileKeyedAPI,
      public chromeos::SessionManagerClient::Observer {
 public:
  explicit ScreenlockPrivateEventRouter(Profile* profile);
  virtual ~ScreenlockPrivateEventRouter();

  void OnButtonClicked();

  void OnAuthAttempted(chromeos::LoginDisplay::AuthType auth_type,
                       const std::string& value);

  // ProfileKeyedAPI
  static extensions::ProfileKeyedAPIFactory<ScreenlockPrivateEventRouter>*
    GetFactoryInstance();
  virtual void Shutdown() OVERRIDE;

  // chromeos::SessionManagerClient::Observer
  virtual void ScreenIsLocked() OVERRIDE;
  virtual void ScreenIsUnlocked() OVERRIDE;

 private:
  friend class extensions::ProfileKeyedAPIFactory<ScreenlockPrivateEventRouter>;

  // ProfileKeyedAPI
  static const char* service_name() {
    return "ScreenlockPrivateEventRouter";
  }
  static const bool kServiceIsNULLWhileTesting = true;
  static const bool kServiceRedirectedInIncognito = true;

  void DispatchEvent(const std::string& event_name, base::Value* arg);

  Profile* profile_;
  DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateEventRouter);
};

}  // namespace extensions

#endif  // CHROME_BROWSER_CHROMEOS_EXTENSIONS_SCREENLOCK_PRIVATE_API_H_