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

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

Issue 1334763002: bluetooth: Subscribe to notifications (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-origin
Patch Set: Address jyasskin's comments Created 5 years, 3 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 1627bbf86c6766cfdad4791a89cd64c151f9f436..b06ca3821b70f52051975ba0c6ad0428a38f6bd8 100644
--- a/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTCharacteristic.cpp
+++ b/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTCharacteristic.cpp
@@ -17,17 +17,26 @@
namespace blink {
-BluetoothGATTCharacteristic::BluetoothGATTCharacteristic(PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic)
- : m_webCharacteristic(webCharacteristic)
+BluetoothGATTCharacteristic::BluetoothGATTCharacteristic(ExecutionContext* context, PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic)
+ : ActiveDOMObject(context)
+ , m_webCharacteristic(webCharacteristic)
{
+ // See note in ActiveDOMObject about suspendIfNeeded.
+ suspendIfNeeded();
}
-BluetoothGATTCharacteristic* BluetoothGATTCharacteristic::take(ScriptPromiseResolver*, PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic)
+BluetoothGATTCharacteristic* BluetoothGATTCharacteristic::take(ScriptPromiseResolver* resolver, PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic)
{
if (!webCharacteristic) {
return nullptr;
}
- return new BluetoothGATTCharacteristic(webCharacteristic);
+ return new BluetoothGATTCharacteristic(resolver->executionContext(), webCharacteristic);
+}
+
+void BluetoothGATTCharacteristic::stop()
+{
+ WebBluetooth* webbluetooth = BluetoothSupplement::from(ActiveDOMObject::executionContext());
+ webbluetooth->characteristicObjectRemoved(m_webCharacteristic->characteristicInstanceID, this);
}
ScriptPromise BluetoothGATTCharacteristic::readValue(ScriptState* scriptState)
@@ -63,4 +72,27 @@ ScriptPromise BluetoothGATTCharacteristic::writeValue(ScriptState* scriptState,
return promise;
}
+ScriptPromise BluetoothGATTCharacteristic::startNotifications(ScriptState* scriptState)
+{
+ WebBluetooth* webbluetooth = BluetoothSupplement::from(scriptState);
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
+ ScriptPromise promise = resolver->promise();
+ webbluetooth->startNotifications(m_webCharacteristic->characteristicInstanceID, this, new CallbackPromiseAdapter<void, BluetoothError>(resolver));
+ return promise;
+}
+
+ScriptPromise BluetoothGATTCharacteristic::stopNotifications(ScriptState* scriptState)
+{
+ WebBluetooth* webbluetooth = BluetoothSupplement::from(scriptState);
+ ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
+ ScriptPromise promise = resolver->promise();
+ webbluetooth->stopNotifications(m_webCharacteristic->characteristicInstanceID, this, new CallbackPromiseAdapter<void, BluetoothError>(resolver));
+ return promise;
+}
+
+DEFINE_TRACE(BluetoothGATTCharacteristic)
+{
+ ActiveDOMObject::trace(visitor);
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698