Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(976)

Unified Diff: third_party/WebKit/Source/modules/bluetooth/BluetoothGATTCharacteristic.cpp

Issue 1382743002: bluetooth: Add characteristicvaluechanged event (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-notifications-1
Patch Set: Address tkent's comments Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..16a629b7e33362b1c11a8f62d432a3c239f1c70f 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,27 @@ 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)
+{
+ // We will also need to unregister a characteristic once all the event
+ // listeners have been removed. See http://crbug.com/541390
+ 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 +141,7 @@ ScriptPromise BluetoothGATTCharacteristic::stopNotifications(ScriptState* script
DEFINE_TRACE(BluetoothGATTCharacteristic)
{
+ RefCountedGarbageCollectedEventTargetWithInlineData<BluetoothGATTCharacteristic>::trace(visitor);
ActiveDOMObject::trace(visitor);
}

Powered by Google App Engine
This is Rietveld 408576698