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.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_EASY_UNLOCK_PRIVATE_EASY_UNLOCK_PRIVATE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_EASY_UNLOCK_PRIVATE_EASY_UNLOCK_PRIVATE_API_H_
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "extensions/browser/api/bluetooth_socket/bluetooth_socket_api.h"
13 #include "extensions/browser/browser_context_keyed_api_factory.h"
14 #include "extensions/browser/extension_function.h"
16 // Implementations for chrome.easyUnlockPrivate API functions.
22 namespace extensions {
25 namespace easy_unlock {
26 struct SeekDeviceResult;
29 class EasyUnlockPrivateCryptoDelegate;
31 class EasyUnlockPrivateAPI : public BrowserContextKeyedAPI {
33 static BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI>*
36 static const bool kServiceRedirectedInIncognito = true;
38 explicit EasyUnlockPrivateAPI(content::BrowserContext* context);
39 ~EasyUnlockPrivateAPI() override;
41 EasyUnlockPrivateCryptoDelegate* crypto_delegate() {
42 return crypto_delegate_.get();
46 friend class BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI>;
48 // BrowserContextKeyedAPI implementation.
49 static const char* service_name() { return "EasyUnlockPrivate"; }
51 scoped_ptr<EasyUnlockPrivateCryptoDelegate> crypto_delegate_;
53 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateAPI);
56 // TODO(tbarzic): Replace SyncExtensionFunction/AsyncExtensionFunction overrides
57 // with UIThreadExtensionFunction throughout the file.
58 class EasyUnlockPrivateGetStringsFunction : public SyncExtensionFunction {
60 EasyUnlockPrivateGetStringsFunction();
63 ~EasyUnlockPrivateGetStringsFunction() override;
65 // SyncExtensionFunction:
66 bool RunSync() override;
69 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getStrings",
70 EASYUNLOCKPRIVATE_GETSTRINGS)
72 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetStringsFunction);
75 class EasyUnlockPrivatePerformECDHKeyAgreementFunction
76 : public AsyncExtensionFunction {
78 EasyUnlockPrivatePerformECDHKeyAgreementFunction();
81 ~EasyUnlockPrivatePerformECDHKeyAgreementFunction() override;
83 bool RunAsync() override;
86 void OnData(const std::string& secret_key);
88 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.performECDHKeyAgreement",
89 EASYUNLOCKPRIVATE_PERFORMECDHKEYAGREEMENT)
91 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivatePerformECDHKeyAgreementFunction);
94 class EasyUnlockPrivateGenerateEcP256KeyPairFunction
95 : public AsyncExtensionFunction {
97 EasyUnlockPrivateGenerateEcP256KeyPairFunction();
100 ~EasyUnlockPrivateGenerateEcP256KeyPairFunction() override;
102 bool RunAsync() override;
105 void OnData(const std::string& public_key,
106 const std::string& private_key);
108 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.generateEcP256KeyPair",
109 EASYUNLOCKPRIVATE_GENERATEECP256KEYPAIR)
111 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGenerateEcP256KeyPairFunction);
114 class EasyUnlockPrivateCreateSecureMessageFunction
115 : public AsyncExtensionFunction {
117 EasyUnlockPrivateCreateSecureMessageFunction();
120 ~EasyUnlockPrivateCreateSecureMessageFunction() override;
122 bool RunAsync() override;
125 void OnData(const std::string& message);
127 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.createSecureMessage",
128 EASYUNLOCKPRIVATE_CREATESECUREMESSAGE)
130 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateCreateSecureMessageFunction);
133 class EasyUnlockPrivateUnwrapSecureMessageFunction
134 : public AsyncExtensionFunction {
136 EasyUnlockPrivateUnwrapSecureMessageFunction();
139 ~EasyUnlockPrivateUnwrapSecureMessageFunction() override;
141 bool RunAsync() override;
144 void OnData(const std::string& data);
146 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.unwrapSecureMessage",
147 EASYUNLOCKPRIVATE_UNWRAPSECUREMESSAGE)
149 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateUnwrapSecureMessageFunction);
152 class EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction
153 : public AsyncExtensionFunction {
155 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.seekBluetoothDeviceByAddress",
156 EASYUNLOCKPRIVATE_SEEKBLUETOOTHDEVICEBYADDRESS)
157 EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction();
160 ~EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction() override;
162 // AsyncExtensionFunction:
163 bool RunAsync() override;
165 // Callbacks that are called when the seek operation succeeds or fails.
166 void OnSeekSuccess();
167 void OnSeekFailure(const std::string& error_message);
169 DISALLOW_COPY_AND_ASSIGN(
170 EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction);
173 class EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction
174 : public core_api::BluetoothSocketAbstractConnectFunction {
176 DECLARE_EXTENSION_FUNCTION(
177 "easyUnlockPrivate.connectToBluetoothServiceInsecurely",
178 EASYUNLOCKPRIVATE_CONNECTTOBLUETOOTHSERVICEINSECURELY)
179 EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction();
182 ~EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction() override;
184 // BluetoothSocketAbstractConnectFunction:
185 void ConnectToService(device::BluetoothDevice* device,
186 const device::BluetoothUUID& uuid) override;
188 DISALLOW_COPY_AND_ASSIGN(
189 EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction);
192 class EasyUnlockPrivateUpdateScreenlockStateFunction
193 : public SyncExtensionFunction {
195 EasyUnlockPrivateUpdateScreenlockStateFunction();
198 ~EasyUnlockPrivateUpdateScreenlockStateFunction() override;
200 bool RunSync() override;
203 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.updateScreenlockState",
204 EASYUNLOCKPRIVATE_UPDATESCREENLOCKSTATE)
206 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateUpdateScreenlockStateFunction);
209 class EasyUnlockPrivateSetPermitAccessFunction : public SyncExtensionFunction {
211 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.setPermitAccess",
212 EASYUNLOCKPRIVATE_SETPERMITACCESS)
213 EasyUnlockPrivateSetPermitAccessFunction();
216 ~EasyUnlockPrivateSetPermitAccessFunction() override;
218 // SyncExtensionFunction:
219 bool RunSync() override;
221 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateSetPermitAccessFunction);
224 class EasyUnlockPrivateGetPermitAccessFunction : public SyncExtensionFunction {
226 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getPermitAccess",
227 EASYUNLOCKPRIVATE_GETPERMITACCESS)
228 EasyUnlockPrivateGetPermitAccessFunction();
231 ~EasyUnlockPrivateGetPermitAccessFunction() override;
233 // SyncExtensionFunction:
234 bool RunSync() override;
236 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetPermitAccessFunction);
239 class EasyUnlockPrivateClearPermitAccessFunction
240 : public SyncExtensionFunction {
242 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.clearPermitAccess",
243 EASYUNLOCKPRIVATE_CLEARPERMITACCESS)
244 EasyUnlockPrivateClearPermitAccessFunction();
247 ~EasyUnlockPrivateClearPermitAccessFunction() override;
249 // SyncExtensionFunction:
250 bool RunSync() override;
252 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateClearPermitAccessFunction);
255 class EasyUnlockPrivateSetRemoteDevicesFunction : public SyncExtensionFunction {
257 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.setRemoteDevices",
258 EASYUNLOCKPRIVATE_SETREMOTEDEVICES)
259 EasyUnlockPrivateSetRemoteDevicesFunction();
262 ~EasyUnlockPrivateSetRemoteDevicesFunction() override;
264 // SyncExtensionFunction:
265 bool RunSync() override;
267 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateSetRemoteDevicesFunction);
270 class EasyUnlockPrivateGetRemoteDevicesFunction : public SyncExtensionFunction {
272 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getRemoteDevices",
273 EASYUNLOCKPRIVATE_GETREMOTEDEVICES)
274 EasyUnlockPrivateGetRemoteDevicesFunction();
277 ~EasyUnlockPrivateGetRemoteDevicesFunction() override;
279 // SyncExtensionFunction:
280 bool RunSync() override;
282 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetRemoteDevicesFunction);
285 class EasyUnlockPrivateGetSignInChallengeFunction :
286 public SyncExtensionFunction {
288 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getSignInChallenge",
289 EASYUNLOCKPRIVATE_GETSIGNINCHALLENGE)
290 EasyUnlockPrivateGetSignInChallengeFunction();
293 ~EasyUnlockPrivateGetSignInChallengeFunction() override;
295 // SyncExtensionFunction:
296 bool RunSync() override;
298 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetSignInChallengeFunction);
301 class EasyUnlockPrivateTrySignInSecretFunction :
302 public SyncExtensionFunction {
304 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.trySignInSecret",
305 EASYUNLOCKPRIVATE_TRYSIGNINSECRET)
306 EasyUnlockPrivateTrySignInSecretFunction();
309 ~EasyUnlockPrivateTrySignInSecretFunction() override;
311 // SyncExtensionFunction:
312 bool RunSync() override;
314 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateTrySignInSecretFunction);
317 class EasyUnlockPrivateGetUserInfoFunction : public SyncExtensionFunction {
319 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getUserInfo",
320 EASYUNLOCKPRIVATE_GETUSERINFO)
321 EasyUnlockPrivateGetUserInfoFunction();
324 ~EasyUnlockPrivateGetUserInfoFunction() override;
326 // SyncExtensionFunction:
327 bool RunSync() override;
329 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetUserInfoFunction);
332 class EasyUnlockPrivateGetUserImageFunction : public SyncExtensionFunction {
334 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getUserImage",
335 EASYUNLOCKPRIVATE_GETUSERIMAGE)
336 EasyUnlockPrivateGetUserImageFunction();
339 ~EasyUnlockPrivateGetUserImageFunction() override;
341 // SyncExtensionFunction:
342 bool RunSync() override;
344 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetUserImageFunction);
348 } // namespace extensions
350 #endif // CHROME_BROWSER_EXTENSIONS_API_EASY_UNLOCK_PRIVATE_EASY_UNLOCK_PRIVATE_API_H_