| 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 : SuspendableObject(context), | 47 : ContextLifecycleObserver(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 } | 53 } |
| 54 | 54 |
| 55 BluetoothRemoteGATTCharacteristic* BluetoothRemoteGATTCharacteristic::create( | 55 BluetoothRemoteGATTCharacteristic* BluetoothRemoteGATTCharacteristic::create( |
| 56 ExecutionContext* context, | 56 ExecutionContext* context, |
| 57 std::unique_ptr<WebBluetoothRemoteGATTCharacteristicInit> webCharacteristic, | 57 std::unique_ptr<WebBluetoothRemoteGATTCharacteristicInit> webCharacteristic, |
| 58 BluetoothRemoteGATTService* service) { | 58 BluetoothRemoteGATTService* service) { |
| 59 DCHECK(webCharacteristic); | 59 DCHECK(webCharacteristic); |
| 60 | 60 |
| 61 BluetoothRemoteGATTCharacteristic* characteristic = | 61 return new BluetoothRemoteGATTCharacteristic( |
| 62 new BluetoothRemoteGATTCharacteristic( | 62 context, std::move(webCharacteristic), service); |
| 63 context, std::move(webCharacteristic), service); | |
| 64 // See note in SuspendableObject about suspendIfNeeded. | |
| 65 characteristic->suspendIfNeeded(); | |
| 66 return characteristic; | |
| 67 } | 63 } |
| 68 | 64 |
| 69 void BluetoothRemoteGATTCharacteristic::setValue(DOMDataView* domDataView) { | 65 void BluetoothRemoteGATTCharacteristic::setValue(DOMDataView* domDataView) { |
| 70 m_value = domDataView; | 66 m_value = domDataView; |
| 71 } | 67 } |
| 72 | 68 |
| 73 void BluetoothRemoteGATTCharacteristic::dispatchCharacteristicValueChanged( | 69 void BluetoothRemoteGATTCharacteristic::dispatchCharacteristicValueChanged( |
| 74 const WebVector<uint8_t>& value) { | 70 const WebVector<uint8_t>& value) { |
| 75 this->setValue(ConvertWebVectorToDataView(value)); | 71 this->setValue(ConvertWebVectorToDataView(value)); |
| 76 dispatchEvent(Event::create(EventTypeNames::characteristicvaluechanged)); | 72 dispatchEvent(Event::create(EventTypeNames::characteristicvaluechanged)); |
| 77 } | 73 } |
| 78 | 74 |
| 79 void BluetoothRemoteGATTCharacteristic::contextDestroyed() { | 75 void BluetoothRemoteGATTCharacteristic::contextDestroyed() { |
| 80 notifyCharacteristicObjectRemoved(); | 76 notifyCharacteristicObjectRemoved(); |
| 81 } | 77 } |
| 82 | 78 |
| 83 void BluetoothRemoteGATTCharacteristic::dispose() { | 79 void BluetoothRemoteGATTCharacteristic::dispose() { |
| 84 notifyCharacteristicObjectRemoved(); | 80 notifyCharacteristicObjectRemoved(); |
| 85 } | 81 } |
| 86 | 82 |
| 87 void BluetoothRemoteGATTCharacteristic::notifyCharacteristicObjectRemoved() { | 83 void BluetoothRemoteGATTCharacteristic::notifyCharacteristicObjectRemoved() { |
| 88 if (!m_stopped) { | 84 if (!m_stopped) { |
| 89 m_stopped = true; | 85 m_stopped = true; |
| 90 WebBluetooth* webbluetooth = BluetoothSupplement::fromExecutionContext( | 86 WebBluetooth* webbluetooth = BluetoothSupplement::fromExecutionContext( |
| 91 SuspendableObject::getExecutionContext()); | 87 ContextLifecycleObserver::getExecutionContext()); |
| 92 webbluetooth->characteristicObjectRemoved( | 88 webbluetooth->characteristicObjectRemoved( |
| 93 m_webCharacteristic->characteristicInstanceID, this); | 89 m_webCharacteristic->characteristicInstanceID, this); |
| 94 } | 90 } |
| 95 } | 91 } |
| 96 | 92 |
| 97 const WTF::AtomicString& BluetoothRemoteGATTCharacteristic::interfaceName() | 93 const WTF::AtomicString& BluetoothRemoteGATTCharacteristic::interfaceName() |
| 98 const { | 94 const { |
| 99 return EventTargetNames::BluetoothRemoteGATTCharacteristic; | 95 return EventTargetNames::BluetoothRemoteGATTCharacteristic; |
| 100 } | 96 } |
| 101 | 97 |
| 102 ExecutionContext* BluetoothRemoteGATTCharacteristic::getExecutionContext() | 98 ExecutionContext* BluetoothRemoteGATTCharacteristic::getExecutionContext() |
| 103 const { | 99 const { |
| 104 return SuspendableObject::getExecutionContext(); | 100 return ContextLifecycleObserver::getExecutionContext(); |
| 105 } | 101 } |
| 106 | 102 |
| 107 void BluetoothRemoteGATTCharacteristic::addedEventListener( | 103 void BluetoothRemoteGATTCharacteristic::addedEventListener( |
| 108 const AtomicString& eventType, | 104 const AtomicString& eventType, |
| 109 RegisteredEventListener& registeredListener) { | 105 RegisteredEventListener& registeredListener) { |
| 110 EventTargetWithInlineData::addedEventListener(eventType, registeredListener); | 106 EventTargetWithInlineData::addedEventListener(eventType, registeredListener); |
| 111 // We will also need to unregister a characteristic once all the event | 107 // We will also need to unregister a characteristic once all the event |
| 112 // listeners have been removed. See http://crbug.com/541390 | 108 // listeners have been removed. See http://crbug.com/541390 |
| 113 if (eventType == EventTypeNames::characteristicvaluechanged) { | 109 if (eventType == EventTypeNames::characteristicvaluechanged) { |
| 114 WebBluetooth* webbluetooth = | 110 WebBluetooth* webbluetooth = |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 webbluetooth->stopNotifications(m_webCharacteristic->characteristicInstanceID, | 382 webbluetooth->stopNotifications(m_webCharacteristic->characteristicInstanceID, |
| 387 new NotificationsCallback(this, resolver)); | 383 new NotificationsCallback(this, resolver)); |
| 388 return promise; | 384 return promise; |
| 389 } | 385 } |
| 390 | 386 |
| 391 DEFINE_TRACE(BluetoothRemoteGATTCharacteristic) { | 387 DEFINE_TRACE(BluetoothRemoteGATTCharacteristic) { |
| 392 visitor->trace(m_service); | 388 visitor->trace(m_service); |
| 393 visitor->trace(m_properties); | 389 visitor->trace(m_properties); |
| 394 visitor->trace(m_value); | 390 visitor->trace(m_value); |
| 395 EventTargetWithInlineData::trace(visitor); | 391 EventTargetWithInlineData::trace(visitor); |
| 396 SuspendableObject::trace(visitor); | 392 ContextLifecycleObserver::trace(visitor); |
| 397 } | 393 } |
| 398 | 394 |
| 399 } // namespace blink | 395 } // namespace blink |
| OLD | NEW |