Index: content/renderer/bluetooth/web_bluetooth_impl.cc |
diff --git a/content/renderer/bluetooth/web_bluetooth_impl.cc b/content/renderer/bluetooth/web_bluetooth_impl.cc |
index ebfcce61da8aec0458e0e6be632de281274c1177..fcea1384506f5f72af7b8be2ef9c8b67eded73b8 100644 |
--- a/content/renderer/bluetooth/web_bluetooth_impl.cc |
+++ b/content/renderer/bluetooth/web_bluetooth_impl.cc |
@@ -21,6 +21,8 @@ |
#include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothDeviceInit.h" |
#include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemoteGATTCharacteristic.h" |
#include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemoteGATTCharacteristicInit.h" |
+#include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemoteGATTDescriptor.h" |
+#include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemoteGATTDescriptorInit.h" |
#include "third_party/WebKit/public/platform/modules/bluetooth/WebBluetoothRemoteGATTService.h" |
#include "third_party/WebKit/public/platform/modules/bluetooth/WebRequestDeviceOptions.h" |
@@ -112,7 +114,7 @@ void WebBluetoothImpl::getCharacteristics( |
base::Passed(base::WrapUnique(callbacks)))); |
} |
-void WebBluetoothImpl::readValue( |
+void WebBluetoothImpl::characteristicReadValue( |
const blink::WebString& characteristic_instance_id, |
blink::WebBluetoothReadValueCallbacks* callbacks) { |
GetWebBluetoothService().RemoteCharacteristicReadValue( |
@@ -121,7 +123,7 @@ void WebBluetoothImpl::readValue( |
base::Passed(base::WrapUnique(callbacks)))); |
} |
-void WebBluetoothImpl::writeValue( |
+void WebBluetoothImpl::characteristicWriteValue( |
const blink::WebString& characteristic_instance_id, |
const blink::WebVector<uint8_t>& value, |
blink::WebBluetoothWriteValueCallbacks* callbacks) { |
@@ -153,6 +155,46 @@ void WebBluetoothImpl::stopNotifications( |
base::Passed(base::WrapUnique(callbacks)))); |
} |
+void WebBluetoothImpl::getDescriptors( |
+ const blink::WebString& characteristic_instance_id, |
+ int32_t quantity, |
+ const blink::WebString& descriptors_uuid, |
+ blink::WebBluetoothGetDescriptorsCallbacks* callbacks) { |
+ DCHECK(blink::mojom::IsKnownEnumValue( |
+ static_cast<blink::mojom::WebBluetoothGATTQueryQuantity>(quantity))); |
+ |
+ GetWebBluetoothService().RemoteCharacteristicGetDescriptors( |
+ mojo::String::From(characteristic_instance_id), |
+ static_cast<blink::mojom::WebBluetoothGATTQueryQuantity>(quantity), |
+ descriptors_uuid.isEmpty() |
+ ? base::nullopt |
+ : base::make_optional(device::BluetoothUUID(descriptors_uuid.utf8())), |
+ base::Bind(&WebBluetoothImpl::OnGetDescriptorsComplete, |
+ base::Unretained(this), characteristic_instance_id, |
+ base::Passed(base::WrapUnique(callbacks)))); |
+} |
+ |
+void WebBluetoothImpl::descriptorReadValue( |
+ const blink::WebString& descriptor_instance_id, |
+ blink::WebBluetoothReadValueCallbacks* callbacks) { |
+ GetWebBluetoothService().RemoteDescriptorReadValue( |
+ mojo::String::From(descriptor_instance_id), |
+ base::Bind(&WebBluetoothImpl::OnReadValueComplete, base::Unretained(this), |
+ base::Passed(base::WrapUnique(callbacks)))); |
+} |
+ |
+void WebBluetoothImpl::descriptorWriteValue( |
+ const blink::WebString& descriptor_instance_id, |
+ const blink::WebVector<uint8_t>& value, |
+ blink::WebBluetoothWriteValueCallbacks* callbacks) { |
+ GetWebBluetoothService().RemoteDescriptorWriteValue( |
+ mojo::String::From(descriptor_instance_id), |
+ mojo::Array<uint8_t>::From(value), |
+ base::Bind(&WebBluetoothImpl::OnWriteValueComplete, |
+ base::Unretained(this), value, |
+ base::Passed(base::WrapUnique(callbacks)))); |
+} |
+ |
void WebBluetoothImpl::characteristicObjectRemoved( |
const blink::WebString& characteristic_instance_id, |
blink::WebBluetoothRemoteGATTCharacteristic* characteristic) { |
@@ -181,6 +223,33 @@ void WebBluetoothImpl::RemoteCharacteristicValueChanged( |
value.PassStorage())); |
} |
+void WebBluetoothImpl::RemoteDescriptorValueChanged( |
+ const mojo::String& descriptor_instance_id, |
+ mojo::Array<uint8_t> value) { |
+ // We post a task so that the event is fired after any pending promises have |
+ // resolved. |
+ base::ThreadTaskRunnerHandle::Get()->PostTask( |
+ FROM_HERE, base::Bind(&WebBluetoothImpl::DispatchDescriptorValueChanged, |
+ base::Unretained(this), descriptor_instance_id, |
+ value.PassStorage())); |
+} |
+ |
+void WebBluetoothImpl::descriptorObjectRemoved( |
+ const blink::WebString& descriptor_instance_id, |
+ blink::WebBluetoothRemoteGATTDescriptor* descriptor) { |
+ active_descriptors_.erase(descriptor_instance_id.utf8()); |
+} |
+ |
+void WebBluetoothImpl::registerDescriptorObject( |
+ const blink::WebString& descriptor_instance_id, |
+ blink::WebBluetoothRemoteGATTDescriptor* descriptor) { |
+ // TODO(dft): After the Bluetooth Tree is implemented, there will |
+ // only be one object per descriptor. But for now we replace |
+ // the previous object. |
+ // https://crbug.com/xxx |
+ active_descriptors_[descriptor_instance_id.utf8()] = descriptor; |
+} |
+ |
void WebBluetoothImpl::OnRequestDeviceComplete( |
std::unique_ptr<blink::WebBluetoothRequestDeviceCallbacks> callbacks, |
const blink::mojom::WebBluetoothResult result, |
@@ -266,6 +335,29 @@ void WebBluetoothImpl::OnGetCharacteristicsComplete( |
} |
} |
+void WebBluetoothImpl::OnGetDescriptorsComplete( |
+ const blink::WebString& characteristic_instance_id, |
+ std::unique_ptr<blink::WebBluetoothGetDescriptorsCallbacks> callbacks, |
+ blink::mojom::WebBluetoothResult result, |
+ mojo::Array<blink::mojom::WebBluetoothRemoteGATTDescriptorPtr> |
+ descriptors) { |
+ if (result == blink::mojom::WebBluetoothResult::SUCCESS) { |
+ // TODO(dcheng): This WebVector should use smart pointers. |
+ blink::WebVector<blink::WebBluetoothRemoteGATTDescriptorInit*> |
+ promise_descriptors(descriptors.size()); |
+ |
+ for (size_t i = 0; i < descriptors.size(); i++) { |
+ promise_descriptors[i] = new blink::WebBluetoothRemoteGATTDescriptorInit( |
+ characteristic_instance_id, |
+ blink::WebString::fromUTF8(descriptors[i]->instance_id), |
+ blink::WebString::fromUTF8(descriptors[i]->uuid)); |
+ } |
+ callbacks->onSuccess(promise_descriptors); |
+ } else { |
+ callbacks->onError(ToInt32(result)); |
+ } |
+} |
+ |
void WebBluetoothImpl::OnReadValueComplete( |
std::unique_ptr<blink::WebBluetoothReadValueCallbacks> callbacks, |
blink::mojom::WebBluetoothResult result, |
@@ -312,6 +404,15 @@ void WebBluetoothImpl::DispatchCharacteristicValueChanged( |
} |
} |
+void WebBluetoothImpl::DispatchDescriptorValueChanged( |
+ const std::string& descriptor_instance_id, |
+ const std::vector<uint8_t>& value) { |
+ auto active_iter = active_descriptors_.find(descriptor_instance_id); |
+ if (active_iter != active_descriptors_.end()) { |
+ active_iter->second->dispatchDescriptorValueChanged(value); |
+ } |
+} |
+ |
blink::mojom::WebBluetoothService& WebBluetoothImpl::GetWebBluetoothService() { |
if (!web_bluetooth_service_) { |
remote_interfaces_->GetInterface(mojo::GetProxy(&web_bluetooth_service_)); |