| Index: third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.cpp
|
| diff --git a/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.cpp b/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.cpp
|
| index 44d46662c83803a736b5d14599f86a61d7b0317d..6f062601b964d5aa19e117a233e6dd5e57d8442f 100644
|
| --- a/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.cpp
|
| +++ b/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.cpp
|
| @@ -31,8 +31,8 @@ BluetoothRemoteGATTCharacteristic::BluetoothRemoteGATTCharacteristic(
|
| : ContextLifecycleObserver(context),
|
| m_characteristic(std::move(characteristic)),
|
| m_service(service),
|
| - m_stopped(false),
|
| - m_device(device) {
|
| + m_device(device),
|
| + m_clientBinding(this) {
|
| m_properties =
|
| BluetoothCharacteristicProperties::create(m_characteristic->properties);
|
| }
|
| @@ -50,8 +50,8 @@ void BluetoothRemoteGATTCharacteristic::setValue(DOMDataView* domDataView) {
|
| m_value = domDataView;
|
| }
|
|
|
| -void BluetoothRemoteGATTCharacteristic::dispatchCharacteristicValueChanged(
|
| - const Vector<uint8_t>& value) {
|
| +void BluetoothRemoteGATTCharacteristic::RemoteCharacteristicValueChanged(
|
| + const WTF::Vector<uint8_t>& value) {
|
| if (!getGatt()->connected())
|
| return;
|
| this->setValue(BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value));
|
| @@ -59,19 +59,12 @@ void BluetoothRemoteGATTCharacteristic::dispatchCharacteristicValueChanged(
|
| }
|
|
|
| void BluetoothRemoteGATTCharacteristic::contextDestroyed(ExecutionContext*) {
|
| - notifyCharacteristicObjectRemoved();
|
| + dispose();
|
| }
|
|
|
| void BluetoothRemoteGATTCharacteristic::dispose() {
|
| - notifyCharacteristicObjectRemoved();
|
| -}
|
| -
|
| -void BluetoothRemoteGATTCharacteristic::notifyCharacteristicObjectRemoved() {
|
| - if (!m_stopped) {
|
| - m_stopped = true;
|
| - m_device->bluetooth()->characteristicObjectRemoved(
|
| - m_characteristic->instance_id);
|
| - }
|
| + if (m_clientBinding.is_bound())
|
| + m_clientBinding.Close();
|
| }
|
|
|
| const WTF::AtomicString& BluetoothRemoteGATTCharacteristic::interfaceName()
|
| @@ -88,12 +81,6 @@ void BluetoothRemoteGATTCharacteristic::addedEventListener(
|
| const AtomicString& eventType,
|
| RegisteredEventListener& registeredListener) {
|
| EventTargetWithInlineData::addedEventListener(eventType, registeredListener);
|
| - // We will also need to unregister a characteristic once all the event
|
| - // listeners have been removed. See http://crbug.com/541390
|
| - if (eventType == EventTypeNames::characteristicvaluechanged) {
|
| - m_device->bluetooth()->registerCharacteristicObject(
|
| - m_characteristic->instance_id, this);
|
| - }
|
| }
|
|
|
| void BluetoothRemoteGATTCharacteristic::ReadValueCallback(
|
| @@ -116,6 +103,7 @@ void BluetoothRemoteGATTCharacteristic::ReadValueCallback(
|
| DOMDataView* domDataView =
|
| BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value.value());
|
| setValue(domDataView);
|
| + dispatchEvent(Event::create(EventTypeNames::characteristicvaluechanged));
|
| resolver->resolve(domDataView);
|
| } else {
|
| resolver->reject(BluetoothError::createDOMException(result));
|
| @@ -219,7 +207,8 @@ ScriptPromise BluetoothRemoteGATTCharacteristic::writeValue(
|
|
|
| void BluetoothRemoteGATTCharacteristic::NotificationsCallback(
|
| ScriptPromiseResolver* resolver,
|
| - mojom::blink::WebBluetoothResult result) {
|
| + mojom::blink::WebBluetoothResult result,
|
| + mojom::blink::WebBluetoothCharacteristicClientAssociatedRequest request) {
|
| if (!resolver->getExecutionContext() ||
|
| resolver->getExecutionContext()->isContextDestroyed())
|
| return;
|
| @@ -232,6 +221,8 @@ void BluetoothRemoteGATTCharacteristic::NotificationsCallback(
|
| }
|
|
|
| if (result == mojom::blink::WebBluetoothResult::SUCCESS) {
|
| + if (request.is_pending())
|
| + m_clientBinding.Bind(std::move(request));
|
| resolver->resolve(this);
|
| } else {
|
| resolver->reject(BluetoothError::createDOMException(result));
|
| @@ -290,7 +281,7 @@ ScriptPromise BluetoothRemoteGATTCharacteristic::stopNotifications(
|
| convertToBaseCallback(
|
| WTF::bind(&BluetoothRemoteGATTCharacteristic::NotificationsCallback,
|
| wrapPersistent(this), wrapPersistent(resolver),
|
| - mojom::blink::WebBluetoothResult::SUCCESS)));
|
| + mojom::blink::WebBluetoothResult::SUCCESS, nullptr)));
|
| return promise;
|
| }
|
|
|
|
|