| 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 "modules/bluetooth/BluetoothRemoteGATTCharacteristic.h" | 5 #include "modules/bluetooth/BluetoothRemoteGATTCharacteristic.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
| 9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 10 #include "core/dom/DOMDataView.h" | 10 #include "core/dom/DOMDataView.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 "core/events/Event.h" | 13 #include "core/events/Event.h" |
| 14 #include "core/inspector/ConsoleMessage.h" | 14 #include "core/inspector/ConsoleMessage.h" |
| 15 #include "modules/bluetooth/BluetoothCharacteristicProperties.h" | 15 #include "modules/bluetooth/BluetoothCharacteristicProperties.h" |
| 16 #include "modules/bluetooth/BluetoothError.h" | 16 #include "modules/bluetooth/BluetoothError.h" |
| 17 #include "modules/bluetooth/BluetoothSupplement.h" | 17 #include "modules/bluetooth/BluetoothSupplement.h" |
| 18 #include "public/platform/modules/bluetooth/WebBluetooth.h" | 18 #include "public/platform/modules/bluetooth/WebBluetooth.h" |
| 19 #include <memory> |
| 19 | 20 |
| 20 namespace blink { | 21 namespace blink { |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 DOMDataView* ConvertWebVectorToDataView(const WebVector<uint8_t>& webVector) | 25 DOMDataView* ConvertWebVectorToDataView(const WebVector<uint8_t>& webVector) |
| 25 { | 26 { |
| 26 static_assert(sizeof(*webVector.data()) == 1, "uint8_t should be a single by
te"); | 27 static_assert(sizeof(*webVector.data()) == 1, "uint8_t should be a single by
te"); |
| 27 DOMArrayBuffer* domBuffer = DOMArrayBuffer::create(webVector.data(), webVect
or.size()); | 28 DOMArrayBuffer* domBuffer = DOMArrayBuffer::create(webVector.data(), webVect
or.size()); |
| 28 return DOMDataView::create(domBuffer, 0, webVector.size()); | 29 return DOMDataView::create(domBuffer, 0, webVector.size()); |
| 29 } | 30 } |
| 30 | 31 |
| 31 } // anonymous namespace | 32 } // anonymous namespace |
| 32 | 33 |
| 33 BluetoothRemoteGATTCharacteristic::BluetoothRemoteGATTCharacteristic(ExecutionCo
ntext* context, PassOwnPtr<WebBluetoothRemoteGATTCharacteristicInit> webCharacte
ristic) | 34 BluetoothRemoteGATTCharacteristic::BluetoothRemoteGATTCharacteristic(ExecutionCo
ntext* context, std::unique_ptr<WebBluetoothRemoteGATTCharacteristicInit> webCha
racteristic) |
| 34 : ActiveDOMObject(context) | 35 : ActiveDOMObject(context) |
| 35 , m_webCharacteristic(std::move(webCharacteristic)) | 36 , m_webCharacteristic(std::move(webCharacteristic)) |
| 36 , m_stopped(false) | 37 , m_stopped(false) |
| 37 { | 38 { |
| 38 m_properties = BluetoothCharacteristicProperties::create(m_webCharacteristic
->characteristicProperties); | 39 m_properties = BluetoothCharacteristicProperties::create(m_webCharacteristic
->characteristicProperties); |
| 39 // See example in Source/platform/heap/ThreadState.h | 40 // See example in Source/platform/heap/ThreadState.h |
| 40 ThreadState::current()->registerPreFinalizer(this); | 41 ThreadState::current()->registerPreFinalizer(this); |
| 41 } | 42 } |
| 42 | 43 |
| 43 BluetoothRemoteGATTCharacteristic* BluetoothRemoteGATTCharacteristic::take(Scrip
tPromiseResolver* resolver, PassOwnPtr<WebBluetoothRemoteGATTCharacteristicInit>
webCharacteristic) | 44 BluetoothRemoteGATTCharacteristic* BluetoothRemoteGATTCharacteristic::take(Scrip
tPromiseResolver* resolver, std::unique_ptr<WebBluetoothRemoteGATTCharacteristic
Init> webCharacteristic) |
| 44 { | 45 { |
| 45 if (!webCharacteristic) { | 46 if (!webCharacteristic) { |
| 46 return nullptr; | 47 return nullptr; |
| 47 } | 48 } |
| 48 BluetoothRemoteGATTCharacteristic* characteristic = new BluetoothRemoteGATTC
haracteristic(resolver->getExecutionContext(), std::move(webCharacteristic)); | 49 BluetoothRemoteGATTCharacteristic* characteristic = new BluetoothRemoteGATTC
haracteristic(resolver->getExecutionContext(), std::move(webCharacteristic)); |
| 49 // See note in ActiveDOMObject about suspendIfNeeded. | 50 // See note in ActiveDOMObject about suspendIfNeeded. |
| 50 characteristic->suspendIfNeeded(); | 51 characteristic->suspendIfNeeded(); |
| 51 return characteristic; | 52 return characteristic; |
| 52 } | 53 } |
| 53 | 54 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 242 |
| 242 DEFINE_TRACE(BluetoothRemoteGATTCharacteristic) | 243 DEFINE_TRACE(BluetoothRemoteGATTCharacteristic) |
| 243 { | 244 { |
| 244 visitor->trace(m_properties); | 245 visitor->trace(m_properties); |
| 245 visitor->trace(m_value); | 246 visitor->trace(m_value); |
| 246 EventTargetWithInlineData::trace(visitor); | 247 EventTargetWithInlineData::trace(visitor); |
| 247 ActiveDOMObject::trace(visitor); | 248 ActiveDOMObject::trace(visitor); |
| 248 } | 249 } |
| 249 | 250 |
| 250 } // namespace blink | 251 } // namespace blink |
| OLD | NEW |