1 // Copyright 2013 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_EXTENSIONS_API_SCREENLOCK_PRIVATE_SCREENLOCK_PRIVATE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_SCREENLOCK_PRIVATE_SCREENLOCK_PRIVATE_API_H_
8 #include "chrome/browser/extensions/chrome_extension_function.h"
9 #include "chrome/browser/signin/screenlock_bridge.h"
10 #include "extensions/browser/browser_context_keyed_api_factory.h"
16 namespace extensions {
18 class ScreenlockPrivateGetLockedFunction : public ChromeAsyncExtensionFunction {
20 DECLARE_EXTENSION_FUNCTION("screenlockPrivate.getLocked",
21 SCREENLOCKPRIVATE_GETLOCKED)
22 ScreenlockPrivateGetLockedFunction();
23 virtual bool RunAsync() OVERRIDE;
26 virtual ~ScreenlockPrivateGetLockedFunction();
27 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateGetLockedFunction);
30 class ScreenlockPrivateSetLockedFunction : public ChromeAsyncExtensionFunction {
32 DECLARE_EXTENSION_FUNCTION("screenlockPrivate.setLocked",
33 SCREENLOCKPRIVATE_SETLOCKED)
34 ScreenlockPrivateSetLockedFunction();
35 virtual bool RunAsync() OVERRIDE;
38 virtual ~ScreenlockPrivateSetLockedFunction();
39 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateSetLockedFunction);
42 class ScreenlockPrivateShowMessageFunction
43 : public ChromeAsyncExtensionFunction {
45 DECLARE_EXTENSION_FUNCTION("screenlockPrivate.showMessage",
46 SCREENLOCKPRIVATE_SHOWMESSAGE)
47 ScreenlockPrivateShowMessageFunction();
48 virtual bool RunAsync() OVERRIDE;
51 virtual ~ScreenlockPrivateShowMessageFunction();
52 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateShowMessageFunction );
55 class ScreenlockPrivateShowButtonFunction
56 : public ChromeAsyncExtensionFunction {
58 DECLARE_EXTENSION_FUNCTION("screenlockPrivate.showButton",
59 SCREENLOCKPRIVATE_SHOWBUTTON)
60 ScreenlockPrivateShowButtonFunction();
61 virtual bool RunAsync() OVERRIDE;
64 virtual ~ScreenlockPrivateShowButtonFunction();
65 void OnImageLoaded(const gfx::Image& image);
66 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateShowButtonFunction);
69 class ScreenlockPrivateHideButtonFunction
70 : public ChromeAsyncExtensionFunction {
72 DECLARE_EXTENSION_FUNCTION("screenlockPrivate.hideButton",
73 SCREENLOCKPRIVATE_HIDEBUTTON)
74 ScreenlockPrivateHideButtonFunction();
75 virtual bool RunAsync() OVERRIDE;
78 virtual ~ScreenlockPrivateHideButtonFunction();
79 void OnImageLoaded(const gfx::Image& image);
80 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateHideButtonFunction);
83 class ScreenlockPrivateSetAuthTypeFunction
84 : public ChromeAsyncExtensionFunction {
86 DECLARE_EXTENSION_FUNCTION("screenlockPrivate.setAuthType",
87 SCREENLOCKPRIVATE_SETAUTHTYPE)
88 ScreenlockPrivateSetAuthTypeFunction();
89 virtual bool RunAsync() OVERRIDE;
92 virtual ~ScreenlockPrivateSetAuthTypeFunction();
93 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateSetAuthTypeFunction);
96 class ScreenlockPrivateGetAuthTypeFunction
97 : public ChromeAsyncExtensionFunction {
99 DECLARE_EXTENSION_FUNCTION("screenlockPrivate.getAuthType",
100 SCREENLOCKPRIVATE_GETAUTHTYPE)
101 ScreenlockPrivateGetAuthTypeFunction();
102 virtual bool RunAsync() OVERRIDE;
105 virtual ~ScreenlockPrivateGetAuthTypeFunction();
106 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateGetAuthTypeFunction);
109 class ScreenlockPrivateAcceptAuthAttemptFunction
110 : public ChromeAsyncExtensionFunction {
112 DECLARE_EXTENSION_FUNCTION("screenlockPrivate.acceptAuthAttempt",
113 SCREENLOCKPRIVATE_ACCEPTAUTHATTEMPT)
114 ScreenlockPrivateAcceptAuthAttemptFunction();
115 virtual bool RunAsync() OVERRIDE;
118 virtual ~ScreenlockPrivateAcceptAuthAttemptFunction();
119 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateAcceptAuthAttemptFunction);
122 class ScreenlockPrivateEventRouter : public extensions::BrowserContextKeyedAPI,
123 public ScreenlockBridge::Observer {
125 explicit ScreenlockPrivateEventRouter(content::BrowserContext* context);
126 virtual ~ScreenlockPrivateEventRouter();
128 void OnButtonClicked();
130 void OnAuthAttempted(ScreenlockBridge::LockHandler::AuthType auth_type,
131 const std::string& value);
133 // BrowserContextKeyedAPI
134 static extensions::BrowserContextKeyedAPIFactory<
135 ScreenlockPrivateEventRouter>*
136 GetFactoryInstance();
137 virtual void Shutdown() OVERRIDE;
139 // ScreenlockBridge::Observer
140 virtual void OnScreenDidLock() OVERRIDE;
141 virtual void OnScreenDidUnlock() OVERRIDE;
144 friend class extensions::BrowserContextKeyedAPIFactory<
145 ScreenlockPrivateEventRouter>;
147 // BrowserContextKeyedAPI
148 static const char* service_name() {
149 return "ScreenlockPrivateEventRouter";
151 static const bool kServiceIsNULLWhileTesting = true;
152 static const bool kServiceRedirectedInIncognito = true;
154 void DispatchEvent(const std::string& event_name, base::Value* arg);
156 content::BrowserContext* browser_context_;
157 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateEventRouter);
160 } // namespace extensions
162 #endif // CHROME_BROWSER_EXTENSIONS_API_SCREENLOCK_PRIVATE_SCREENLOCK_PRIVATE_API_H_