| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "content/renderer/bluetooth/web_bluetooth_impl.h" | 5 #include "content/renderer/bluetooth/web_bluetooth_impl.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic
eInit.h" | 21 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic
eInit.h" |
| 22 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot
eGATTCharacteristic.h" | 22 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot
eGATTCharacteristic.h" |
| 23 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot
eGATTCharacteristicInit.h" | 23 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot
eGATTCharacteristicInit.h" |
| 24 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot
eGATTService.h" | 24 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot
eGATTService.h" |
| 25 #include "third_party/WebKit/public/platform/modules/bluetooth/WebRequestDeviceO
ptions.h" | 25 #include "third_party/WebKit/public/platform/modules/bluetooth/WebRequestDeviceO
ptions.h" |
| 26 | 26 |
| 27 namespace content { | 27 namespace content { |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 // Blink can't use non-blink mojo enums like blink::mojom::WebBluetoothError, so | 31 // Blink can't use non-blink mojo enums like blink::mojom::WebBluetoothResult, |
| 32 // we pass it as an int32 across the boundary. | 32 // so we pass it as an int32 across the boundary. |
| 33 int32_t ToInt32(blink::mojom::WebBluetoothError error) { | 33 int32_t ToInt32(blink::mojom::WebBluetoothResult result) { |
| 34 return static_cast<int32_t>(error); | 34 return static_cast<int32_t>(result); |
| 35 } | 35 } |
| 36 | 36 |
| 37 } // namespace | 37 } // namespace |
| 38 | 38 |
| 39 WebBluetoothImpl::WebBluetoothImpl(shell::InterfaceProvider* remote_interfaces) | 39 WebBluetoothImpl::WebBluetoothImpl(shell::InterfaceProvider* remote_interfaces) |
| 40 : remote_interfaces_(remote_interfaces), binding_(this) {} | 40 : remote_interfaces_(remote_interfaces), binding_(this) {} |
| 41 | 41 |
| 42 WebBluetoothImpl::~WebBluetoothImpl() { | 42 WebBluetoothImpl::~WebBluetoothImpl() { |
| 43 } | 43 } |
| 44 | 44 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 // resolved. | 175 // resolved. |
| 176 base::ThreadTaskRunnerHandle::Get()->PostTask( | 176 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 177 FROM_HERE, | 177 FROM_HERE, |
| 178 base::Bind(&WebBluetoothImpl::DispatchCharacteristicValueChanged, | 178 base::Bind(&WebBluetoothImpl::DispatchCharacteristicValueChanged, |
| 179 base::Unretained(this), characteristic_instance_id, | 179 base::Unretained(this), characteristic_instance_id, |
| 180 value.PassStorage())); | 180 value.PassStorage())); |
| 181 } | 181 } |
| 182 | 182 |
| 183 void WebBluetoothImpl::OnRequestDeviceComplete( | 183 void WebBluetoothImpl::OnRequestDeviceComplete( |
| 184 std::unique_ptr<blink::WebBluetoothRequestDeviceCallbacks> callbacks, | 184 std::unique_ptr<blink::WebBluetoothRequestDeviceCallbacks> callbacks, |
| 185 const blink::mojom::WebBluetoothError error, | 185 const blink::mojom::WebBluetoothResult result, |
| 186 blink::mojom::WebBluetoothDevicePtr device) { | 186 blink::mojom::WebBluetoothDevicePtr device) { |
| 187 if (error == blink::mojom::WebBluetoothError::SUCCESS) { | 187 if (result == blink::mojom::WebBluetoothResult::SUCCESS) { |
| 188 blink::WebVector<blink::WebString> uuids(device->uuids.size()); | 188 blink::WebVector<blink::WebString> uuids(device->uuids.size()); |
| 189 for (size_t i = 0; i < device->uuids.size(); ++i) | 189 for (size_t i = 0; i < device->uuids.size(); ++i) |
| 190 uuids[i] = blink::WebString::fromUTF8(device->uuids[i]); | 190 uuids[i] = blink::WebString::fromUTF8(device->uuids[i]); |
| 191 | 191 |
| 192 callbacks->onSuccess(base::MakeUnique<blink::WebBluetoothDeviceInit>( | 192 callbacks->onSuccess(base::MakeUnique<blink::WebBluetoothDeviceInit>( |
| 193 blink::WebString::fromUTF8(device->id.str()), | 193 blink::WebString::fromUTF8(device->id.str()), |
| 194 device->name.is_null() ? blink::WebString() | 194 device->name.is_null() ? blink::WebString() |
| 195 : blink::WebString::fromUTF8(device->name), | 195 : blink::WebString::fromUTF8(device->name), |
| 196 uuids)); | 196 uuids)); |
| 197 } else { | 197 } else { |
| 198 callbacks->onError(ToInt32(error)); | 198 callbacks->onError(ToInt32(result)); |
| 199 } | 199 } |
| 200 } | 200 } |
| 201 | 201 |
| 202 void WebBluetoothImpl::GattServerDisconnected( | 202 void WebBluetoothImpl::GattServerDisconnected( |
| 203 const WebBluetoothDeviceId& device_id) { | 203 const WebBluetoothDeviceId& device_id) { |
| 204 auto device_iter = connected_devices_.find(device_id); | 204 auto device_iter = connected_devices_.find(device_id); |
| 205 if (device_iter != connected_devices_.end()) { | 205 if (device_iter != connected_devices_.end()) { |
| 206 // Remove device from the map before calling dispatchGattServerDisconnected | 206 // Remove device from the map before calling dispatchGattServerDisconnected |
| 207 // to avoid removing a device the gattserverdisconnected event handler might | 207 // to avoid removing a device the gattserverdisconnected event handler might |
| 208 // have re-connected. | 208 // have re-connected. |
| 209 blink::WebBluetoothDevice* device = device_iter->second; | 209 blink::WebBluetoothDevice* device = device_iter->second; |
| 210 connected_devices_.erase(device_iter); | 210 connected_devices_.erase(device_iter); |
| 211 device->dispatchGattServerDisconnected(); | 211 device->dispatchGattServerDisconnected(); |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 | 214 |
| 215 void WebBluetoothImpl::OnConnectComplete( | 215 void WebBluetoothImpl::OnConnectComplete( |
| 216 std::unique_ptr<blink::WebBluetoothRemoteGATTServerConnectCallbacks> | 216 std::unique_ptr<blink::WebBluetoothRemoteGATTServerConnectCallbacks> |
| 217 callbacks, | 217 callbacks, |
| 218 blink::mojom::WebBluetoothError error) { | 218 blink::mojom::WebBluetoothResult result) { |
| 219 if (error == blink::mojom::WebBluetoothError::SUCCESS) { | 219 if (result == blink::mojom::WebBluetoothResult::SUCCESS) { |
| 220 callbacks->onSuccess(); | 220 callbacks->onSuccess(); |
| 221 } else { | 221 } else { |
| 222 callbacks->onError(ToInt32(error)); | 222 callbacks->onError(ToInt32(result)); |
| 223 } | 223 } |
| 224 } | 224 } |
| 225 | 225 |
| 226 void WebBluetoothImpl::OnGetPrimaryServicesComplete( | 226 void WebBluetoothImpl::OnGetPrimaryServicesComplete( |
| 227 const blink::WebString& device_id, | 227 const blink::WebString& device_id, |
| 228 std::unique_ptr<blink::WebBluetoothGetPrimaryServicesCallbacks> callbacks, | 228 std::unique_ptr<blink::WebBluetoothGetPrimaryServicesCallbacks> callbacks, |
| 229 blink::mojom::WebBluetoothError error, | 229 blink::mojom::WebBluetoothResult result, |
| 230 mojo::Array<blink::mojom::WebBluetoothRemoteGATTServicePtr> services) { | 230 mojo::Array<blink::mojom::WebBluetoothRemoteGATTServicePtr> services) { |
| 231 if (error == blink::mojom::WebBluetoothError::SUCCESS) { | 231 if (result == blink::mojom::WebBluetoothResult::SUCCESS) { |
| 232 // TODO(dcheng): This WebVector should use smart pointers. | 232 // TODO(dcheng): This WebVector should use smart pointers. |
| 233 blink::WebVector<blink::WebBluetoothRemoteGATTService*> promise_services( | 233 blink::WebVector<blink::WebBluetoothRemoteGATTService*> promise_services( |
| 234 services.size()); | 234 services.size()); |
| 235 | 235 |
| 236 for (size_t i = 0; i < services.size(); i++) { | 236 for (size_t i = 0; i < services.size(); i++) { |
| 237 promise_services[i] = new blink::WebBluetoothRemoteGATTService( | 237 promise_services[i] = new blink::WebBluetoothRemoteGATTService( |
| 238 blink::WebString::fromUTF8(services[i]->instance_id), | 238 blink::WebString::fromUTF8(services[i]->instance_id), |
| 239 blink::WebString::fromUTF8(services[i]->uuid), true /* isPrimary */, | 239 blink::WebString::fromUTF8(services[i]->uuid), true /* isPrimary */, |
| 240 device_id); | 240 device_id); |
| 241 } | 241 } |
| 242 callbacks->onSuccess(promise_services); | 242 callbacks->onSuccess(promise_services); |
| 243 } else { | 243 } else { |
| 244 callbacks->onError(ToInt32(error)); | 244 callbacks->onError(ToInt32(result)); |
| 245 } | 245 } |
| 246 } | 246 } |
| 247 | 247 |
| 248 void WebBluetoothImpl::OnGetCharacteristicsComplete( | 248 void WebBluetoothImpl::OnGetCharacteristicsComplete( |
| 249 const blink::WebString& service_instance_id, | 249 const blink::WebString& service_instance_id, |
| 250 std::unique_ptr<blink::WebBluetoothGetCharacteristicsCallbacks> callbacks, | 250 std::unique_ptr<blink::WebBluetoothGetCharacteristicsCallbacks> callbacks, |
| 251 blink::mojom::WebBluetoothError error, | 251 blink::mojom::WebBluetoothResult result, |
| 252 mojo::Array<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr> | 252 mojo::Array<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr> |
| 253 characteristics) { | 253 characteristics) { |
| 254 if (error == blink::mojom::WebBluetoothError::SUCCESS) { | 254 if (result == blink::mojom::WebBluetoothResult::SUCCESS) { |
| 255 // TODO(dcheng): This WebVector should use smart pointers. | 255 // TODO(dcheng): This WebVector should use smart pointers. |
| 256 blink::WebVector<blink::WebBluetoothRemoteGATTCharacteristicInit*> | 256 blink::WebVector<blink::WebBluetoothRemoteGATTCharacteristicInit*> |
| 257 promise_characteristics(characteristics.size()); | 257 promise_characteristics(characteristics.size()); |
| 258 | 258 |
| 259 for (size_t i = 0; i < characteristics.size(); i++) { | 259 for (size_t i = 0; i < characteristics.size(); i++) { |
| 260 promise_characteristics[i] = | 260 promise_characteristics[i] = |
| 261 new blink::WebBluetoothRemoteGATTCharacteristicInit( | 261 new blink::WebBluetoothRemoteGATTCharacteristicInit( |
| 262 service_instance_id, | 262 service_instance_id, |
| 263 blink::WebString::fromUTF8(characteristics[i]->instance_id), | 263 blink::WebString::fromUTF8(characteristics[i]->instance_id), |
| 264 blink::WebString::fromUTF8(characteristics[i]->uuid), | 264 blink::WebString::fromUTF8(characteristics[i]->uuid), |
| 265 characteristics[i]->properties); | 265 characteristics[i]->properties); |
| 266 } | 266 } |
| 267 callbacks->onSuccess(promise_characteristics); | 267 callbacks->onSuccess(promise_characteristics); |
| 268 } else { | 268 } else { |
| 269 callbacks->onError(ToInt32(error)); | 269 callbacks->onError(ToInt32(result)); |
| 270 } | 270 } |
| 271 } | 271 } |
| 272 | 272 |
| 273 void WebBluetoothImpl::OnReadValueComplete( | 273 void WebBluetoothImpl::OnReadValueComplete( |
| 274 std::unique_ptr<blink::WebBluetoothReadValueCallbacks> callbacks, | 274 std::unique_ptr<blink::WebBluetoothReadValueCallbacks> callbacks, |
| 275 blink::mojom::WebBluetoothError error, | 275 blink::mojom::WebBluetoothResult result, |
| 276 mojo::Array<uint8_t> value) { | 276 mojo::Array<uint8_t> value) { |
| 277 if (error == blink::mojom::WebBluetoothError::SUCCESS) { | 277 if (result == blink::mojom::WebBluetoothResult::SUCCESS) { |
| 278 callbacks->onSuccess(value.PassStorage()); | 278 callbacks->onSuccess(value.PassStorage()); |
| 279 } else { | 279 } else { |
| 280 callbacks->onError(ToInt32(error)); | 280 callbacks->onError(ToInt32(result)); |
| 281 } | 281 } |
| 282 } | 282 } |
| 283 | 283 |
| 284 void WebBluetoothImpl::OnWriteValueComplete( | 284 void WebBluetoothImpl::OnWriteValueComplete( |
| 285 const blink::WebVector<uint8_t>& value, | 285 const blink::WebVector<uint8_t>& value, |
| 286 std::unique_ptr<blink::WebBluetoothWriteValueCallbacks> callbacks, | 286 std::unique_ptr<blink::WebBluetoothWriteValueCallbacks> callbacks, |
| 287 blink::mojom::WebBluetoothError error) { | 287 blink::mojom::WebBluetoothResult result) { |
| 288 if (error == blink::mojom::WebBluetoothError::SUCCESS) { | 288 if (result == blink::mojom::WebBluetoothResult::SUCCESS) { |
| 289 callbacks->onSuccess(value); | 289 callbacks->onSuccess(value); |
| 290 } else { | 290 } else { |
| 291 callbacks->onError(ToInt32(error)); | 291 callbacks->onError(ToInt32(result)); |
| 292 } | 292 } |
| 293 } | 293 } |
| 294 | 294 |
| 295 void WebBluetoothImpl::OnStartNotificationsComplete( | 295 void WebBluetoothImpl::OnStartNotificationsComplete( |
| 296 std::unique_ptr<blink::WebBluetoothNotificationsCallbacks> callbacks, | 296 std::unique_ptr<blink::WebBluetoothNotificationsCallbacks> callbacks, |
| 297 blink::mojom::WebBluetoothError error) { | 297 blink::mojom::WebBluetoothResult result) { |
| 298 if (error == blink::mojom::WebBluetoothError::SUCCESS) { | 298 if (result == blink::mojom::WebBluetoothResult::SUCCESS) { |
| 299 callbacks->onSuccess(); | 299 callbacks->onSuccess(); |
| 300 } else { | 300 } else { |
| 301 callbacks->onError(ToInt32(error)); | 301 callbacks->onError(ToInt32(result)); |
| 302 } | 302 } |
| 303 } | 303 } |
| 304 | 304 |
| 305 void WebBluetoothImpl::OnStopNotificationsComplete( | 305 void WebBluetoothImpl::OnStopNotificationsComplete( |
| 306 std::unique_ptr<blink::WebBluetoothNotificationsCallbacks> callbacks) { | 306 std::unique_ptr<blink::WebBluetoothNotificationsCallbacks> callbacks) { |
| 307 callbacks->onSuccess(); | 307 callbacks->onSuccess(); |
| 308 } | 308 } |
| 309 | 309 |
| 310 void WebBluetoothImpl::DispatchCharacteristicValueChanged( | 310 void WebBluetoothImpl::DispatchCharacteristicValueChanged( |
| 311 const std::string& characteristic_instance_id, | 311 const std::string& characteristic_instance_id, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 322 // Create an associated interface ptr and pass it to the WebBluetoothService | 322 // Create an associated interface ptr and pass it to the WebBluetoothService |
| 323 // so that it can send us events without us prompting. | 323 // so that it can send us events without us prompting. |
| 324 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; | 324 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; |
| 325 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); | 325 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); |
| 326 web_bluetooth_service_->SetClient(std::move(ptr_info)); | 326 web_bluetooth_service_->SetClient(std::move(ptr_info)); |
| 327 } | 327 } |
| 328 return *web_bluetooth_service_; | 328 return *web_bluetooth_service_; |
| 329 } | 329 } |
| 330 | 330 |
| 331 } // namespace content | 331 } // namespace content |
| OLD | NEW |