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" |
22 #include "extensions/browser/event_router.h" | 23 #include "extensions/browser/event_router.h" |
23 #include "extensions/browser/extension_system.h" | 24 #include "extensions/browser/extension_system.h" |
24 #include "extensions/common/permissions/permissions_data.h" | 25 #include "extensions/common/permissions/permissions_data.h" |
25 #include "net/base/io_buffer.h" | 26 #include "net/base/io_buffer.h" |
26 | 27 |
27 using content::BrowserContext; | 28 using content::BrowserContext; |
28 using device::BluetoothAdapter; | 29 using device::BluetoothAdapter; |
29 using device::BluetoothDevice; | 30 using device::BluetoothDevice; |
30 using device::BluetoothProfile; | 31 using device::BluetoothProfile; |
31 using device::BluetoothServiceRecord; | 32 using device::BluetoothServiceRecord; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 | 127 |
127 namespace api { | 128 namespace api { |
128 | 129 |
129 BluetoothAddProfileFunction::BluetoothAddProfileFunction() { | 130 BluetoothAddProfileFunction::BluetoothAddProfileFunction() { |
130 } | 131 } |
131 | 132 |
132 bool BluetoothAddProfileFunction::RunImpl() { | 133 bool BluetoothAddProfileFunction::RunImpl() { |
133 scoped_ptr<AddProfile::Params> params(AddProfile::Params::Create(*args_)); | 134 scoped_ptr<AddProfile::Params> params(AddProfile::Params::Create(*args_)); |
134 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); | 135 EXTENSION_FUNCTION_VALIDATE(params.get() != NULL); |
135 | 136 |
136 device::BluetoothUUID uuid(params->profile.uuid); | 137 if (!BluetoothDevice::IsUUIDValid(params->profile.uuid)) { |
137 | |
138 if (!uuid.IsValid()) { | |
139 SetError(kInvalidUuid); | 138 SetError(kInvalidUuid); |
140 return false; | 139 return false; |
141 } | 140 } |
142 | 141 |
143 BluetoothPermissionRequest param(params->profile.uuid); | 142 BluetoothPermissionRequest param(params->profile.uuid); |
144 if (!BluetoothManifestData::CheckRequest(GetExtension(), param)) { | 143 if (!BluetoothManifestData::CheckRequest(GetExtension(), param)) { |
145 error_ = kPermissionDenied; | 144 error_ = kPermissionDenied; |
146 return false; | 145 return false; |
147 } | 146 } |
148 | 147 |
149 uuid_ = uuid; | 148 uuid_ = device::bluetooth_utils::CanonicalUuid(params->profile.uuid); |
150 | 149 |
151 if (GetEventRouter(browser_context())->HasProfile(uuid_)) { | 150 if (GetEventRouter(browser_context())->HasProfile(uuid_)) { |
152 SetError(kProfileAlreadyRegistered); | 151 SetError(kProfileAlreadyRegistered); |
153 return false; | 152 return false; |
154 } | 153 } |
155 | 154 |
156 BluetoothProfile::Options options; | 155 BluetoothProfile::Options options; |
157 if (params->profile.name.get()) | 156 if (params->profile.name.get()) |
158 options.name = *params->profile.name.get(); | 157 options.name = *params->profile.name.get(); |
159 if (params->profile.channel.get()) | 158 if (params->profile.channel.get()) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 uuid_)); | 209 uuid_)); |
211 GetEventRouter(browser_context()) | 210 GetEventRouter(browser_context()) |
212 ->AddProfile(uuid_, extension_id(), bluetooth_profile); | 211 ->AddProfile(uuid_, extension_id(), bluetooth_profile); |
213 SendResponse(true); | 212 SendResponse(true); |
214 } | 213 } |
215 | 214 |
216 bool BluetoothRemoveProfileFunction::RunImpl() { | 215 bool BluetoothRemoveProfileFunction::RunImpl() { |
217 scoped_ptr<RemoveProfile::Params> params( | 216 scoped_ptr<RemoveProfile::Params> params( |
218 RemoveProfile::Params::Create(*args_)); | 217 RemoveProfile::Params::Create(*args_)); |
219 | 218 |
220 device::BluetoothUUID uuid(params->profile.uuid); | 219 if (!BluetoothDevice::IsUUIDValid(params->profile.uuid)) { |
221 | |
222 if (!uuid.IsValid()) { | |
223 SetError(kInvalidUuid); | 220 SetError(kInvalidUuid); |
224 return false; | 221 return false; |
225 } | 222 } |
226 | 223 |
| 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 device::BluetoothUUID uuid(options.profile.uuid); | 306 if (!BluetoothDevice::IsUUIDValid(options.profile.uuid)) { |
307 | |
308 if (!uuid.IsValid()) { | |
309 SetError(kInvalidUuid); | 307 SetError(kInvalidUuid); |
310 SendResponse(false); | 308 SendResponse(false); |
311 return false; | 309 return false; |
312 } | 310 } |
313 | 311 |
314 BluetoothDevice* device = adapter->GetDevice(options.device.address); | 312 BluetoothDevice* device = adapter->GetDevice(options.device.address); |
315 if (!device) { | 313 if (!device) { |
316 SetError(kInvalidDevice); | 314 SetError(kInvalidDevice); |
317 SendResponse(false); | 315 SendResponse(false); |
318 return false; | 316 return false; |
319 } | 317 } |
320 | 318 |
| 319 std::string uuid = device::bluetooth_utils::CanonicalUuid( |
| 320 options.profile.uuid); |
| 321 |
321 BluetoothProfile* bluetooth_profile = | 322 BluetoothProfile* bluetooth_profile = |
322 GetEventRouter(browser_context())->GetProfile(uuid); | 323 GetEventRouter(browser_context())->GetProfile(uuid); |
323 if (!bluetooth_profile) { | 324 if (!bluetooth_profile) { |
324 SetError(kProfileNotFound); | 325 SetError(kProfileNotFound); |
325 SendResponse(false); | 326 SendResponse(false); |
326 return false; | 327 return false; |
327 } | 328 } |
328 | 329 |
329 device->ConnectToProfile( | 330 device->ConnectToProfile( |
330 bluetooth_profile, | 331 bluetooth_profile, |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 adapter, | 573 adapter, |
573 extension_id(), | 574 extension_id(), |
574 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), | 575 base::Bind(&BluetoothStopDiscoveryFunction::OnSuccessCallback, this), |
575 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); | 576 base::Bind(&BluetoothStopDiscoveryFunction::OnErrorCallback, this)); |
576 | 577 |
577 return true; | 578 return true; |
578 } | 579 } |
579 | 580 |
580 } // namespace api | 581 } // namespace api |
581 } // namespace extensions | 582 } // namespace extensions |
OLD | NEW |