Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "modules/bluetooth/BluetoothGATTCharacteristic.h" | 6 #include "modules/bluetooth/BluetoothGATTCharacteristic.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 8 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 9 #include "bindings/core/v8/ScriptPromise.h" | 9 #include "bindings/core/v8/ScriptPromise.h" |
| 10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 11 #include "core/dom/DOMException.h" | 11 #include "core/dom/DOMException.h" |
| 12 #include "core/dom/ExceptionCode.h" | 12 #include "core/dom/ExceptionCode.h" |
| 13 #include "modules/bluetooth/BluetoothError.h" | 13 #include "modules/bluetooth/BluetoothError.h" |
| 14 #include "modules/bluetooth/BluetoothSupplement.h" | 14 #include "modules/bluetooth/BluetoothSupplement.h" |
| 15 #include "modules/bluetooth/ConvertWebVectorToArrayBuffer.h" | 15 #include "modules/bluetooth/ConvertWebVectorToArrayBuffer.h" |
| 16 #include "public/platform/modules/bluetooth/WebBluetooth.h" | 16 #include "public/platform/modules/bluetooth/WebBluetooth.h" |
| 17 | 17 |
| 18 namespace blink { | 18 namespace blink { |
| 19 | 19 |
| 20 BluetoothGATTCharacteristic::BluetoothGATTCharacteristic(PassOwnPtr<WebBluetooth GATTCharacteristicInit> webCharacteristic) | 20 BluetoothGATTCharacteristic::BluetoothGATTCharacteristic(ExecutionContext* conte xt, PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic) |
| 21 : m_webCharacteristic(webCharacteristic) | 21 : ActiveDOMObject(context) |
| 22 , 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.
| |
| 22 { | 23 { |
| 24 // See example in Source/platform/heap/ThreadState.h | |
| 25 ThreadState::current()->registerPreFinalizer(this); | |
| 23 } | 26 } |
| 24 | 27 |
| 25 BluetoothGATTCharacteristic* BluetoothGATTCharacteristic::take(ScriptPromiseReso lver*, PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic) | 28 BluetoothGATTCharacteristic* BluetoothGATTCharacteristic::take(ScriptPromiseReso lver* resolver, PassOwnPtr<WebBluetoothGATTCharacteristicInit> webCharacteristic ) |
| 26 { | 29 { |
| 27 if (!webCharacteristic) { | 30 if (!webCharacteristic) { |
| 28 return nullptr; | 31 return nullptr; |
| 29 } | 32 } |
| 30 return new BluetoothGATTCharacteristic(webCharacteristic); | 33 BluetoothGATTCharacteristic* characteristic = new BluetoothGATTCharacteristi c(resolver->executionContext(), webCharacteristic); |
| 34 // See note in ActiveDOMObject about suspendIfNeeded. | |
| 35 characteristic->suspendIfNeeded(); | |
| 36 return characteristic; | |
| 37 } | |
| 38 | |
| 39 void BluetoothGATTCharacteristic::stop() | |
| 40 { | |
| 41 notifyCharacteristicObjectRemoved(); | |
| 42 } | |
| 43 | |
| 44 void BluetoothGATTCharacteristic::dispose() | |
| 45 { | |
| 46 notifyCharacteristicObjectRemoved(); | |
| 47 } | |
| 48 | |
| 49 void BluetoothGATTCharacteristic::notifyCharacteristicObjectRemoved() | |
| 50 { | |
| 51 if (!m_stopped) { | |
| 52 m_stopped = true; | |
| 53 WebBluetooth* webbluetooth = BluetoothSupplement::getFromExecutionContex t(ActiveDOMObject::executionContext()); | |
| 54 webbluetooth->characteristicObjectRemoved(m_webCharacteristic->character isticInstanceID, this); | |
| 55 } | |
| 31 } | 56 } |
| 32 | 57 |
| 33 ScriptPromise BluetoothGATTCharacteristic::readValue(ScriptState* scriptState) | 58 ScriptPromise BluetoothGATTCharacteristic::readValue(ScriptState* scriptState) |
| 34 { | 59 { |
| 35 WebBluetooth* webbluetooth = BluetoothSupplement::getFromScriptState(scriptS tate); | 60 WebBluetooth* webbluetooth = BluetoothSupplement::getFromScriptState(scriptS tate); |
| 36 | 61 |
| 37 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | 62 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; |
| 38 ScriptPromise promise = resolver->promise(); | 63 ScriptPromise promise = resolver->promise(); |
| 39 webbluetooth->readValue(m_webCharacteristic->characteristicInstanceID, new C allbackPromiseAdapter<ConvertWebVectorToArrayBuffer, BluetoothError>(resolver)); | 64 webbluetooth->readValue(m_webCharacteristic->characteristicInstanceID, new C allbackPromiseAdapter<ConvertWebVectorToArrayBuffer, BluetoothError>(resolver)); |
| 40 | 65 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 56 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidModificationError, "Value can't exceed 512 bytes.")); | 81 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidModificationError, "Value can't exceed 512 bytes.")); |
| 57 | 82 |
| 58 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | 83 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; |
| 59 | 84 |
| 60 ScriptPromise promise = resolver->promise(); | 85 ScriptPromise promise = resolver->promise(); |
| 61 webbluetooth->writeValue(m_webCharacteristic->characteristicInstanceID, valu eVector, new CallbackPromiseAdapter<void, BluetoothError>(resolver)); | 86 webbluetooth->writeValue(m_webCharacteristic->characteristicInstanceID, valu eVector, new CallbackPromiseAdapter<void, BluetoothError>(resolver)); |
| 62 | 87 |
| 63 return promise; | 88 return promise; |
| 64 } | 89 } |
| 65 | 90 |
| 91 ScriptPromise BluetoothGATTCharacteristic::startNotifications(ScriptState* scrip tState) | |
| 92 { | |
| 93 WebBluetooth* webbluetooth = BluetoothSupplement::getFromScriptState(scriptS tate); | |
| 94 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | |
| 95 ScriptPromise promise = resolver->promise(); | |
| 96 webbluetooth->startNotifications(m_webCharacteristic->characteristicInstance ID, this, new CallbackPromiseAdapter<void, BluetoothError>(resolver)); | |
| 97 return promise; | |
| 98 } | |
| 99 | |
| 100 ScriptPromise BluetoothGATTCharacteristic::stopNotifications(ScriptState* script State) | |
| 101 { | |
| 102 WebBluetooth* webbluetooth = BluetoothSupplement::getFromScriptState(scriptS tate); | |
| 103 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; | |
| 104 ScriptPromise promise = resolver->promise(); | |
| 105 webbluetooth->stopNotifications(m_webCharacteristic->characteristicInstanceI D, this, new CallbackPromiseAdapter<void, BluetoothError>(resolver)); | |
| 106 return promise; | |
| 107 } | |
| 108 | |
| 109 DEFINE_TRACE(BluetoothGATTCharacteristic) | |
| 110 { | |
| 111 ActiveDOMObject::trace(visitor); | |
| 112 } | |
| 113 | |
| 66 } // namespace blink | 114 } // namespace blink |
| OLD | NEW |