| 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/DOMException.h" |
| 9 #include "core/events/Event.h" | 10 #include "core/events/Event.h" |
| 10 #include "core/inspector/ConsoleMessage.h" | 11 #include "core/inspector/ConsoleMessage.h" |
| 11 #include "modules/bluetooth/Bluetooth.h" | 12 #include "modules/bluetooth/Bluetooth.h" |
| 12 #include "modules/bluetooth/BluetoothCharacteristicProperties.h" | 13 #include "modules/bluetooth/BluetoothCharacteristicProperties.h" |
| 13 #include "modules/bluetooth/BluetoothDevice.h" | 14 #include "modules/bluetooth/BluetoothDevice.h" |
| 14 #include "modules/bluetooth/BluetoothError.h" | 15 #include "modules/bluetooth/BluetoothError.h" |
| 15 #include "modules/bluetooth/BluetoothRemoteGATTDescriptor.h" | 16 #include "modules/bluetooth/BluetoothRemoteGATTDescriptor.h" |
| 16 #include "modules/bluetooth/BluetoothRemoteGATTService.h" | 17 #include "modules/bluetooth/BluetoothRemoteGATTService.h" |
| 17 #include "modules/bluetooth/BluetoothRemoteGATTUtils.h" | 18 #include "modules/bluetooth/BluetoothRemoteGATTUtils.h" |
| 18 #include "modules/bluetooth/BluetoothUUID.h" | 19 #include "modules/bluetooth/BluetoothUUID.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 void BluetoothRemoteGATTCharacteristic::ReadValueCallback( | 99 void BluetoothRemoteGATTCharacteristic::ReadValueCallback( |
| 99 ScriptPromiseResolver* resolver, | 100 ScriptPromiseResolver* resolver, |
| 100 mojom::blink::WebBluetoothResult result, | 101 mojom::blink::WebBluetoothResult result, |
| 101 const Optional<Vector<uint8_t>>& value) { | 102 const Optional<Vector<uint8_t>>& value) { |
| 102 if (!resolver->getExecutionContext() || | 103 if (!resolver->getExecutionContext() || |
| 103 resolver->getExecutionContext()->isContextDestroyed()) | 104 resolver->getExecutionContext()->isContextDestroyed()) |
| 104 return; | 105 return; |
| 105 | 106 |
| 106 // If the device is disconnected, reject. | 107 // If the device is disconnected, reject. |
| 107 if (!getGatt()->RemoveFromActiveAlgorithms(resolver)) { | 108 if (!getGatt()->RemoveFromActiveAlgorithms(resolver)) { |
| 108 resolver->reject(BluetoothRemoteGATTUtils::CreateDOMException( | 109 resolver->reject(BluetoothError::createDOMException( |
| 109 BluetoothRemoteGATTUtils::ExceptionType::kGATTServerDisconnected)); | 110 blink::mojom::WebBluetoothResult::GATT_SERVER_DISCONNECTED)); |
| 110 return; | 111 return; |
| 111 } | 112 } |
| 112 | 113 |
| 113 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { | 114 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { |
| 114 DCHECK(value); | 115 DCHECK(value); |
| 115 DOMDataView* domDataView = | 116 DOMDataView* domDataView = |
| 116 BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value.value()); | 117 BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value.value()); |
| 117 setValue(domDataView); | 118 setValue(domDataView); |
| 118 resolver->resolve(domDataView); | 119 resolver->resolve(domDataView); |
| 119 } else { | 120 } else { |
| 120 resolver->reject(BluetoothError::take(resolver, result)); | 121 resolver->reject(BluetoothError::createDOMException(result)); |
| 121 } | 122 } |
| 122 } | 123 } |
| 123 | 124 |
| 124 ScriptPromise BluetoothRemoteGATTCharacteristic::readValue( | 125 ScriptPromise BluetoothRemoteGATTCharacteristic::readValue( |
| 125 ScriptState* scriptState) { | 126 ScriptState* scriptState) { |
| 126 if (!getGatt()->connected()) { | 127 if (!getGatt()->connected()) { |
| 127 return ScriptPromise::rejectWithDOMException( | 128 return ScriptPromise::rejectWithDOMException( |
| 128 scriptState, | 129 scriptState, |
| 129 BluetoothRemoteGATTUtils::CreateDOMException( | 130 BluetoothError::createDOMException( |
| 130 BluetoothRemoteGATTUtils::ExceptionType::kGATTServerNotConnected)); | 131 blink::mojom::WebBluetoothResult::GATT_SERVER_NOT_CONNECTED)); |
| 131 } | 132 } |
| 132 | 133 |
| 133 if (!getGatt()->device()->isValidCharacteristic( | 134 if (!getGatt()->device()->isValidCharacteristic( |
| 134 m_characteristic->instance_id)) { | 135 m_characteristic->instance_id)) { |
| 135 return ScriptPromise::rejectWithDOMException( | 136 return ScriptPromise::rejectWithDOMException( |
| 136 scriptState, | 137 scriptState, createInvalidCharacteristicError()); |
| 137 BluetoothRemoteGATTUtils::CreateDOMException( | |
| 138 BluetoothRemoteGATTUtils::ExceptionType::kInvalidCharacteristic)); | |
| 139 } | 138 } |
| 140 | 139 |
| 141 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 140 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 142 ScriptPromise promise = resolver->promise(); | 141 ScriptPromise promise = resolver->promise(); |
| 143 getGatt()->AddToActiveAlgorithms(resolver); | 142 getGatt()->AddToActiveAlgorithms(resolver); |
| 144 | 143 |
| 145 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); | 144 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); |
| 146 service->RemoteCharacteristicReadValue( | 145 service->RemoteCharacteristicReadValue( |
| 147 m_characteristic->instance_id, | 146 m_characteristic->instance_id, |
| 148 convertToBaseCallback( | 147 convertToBaseCallback( |
| 149 WTF::bind(&BluetoothRemoteGATTCharacteristic::ReadValueCallback, | 148 WTF::bind(&BluetoothRemoteGATTCharacteristic::ReadValueCallback, |
| 150 wrapPersistent(this), wrapPersistent(resolver)))); | 149 wrapPersistent(this), wrapPersistent(resolver)))); |
| 151 | 150 |
| 152 return promise; | 151 return promise; |
| 153 } | 152 } |
| 154 | 153 |
| 155 void BluetoothRemoteGATTCharacteristic::WriteValueCallback( | 154 void BluetoothRemoteGATTCharacteristic::WriteValueCallback( |
| 156 ScriptPromiseResolver* resolver, | 155 ScriptPromiseResolver* resolver, |
| 157 const Vector<uint8_t>& value, | 156 const Vector<uint8_t>& value, |
| 158 mojom::blink::WebBluetoothResult result) { | 157 mojom::blink::WebBluetoothResult result) { |
| 159 if (!resolver->getExecutionContext() || | 158 if (!resolver->getExecutionContext() || |
| 160 resolver->getExecutionContext()->isContextDestroyed()) | 159 resolver->getExecutionContext()->isContextDestroyed()) |
| 161 return; | 160 return; |
| 162 | 161 |
| 163 // If the device is disconnected, reject. | 162 // If the device is disconnected, reject. |
| 164 if (!getGatt()->RemoveFromActiveAlgorithms(resolver)) { | 163 if (!getGatt()->RemoveFromActiveAlgorithms(resolver)) { |
| 165 resolver->reject(BluetoothRemoteGATTUtils::CreateDOMException( | 164 resolver->reject(BluetoothError::createDOMException( |
| 166 BluetoothRemoteGATTUtils::ExceptionType::kGATTServerDisconnected)); | 165 blink::mojom::WebBluetoothResult::GATT_SERVER_DISCONNECTED)); |
| 167 return; | 166 return; |
| 168 } | 167 } |
| 169 | 168 |
| 170 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { | 169 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { |
| 171 setValue(BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value)); | 170 setValue(BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value)); |
| 172 resolver->resolve(); | 171 resolver->resolve(); |
| 173 } else { | 172 } else { |
| 174 resolver->reject(BluetoothError::take(resolver, result)); | 173 resolver->reject(BluetoothError::createDOMException(result)); |
| 175 } | 174 } |
| 176 } | 175 } |
| 177 | 176 |
| 178 ScriptPromise BluetoothRemoteGATTCharacteristic::writeValue( | 177 ScriptPromise BluetoothRemoteGATTCharacteristic::writeValue( |
| 179 ScriptState* scriptState, | 178 ScriptState* scriptState, |
| 180 const DOMArrayPiece& value) { | 179 const DOMArrayPiece& value) { |
| 181 if (!getGatt()->connected()) { | 180 if (!getGatt()->connected()) { |
| 182 return ScriptPromise::rejectWithDOMException( | 181 return ScriptPromise::rejectWithDOMException( |
| 183 scriptState, | 182 scriptState, |
| 184 BluetoothRemoteGATTUtils::CreateDOMException( | 183 BluetoothError::createDOMException( |
| 185 BluetoothRemoteGATTUtils::ExceptionType::kGATTServerNotConnected)); | 184 blink::mojom::WebBluetoothResult::GATT_SERVER_NOT_CONNECTED)); |
| 186 } | 185 } |
| 187 | 186 |
| 188 if (!getGatt()->device()->isValidCharacteristic( | 187 if (!getGatt()->device()->isValidCharacteristic( |
| 189 m_characteristic->instance_id)) { | 188 m_characteristic->instance_id)) { |
| 190 return ScriptPromise::rejectWithDOMException( | 189 return ScriptPromise::rejectWithDOMException( |
| 191 scriptState, | 190 scriptState, createInvalidCharacteristicError()); |
| 192 BluetoothRemoteGATTUtils::CreateDOMException( | |
| 193 BluetoothRemoteGATTUtils::ExceptionType::kInvalidCharacteristic)); | |
| 194 } | 191 } |
| 195 | 192 |
| 196 // Partial implementation of writeValue algorithm: | 193 // Partial implementation of writeValue algorithm: |
| 197 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattchar
acteristic-writevalue | 194 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattchar
acteristic-writevalue |
| 198 | 195 |
| 199 // If bytes is more than 512 bytes long (the maximum length of an attribute | 196 // If bytes is more than 512 bytes long (the maximum length of an attribute |
| 200 // value, per Long Attribute Values) return a promise rejected with an | 197 // value, per Long Attribute Values) return a promise rejected with an |
| 201 // InvalidModificationError and abort. | 198 // InvalidModificationError and abort. |
| 202 if (value.byteLength() > 512) | 199 if (value.byteLength() > 512) |
| 203 return ScriptPromise::rejectWithDOMException( | 200 return ScriptPromise::rejectWithDOMException( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 224 | 221 |
| 225 void BluetoothRemoteGATTCharacteristic::NotificationsCallback( | 222 void BluetoothRemoteGATTCharacteristic::NotificationsCallback( |
| 226 ScriptPromiseResolver* resolver, | 223 ScriptPromiseResolver* resolver, |
| 227 mojom::blink::WebBluetoothResult result) { | 224 mojom::blink::WebBluetoothResult result) { |
| 228 if (!resolver->getExecutionContext() || | 225 if (!resolver->getExecutionContext() || |
| 229 resolver->getExecutionContext()->isContextDestroyed()) | 226 resolver->getExecutionContext()->isContextDestroyed()) |
| 230 return; | 227 return; |
| 231 | 228 |
| 232 // If the device is disconnected, reject. | 229 // If the device is disconnected, reject. |
| 233 if (!getGatt()->RemoveFromActiveAlgorithms(resolver)) { | 230 if (!getGatt()->RemoveFromActiveAlgorithms(resolver)) { |
| 234 resolver->reject(BluetoothRemoteGATTUtils::CreateDOMException( | 231 resolver->reject(BluetoothError::createDOMException( |
| 235 BluetoothRemoteGATTUtils::ExceptionType::kGATTServerDisconnected)); | 232 blink::mojom::WebBluetoothResult::GATT_SERVER_DISCONNECTED)); |
| 236 return; | 233 return; |
| 237 } | 234 } |
| 238 | 235 |
| 239 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { | 236 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { |
| 240 resolver->resolve(this); | 237 resolver->resolve(this); |
| 241 } else { | 238 } else { |
| 242 resolver->reject(BluetoothError::take(resolver, result)); | 239 resolver->reject(BluetoothError::createDOMException(result)); |
| 243 } | 240 } |
| 244 } | 241 } |
| 245 | 242 |
| 246 ScriptPromise BluetoothRemoteGATTCharacteristic::startNotifications( | 243 ScriptPromise BluetoothRemoteGATTCharacteristic::startNotifications( |
| 247 ScriptState* scriptState) { | 244 ScriptState* scriptState) { |
| 248 if (!getGatt()->connected()) { | 245 if (!getGatt()->connected()) { |
| 249 return ScriptPromise::rejectWithDOMException( | 246 return ScriptPromise::rejectWithDOMException( |
| 250 scriptState, | 247 scriptState, |
| 251 BluetoothRemoteGATTUtils::CreateDOMException( | 248 BluetoothError::createDOMException( |
| 252 BluetoothRemoteGATTUtils::ExceptionType::kGATTServerNotConnected)); | 249 blink::mojom::WebBluetoothResult::GATT_SERVER_NOT_CONNECTED)); |
| 253 } | 250 } |
| 254 | 251 |
| 255 if (!getGatt()->device()->isValidCharacteristic( | 252 if (!getGatt()->device()->isValidCharacteristic( |
| 256 m_characteristic->instance_id)) { | 253 m_characteristic->instance_id)) { |
| 257 return ScriptPromise::rejectWithDOMException( | 254 return ScriptPromise::rejectWithDOMException( |
| 258 scriptState, | 255 scriptState, createInvalidCharacteristicError()); |
| 259 BluetoothRemoteGATTUtils::CreateDOMException( | |
| 260 BluetoothRemoteGATTUtils::ExceptionType::kInvalidCharacteristic)); | |
| 261 } | 256 } |
| 262 | 257 |
| 263 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 258 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 264 ScriptPromise promise = resolver->promise(); | 259 ScriptPromise promise = resolver->promise(); |
| 265 getGatt()->AddToActiveAlgorithms(resolver); | 260 getGatt()->AddToActiveAlgorithms(resolver); |
| 266 | 261 |
| 267 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); | 262 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); |
| 268 service->RemoteCharacteristicStartNotifications( | 263 service->RemoteCharacteristicStartNotifications( |
| 269 m_characteristic->instance_id, | 264 m_characteristic->instance_id, |
| 270 convertToBaseCallback( | 265 convertToBaseCallback( |
| 271 WTF::bind(&BluetoothRemoteGATTCharacteristic::NotificationsCallback, | 266 WTF::bind(&BluetoothRemoteGATTCharacteristic::NotificationsCallback, |
| 272 wrapPersistent(this), wrapPersistent(resolver)))); | 267 wrapPersistent(this), wrapPersistent(resolver)))); |
| 273 | 268 |
| 274 return promise; | 269 return promise; |
| 275 } | 270 } |
| 276 | 271 |
| 277 ScriptPromise BluetoothRemoteGATTCharacteristic::stopNotifications( | 272 ScriptPromise BluetoothRemoteGATTCharacteristic::stopNotifications( |
| 278 ScriptState* scriptState) { | 273 ScriptState* scriptState) { |
| 279 if (!getGatt()->connected()) { | 274 if (!getGatt()->connected()) { |
| 280 return ScriptPromise::rejectWithDOMException( | 275 return ScriptPromise::rejectWithDOMException( |
| 281 scriptState, | 276 scriptState, |
| 282 BluetoothRemoteGATTUtils::CreateDOMException( | 277 BluetoothError::createDOMException( |
| 283 BluetoothRemoteGATTUtils::ExceptionType::kGATTServerNotConnected)); | 278 blink::mojom::WebBluetoothResult::GATT_SERVER_NOT_CONNECTED)); |
| 284 } | 279 } |
| 285 | 280 |
| 286 if (!getGatt()->device()->isValidCharacteristic( | 281 if (!getGatt()->device()->isValidCharacteristic( |
| 287 m_characteristic->instance_id)) { | 282 m_characteristic->instance_id)) { |
| 288 return ScriptPromise::rejectWithDOMException( | 283 return ScriptPromise::rejectWithDOMException( |
| 289 scriptState, | 284 scriptState, createInvalidCharacteristicError()); |
| 290 BluetoothRemoteGATTUtils::CreateDOMException( | |
| 291 BluetoothRemoteGATTUtils::ExceptionType::kInvalidCharacteristic)); | |
| 292 } | 285 } |
| 293 | 286 |
| 294 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 287 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 295 ScriptPromise promise = resolver->promise(); | 288 ScriptPromise promise = resolver->promise(); |
| 296 getGatt()->AddToActiveAlgorithms(resolver); | 289 getGatt()->AddToActiveAlgorithms(resolver); |
| 297 | 290 |
| 298 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); | 291 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); |
| 299 service->RemoteCharacteristicStopNotifications( | 292 service->RemoteCharacteristicStopNotifications( |
| 300 m_characteristic->instance_id, | 293 m_characteristic->instance_id, |
| 301 convertToBaseCallback( | 294 convertToBaseCallback( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 descriptor); | 333 descriptor); |
| 341 } | 334 } |
| 342 | 335 |
| 343 ScriptPromise BluetoothRemoteGATTCharacteristic::getDescriptorsImpl( | 336 ScriptPromise BluetoothRemoteGATTCharacteristic::getDescriptorsImpl( |
| 344 ScriptState* scriptState, | 337 ScriptState* scriptState, |
| 345 mojom::blink::WebBluetoothGATTQueryQuantity quantity, | 338 mojom::blink::WebBluetoothGATTQueryQuantity quantity, |
| 346 const String& descriptorsUUID) { | 339 const String& descriptorsUUID) { |
| 347 if (!getGatt()->connected()) { | 340 if (!getGatt()->connected()) { |
| 348 return ScriptPromise::rejectWithDOMException( | 341 return ScriptPromise::rejectWithDOMException( |
| 349 scriptState, | 342 scriptState, |
| 350 BluetoothRemoteGATTUtils::CreateDOMException( | 343 BluetoothError::createDOMException( |
| 351 BluetoothRemoteGATTUtils::ExceptionType::kGATTServerNotConnected)); | 344 blink::mojom::WebBluetoothResult::GATT_SERVER_NOT_CONNECTED)); |
| 352 } | 345 } |
| 353 | 346 |
| 354 if (!getGatt()->device()->isValidCharacteristic( | 347 if (!getGatt()->device()->isValidCharacteristic( |
| 355 m_characteristic->instance_id)) { | 348 m_characteristic->instance_id)) { |
| 356 return ScriptPromise::rejectWithDOMException( | 349 return ScriptPromise::rejectWithDOMException( |
| 357 scriptState, | 350 scriptState, createInvalidCharacteristicError()); |
| 358 BluetoothRemoteGATTUtils::CreateDOMException( | |
| 359 BluetoothRemoteGATTUtils::ExceptionType::kInvalidCharacteristic)); | |
| 360 } | 351 } |
| 361 | 352 |
| 362 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 353 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 363 ScriptPromise promise = resolver->promise(); | 354 ScriptPromise promise = resolver->promise(); |
| 364 getGatt()->AddToActiveAlgorithms(resolver); | 355 getGatt()->AddToActiveAlgorithms(resolver); |
| 365 | 356 |
| 366 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); | 357 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); |
| 367 service->RemoteCharacteristicGetDescriptors( | 358 service->RemoteCharacteristicGetDescriptors( |
| 368 m_characteristic->instance_id, quantity, descriptorsUUID, | 359 m_characteristic->instance_id, quantity, descriptorsUUID, |
| 369 convertToBaseCallback( | 360 convertToBaseCallback(WTF::bind( |
| 370 WTF::bind(&BluetoothRemoteGATTCharacteristic::GetDescriptorsCallback, | 361 &BluetoothRemoteGATTCharacteristic::GetDescriptorsCallback, |
| 371 wrapPersistent(this), m_characteristic->instance_id, | 362 wrapPersistent(this), descriptorsUUID, m_characteristic->instance_id, |
| 372 quantity, wrapPersistent(resolver)))); | 363 quantity, wrapPersistent(resolver)))); |
| 373 | 364 |
| 374 return promise; | 365 return promise; |
| 375 } | 366 } |
| 376 | 367 |
| 377 // Callback that allows us to resolve the promise with a single descriptor | 368 // Callback that allows us to resolve the promise with a single descriptor |
| 378 // or with a vector owning the descriptors. | 369 // or with a vector owning the descriptors. |
| 379 void BluetoothRemoteGATTCharacteristic::GetDescriptorsCallback( | 370 void BluetoothRemoteGATTCharacteristic::GetDescriptorsCallback( |
| 371 const String& requestedDescriptorUUID, |
| 380 const String& characteristicInstanceId, | 372 const String& characteristicInstanceId, |
| 381 mojom::blink::WebBluetoothGATTQueryQuantity quantity, | 373 mojom::blink::WebBluetoothGATTQueryQuantity quantity, |
| 382 ScriptPromiseResolver* resolver, | 374 ScriptPromiseResolver* resolver, |
| 383 mojom::blink::WebBluetoothResult result, | 375 mojom::blink::WebBluetoothResult result, |
| 384 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTDescriptorPtr>> | 376 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTDescriptorPtr>> |
| 385 descriptors) { | 377 descriptors) { |
| 386 if (!resolver->getExecutionContext() || | 378 if (!resolver->getExecutionContext() || |
| 387 resolver->getExecutionContext()->isContextDestroyed()) | 379 resolver->getExecutionContext()->isContextDestroyed()) |
| 388 return; | 380 return; |
| 389 | 381 |
| 390 // If the device is disconnected, reject. | 382 // If the device is disconnected, reject. |
| 391 if (!service()->device()->gatt()->RemoveFromActiveAlgorithms(resolver)) { | 383 if (!service()->device()->gatt()->RemoveFromActiveAlgorithms(resolver)) { |
| 392 resolver->reject(BluetoothRemoteGATTUtils::CreateDOMException( | 384 resolver->reject(BluetoothError::createDOMException( |
| 393 BluetoothRemoteGATTUtils::ExceptionType::kGATTServerDisconnected)); | 385 blink::mojom::WebBluetoothResult::GATT_SERVER_DISCONNECTED)); |
| 394 return; | 386 return; |
| 395 } | 387 } |
| 396 | 388 |
| 397 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { | 389 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { |
| 398 DCHECK(descriptors); | 390 DCHECK(descriptors); |
| 399 | 391 |
| 400 if (quantity == mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE) { | 392 if (quantity == mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE) { |
| 401 DCHECK_EQ(1u, descriptors->size()); | 393 DCHECK_EQ(1u, descriptors->size()); |
| 402 resolver->resolve( | 394 resolver->resolve( |
| 403 service()->device()->getOrCreateBluetoothRemoteGATTDescriptor( | 395 service()->device()->getOrCreateBluetoothRemoteGATTDescriptor( |
| 404 std::move(descriptors.value()[0]), this)); | 396 std::move(descriptors.value()[0]), this)); |
| 405 return; | 397 return; |
| 406 } | 398 } |
| 407 | 399 |
| 408 HeapVector<Member<BluetoothRemoteGATTDescriptor>> gattDescriptors; | 400 HeapVector<Member<BluetoothRemoteGATTDescriptor>> gattDescriptors; |
| 409 gattDescriptors.reserveInitialCapacity(descriptors->size()); | 401 gattDescriptors.reserveInitialCapacity(descriptors->size()); |
| 410 for (auto& descriptor : descriptors.value()) { | 402 for (auto& descriptor : descriptors.value()) { |
| 411 gattDescriptors.push_back( | 403 gattDescriptors.push_back( |
| 412 service()->device()->getOrCreateBluetoothRemoteGATTDescriptor( | 404 service()->device()->getOrCreateBluetoothRemoteGATTDescriptor( |
| 413 std::move(descriptor), this)); | 405 std::move(descriptor), this)); |
| 414 } | 406 } |
| 415 resolver->resolve(gattDescriptors); | 407 resolver->resolve(gattDescriptors); |
| 416 } else { | 408 } else { |
| 417 resolver->reject(BluetoothError::take(resolver, result)); | 409 if (result == mojom::blink::WebBluetoothResult::DESCRIPTOR_NOT_FOUND) { |
| 410 resolver->reject(BluetoothError::createDOMException( |
| 411 BluetoothErrorCode::DescriptorNotFound, |
| 412 "No Descriptors matching UUID " + requestedDescriptorUUID + |
| 413 " found in Characteristic with UUID " + uuid() + ".")); |
| 414 } else { |
| 415 resolver->reject(BluetoothError::createDOMException(result)); |
| 416 } |
| 418 } | 417 } |
| 419 } | 418 } |
| 420 | 419 |
| 420 DOMException* |
| 421 BluetoothRemoteGATTCharacteristic::createInvalidCharacteristicError() { |
| 422 return BluetoothError::createDOMException( |
| 423 BluetoothErrorCode::InvalidCharacteristic, |
| 424 "Characteristic with UUID " + uuid() + |
| 425 " is no longer valid. Remember to retrieve the characteristic again " |
| 426 "after reconnecting."); |
| 427 } |
| 428 |
| 421 DEFINE_TRACE(BluetoothRemoteGATTCharacteristic) { | 429 DEFINE_TRACE(BluetoothRemoteGATTCharacteristic) { |
| 422 visitor->trace(m_service); | 430 visitor->trace(m_service); |
| 423 visitor->trace(m_properties); | 431 visitor->trace(m_properties); |
| 424 visitor->trace(m_value); | 432 visitor->trace(m_value); |
| 425 visitor->trace(m_device); | 433 visitor->trace(m_device); |
| 426 EventTargetWithInlineData::trace(visitor); | 434 EventTargetWithInlineData::trace(visitor); |
| 427 ContextLifecycleObserver::trace(visitor); | 435 ContextLifecycleObserver::trace(visitor); |
| 428 } | 436 } |
| 429 | 437 |
| 430 } // namespace blink | 438 } // namespace blink |
| OLD | NEW |