OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" | 5 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api.h" |
6 | 6 |
7 #if defined(OS_CHROMEOS) | 7 #if defined(OS_CHROMEOS) |
8 #include <errno.h> | 8 #include <errno.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_factory.h" | 14 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_factory.h" |
15 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h" | 15 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h" |
16 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" | 16 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" |
17 #include "chrome/browser/extensions/event_names.h" | 17 #include "chrome/browser/extensions/event_names.h" |
18 #include "chrome/browser/extensions/event_router.h" | 18 #include "chrome/browser/extensions/event_router.h" |
19 #include "chrome/browser/extensions/extension_system.h" | 19 #include "chrome/browser/extensions/extension_system.h" |
20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/common/extensions/api/bluetooth.h" | 21 #include "chrome/common/extensions/api/bluetooth.h" |
| 22 #include "chrome/common/extensions/permissions/bluetooth_device_permission.h" |
22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
23 #include "device/bluetooth/bluetooth_adapter.h" | 24 #include "device/bluetooth/bluetooth_adapter.h" |
24 #include "device/bluetooth/bluetooth_device.h" | 25 #include "device/bluetooth/bluetooth_device.h" |
25 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" | 26 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" |
26 #include "device/bluetooth/bluetooth_service_record.h" | 27 #include "device/bluetooth/bluetooth_service_record.h" |
27 #include "device/bluetooth/bluetooth_socket.h" | 28 #include "device/bluetooth/bluetooth_socket.h" |
28 #include "device/bluetooth/bluetooth_utils.h" | 29 #include "device/bluetooth/bluetooth_utils.h" |
29 | 30 |
30 #if defined(OS_CHROMEOS) | 31 #if defined(OS_CHROMEOS) |
31 #include "base/safe_strerror_posix.h" | 32 #include "base/safe_strerror_posix.h" |
(...skipping 23 matching lines...) Expand all Loading... |
55 } | 56 } |
56 | 57 |
57 } // namespace | 58 } // namespace |
58 | 59 |
59 namespace { | 60 namespace { |
60 | 61 |
61 const char kCouldNotGetLocalOutOfBandPairingData[] = | 62 const char kCouldNotGetLocalOutOfBandPairingData[] = |
62 "Could not get local Out Of Band Pairing Data"; | 63 "Could not get local Out Of Band Pairing Data"; |
63 const char kCouldNotSetOutOfBandPairingData[] = | 64 const char kCouldNotSetOutOfBandPairingData[] = |
64 "Could not set Out Of Band Pairing Data"; | 65 "Could not set Out Of Band Pairing Data"; |
| 66 const char kDevicePermissionDenied[] = "Permission to access device denied"; |
65 const char kFailedToConnect[] = "Connection failed"; | 67 const char kFailedToConnect[] = "Connection failed"; |
66 const char kInvalidDevice[] = "Invalid device"; | 68 const char kInvalidDevice[] = "Invalid device"; |
67 const char kInvalidUuid[] = "Invalid UUID"; | 69 const char kInvalidUuid[] = "Invalid UUID"; |
68 const char kPlatformNotSupported[] = | 70 const char kPlatformNotSupported[] = |
69 "This operation is not supported on your platform"; | 71 "This operation is not supported on your platform"; |
70 const char kServiceDiscoveryFailed[] = "Service discovery failed"; | 72 const char kServiceDiscoveryFailed[] = "Service discovery failed"; |
71 const char kSocketNotFoundError[] = "Socket not found: invalid socket id"; | 73 const char kSocketNotFoundError[] = "Socket not found: invalid socket id"; |
72 const char kStartDiscoveryFailed[] = "Starting discovery failed"; | 74 const char kStartDiscoveryFailed[] = "Starting discovery failed"; |
73 const char kStopDiscoveryFailed[] = "Failed to stop discovery"; | 75 const char kStopDiscoveryFailed[] = "Failed to stop discovery"; |
74 | 76 |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 bool BluetoothConnectFunction::RunImpl() { | 338 bool BluetoothConnectFunction::RunImpl() { |
337 if (!IsBluetoothSupported(profile())) { | 339 if (!IsBluetoothSupported(profile())) { |
338 SetError(kPlatformNotSupported); | 340 SetError(kPlatformNotSupported); |
339 return false; | 341 return false; |
340 } | 342 } |
341 | 343 |
342 scoped_ptr<Connect::Params> params(Connect::Params::Create(*args_)); | 344 scoped_ptr<Connect::Params> params(Connect::Params::Create(*args_)); |
343 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 345 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
344 const bluetooth::ConnectOptions& options = params->options; | 346 const bluetooth::ConnectOptions& options = params->options; |
345 | 347 |
| 348 BluetoothDevicePermission::CheckParam param(options.device_address); |
| 349 if (!GetExtension()->CheckAPIPermissionWithParam( |
| 350 APIPermission::kBluetoothDevice, ¶m)) { |
| 351 SetError(kDevicePermissionDenied); |
| 352 return false; |
| 353 } |
| 354 |
346 std::string uuid = device::bluetooth_utils::CanonicalUuid( | 355 std::string uuid = device::bluetooth_utils::CanonicalUuid( |
347 options.service_uuid); | 356 options.service_uuid); |
348 if (uuid.empty()) { | 357 if (uuid.empty()) { |
349 SetError(kInvalidUuid); | 358 SetError(kInvalidUuid); |
350 return false; | 359 return false; |
351 } | 360 } |
352 | 361 |
353 BluetoothDevice* device = | 362 BluetoothDevice* device = |
354 GetMutableAdapter(profile())->GetDevice(options.device_address); | 363 GetMutableAdapter(profile())->GetDevice(options.device_address); |
355 if (!device) { | 364 if (!device) { |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 if (GetEventRouter(profile())->IsResponsibleForDiscovery()) { | 653 if (GetEventRouter(profile())->IsResponsibleForDiscovery()) { |
645 GetMutableAdapter(profile())->SetDiscovering(false, | 654 GetMutableAdapter(profile())->SetDiscovering(false, |
646 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), | 655 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), |
647 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); | 656 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); |
648 } | 657 } |
649 return true; | 658 return true; |
650 } | 659 } |
651 | 660 |
652 } // namespace api | 661 } // namespace api |
653 } // namespace extensions | 662 } // namespace extensions |
OLD | NEW |