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_
10 #include "chrome/browser/extensions/chrome_extension_function.h"
11 #include "chrome/browser/signin/screenlock_bridge.h"
12 #include "extensions/browser/browser_context_keyed_api_factory.h"
18 namespace extensions
{
20 class ScreenlockPrivateGetLockedFunction
: public ChromeAsyncExtensionFunction
{
22 DECLARE_EXTENSION_FUNCTION("screenlockPrivate.getLocked",
23 SCREENLOCKPRIVATE_GETLOCKED
)
24 ScreenlockPrivateGetLockedFunction();
25 virtual bool RunAsync() OVERRIDE
;
28 virtual ~ScreenlockPrivateGetLockedFunction();
29 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateGetLockedFunction
);
32 class ScreenlockPrivateSetLockedFunction
: public ChromeAsyncExtensionFunction
{
34 DECLARE_EXTENSION_FUNCTION("screenlockPrivate.setLocked",
35 SCREENLOCKPRIVATE_SETLOCKED
)
36 ScreenlockPrivateSetLockedFunction();
37 virtual bool RunAsync() OVERRIDE
;
40 virtual ~ScreenlockPrivateSetLockedFunction();
41 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateSetLockedFunction
);
44 class ScreenlockPrivateShowMessageFunction
45 : public ChromeAsyncExtensionFunction
{
47 DECLARE_EXTENSION_FUNCTION("screenlockPrivate.showMessage",
48 SCREENLOCKPRIVATE_SHOWMESSAGE
)
49 ScreenlockPrivateShowMessageFunction();
50 virtual bool RunAsync() OVERRIDE
;
53 virtual ~ScreenlockPrivateShowMessageFunction();
54 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateShowMessageFunction
);
57 class ScreenlockPrivateShowCustomIconFunction
58 : public ChromeAsyncExtensionFunction
{
60 DECLARE_EXTENSION_FUNCTION("screenlockPrivate.showCustomIcon",
61 SCREENLOCKPRIVATE_SHOWCUSTOMICON
)
62 ScreenlockPrivateShowCustomIconFunction();
63 virtual bool RunAsync() OVERRIDE
;
66 virtual ~ScreenlockPrivateShowCustomIconFunction();
67 void OnImageLoaded(const gfx::Image
& image
);
68 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateShowCustomIconFunction
);
71 class ScreenlockPrivateHideCustomIconFunction
72 : public ChromeAsyncExtensionFunction
{
74 DECLARE_EXTENSION_FUNCTION("screenlockPrivate.hideCustomIcon",
75 SCREENLOCKPRIVATE_HIDECUSTOMICON
)
76 ScreenlockPrivateHideCustomIconFunction();
77 virtual bool RunAsync() OVERRIDE
;
80 virtual ~ScreenlockPrivateHideCustomIconFunction();
81 void OnImageLoaded(const gfx::Image
& image
);
82 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateHideCustomIconFunction
);
85 class ScreenlockPrivateSetAuthTypeFunction
86 : public ChromeAsyncExtensionFunction
{
88 DECLARE_EXTENSION_FUNCTION("screenlockPrivate.setAuthType",
89 SCREENLOCKPRIVATE_SETAUTHTYPE
)
90 ScreenlockPrivateSetAuthTypeFunction();
91 virtual bool RunAsync() OVERRIDE
;
94 virtual ~ScreenlockPrivateSetAuthTypeFunction();
95 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateSetAuthTypeFunction
);
98 class ScreenlockPrivateGetAuthTypeFunction
99 : public ChromeAsyncExtensionFunction
{
101 DECLARE_EXTENSION_FUNCTION("screenlockPrivate.getAuthType",
102 SCREENLOCKPRIVATE_GETAUTHTYPE
)
103 ScreenlockPrivateGetAuthTypeFunction();
104 virtual bool RunAsync() OVERRIDE
;
107 virtual ~ScreenlockPrivateGetAuthTypeFunction();
108 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateGetAuthTypeFunction
);
111 class ScreenlockPrivateAcceptAuthAttemptFunction
112 : public ChromeAsyncExtensionFunction
{
114 DECLARE_EXTENSION_FUNCTION("screenlockPrivate.acceptAuthAttempt",
115 SCREENLOCKPRIVATE_ACCEPTAUTHATTEMPT
)
116 ScreenlockPrivateAcceptAuthAttemptFunction();
117 virtual bool RunAsync() OVERRIDE
;
120 virtual ~ScreenlockPrivateAcceptAuthAttemptFunction();
121 DISALLOW_COPY_AND_ASSIGN(ScreenlockPrivateAcceptAuthAttemptFunction
);
124 class ScreenlockPrivateEventRouter
: public extensions::BrowserContextKeyedAPI
,
125 public ScreenlockBridge::Observer
{
127 explicit ScreenlockPrivateEventRouter(content::BrowserContext
* context
);
128 virtual ~ScreenlockPrivateEventRouter();
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_