Chromium Code Reviews| 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..724b137e3e932903cb6d5b441d4ad54a17325036 100644 |
| --- a/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTCharacteristic.cpp |
| +++ b/third_party/WebKit/Source/modules/bluetooth/BluetoothGATTCharacteristic.cpp |
| @@ -17,17 +17,38 @@ |
| 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(); |
|
haraken
2015/10/07 01:22:33
Nit: Can we move suspendIfNeeded() into the take m
ortuno
2015/10/07 17:03:55
Done. Is there any reason for that? I see a couple
|
| + // 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); |
| + return new BluetoothGATTCharacteristic(resolver->executionContext(), webCharacteristic); |
| +} |
| + |
| +void BluetoothGATTCharacteristic::stop() |
| +{ |
| + m_stopped = true; |
| + WebBluetooth* webbluetooth = BluetoothSupplement::from(ActiveDOMObject::executionContext()); |
| + webbluetooth->characteristicObjectRemoved(m_webCharacteristic->characteristicInstanceID, this); |
| +} |
| + |
| +void BluetoothGATTCharacteristic::dispose() |
| +{ |
| + // stop gets called when the parent document is detached so no need to call |
| + // again. |
|
haraken
2015/10/07 01:22:33
Is this comment correct? If the parent document is
ortuno
2015/10/07 17:03:55
Moved things around a bit to make our intention cl
|
| + if (!m_stopped) { |
| + stop(); |
| + } |
| } |
| ScriptPromise BluetoothGATTCharacteristic::readValue(ScriptState* scriptState) |
| @@ -63,4 +84,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 |