| 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/ScriptPromise.h" | 7 #include "bindings/core/v8/ScriptPromise.h" |
| 8 #include "bindings/core/v8/ScriptPromiseResolver.h" | 8 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 9 #include "core/dom/DOMDataView.h" | 9 #include "core/dom/DOMDataView.h" |
| 10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 DOMArrayBuffer::create(webVector.data(), webVector.size()); | 37 DOMArrayBuffer::create(webVector.data(), webVector.size()); |
| 38 return DOMDataView::create(domBuffer, 0, webVector.size()); | 38 return DOMDataView::create(domBuffer, 0, webVector.size()); |
| 39 } | 39 } |
| 40 | 40 |
| 41 } // anonymous namespace | 41 } // anonymous namespace |
| 42 | 42 |
| 43 BluetoothRemoteGATTCharacteristic::BluetoothRemoteGATTCharacteristic( | 43 BluetoothRemoteGATTCharacteristic::BluetoothRemoteGATTCharacteristic( |
| 44 ExecutionContext* context, | 44 ExecutionContext* context, |
| 45 std::unique_ptr<WebBluetoothRemoteGATTCharacteristicInit> webCharacteristic, | 45 std::unique_ptr<WebBluetoothRemoteGATTCharacteristicInit> webCharacteristic, |
| 46 BluetoothRemoteGATTService* service) | 46 BluetoothRemoteGATTService* service) |
| 47 : ActiveDOMObject(context), | 47 : SuspendableObject(context), |
| 48 m_webCharacteristic(std::move(webCharacteristic)), | 48 m_webCharacteristic(std::move(webCharacteristic)), |
| 49 m_service(service), | 49 m_service(service), |
| 50 m_stopped(false) { | 50 m_stopped(false) { |
| 51 m_properties = BluetoothCharacteristicProperties::create( | 51 m_properties = BluetoothCharacteristicProperties::create( |
| 52 m_webCharacteristic->characteristicProperties); | 52 m_webCharacteristic->characteristicProperties); |
| 53 // See example in Source/platform/heap/ThreadState.h | 53 // See example in Source/platform/heap/ThreadState.h |
| 54 ThreadState::current()->registerPreFinalizer(this); | 54 ThreadState::current()->registerPreFinalizer(this); |
| 55 } | 55 } |
| 56 | 56 |
| 57 BluetoothRemoteGATTCharacteristic* BluetoothRemoteGATTCharacteristic::create( | 57 BluetoothRemoteGATTCharacteristic* BluetoothRemoteGATTCharacteristic::create( |
| 58 ExecutionContext* context, | 58 ExecutionContext* context, |
| 59 std::unique_ptr<WebBluetoothRemoteGATTCharacteristicInit> webCharacteristic, | 59 std::unique_ptr<WebBluetoothRemoteGATTCharacteristicInit> webCharacteristic, |
| 60 BluetoothRemoteGATTService* service) { | 60 BluetoothRemoteGATTService* service) { |
| 61 DCHECK(webCharacteristic); | 61 DCHECK(webCharacteristic); |
| 62 | 62 |
| 63 BluetoothRemoteGATTCharacteristic* characteristic = | 63 BluetoothRemoteGATTCharacteristic* characteristic = |
| 64 new BluetoothRemoteGATTCharacteristic( | 64 new BluetoothRemoteGATTCharacteristic( |
| 65 context, std::move(webCharacteristic), service); | 65 context, std::move(webCharacteristic), service); |
| 66 // See note in ActiveDOMObject about suspendIfNeeded. | 66 // See note in SuspendableObject about suspendIfNeeded. |
| 67 characteristic->suspendIfNeeded(); | 67 characteristic->suspendIfNeeded(); |
| 68 return characteristic; | 68 return characteristic; |
| 69 } | 69 } |
| 70 | 70 |
| 71 void BluetoothRemoteGATTCharacteristic::setValue(DOMDataView* domDataView) { | 71 void BluetoothRemoteGATTCharacteristic::setValue(DOMDataView* domDataView) { |
| 72 m_value = domDataView; | 72 m_value = domDataView; |
| 73 } | 73 } |
| 74 | 74 |
| 75 void BluetoothRemoteGATTCharacteristic::dispatchCharacteristicValueChanged( | 75 void BluetoothRemoteGATTCharacteristic::dispatchCharacteristicValueChanged( |
| 76 const WebVector<uint8_t>& value) { | 76 const WebVector<uint8_t>& value) { |
| 77 this->setValue(ConvertWebVectorToDataView(value)); | 77 this->setValue(ConvertWebVectorToDataView(value)); |
| 78 dispatchEvent(Event::create(EventTypeNames::characteristicvaluechanged)); | 78 dispatchEvent(Event::create(EventTypeNames::characteristicvaluechanged)); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void BluetoothRemoteGATTCharacteristic::contextDestroyed() { | 81 void BluetoothRemoteGATTCharacteristic::contextDestroyed() { |
| 82 notifyCharacteristicObjectRemoved(); | 82 notifyCharacteristicObjectRemoved(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void BluetoothRemoteGATTCharacteristic::dispose() { | 85 void BluetoothRemoteGATTCharacteristic::dispose() { |
| 86 notifyCharacteristicObjectRemoved(); | 86 notifyCharacteristicObjectRemoved(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void BluetoothRemoteGATTCharacteristic::notifyCharacteristicObjectRemoved() { | 89 void BluetoothRemoteGATTCharacteristic::notifyCharacteristicObjectRemoved() { |
| 90 if (!m_stopped) { | 90 if (!m_stopped) { |
| 91 m_stopped = true; | 91 m_stopped = true; |
| 92 WebBluetooth* webbluetooth = BluetoothSupplement::fromExecutionContext( | 92 WebBluetooth* webbluetooth = BluetoothSupplement::fromExecutionContext( |
| 93 ActiveDOMObject::getExecutionContext()); | 93 SuspendableObject::getExecutionContext()); |
| 94 webbluetooth->characteristicObjectRemoved( | 94 webbluetooth->characteristicObjectRemoved( |
| 95 m_webCharacteristic->characteristicInstanceID, this); | 95 m_webCharacteristic->characteristicInstanceID, this); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 | 98 |
| 99 const WTF::AtomicString& BluetoothRemoteGATTCharacteristic::interfaceName() | 99 const WTF::AtomicString& BluetoothRemoteGATTCharacteristic::interfaceName() |
| 100 const { | 100 const { |
| 101 return EventTargetNames::BluetoothRemoteGATTCharacteristic; | 101 return EventTargetNames::BluetoothRemoteGATTCharacteristic; |
| 102 } | 102 } |
| 103 | 103 |
| 104 ExecutionContext* BluetoothRemoteGATTCharacteristic::getExecutionContext() | 104 ExecutionContext* BluetoothRemoteGATTCharacteristic::getExecutionContext() |
| 105 const { | 105 const { |
| 106 return ActiveDOMObject::getExecutionContext(); | 106 return SuspendableObject::getExecutionContext(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void BluetoothRemoteGATTCharacteristic::addedEventListener( | 109 void BluetoothRemoteGATTCharacteristic::addedEventListener( |
| 110 const AtomicString& eventType, | 110 const AtomicString& eventType, |
| 111 RegisteredEventListener& registeredListener) { | 111 RegisteredEventListener& registeredListener) { |
| 112 EventTargetWithInlineData::addedEventListener(eventType, registeredListener); | 112 EventTargetWithInlineData::addedEventListener(eventType, registeredListener); |
| 113 // We will also need to unregister a characteristic once all the event | 113 // We will also need to unregister a characteristic once all the event |
| 114 // listeners have been removed. See http://crbug.com/541390 | 114 // listeners have been removed. See http://crbug.com/541390 |
| 115 if (eventType == EventTypeNames::characteristicvaluechanged) { | 115 if (eventType == EventTypeNames::characteristicvaluechanged) { |
| 116 WebBluetooth* webbluetooth = | 116 WebBluetooth* webbluetooth = |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 webbluetooth->stopNotifications(m_webCharacteristic->characteristicInstanceID, | 396 webbluetooth->stopNotifications(m_webCharacteristic->characteristicInstanceID, |
| 397 new NotificationsCallback(this, resolver)); | 397 new NotificationsCallback(this, resolver)); |
| 398 return promise; | 398 return promise; |
| 399 } | 399 } |
| 400 | 400 |
| 401 DEFINE_TRACE(BluetoothRemoteGATTCharacteristic) { | 401 DEFINE_TRACE(BluetoothRemoteGATTCharacteristic) { |
| 402 visitor->trace(m_service); | 402 visitor->trace(m_service); |
| 403 visitor->trace(m_properties); | 403 visitor->trace(m_properties); |
| 404 visitor->trace(m_value); | 404 visitor->trace(m_value); |
| 405 EventTargetWithInlineData::trace(visitor); | 405 EventTargetWithInlineData::trace(visitor); |
| 406 ActiveDOMObject::trace(visitor); | 406 SuspendableObject::trace(visitor); |
| 407 } | 407 } |
| 408 | 408 |
| 409 } // namespace blink | 409 } // namespace blink |
| OLD | NEW |