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 7b0ca8417590b8d35387157534636191a690f71c..6e440a8a0375c50ddbc5f70f9cbcda4141280114 100644 |
--- a/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTCharacteristic.cpp |
+++ b/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTCharacteristic.cpp |
@@ -17,17 +17,42 @@ |
namespace blink { |
-BluetoothGATTCharacteristic::BluetoothGATTCharacteristic(PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic) |
- : m_webCharacteristic(webCharacteristic) |
+BluetoothGATTCharacteristic::BluetoothGATTCharacteristic(ExecutionContext* context, PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic) |
+ : ActiveDOMObject(context) |
+ , m_webCharacteristic(webCharacteristic) |
haraken
2015/10/10 14:19:35
Shall we initialize m_stopped in the constructor?
ortuno
2015/10/12 17:46:07
Done.
|
{ |
+ // See example in Source/platform/heap/ThreadState.h |
+ ThreadState::current()->registerPreFinalizer(this); |
} |
-BluetoothGATTCharacteristic* BluetoothGATTCharacteristic::take(ScriptPromiseResolver*, PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic) |
+BluetoothGATTCharacteristic* BluetoothGATTCharacteristic::take(ScriptPromiseResolver* resolver, PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic) |
{ |
if (!webCharacteristic) { |
return nullptr; |
} |
- return new BluetoothGATTCharacteristic(webCharacteristic); |
+ BluetoothGATTCharacteristic* characteristic = new BluetoothGATTCharacteristic(resolver->executionContext(), webCharacteristic); |
+ // See note in ActiveDOMObject about suspendIfNeeded. |
+ characteristic->suspendIfNeeded(); |
+ return characteristic; |
+} |
+ |
+void BluetoothGATTCharacteristic::stop() |
+{ |
+ notifyCharacteristicObjectRemoved(); |
+} |
+ |
+void BluetoothGATTCharacteristic::dispose() |
+{ |
+ notifyCharacteristicObjectRemoved(); |
+} |
+ |
+void BluetoothGATTCharacteristic::notifyCharacteristicObjectRemoved() |
+{ |
+ if (!m_stopped) { |
+ m_stopped = true; |
+ WebBluetooth* webbluetooth = BluetoothSupplement::getFromExecutionContext(ActiveDOMObject::executionContext()); |
+ webbluetooth->characteristicObjectRemoved(m_webCharacteristic->characteristicInstanceID, this); |
+ } |
} |
ScriptPromise BluetoothGATTCharacteristic::readValue(ScriptState* scriptState) |
@@ -63,4 +88,27 @@ ScriptPromise BluetoothGATTCharacteristic::writeValue(ScriptState* scriptState, |
return promise; |
} |
+ScriptPromise BluetoothGATTCharacteristic::startNotifications(ScriptState* scriptState) |
+{ |
+ WebBluetooth* webbluetooth = BluetoothSupplement::getFromScriptState(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::getFromScriptState(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 |