 Chromium Code Reviews
 Chromium Code Reviews Issue 1382743002:
  bluetooth: Add characteristicvaluechanged event  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-notifications-1
    
  
    Issue 1382743002:
  bluetooth: Add characteristicvaluechanged event  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-notifications-1| 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 fa4b8b6581ab760ffa7131cab4118991f958868c..86752af058564593f12ee6cc029675a5030106cc 100644 | 
| --- a/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTCharacteristic.cpp | 
| +++ b/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTCharacteristic.cpp | 
| @@ -10,6 +10,7 @@ | 
| #include "bindings/core/v8/ScriptPromiseResolver.h" | 
| #include "core/dom/DOMException.h" | 
| #include "core/dom/ExceptionCode.h" | 
| +#include "core/events/Event.h" | 
| #include "modules/bluetooth/BluetoothError.h" | 
| #include "modules/bluetooth/BluetoothSupplement.h" | 
| #include "modules/bluetooth/ConvertWebVectorToArrayBuffer.h" | 
| @@ -37,6 +38,16 @@ BluetoothGATTCharacteristic* BluetoothGATTCharacteristic::take(ScriptPromiseReso | 
| return characteristic; | 
| } | 
| +void BluetoothGATTCharacteristic::dispatchCharacteristicValueChanged( | 
| + 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()); | 
| + | 
| + dispatchEvent(Event::create(EventTypeNames::characteristicvaluechanged)); | 
| +} | 
| + | 
| void BluetoothGATTCharacteristic::stop() | 
| { | 
| notifyCharacteristicObjectRemoved(); | 
| @@ -56,6 +67,25 @@ void BluetoothGATTCharacteristic::notifyCharacteristicObjectRemoved() | 
| } | 
| } | 
| +const WTF::AtomicString& BluetoothGATTCharacteristic::interfaceName() const | 
| +{ | 
| + return EventTargetNames::BluetoothGATTCharacteristic; | 
| +} | 
| + | 
| +ExecutionContext* BluetoothGATTCharacteristic::executionContext() const | 
| +{ | 
| + return ActiveDOMObject::executionContext(); | 
| +} | 
| + | 
| +bool BluetoothGATTCharacteristic::addEventListener(const AtomicString& eventType, PassRefPtrWillBeRawPtr<EventListener> listener, bool useCapture) | 
| 
Jeffrey Yasskin
2015/10/15 23:00:51
Presumably we'll also need to unregister on remove
 
ortuno
2015/10/16 01:24:21
Done.
 | 
| +{ | 
| + if (eventType == EventTypeNames::characteristicvaluechanged) { | 
| + WebBluetooth* webbluetooth = BluetoothSupplement::fromExecutionContext(executionContext()); | 
| + webbluetooth->registerCharacteristicObject(m_webCharacteristic->characteristicInstanceID, this); | 
| + } | 
| + return EventTarget::addEventListener(eventType, listener, useCapture); | 
| +} | 
| + | 
| ScriptPromise BluetoothGATTCharacteristic::readValue(ScriptState* scriptState) | 
| { | 
| WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptState); | 
| @@ -109,6 +139,7 @@ ScriptPromise BluetoothGATTCharacteristic::stopNotifications(ScriptState* script | 
| DEFINE_TRACE(BluetoothGATTCharacteristic) | 
| { | 
| + RefCountedGarbageCollectedEventTargetWithInlineData<BluetoothGATTCharacteristic>::trace(visitor); | 
| ActiveDOMObject::trace(visitor); | 
| } |