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 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h" | 11 #include "chrome/browser/extensions/api/bluetooth/bluetooth_api_utils.h" |
12 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" | 12 #include "chrome/browser/extensions/api/bluetooth/bluetooth_event_router.h" |
13 #include "chrome/common/extensions/api/bluetooth.h" | 13 #include "chrome/common/extensions/api/bluetooth.h" |
14 #include "chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h" | 14 #include "chrome/common/extensions/api/bluetooth/bluetooth_manifest_data.h" |
15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
16 #include "device/bluetooth/bluetooth_adapter.h" | 16 #include "device/bluetooth/bluetooth_adapter.h" |
17 #include "device/bluetooth/bluetooth_device.h" | 17 #include "device/bluetooth/bluetooth_device.h" |
18 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" | 18 #include "device/bluetooth/bluetooth_out_of_band_pairing_data.h" |
19 #include "device/bluetooth/bluetooth_profile.h" | 19 #include "device/bluetooth/bluetooth_profile.h" |
20 #include "device/bluetooth/bluetooth_service_record.h" | 20 #include "device/bluetooth/bluetooth_service_record.h" |
21 #include "device/bluetooth/bluetooth_socket.h" | 21 #include "device/bluetooth/bluetooth_socket.h" |
22 #include "device/bluetooth/bluetooth_utils.h" | |
23 #include "extensions/browser/event_router.h" | 22 #include "extensions/browser/event_router.h" |
24 #include "extensions/browser/extension_system.h" | 23 #include "extensions/browser/extension_system.h" |
25 #include "extensions/common/permissions/permissions_data.h" | 24 #include "extensions/common/permissions/permissions_data.h" |
26 #include "net/base/io_buffer.h" | 25 #include "net/base/io_buffer.h" |
27 | 26 |
28 using content::BrowserContext; | 27 using content::BrowserContext; |
29 using device::BluetoothAdapter; | 28 using device::BluetoothAdapter; |
30 using device::BluetoothDevice; | 29 using device::BluetoothDevice; |
31 using device::BluetoothProfile; | 30 using device::BluetoothProfile; |
32 using device::BluetoothServiceRecord; | 31 using device::BluetoothServiceRecord; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 126 |
128 namespace api { | 127 namespace api { |
129 | 128 |
130 BluetoothAddProfileFunction::BluetoothAddProfileFunction() { | 129 BluetoothAddProfileFunction::BluetoothAddProfileFunction() { |
131 } | 130 } |
132 | 131 |
133 bool BluetoothAddProfileFunction::RunImpl() { | 132 bool BluetoothAddProfileFunction::RunImpl() { |
134 scoped_ptr<AddProfile::Params> params(AddProfile::Params::Create(*args_)); | 133 scoped_ptr<AddProfile::Params> params(AddProfile::Params::Create(*args_)); |
135 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 134 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
136 | 135 |
137 if (!BluetoothDevice::IsUUIDValid(params->profile.uuid)) { | 136 device::BluetoothUUID uuid(params->profile.uuid); |
| 137 |
| 138 if (!uuid.IsValid()) { |
138 SetError(kInvalidUuid); | 139 SetError(kInvalidUuid); |
139 return false; | 140 return false; |
140 } | 141 } |
141 | 142 |
142 BluetoothPermissionRequest param(params->profile.uuid); | 143 BluetoothPermissionRequest param(params->profile.uuid); |
143 if (!BluetoothManifestData::CheckRequest(GetExtension(), param)) { | 144 if (!BluetoothManifestData::CheckRequest(GetExtension(), param)) { |
144 error_ = kPermissionDenied; | 145 error_ = kPermissionDenied; |
145 return false; | 146 return false; |
146 } | 147 } |
147 | 148 |
148 uuid_ = device::bluetooth_utils::CanonicalUuid(params->profile.uuid); | 149 uuid_ = uuid; |
149 | 150 |
150 if (GetEventRouter(browser_context())->HasProfile(uuid_)) { | 151 if (GetEventRouter(browser_context())->HasProfile(uuid_)) { |
151 SetError(kProfileAlreadyRegistered); | 152 SetError(kProfileAlreadyRegistered); |
152 return false; | 153 return false; |
153 } | 154 } |
154 | 155 |
155 BluetoothProfile::Options options; | 156 BluetoothProfile::Options options; |
156 if (params->profile.name.get()) | 157 if (params->profile.name.get()) |
157 options.name = *params->profile.name.get(); | 158 options.name = *params->profile.name.get(); |
158 if (params->profile.channel.get()) | 159 if (params->profile.channel.get()) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 uuid_)); | 210 uuid_)); |
210 GetEventRouter(browser_context()) | 211 GetEventRouter(browser_context()) |
211 ->AddProfile(uuid_, extension_id(), bluetooth_profile); | 212 ->AddProfile(uuid_, extension_id(), bluetooth_profile); |
212 SendResponse(true); | 213 SendResponse(true); |
213 } | 214 } |
214 | 215 |
215 bool BluetoothRemoveProfileFunction::RunImpl() { | 216 bool BluetoothRemoveProfileFunction::RunImpl() { |
216 scoped_ptr<RemoveProfile::Params> params( | 217 scoped_ptr<RemoveProfile::Params> params( |
217 RemoveProfile::Params::Create(*args_)); | 218 RemoveProfile::Params::Create(*args_)); |
218 | 219 |
219 if (!BluetoothDevice::IsUUIDValid(params->profile.uuid)) { | 220 device::BluetoothUUID uuid(params->profile.uuid); |
| 221 |
| 222 if (!uuid.IsValid()) { |
220 SetError(kInvalidUuid); | 223 SetError(kInvalidUuid); |
221 return false; | 224 return false; |
222 } | 225 } |
223 | 226 |
224 std::string uuid = | |
225 device::bluetooth_utils::CanonicalUuid(params->profile.uuid); | |
226 | |
227 if (!GetEventRouter(browser_context())->HasProfile(uuid)) { | 227 if (!GetEventRouter(browser_context())->HasProfile(uuid)) { |
228 SetError(kProfileNotFound); | 228 SetError(kProfileNotFound); |
229 return false; | 229 return false; |
230 } | 230 } |
231 | 231 |
232 GetEventRouter(browser_context())->RemoveProfile(uuid); | 232 GetEventRouter(browser_context())->RemoveProfile(uuid); |
233 return true; | 233 return true; |
234 } | 234 } |
235 | 235 |
236 bool BluetoothGetAdapterStateFunction::DoWork( | 236 bool BluetoothGetAdapterStateFunction::DoWork( |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 void BluetoothConnectFunction::OnErrorCallback() { | 296 void BluetoothConnectFunction::OnErrorCallback() { |
297 SetError(kFailedToConnect); | 297 SetError(kFailedToConnect); |
298 SendResponse(false); | 298 SendResponse(false); |
299 } | 299 } |
300 | 300 |
301 bool BluetoothConnectFunction::DoWork(scoped_refptr<BluetoothAdapter> adapter) { | 301 bool BluetoothConnectFunction::DoWork(scoped_refptr<BluetoothAdapter> adapter) { |
302 scoped_ptr<Connect::Params> params(Connect::Params::Create(*args_)); | 302 scoped_ptr<Connect::Params> params(Connect::Params::Create(*args_)); |
303 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 303 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
304 const bluetooth::ConnectOptions& options = params->options; | 304 const bluetooth::ConnectOptions& options = params->options; |
305 | 305 |
306 if (!BluetoothDevice::IsUUIDValid(options.profile.uuid)) { | 306 device::BluetoothUUID uuid(options.profile.uuid); |
| 307 |
| 308 if (!uuid.IsValid()) { |
307 SetError(kInvalidUuid); | 309 SetError(kInvalidUuid); |
308 SendResponse(false); | 310 SendResponse(false); |
309 return false; | 311 return false; |
310 } | 312 } |
311 | 313 |
312 BluetoothDevice* device = adapter->GetDevice(options.device.address); | 314 BluetoothDevice* device = adapter->GetDevice(options.device.address); |
313 if (!device) { | 315 if (!device) { |
314 SetError(kInvalidDevice); | 316 SetError(kInvalidDevice); |
315 SendResponse(false); | 317 SendResponse(false); |
316 return false; | 318 return false; |
317 } | 319 } |
318 | 320 |
319 std::string uuid = device::bluetooth_utils::CanonicalUuid( | |
320 options.profile.uuid); | |
321 | |
322 BluetoothProfile* bluetooth_profile = | 321 BluetoothProfile* bluetooth_profile = |
323 GetEventRouter(browser_context())->GetProfile(uuid); | 322 GetEventRouter(browser_context())->GetProfile(uuid); |
324 if (!bluetooth_profile) { | 323 if (!bluetooth_profile) { |
325 SetError(kProfileNotFound); | 324 SetError(kProfileNotFound); |
326 SendResponse(false); | 325 SendResponse(false); |
327 return false; | 326 return false; |
328 } | 327 } |
329 | 328 |
330 device->ConnectToProfile( | 329 device->ConnectToProfile( |
331 bluetooth_profile, | 330 bluetooth_profile, |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 adapter, | 572 adapter, |
574 extension_id(), | 573 extension_id(), |
575 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), | 574 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), |
576 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); | 575 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); |
577 | 576 |
578 return true; | 577 return true; |
579 } | 578 } |
580 | 579 |
581 } // namespace api | 580 } // namespace api |
582 } // namespace extensions | 581 } // namespace extensions |
OLD | NEW |