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. 4 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_ 7 8#include <string> 9 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" 15 16// Implementations for chrome.easyUnlockPrivate API functions. 17 18namespace content { 19class BrowserContext; 20} 21 22namespace extensions { 23namespace api { 24 25namespace easy_unlock { 26struct SeekDeviceResult; 27} // easy_unlock 28 29class EasyUnlockPrivateCryptoDelegate; 30 31class EasyUnlockPrivateAPI : public BrowserContextKeyedAPI { 32 public: 33 static BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI>* 34 GetFactoryInstance(); 35 36 static const bool kServiceRedirectedInIncognito = true; 37 38 explicit EasyUnlockPrivateAPI(content::BrowserContext* context); 39 virtual ~EasyUnlockPrivateAPI(); 40 41 EasyUnlockPrivateCryptoDelegate* crypto_delegate() { 42 return crypto_delegate_.get(); 43 } 44 45 private: 46 friend class BrowserContextKeyedAPIFactory<EasyUnlockPrivateAPI>; 47 48 // BrowserContextKeyedAPI implementation. 49 static const char* service_name() { return "EasyUnlockPrivate"; } 50 51 scoped_ptr<EasyUnlockPrivateCryptoDelegate> crypto_delegate_; 52 53 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateAPI); 54}; 55 56// TODO(tbarzic): Replace SyncExtensionFunction/AsyncExtensionFunction overrides 57// with UIThreadExtensionFunction throughout the file. 58class EasyUnlockPrivateGetStringsFunction : public SyncExtensionFunction { 59 public: 60 EasyUnlockPrivateGetStringsFunction(); 61 62 protected: 63 virtual ~EasyUnlockPrivateGetStringsFunction(); 64 65 // SyncExtensionFunction: 66 virtual bool RunSync() OVERRIDE; 67 68 private: 69 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getStrings", 70 EASYUNLOCKPRIVATE_GETSTRINGS) 71 72 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetStringsFunction); 73}; 74 75class EasyUnlockPrivatePerformECDHKeyAgreementFunction 76 : public AsyncExtensionFunction { 77 public: 78 EasyUnlockPrivatePerformECDHKeyAgreementFunction(); 79 80 protected: 81 virtual ~EasyUnlockPrivatePerformECDHKeyAgreementFunction(); 82 83 virtual bool RunAsync() OVERRIDE; 84 85 private: 86 void OnData(const std::string& secret_key); 87 88 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.performECDHKeyAgreement", 89 EASYUNLOCKPRIVATE_PERFORMECDHKEYAGREEMENT) 90 91 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivatePerformECDHKeyAgreementFunction); 92}; 93 94class EasyUnlockPrivateGenerateEcP256KeyPairFunction 95 : public AsyncExtensionFunction { 96 public: 97 EasyUnlockPrivateGenerateEcP256KeyPairFunction(); 98 99 protected: 100 virtual ~EasyUnlockPrivateGenerateEcP256KeyPairFunction(); 101 102 virtual bool RunAsync() OVERRIDE; 103 104 private: 105 void OnData(const std::string& public_key, 106 const std::string& private_key); 107 108 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.generateEcP256KeyPair", 109 EASYUNLOCKPRIVATE_GENERATEECP256KEYPAIR) 110 111 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGenerateEcP256KeyPairFunction); 112}; 113 114class EasyUnlockPrivateCreateSecureMessageFunction 115 : public AsyncExtensionFunction { 116 public: 117 EasyUnlockPrivateCreateSecureMessageFunction(); 118 119 protected: 120 virtual ~EasyUnlockPrivateCreateSecureMessageFunction(); 121 122 virtual bool RunAsync() OVERRIDE; 123 124 private: 125 void OnData(const std::string& message); 126 127 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.createSecureMessage", 128 EASYUNLOCKPRIVATE_CREATESECUREMESSAGE) 129 130 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateCreateSecureMessageFunction); 131}; 132 133class EasyUnlockPrivateUnwrapSecureMessageFunction 134 : public AsyncExtensionFunction { 135 public: 136 EasyUnlockPrivateUnwrapSecureMessageFunction(); 137 138 protected: 139 virtual ~EasyUnlockPrivateUnwrapSecureMessageFunction(); 140 141 virtual bool RunAsync() OVERRIDE; 142 143 private: 144 void OnData(const std::string& data); 145 146 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.unwrapSecureMessage", 147 EASYUNLOCKPRIVATE_UNWRAPSECUREMESSAGE) 148 149 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateUnwrapSecureMessageFunction); 150}; 151 152class EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction 153 : public AsyncExtensionFunction { 154 public: 155 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.seekBluetoothDeviceByAddress", 156 EASYUNLOCKPRIVATE_SEEKBLUETOOTHDEVICEBYADDRESS) 157 EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction(); 158 159 private: 160 virtual ~EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction(); 161 162 // AsyncExtensionFunction: 163 virtual bool RunAsync() OVERRIDE; 164 165 // Callbacks that are called when the seek operation succeeds or fails. 166 void OnSeekSuccess(); 167 void OnSeekFailure(const std::string& error_message); 168 169 DISALLOW_COPY_AND_ASSIGN( 170 EasyUnlockPrivateSeekBluetoothDeviceByAddressFunction); 171}; 172 173class EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction 174 : public core_api::BluetoothSocketAbstractConnectFunction { 175 public: 176 DECLARE_EXTENSION_FUNCTION( 177 "easyUnlockPrivate.connectToBluetoothServiceInsecurely", 178 EASYUNLOCKPRIVATE_CONNECTTOBLUETOOTHSERVICEINSECURELY) 179 EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction(); 180 181 private: 182 virtual ~EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction(); 183 184 // BluetoothSocketAbstractConnectFunction: 185 virtual void ConnectToService(device::BluetoothDevice* device, 186 const device::BluetoothUUID& uuid) OVERRIDE; 187 188 DISALLOW_COPY_AND_ASSIGN( 189 EasyUnlockPrivateConnectToBluetoothServiceInsecurelyFunction); 190}; 191 192class EasyUnlockPrivateUpdateScreenlockStateFunction 193 : public SyncExtensionFunction { 194 public: 195 EasyUnlockPrivateUpdateScreenlockStateFunction(); 196 197 protected: 198 virtual ~EasyUnlockPrivateUpdateScreenlockStateFunction(); 199 200 virtual bool RunSync() OVERRIDE; 201 202 private: 203 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.updateScreenlockState", 204 EASYUNLOCKPRIVATE_UPDATESCREENLOCKSTATE) 205 206 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateUpdateScreenlockStateFunction); 207}; 208 209class EasyUnlockPrivateSetPermitAccessFunction : public SyncExtensionFunction { 210 public: 211 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.setPermitAccess", 212 EASYUNLOCKPRIVATE_SETPERMITACCESS) 213 EasyUnlockPrivateSetPermitAccessFunction(); 214 215 private: 216 virtual ~EasyUnlockPrivateSetPermitAccessFunction(); 217 218 // SyncExtensionFunction: 219 virtual bool RunSync() OVERRIDE; 220 221 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateSetPermitAccessFunction); 222}; 223 224class EasyUnlockPrivateGetPermitAccessFunction : public SyncExtensionFunction { 225 public: 226 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getPermitAccess", 227 EASYUNLOCKPRIVATE_GETPERMITACCESS) 228 EasyUnlockPrivateGetPermitAccessFunction(); 229 230 private: 231 virtual ~EasyUnlockPrivateGetPermitAccessFunction(); 232 233 // SyncExtensionFunction: 234 virtual bool RunSync() OVERRIDE; 235 236 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetPermitAccessFunction); 237}; 238 239class EasyUnlockPrivateClearPermitAccessFunction 240 : public SyncExtensionFunction { 241 public: 242 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.clearPermitAccess", 243 EASYUNLOCKPRIVATE_CLEARPERMITACCESS) 244 EasyUnlockPrivateClearPermitAccessFunction(); 245 246 private: 247 virtual ~EasyUnlockPrivateClearPermitAccessFunction(); 248 249 // SyncExtensionFunction: 250 virtual bool RunSync() OVERRIDE; 251 252 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateClearPermitAccessFunction); 253}; 254 255class EasyUnlockPrivateSetRemoteDevicesFunction : public SyncExtensionFunction { 256 public: 257 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.setRemoteDevices", 258 EASYUNLOCKPRIVATE_SETREMOTEDEVICES) 259 EasyUnlockPrivateSetRemoteDevicesFunction(); 260 261 private: 262 virtual ~EasyUnlockPrivateSetRemoteDevicesFunction(); 263 264 // SyncExtensionFunction: 265 virtual bool RunSync() OVERRIDE; 266 267 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateSetRemoteDevicesFunction); 268}; 269 270class EasyUnlockPrivateGetRemoteDevicesFunction : public SyncExtensionFunction { 271 public: 272 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getRemoteDevices", 273 EASYUNLOCKPRIVATE_GETREMOTEDEVICES) 274 EasyUnlockPrivateGetRemoteDevicesFunction(); 275 276 private: 277 virtual ~EasyUnlockPrivateGetRemoteDevicesFunction(); 278 279 // SyncExtensionFunction: 280 virtual bool RunSync() OVERRIDE; 281 282 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetRemoteDevicesFunction); 283}; 284 285class EasyUnlockPrivateGetSignInChallengeFunction : 286 public SyncExtensionFunction { 287 public: 288 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getSignInChallenge", 289 EASYUNLOCKPRIVATE_GETSIGNINCHALLENGE) 290 EasyUnlockPrivateGetSignInChallengeFunction(); 291 292 private: 293 virtual ~EasyUnlockPrivateGetSignInChallengeFunction(); 294 295 // SyncExtensionFunction: 296 virtual bool RunSync() OVERRIDE; 297 298 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetSignInChallengeFunction); 299}; 300 301class EasyUnlockPrivateTrySignInSecretFunction : 302 public SyncExtensionFunction { 303 public: 304 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.trySignInSecret", 305 EASYUNLOCKPRIVATE_TRYSIGNINSECRET) 306 EasyUnlockPrivateTrySignInSecretFunction(); 307 308 private: 309 virtual ~EasyUnlockPrivateTrySignInSecretFunction(); 310 311 // SyncExtensionFunction: 312 virtual bool RunSync() OVERRIDE; 313 314 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateTrySignInSecretFunction); 315}; 316 317class EasyUnlockPrivateGetUserInfoFunction : public SyncExtensionFunction { 318 public: 319 DECLARE_EXTENSION_FUNCTION("easyUnlockPrivate.getUserInfo", 320 EASYUNLOCKPRIVATE_GETUSERINFO) 321 EasyUnlockPrivateGetUserInfoFunction(); 322 323 private: 324 virtual ~EasyUnlockPrivateGetUserInfoFunction(); 325 326 // SyncExtensionFunction: 327 virtual bool RunSync() OVERRIDE; 328 329 DISALLOW_COPY_AND_ASSIGN(EasyUnlockPrivateGetUserInfoFunction); 330}; 331 332} // namespace api 333} // namespace extensions 334 335#endif // CHROME_BROWSER_EXTENSIONS_API_EASY_UNLOCK_PRIVATE_EASY_UNLOCK_PRIVATE_API_H_ 336