Commit e0b2c889 authored by beaufort.francois's avatar beaufort.francois Committed by Commit bot

bluetooth: Switch BluetoothGattCharacteristic.value to DataView

BUG=579148

Review URL: https://codereview.chromium.org/1603893002

Cr-Commit-Position: refs/heads/master@{#370664}
parent c5d84372
...@@ -18,10 +18,10 @@ promise_test(() => { ...@@ -18,10 +18,10 @@ promise_test(() => {
'readValue', 'readValue',
'characteristicvaluechanged'); 'characteristicvaluechanged');
}).then(results => { }).then(results => {
let read_value = new Uint8Array(results[0]); let read_value = results[0].buffer;
let event_value = new Uint8Array(results[1]); let event_value = results[1].buffer;
// TODO(ortuno): The ArrayBuffer used to resolve the promise // TODO(ortuno): The DataView used to resolve the promise
// should be the same ArrayBuffer as the one saved in the // should be the same DataView as the one saved in the
// characteristic. // characteristic.
// http://crbug.com/543347 // http://crbug.com/543347
// assert_equals(event.target.value, value); // assert_equals(event.target.value, value);
...@@ -41,11 +41,11 @@ promise_test(() => { ...@@ -41,11 +41,11 @@ promise_test(() => {
'characteristicvaluechanged', 'characteristicvaluechanged',
3 /* attach 3 listeners */); 3 /* attach 3 listeners */);
}).then(results => { }).then(results => {
let read_value = new Uint8Array(results[0]); let read_value = results[0].buffer;
let event_values = results.slice(1).map(v => new Uint8Array(v)); let event_values = results.slice(1).map(v => v.buffer);
for (let event_value of event_values) { for (let event_value of event_values) {
// TODO(ortuno): The ArrayBuffer used to resolve the promise // TODO(ortuno): The DataView used to resolve the promise
// should be the same ArrayBuffer as the one saved in the // should be the same DataView as the one saved in the
// characteristic. // characteristic.
// http://crbug.com/543347 // http://crbug.com/543347
// assert_equals(event.target.value, value); // assert_equals(event.target.value, value);
......
...@@ -5,11 +5,12 @@ ...@@ -5,11 +5,12 @@
#ifndef DOMDataView_h #ifndef DOMDataView_h
#define DOMDataView_h #define DOMDataView_h
#include "core/CoreExport.h"
#include "core/dom/DOMArrayBufferView.h" #include "core/dom/DOMArrayBufferView.h"
namespace blink { namespace blink {
class DOMDataView final : public DOMArrayBufferView { class CORE_EXPORT DOMDataView final : public DOMArrayBufferView {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
typedef char ValueType; typedef char ValueType;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "bindings/core/v8/CallbackPromiseAdapter.h" #include "bindings/core/v8/CallbackPromiseAdapter.h"
#include "bindings/core/v8/ScriptPromise.h" #include "bindings/core/v8/ScriptPromise.h"
#include "bindings/core/v8/ScriptPromiseResolver.h" #include "bindings/core/v8/ScriptPromiseResolver.h"
#include "core/dom/DOMDataView.h"
#include "core/dom/DOMException.h" #include "core/dom/DOMException.h"
#include "core/dom/ExceptionCode.h" #include "core/dom/ExceptionCode.h"
#include "core/events/Event.h" #include "core/events/Event.h"
...@@ -19,12 +20,13 @@ namespace blink { ...@@ -19,12 +20,13 @@ namespace blink {
namespace { namespace {
PassRefPtr<DOMArrayBuffer> ConvertWebVectorToArrayBuffer( PassRefPtr<DOMDataView> ConvertWebVectorToDataView(
const WebVector<uint8_t>& webVector) const WebVector<uint8_t>& webVector)
{ {
static_assert(sizeof(*webVector.data()) == 1, "uint8_t should be a single byte"); static_assert(sizeof(*webVector.data()) == 1, "uint8_t should be a single byte");
RefPtr<DOMArrayBuffer> domBuffer = DOMArrayBuffer::create(webVector.data(), webVector.size()); RefPtr<DOMArrayBuffer> domBuffer = DOMArrayBuffer::create(webVector.data(), webVector.size());
return domBuffer; RefPtr<DOMDataView> domDataView = DOMDataView::create(domBuffer, 0, webVector.size());
return domDataView;
} }
} // anonymous namespace } // anonymous namespace
...@@ -51,16 +53,16 @@ BluetoothGATTCharacteristic* BluetoothGATTCharacteristic::take(ScriptPromiseReso ...@@ -51,16 +53,16 @@ BluetoothGATTCharacteristic* BluetoothGATTCharacteristic::take(ScriptPromiseReso
} }
void BluetoothGATTCharacteristic::setValue( void BluetoothGATTCharacteristic::setValue(
const PassRefPtr<DOMArrayBuffer>& domBuffer) const PassRefPtr<DOMDataView>& domDataView)
{ {
m_value = domBuffer; m_value = domDataView;
} }
void BluetoothGATTCharacteristic::dispatchCharacteristicValueChanged( void BluetoothGATTCharacteristic::dispatchCharacteristicValueChanged(
const WebVector<uint8_t>& value) const WebVector<uint8_t>& value)
{ {
RefPtr<DOMArrayBuffer> domBuffer = ConvertWebVectorToArrayBuffer(value); RefPtr<DOMDataView> domDataView = ConvertWebVectorToDataView(value);
this->setValue(domBuffer); this->setValue(domDataView);
dispatchEvent(Event::create(EventTypeNames::characteristicvaluechanged)); dispatchEvent(Event::create(EventTypeNames::characteristicvaluechanged));
} }
...@@ -113,11 +115,11 @@ public: ...@@ -113,11 +115,11 @@ public:
if (!m_resolver->executionContext() || m_resolver->executionContext()->activeDOMObjectsAreStopped()) if (!m_resolver->executionContext() || m_resolver->executionContext()->activeDOMObjectsAreStopped())
return; return;
RefPtr<DOMArrayBuffer> domBuffer = ConvertWebVectorToArrayBuffer(value); RefPtr<DOMDataView> domDataView = ConvertWebVectorToDataView(value);
if (m_webCharacteristic) { if (m_webCharacteristic) {
m_webCharacteristic->setValue(domBuffer); m_webCharacteristic->setValue(domDataView);
} }
m_resolver->resolve(domBuffer); m_resolver->resolve(domDataView);
} }
void onError(const WebBluetoothError& e) override void onError(const WebBluetoothError& e) override
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "bindings/core/v8/ScriptWrappable.h" #include "bindings/core/v8/ScriptWrappable.h"
#include "core/dom/ActiveDOMObject.h" #include "core/dom/ActiveDOMObject.h"
#include "core/dom/DOMArrayPiece.h" #include "core/dom/DOMArrayPiece.h"
#include "core/dom/DOMDataView.h"
#include "modules/EventTargetModules.h" #include "modules/EventTargetModules.h"
#include "platform/heap/Handle.h" #include "platform/heap/Handle.h"
#include "public/platform/modules/bluetooth/WebBluetoothGATTCharacteristic.h" #include "public/platform/modules/bluetooth/WebBluetoothGATTCharacteristic.h"
...@@ -48,7 +49,7 @@ public: ...@@ -48,7 +49,7 @@ public:
static BluetoothGATTCharacteristic* take(ScriptPromiseResolver*, PassOwnPtr<WebBluetoothGATTCharacteristicInit>); static BluetoothGATTCharacteristic* take(ScriptPromiseResolver*, PassOwnPtr<WebBluetoothGATTCharacteristicInit>);
// Save value. // Save value.
void setValue(const PassRefPtr<DOMArrayBuffer>&); void setValue(const PassRefPtr<DOMDataView>&);
// WebBluetoothGATTCharacteristic interface: // WebBluetoothGATTCharacteristic interface:
void dispatchCharacteristicValueChanged(const WebVector<uint8_t>&) override; void dispatchCharacteristicValueChanged(const WebVector<uint8_t>&) override;
...@@ -75,7 +76,7 @@ public: ...@@ -75,7 +76,7 @@ public:
String uuid() { return m_webCharacteristic->uuid; } String uuid() { return m_webCharacteristic->uuid; }
BluetoothCharacteristicProperties* properties() { return m_properties; } BluetoothCharacteristicProperties* properties() { return m_properties; }
PassRefPtr<DOMArrayBuffer> value() const { return m_value; } PassRefPtr<DOMDataView> value() const { return m_value; }
ScriptPromise readValue(ScriptState*); ScriptPromise readValue(ScriptState*);
ScriptPromise writeValue(ScriptState*, const DOMArrayPiece&); ScriptPromise writeValue(ScriptState*, const DOMArrayPiece&);
ScriptPromise startNotifications(ScriptState*); ScriptPromise startNotifications(ScriptState*);
...@@ -91,7 +92,7 @@ private: ...@@ -91,7 +92,7 @@ private:
OwnPtr<WebBluetoothGATTCharacteristicInit> m_webCharacteristic; OwnPtr<WebBluetoothGATTCharacteristicInit> m_webCharacteristic;
bool m_stopped; bool m_stopped;
Member<BluetoothCharacteristicProperties> m_properties; Member<BluetoothCharacteristicProperties> m_properties;
RefPtr<DOMArrayBuffer> m_value; RefPtr<DOMDataView> m_value;
}; };
} // namespace blink } // namespace blink
......
...@@ -14,12 +14,12 @@ ...@@ -14,12 +14,12 @@
// TODO(ortuno): Add test to make sure service matches the service // TODO(ortuno): Add test to make sure service matches the service
// used to call getCharacteristic. // used to call getCharacteristic.
// readonly attribute BluetoothGATTService service; // readonly attribute BluetoothGATTService service;
readonly attribute UUID uuid; readonly attribute UUID uuid;
readonly attribute BluetoothCharacteristicProperties properties; readonly attribute BluetoothCharacteristicProperties properties;
readonly attribute ArrayBuffer? value; readonly attribute DataView? value;
// Promise<BluetoothGATTDescriptor> getDescriptor(BluetoothDescriptorUUID descriptor); // Promise<BluetoothGATTDescriptor> getDescriptor(BluetoothDescriptorUUID descriptor);
// Promise<sequence<BluetoothGATTDescriptor>> getDescriptors(optional BluetoothDescriptorUUID descriptor); // Promise<sequence<BluetoothGATTDescriptor>> getDescriptors(optional BluetoothDescriptorUUID descriptor);
[CallWith=ScriptState] Promise<ArrayBuffer> readValue(); [CallWith=ScriptState] Promise<DataView> readValue();
[CallWith=ScriptState] Promise<void> writeValue(BufferSource value); [CallWith=ScriptState] Promise<void> writeValue(BufferSource value);
[CallWith=ScriptState] Promise<void> startNotifications(); [CallWith=ScriptState] Promise<void> startNotifications();
[CallWith=ScriptState] Promise<void> stopNotifications(); [CallWith=ScriptState] Promise<void> stopNotifications();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment