| 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 ScriptPromiseResolver* resolver) | 126 ScriptPromiseResolver* resolver) |
| 127 : m_characteristic(characteristic), m_resolver(resolver) { | 127 : m_characteristic(characteristic), m_resolver(resolver) { |
| 128 // We always check that the device is connected before constructing this | 128 // We always check that the device is connected before constructing this |
| 129 // object. | 129 // object. |
| 130 CHECK(m_characteristic->gatt()->connected()); | 130 CHECK(m_characteristic->gatt()->connected()); |
| 131 m_characteristic->gatt()->AddToActiveAlgorithms(m_resolver.get()); | 131 m_characteristic->gatt()->AddToActiveAlgorithms(m_resolver.get()); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void onSuccess(const WebVector<uint8_t>& value) override { | 134 void onSuccess(const WebVector<uint8_t>& value) override { |
| 135 if (!m_resolver->getExecutionContext() || | 135 if (!m_resolver->getExecutionContext() || |
| 136 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped()) | 136 m_resolver->getExecutionContext()->isContextDestroyed()) |
| 137 return; | 137 return; |
| 138 | 138 |
| 139 if (!m_characteristic->gatt()->RemoveFromActiveAlgorithms( | 139 if (!m_characteristic->gatt()->RemoveFromActiveAlgorithms( |
| 140 m_resolver.get())) { | 140 m_resolver.get())) { |
| 141 m_resolver->reject( | 141 m_resolver->reject( |
| 142 DOMException::create(NetworkError, kGATTServerDisconnected)); | 142 DOMException::create(NetworkError, kGATTServerDisconnected)); |
| 143 return; | 143 return; |
| 144 } | 144 } |
| 145 | 145 |
| 146 DOMDataView* domDataView = ConvertWebVectorToDataView(value); | 146 DOMDataView* domDataView = ConvertWebVectorToDataView(value); |
| 147 if (m_characteristic) | 147 if (m_characteristic) |
| 148 m_characteristic->setValue(domDataView); | 148 m_characteristic->setValue(domDataView); |
| 149 | 149 |
| 150 m_resolver->resolve(domDataView); | 150 m_resolver->resolve(domDataView); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void onError( | 153 void onError( |
| 154 int32_t | 154 int32_t |
| 155 error /* Corresponds to WebBluetoothResult in web_bluetooth.mojom */) | 155 error /* Corresponds to WebBluetoothResult in web_bluetooth.mojom */) |
| 156 override { | 156 override { |
| 157 if (!m_resolver->getExecutionContext() || | 157 if (!m_resolver->getExecutionContext() || |
| 158 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped()) | 158 m_resolver->getExecutionContext()->isContextDestroyed()) |
| 159 return; | 159 return; |
| 160 | 160 |
| 161 if (!m_characteristic->gatt()->RemoveFromActiveAlgorithms( | 161 if (!m_characteristic->gatt()->RemoveFromActiveAlgorithms( |
| 162 m_resolver.get())) { | 162 m_resolver.get())) { |
| 163 m_resolver->reject( | 163 m_resolver->reject( |
| 164 DOMException::create(NetworkError, kGATTServerDisconnected)); | 164 DOMException::create(NetworkError, kGATTServerDisconnected)); |
| 165 return; | 165 return; |
| 166 } | 166 } |
| 167 | 167 |
| 168 m_resolver->reject(BluetoothError::take(m_resolver, error)); | 168 m_resolver->reject(BluetoothError::take(m_resolver, error)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 ScriptPromiseResolver* resolver) | 205 ScriptPromiseResolver* resolver) |
| 206 : m_characteristic(characteristic), m_resolver(resolver) { | 206 : m_characteristic(characteristic), m_resolver(resolver) { |
| 207 // We always check that the device is connected before constructing this | 207 // We always check that the device is connected before constructing this |
| 208 // object. | 208 // object. |
| 209 CHECK(m_characteristic->gatt()->connected()); | 209 CHECK(m_characteristic->gatt()->connected()); |
| 210 m_characteristic->gatt()->AddToActiveAlgorithms(m_resolver.get()); | 210 m_characteristic->gatt()->AddToActiveAlgorithms(m_resolver.get()); |
| 211 } | 211 } |
| 212 | 212 |
| 213 void onSuccess(const WebVector<uint8_t>& value) override { | 213 void onSuccess(const WebVector<uint8_t>& value) override { |
| 214 if (!m_resolver->getExecutionContext() || | 214 if (!m_resolver->getExecutionContext() || |
| 215 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped()) | 215 m_resolver->getExecutionContext()->isContextDestroyed()) |
| 216 return; | 216 return; |
| 217 | 217 |
| 218 if (!m_characteristic->gatt()->RemoveFromActiveAlgorithms( | 218 if (!m_characteristic->gatt()->RemoveFromActiveAlgorithms( |
| 219 m_resolver.get())) { | 219 m_resolver.get())) { |
| 220 m_resolver->reject( | 220 m_resolver->reject( |
| 221 DOMException::create(NetworkError, kGATTServerDisconnected)); | 221 DOMException::create(NetworkError, kGATTServerDisconnected)); |
| 222 return; | 222 return; |
| 223 } | 223 } |
| 224 | 224 |
| 225 if (m_characteristic) { | 225 if (m_characteristic) { |
| 226 m_characteristic->setValue(ConvertWebVectorToDataView(value)); | 226 m_characteristic->setValue(ConvertWebVectorToDataView(value)); |
| 227 } | 227 } |
| 228 m_resolver->resolve(); | 228 m_resolver->resolve(); |
| 229 } | 229 } |
| 230 | 230 |
| 231 void onError( | 231 void onError( |
| 232 int32_t | 232 int32_t |
| 233 error /* Corresponds to WebBluetoothResult in web_bluetooth.mojom */) | 233 error /* Corresponds to WebBluetoothResult in web_bluetooth.mojom */) |
| 234 override { | 234 override { |
| 235 if (!m_resolver->getExecutionContext() || | 235 if (!m_resolver->getExecutionContext() || |
| 236 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped()) | 236 m_resolver->getExecutionContext()->isContextDestroyed()) |
| 237 return; | 237 return; |
| 238 | 238 |
| 239 if (!m_characteristic->gatt()->RemoveFromActiveAlgorithms( | 239 if (!m_characteristic->gatt()->RemoveFromActiveAlgorithms( |
| 240 m_resolver.get())) { | 240 m_resolver.get())) { |
| 241 m_resolver->reject( | 241 m_resolver->reject( |
| 242 DOMException::create(NetworkError, kGATTServerDisconnected)); | 242 DOMException::create(NetworkError, kGATTServerDisconnected)); |
| 243 return; | 243 return; |
| 244 } | 244 } |
| 245 | 245 |
| 246 m_resolver->reject(BluetoothError::take(m_resolver, error)); | 246 m_resolver->reject(BluetoothError::take(m_resolver, error)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 ScriptPromiseResolver* resolver) | 298 ScriptPromiseResolver* resolver) |
| 299 : m_characteristic(characteristic), m_resolver(resolver) { | 299 : m_characteristic(characteristic), m_resolver(resolver) { |
| 300 // We always check that the device is connected before constructing this | 300 // We always check that the device is connected before constructing this |
| 301 // object. | 301 // object. |
| 302 CHECK(m_characteristic->gatt()->connected()); | 302 CHECK(m_characteristic->gatt()->connected()); |
| 303 m_characteristic->gatt()->AddToActiveAlgorithms(m_resolver.get()); | 303 m_characteristic->gatt()->AddToActiveAlgorithms(m_resolver.get()); |
| 304 } | 304 } |
| 305 | 305 |
| 306 void onSuccess() override { | 306 void onSuccess() override { |
| 307 if (!m_resolver->getExecutionContext() || | 307 if (!m_resolver->getExecutionContext() || |
| 308 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped()) | 308 m_resolver->getExecutionContext()->isContextDestroyed()) |
| 309 return; | 309 return; |
| 310 | 310 |
| 311 if (!m_characteristic->gatt()->RemoveFromActiveAlgorithms( | 311 if (!m_characteristic->gatt()->RemoveFromActiveAlgorithms( |
| 312 m_resolver.get())) { | 312 m_resolver.get())) { |
| 313 m_resolver->reject( | 313 m_resolver->reject( |
| 314 DOMException::create(NetworkError, kGATTServerDisconnected)); | 314 DOMException::create(NetworkError, kGATTServerDisconnected)); |
| 315 return; | 315 return; |
| 316 } | 316 } |
| 317 | 317 |
| 318 m_resolver->resolve(m_characteristic); | 318 m_resolver->resolve(m_characteristic); |
| 319 } | 319 } |
| 320 | 320 |
| 321 void onError( | 321 void onError( |
| 322 int32_t | 322 int32_t |
| 323 error /* Corresponds to WebBluetoothResult in web_bluetooth.mojom */) | 323 error /* Corresponds to WebBluetoothResult in web_bluetooth.mojom */) |
| 324 override { | 324 override { |
| 325 if (!m_resolver->getExecutionContext() || | 325 if (!m_resolver->getExecutionContext() || |
| 326 m_resolver->getExecutionContext()->activeDOMObjectsAreStopped()) | 326 m_resolver->getExecutionContext()->isContextDestroyed()) |
| 327 return; | 327 return; |
| 328 | 328 |
| 329 if (!m_characteristic->gatt()->RemoveFromActiveAlgorithms( | 329 if (!m_characteristic->gatt()->RemoveFromActiveAlgorithms( |
| 330 m_resolver.get())) { | 330 m_resolver.get())) { |
| 331 m_resolver->reject( | 331 m_resolver->reject( |
| 332 DOMException::create(NetworkError, kGATTServerDisconnected)); | 332 DOMException::create(NetworkError, kGATTServerDisconnected)); |
| 333 return; | 333 return; |
| 334 } | 334 } |
| 335 | 335 |
| 336 m_resolver->reject(BluetoothError::take(m_resolver, error)); | 336 m_resolver->reject(BluetoothError::take(m_resolver, error)); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 ActiveDOMObject::trace(visitor); |
| 407 } | 407 } |
| 408 | 408 |
| 409 } // namespace blink | 409 } // namespace blink |
| OLD | NEW |