Chromium Code Reviews| Index: third_party/WebKit/Source/modules/bluetooth/BluetoothGATTCharacteristic.cpp |
| diff --git a/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTCharacteristic.cpp b/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTCharacteristic.cpp |
| index 23250910ad7f10a724d3c1e995096e85b6832766..b95ffe58e885ffbbdf4fed422c0b3acd56b4f280 100644 |
| --- a/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTCharacteristic.cpp |
| +++ b/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTCharacteristic.cpp |
| @@ -13,7 +13,6 @@ |
| #include "modules/bluetooth/BluetoothCharacteristicProperties.h" |
| #include "modules/bluetooth/BluetoothError.h" |
| #include "modules/bluetooth/BluetoothSupplement.h" |
| -#include "modules/bluetooth/ConvertWebVectorToArrayBuffer.h" |
| #include "public/platform/modules/bluetooth/WebBluetooth.h" |
| namespace blink { |
| @@ -39,12 +38,18 @@ BluetoothGATTCharacteristic* BluetoothGATTCharacteristic::take(ScriptPromiseReso |
| return characteristic; |
| } |
| -void BluetoothGATTCharacteristic::dispatchCharacteristicValueChanged( |
| +void BluetoothGATTCharacteristic::setValue( |
| const WebVector<uint8_t>& value) |
| { |
| static_assert(sizeof(*value.data()) == 1, "uint8_t should be a single byte"); |
| m_value = DOMArrayBuffer::create(value.data(), value.size()); |
| +} |
| + |
| +void BluetoothGATTCharacteristic::dispatchCharacteristicValueChanged( |
| + const WebVector<uint8_t>& value) |
| +{ |
| + setValue(value); |
| dispatchEvent(Event::create(EventTypeNames::characteristicvaluechanged)); |
| } |
| @@ -89,13 +94,39 @@ bool BluetoothGATTCharacteristic::addEventListenerInternal(const AtomicString& e |
| return EventTarget::addEventListenerInternal(eventType, listener, options); |
| } |
| + |
| +class ReadValueCallback : public WebBluetoothReadValueCallbacks { |
| +public: |
| + ReadValueCallback(BluetoothGATTCharacteristic* characteristic, ScriptPromiseResolver* resolver) : m_webCharacteristic(characteristic), m_resolver(resolver) {} |
| + |
| + void onSuccess(const WebVector<uint8_t>& value) override |
| + { |
| + if (!m_resolver->executionContext() || m_resolver->executionContext()->activeDOMObjectsAreStopped()) |
| + return; |
| + |
| + m_webCharacteristic->setValue(value); |
| + m_resolver->resolve(m_webCharacteristic->value()); |
| + } |
| + |
| + void onError(const WebBluetoothError& e) override |
| + { |
| + if (!m_resolver->executionContext() || m_resolver->executionContext()->activeDOMObjectsAreStopped()) |
| + return; |
| + m_resolver->reject(BluetoothError::take(m_resolver, e)); |
| + } |
| + |
| +private: |
| + Persistent<BluetoothGATTCharacteristic> m_webCharacteristic; |
|
ortuno
2016/01/13 21:14:09
Talked to jyasskin about this. We don't need to ke
|
| + Persistent<ScriptPromiseResolver> m_resolver; |
| +}; |
| + |
| ScriptPromise BluetoothGATTCharacteristic::readValue(ScriptState* scriptState) |
| { |
| WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptState); |
| ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| ScriptPromise promise = resolver->promise(); |
| - webbluetooth->readValue(m_webCharacteristic->characteristicInstanceID, new CallbackPromiseAdapter<ConvertWebVectorToArrayBuffer, BluetoothError>(resolver)); |
| + webbluetooth->readValue(m_webCharacteristic->characteristicInstanceID, new ReadValueCallback(this, resolver)); |
| return promise; |
| } |