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" | |
23 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
24 #include "device/bluetooth/bluetooth_adapter.h" | 23 #include "device/bluetooth/bluetooth_adapter.h" |
25 #include "device/bluetooth/bluetooth_device.h" | 24 #include "device/bluetooth/bluetooth_device.h" |
26 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" | 25 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" |
27 #include "device/bluetooth/bluetooth_service_record.h" | 26 #include "device/bluetooth/bluetooth_service_record.h" |
28 #include "device/bluetooth/bluetooth_socket.h" | 27 #include "device/bluetooth/bluetooth_socket.h" |
29 #include "device/bluetooth/bluetooth_utils.h" | 28 #include "device/bluetooth/bluetooth_utils.h" |
30 | 29 |
31 #if defined(OS_CHROMEOS) | 30 #if defined(OS_CHROMEOS) |
32 #include "base/safe_strerror_posix.h" | 31 #include "base/safe_strerror_posix.h" |
(...skipping 23 matching lines...) Expand all Loading... |
56 } | 55 } |
57 | 56 |
58 } // namespace | 57 } // namespace |
59 | 58 |
60 namespace { | 59 namespace { |
61 | 60 |
62 const char kCouldNotGetLocalOutOfBandPairingData[] = | 61 const char kCouldNotGetLocalOutOfBandPairingData[] = |
63 "Could not get local Out Of Band Pairing Data"; | 62 "Could not get local Out Of Band Pairing Data"; |
64 const char kCouldNotSetOutOfBandPairingData[] = | 63 const char kCouldNotSetOutOfBandPairingData[] = |
65 "Could not set Out Of Band Pairing Data"; | 64 "Could not set Out Of Band Pairing Data"; |
66 const char kDevicePermissionDenied[] = "Permission to access device denied"; | |
67 const char kFailedToConnect[] = "Connection failed"; | 65 const char kFailedToConnect[] = "Connection failed"; |
68 const char kInvalidDevice[] = "Invalid device"; | 66 const char kInvalidDevice[] = "Invalid device"; |
69 const char kInvalidUuid[] = "Invalid UUID"; | 67 const char kInvalidUuid[] = "Invalid UUID"; |
70 const char kPlatformNotSupported[] = | 68 const char kPlatformNotSupported[] = |
71 "This operation is not supported on your platform"; | 69 "This operation is not supported on your platform"; |
72 const char kServiceDiscoveryFailed[] = "Service discovery failed"; | 70 const char kServiceDiscoveryFailed[] = "Service discovery failed"; |
73 const char kSocketNotFoundError[] = "Socket not found: invalid socket id"; | 71 const char kSocketNotFoundError[] = "Socket not found: invalid socket id"; |
74 const char kStartDiscoveryFailed[] = "Starting discovery failed"; | 72 const char kStartDiscoveryFailed[] = "Starting discovery failed"; |
75 const char kStopDiscoveryFailed[] = "Failed to stop discovery"; | 73 const char kStopDiscoveryFailed[] = "Failed to stop discovery"; |
76 | 74 |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 bool BluetoothConnectFunction::RunImpl() { | 336 bool BluetoothConnectFunction::RunImpl() { |
339 if (!IsBluetoothSupported(profile())) { | 337 if (!IsBluetoothSupported(profile())) { |
340 SetError(kPlatformNotSupported); | 338 SetError(kPlatformNotSupported); |
341 return false; | 339 return false; |
342 } | 340 } |
343 | 341 |
344 scoped_ptr<Connect::Params> params(Connect::Params::Create(*args_)); | 342 scoped_ptr<Connect::Params> params(Connect::Params::Create(*args_)); |
345 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 343 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
346 const bluetooth::ConnectOptions& options = params->options; | 344 const bluetooth::ConnectOptions& options = params->options; |
347 | 345 |
348 BluetoothDevicePermission::CheckParam param(options.device_address); | |
349 if (!GetExtension()->CheckAPIPermissionWithParam( | |
350 APIPermission::kBluetoothDevice, ¶m)) { | |
351 SetError(kDevicePermissionDenied); | |
352 return false; | |
353 } | |
354 | |
355 std::string uuid = device::bluetooth_utils::CanonicalUuid( | 346 std::string uuid = device::bluetooth_utils::CanonicalUuid( |
356 options.service_uuid); | 347 options.service_uuid); |
357 if (uuid.empty()) { | 348 if (uuid.empty()) { |
358 SetError(kInvalidUuid); | 349 SetError(kInvalidUuid); |
359 return false; | 350 return false; |
360 } | 351 } |
361 | 352 |
362 BluetoothDevice* device = | 353 BluetoothDevice* device = |
363 GetMutableAdapter(profile())->GetDevice(options.device_address); | 354 GetMutableAdapter(profile())->GetDevice(options.device_address); |
364 if (!device) { | 355 if (!device) { |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 if (GetEventRouter(profile())->IsResponsibleForDiscovery()) { | 644 if (GetEventRouter(profile())->IsResponsibleForDiscovery()) { |
654 GetMutableAdapter(profile())->SetDiscovering(false, | 645 GetMutableAdapter(profile())->SetDiscovering(false, |
655 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), | 646 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), |
656 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); | 647 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); |
657 } | 648 } |
658 return true; | 649 return true; |
659 } | 650 } |
660 | 651 |
661 } // namespace api | 652 } // namespace api |
662 } // namespace extensions | 653 } // namespace extensions |
OLD | NEW |