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 |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/optional.h" |
12 #include "content/child/mojo/type_converters.h" | 13 #include "content/child/mojo/type_converters.h" |
13 #include "content/child/thread_safe_sender.h" | 14 #include "content/child/thread_safe_sender.h" |
14 #include "content/public/common/service_registry.h" | 15 #include "content/public/common/service_registry.h" |
15 #include "content/renderer/bluetooth/bluetooth_type_converters.h" | 16 #include "content/renderer/bluetooth/bluetooth_type_converters.h" |
16 #include "ipc/ipc_message.h" | 17 #include "ipc/ipc_message.h" |
17 #include "mojo/public/cpp/bindings/array.h" | 18 #include "mojo/public/cpp/bindings/array.h" |
18 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic
e.h" | 19 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic
e.h" |
19 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic
eInit.h" | 20 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDevic
eInit.h" |
20 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot
eGATTCharacteristic.h" | 21 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot
eGATTCharacteristic.h" |
21 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot
eGATTCharacteristicInit.h" | 22 #include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemot
eGATTCharacteristicInit.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 | 60 |
60 GetWebBluetoothService().RemoteServerDisconnect( | 61 GetWebBluetoothService().RemoteServerDisconnect( |
61 mojo::String::From(device_id)); | 62 mojo::String::From(device_id)); |
62 } | 63 } |
63 | 64 |
64 void WebBluetoothImpl::getPrimaryService( | 65 void WebBluetoothImpl::getPrimaryService( |
65 const blink::WebString& device_id, | 66 const blink::WebString& device_id, |
66 const blink::WebString& service_uuid, | 67 const blink::WebString& service_uuid, |
67 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) { | 68 blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) { |
68 GetWebBluetoothService().RemoteServerGetPrimaryService( | 69 GetWebBluetoothService().RemoteServerGetPrimaryService( |
69 mojo::String::From(device_id), mojo::String::From(service_uuid), | 70 mojo::String::From(device_id), |
| 71 base::make_optional(device::BluetoothUUID(service_uuid.utf8())), |
70 base::Bind(&WebBluetoothImpl::OnGetPrimaryServiceComplete, | 72 base::Bind(&WebBluetoothImpl::OnGetPrimaryServiceComplete, |
71 base::Unretained(this), device_id, | 73 base::Unretained(this), device_id, |
72 base::Passed(base::WrapUnique(callbacks)))); | 74 base::Passed(base::WrapUnique(callbacks)))); |
73 } | 75 } |
74 | 76 |
75 void WebBluetoothImpl::getCharacteristics( | 77 void WebBluetoothImpl::getCharacteristics( |
76 const blink::WebString& service_instance_id, | 78 const blink::WebString& service_instance_id, |
77 blink::mojom::WebBluetoothGATTQueryQuantity quantity, | 79 blink::mojom::WebBluetoothGATTQueryQuantity quantity, |
78 const blink::WebString& characteristics_uuid, | 80 const blink::WebString& characteristics_uuid, |
79 blink::WebBluetoothGetCharacteristicsCallbacks* callbacks) { | 81 blink::WebBluetoothGetCharacteristicsCallbacks* callbacks) { |
80 GetWebBluetoothService().RemoteServiceGetCharacteristics( | 82 GetWebBluetoothService().RemoteServiceGetCharacteristics( |
81 mojo::String::From(service_instance_id), quantity, | 83 mojo::String::From(service_instance_id), quantity, |
82 characteristics_uuid.isEmpty() ? nullptr | 84 characteristics_uuid.isEmpty() |
83 : mojo::String::From(characteristics_uuid), | 85 ? base::nullopt |
| 86 : base::make_optional( |
| 87 device::BluetoothUUID(characteristics_uuid.utf8())), |
84 base::Bind(&WebBluetoothImpl::OnGetCharacteristicsComplete, | 88 base::Bind(&WebBluetoothImpl::OnGetCharacteristicsComplete, |
85 base::Unretained(this), service_instance_id, | 89 base::Unretained(this), service_instance_id, |
86 base::Passed(base::WrapUnique(callbacks)))); | 90 base::Passed(base::WrapUnique(callbacks)))); |
87 } | 91 } |
88 | 92 |
89 void WebBluetoothImpl::readValue( | 93 void WebBluetoothImpl::readValue( |
90 const blink::WebString& characteristic_instance_id, | 94 const blink::WebString& characteristic_instance_id, |
91 blink::WebBluetoothReadValueCallbacks* callbacks) { | 95 blink::WebBluetoothReadValueCallbacks* callbacks) { |
92 GetWebBluetoothService().RemoteCharacteristicReadValue( | 96 GetWebBluetoothService().RemoteCharacteristicReadValue( |
93 mojo::String::From(characteristic_instance_id), | 97 mojo::String::From(characteristic_instance_id), |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 // Create an associated interface ptr and pass it to the WebBluetoothService | 289 // Create an associated interface ptr and pass it to the WebBluetoothService |
286 // so that it can send us events without us prompting. | 290 // so that it can send us events without us prompting. |
287 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; | 291 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo ptr_info; |
288 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); | 292 binding_.Bind(&ptr_info, web_bluetooth_service_.associated_group()); |
289 web_bluetooth_service_->SetClient(std::move(ptr_info)); | 293 web_bluetooth_service_->SetClient(std::move(ptr_info)); |
290 } | 294 } |
291 return *web_bluetooth_service_; | 295 return *web_bluetooth_service_; |
292 } | 296 } |
293 | 297 |
294 } // namespace content | 298 } // namespace content |
OLD | NEW |