| 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, |
| 137 BluetoothRemoteGATTUtils::CreateDOMException( | 138 BluetoothError::CreateDOMException( |
| 138 BluetoothRemoteGATTUtils::ExceptionType::kInvalidCharacteristic)); | 139 blink::mojom::WebBluetoothResult::INVALID_CHARACTERISTIC)); |
| 139 } | 140 } |
| 140 | 141 |
| 141 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 142 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 142 ScriptPromise promise = resolver->promise(); | 143 ScriptPromise promise = resolver->promise(); |
| 143 getGatt()->AddToActiveAlgorithms(resolver); | 144 getGatt()->AddToActiveAlgorithms(resolver); |
| 144 | 145 |
| 145 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); | 146 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); |
| 146 service->RemoteCharacteristicReadValue( | 147 service->RemoteCharacteristicReadValue( |
| 147 m_characteristic->instance_id, | 148 m_characteristic->instance_id, |
| 148 convertToBaseCallback( | 149 convertToBaseCallback( |
| 149 WTF::bind(&BluetoothRemoteGATTCharacteristic::ReadValueCallback, | 150 WTF::bind(&BluetoothRemoteGATTCharacteristic::ReadValueCallback, |
| 150 wrapPersistent(this), wrapPersistent(resolver)))); | 151 wrapPersistent(this), wrapPersistent(resolver)))); |
| 151 | 152 |
| 152 return promise; | 153 return promise; |
| 153 } | 154 } |
| 154 | 155 |
| 155 void BluetoothRemoteGATTCharacteristic::WriteValueCallback( | 156 void BluetoothRemoteGATTCharacteristic::WriteValueCallback( |
| 156 ScriptPromiseResolver* resolver, | 157 ScriptPromiseResolver* resolver, |
| 157 const Vector<uint8_t>& value, | 158 const Vector<uint8_t>& value, |
| 158 mojom::blink::WebBluetoothResult result) { | 159 mojom::blink::WebBluetoothResult result) { |
| 159 if (!resolver->getExecutionContext() || | 160 if (!resolver->getExecutionContext() || |
| 160 resolver->getExecutionContext()->isContextDestroyed()) | 161 resolver->getExecutionContext()->isContextDestroyed()) |
| 161 return; | 162 return; |
| 162 | 163 |
| 163 // If the device is disconnected, reject. | 164 // If the device is disconnected, reject. |
| 164 if (!getGatt()->RemoveFromActiveAlgorithms(resolver)) { | 165 if (!getGatt()->RemoveFromActiveAlgorithms(resolver)) { |
| 165 resolver->reject(BluetoothRemoteGATTUtils::CreateDOMException( | 166 resolver->reject(BluetoothError::CreateDOMException( |
| 166 BluetoothRemoteGATTUtils::ExceptionType::kGATTServerDisconnected)); | 167 blink::mojom::WebBluetoothResult::GATT_SERVER_DISCONNECTED)); |
| 167 return; | 168 return; |
| 168 } | 169 } |
| 169 | 170 |
| 170 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { | 171 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { |
| 171 setValue(BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value)); | 172 setValue(BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value)); |
| 172 resolver->resolve(); | 173 resolver->resolve(); |
| 173 } else { | 174 } else { |
| 174 resolver->reject(BluetoothError::take(resolver, result)); | 175 resolver->reject(BluetoothError::CreateDOMException(result)); |
| 175 } | 176 } |
| 176 } | 177 } |
| 177 | 178 |
| 178 ScriptPromise BluetoothRemoteGATTCharacteristic::writeValue( | 179 ScriptPromise BluetoothRemoteGATTCharacteristic::writeValue( |
| 179 ScriptState* scriptState, | 180 ScriptState* scriptState, |
| 180 const DOMArrayPiece& value) { | 181 const DOMArrayPiece& value) { |
| 181 if (!getGatt()->connected()) { | 182 if (!getGatt()->connected()) { |
| 182 return ScriptPromise::rejectWithDOMException( | 183 return ScriptPromise::rejectWithDOMException( |
| 183 scriptState, | 184 scriptState, |
| 184 BluetoothRemoteGATTUtils::CreateDOMException( | 185 BluetoothError::CreateDOMException( |
| 185 BluetoothRemoteGATTUtils::ExceptionType::kGATTServerNotConnected)); | 186 blink::mojom::WebBluetoothResult::GATT_SERVER_NOT_CONNECTED)); |
| 186 } | 187 } |
| 187 | 188 |
| 188 if (!getGatt()->device()->isValidCharacteristic( | 189 if (!getGatt()->device()->isValidCharacteristic( |
| 189 m_characteristic->instance_id)) { | 190 m_characteristic->instance_id)) { |
| 190 return ScriptPromise::rejectWithDOMException( | 191 return ScriptPromise::rejectWithDOMException( |
| 191 scriptState, | 192 scriptState, |
| 192 BluetoothRemoteGATTUtils::CreateDOMException( | 193 BluetoothError::CreateDOMException( |
| 193 BluetoothRemoteGATTUtils::ExceptionType::kInvalidCharacteristic)); | 194 blink::mojom::WebBluetoothResult::INVALID_CHARACTERISTIC)); |
| 194 } | 195 } |
| 195 | 196 |
| 196 // Partial implementation of writeValue algorithm: | 197 // Partial implementation of writeValue algorithm: |
| 197 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattchar
acteristic-writevalue | 198 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattchar
acteristic-writevalue |
| 198 | 199 |
| 199 // If bytes is more than 512 bytes long (the maximum length of an attribute | 200 // 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 | 201 // value, per Long Attribute Values) return a promise rejected with an |
| 201 // InvalidModificationError and abort. | 202 // InvalidModificationError and abort. |
| 202 if (value.byteLength() > 512) | 203 if (value.byteLength() > 512) |
| 203 return ScriptPromise::rejectWithDOMException( | 204 return ScriptPromise::rejectWithDOMException( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 224 | 225 |
| 225 void BluetoothRemoteGATTCharacteristic::NotificationsCallback( | 226 void BluetoothRemoteGATTCharacteristic::NotificationsCallback( |
| 226 ScriptPromiseResolver* resolver, | 227 ScriptPromiseResolver* resolver, |
| 227 mojom::blink::WebBluetoothResult result) { | 228 mojom::blink::WebBluetoothResult result) { |
| 228 if (!resolver->getExecutionContext() || | 229 if (!resolver->getExecutionContext() || |
| 229 resolver->getExecutionContext()->isContextDestroyed()) | 230 resolver->getExecutionContext()->isContextDestroyed()) |
| 230 return; | 231 return; |
| 231 | 232 |
| 232 // If the device is disconnected, reject. | 233 // If the device is disconnected, reject. |
| 233 if (!getGatt()->RemoveFromActiveAlgorithms(resolver)) { | 234 if (!getGatt()->RemoveFromActiveAlgorithms(resolver)) { |
| 234 resolver->reject(BluetoothRemoteGATTUtils::CreateDOMException( | 235 resolver->reject(BluetoothError::CreateDOMException( |
| 235 BluetoothRemoteGATTUtils::ExceptionType::kGATTServerDisconnected)); | 236 blink::mojom::WebBluetoothResult::GATT_SERVER_DISCONNECTED)); |
| 236 return; | 237 return; |
| 237 } | 238 } |
| 238 | 239 |
| 239 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { | 240 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { |
| 240 resolver->resolve(this); | 241 resolver->resolve(this); |
| 241 } else { | 242 } else { |
| 242 resolver->reject(BluetoothError::take(resolver, result)); | 243 resolver->reject(BluetoothError::CreateDOMException(result)); |
| 243 } | 244 } |
| 244 } | 245 } |
| 245 | 246 |
| 246 ScriptPromise BluetoothRemoteGATTCharacteristic::startNotifications( | 247 ScriptPromise BluetoothRemoteGATTCharacteristic::startNotifications( |
| 247 ScriptState* scriptState) { | 248 ScriptState* scriptState) { |
| 248 if (!getGatt()->connected()) { | 249 if (!getGatt()->connected()) { |
| 249 return ScriptPromise::rejectWithDOMException( | 250 return ScriptPromise::rejectWithDOMException( |
| 250 scriptState, | 251 scriptState, |
| 251 BluetoothRemoteGATTUtils::CreateDOMException( | 252 BluetoothError::CreateDOMException( |
| 252 BluetoothRemoteGATTUtils::ExceptionType::kGATTServerNotConnected)); | 253 blink::mojom::WebBluetoothResult::GATT_SERVER_NOT_CONNECTED)); |
| 253 } | 254 } |
| 254 | 255 |
| 255 if (!getGatt()->device()->isValidCharacteristic( | 256 if (!getGatt()->device()->isValidCharacteristic( |
| 256 m_characteristic->instance_id)) { | 257 m_characteristic->instance_id)) { |
| 257 return ScriptPromise::rejectWithDOMException( | 258 return ScriptPromise::rejectWithDOMException( |
| 258 scriptState, | 259 scriptState, |
| 259 BluetoothRemoteGATTUtils::CreateDOMException( | 260 BluetoothError::CreateDOMException( |
| 260 BluetoothRemoteGATTUtils::ExceptionType::kInvalidCharacteristic)); | 261 blink::mojom::WebBluetoothResult::INVALID_CHARACTERISTIC)); |
| 261 } | 262 } |
| 262 | 263 |
| 263 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 264 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 264 ScriptPromise promise = resolver->promise(); | 265 ScriptPromise promise = resolver->promise(); |
| 265 getGatt()->AddToActiveAlgorithms(resolver); | 266 getGatt()->AddToActiveAlgorithms(resolver); |
| 266 | 267 |
| 267 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); | 268 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); |
| 268 service->RemoteCharacteristicStartNotifications( | 269 service->RemoteCharacteristicStartNotifications( |
| 269 m_characteristic->instance_id, | 270 m_characteristic->instance_id, |
| 270 convertToBaseCallback( | 271 convertToBaseCallback( |
| 271 WTF::bind(&BluetoothRemoteGATTCharacteristic::NotificationsCallback, | 272 WTF::bind(&BluetoothRemoteGATTCharacteristic::NotificationsCallback, |
| 272 wrapPersistent(this), wrapPersistent(resolver)))); | 273 wrapPersistent(this), wrapPersistent(resolver)))); |
| 273 | 274 |
| 274 return promise; | 275 return promise; |
| 275 } | 276 } |
| 276 | 277 |
| 277 ScriptPromise BluetoothRemoteGATTCharacteristic::stopNotifications( | 278 ScriptPromise BluetoothRemoteGATTCharacteristic::stopNotifications( |
| 278 ScriptState* scriptState) { | 279 ScriptState* scriptState) { |
| 279 if (!getGatt()->connected()) { | 280 if (!getGatt()->connected()) { |
| 280 return ScriptPromise::rejectWithDOMException( | 281 return ScriptPromise::rejectWithDOMException( |
| 281 scriptState, | 282 scriptState, |
| 282 BluetoothRemoteGATTUtils::CreateDOMException( | 283 BluetoothError::CreateDOMException( |
| 283 BluetoothRemoteGATTUtils::ExceptionType::kGATTServerNotConnected)); | 284 blink::mojom::WebBluetoothResult::GATT_SERVER_NOT_CONNECTED)); |
| 284 } | 285 } |
| 285 | 286 |
| 286 if (!getGatt()->device()->isValidCharacteristic( | 287 if (!getGatt()->device()->isValidCharacteristic( |
| 287 m_characteristic->instance_id)) { | 288 m_characteristic->instance_id)) { |
| 288 return ScriptPromise::rejectWithDOMException( | 289 return ScriptPromise::rejectWithDOMException( |
| 289 scriptState, | 290 scriptState, |
| 290 BluetoothRemoteGATTUtils::CreateDOMException( | 291 BluetoothError::CreateDOMException( |
| 291 BluetoothRemoteGATTUtils::ExceptionType::kInvalidCharacteristic)); | 292 blink::mojom::WebBluetoothResult::INVALID_CHARACTERISTIC)); |
| 292 } | 293 } |
| 293 | 294 |
| 294 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 295 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 295 ScriptPromise promise = resolver->promise(); | 296 ScriptPromise promise = resolver->promise(); |
| 296 getGatt()->AddToActiveAlgorithms(resolver); | 297 getGatt()->AddToActiveAlgorithms(resolver); |
| 297 | 298 |
| 298 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); | 299 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); |
| 299 service->RemoteCharacteristicStopNotifications( | 300 service->RemoteCharacteristicStopNotifications( |
| 300 m_characteristic->instance_id, | 301 m_characteristic->instance_id, |
| 301 convertToBaseCallback( | 302 convertToBaseCallback( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 descriptor); | 341 descriptor); |
| 341 } | 342 } |
| 342 | 343 |
| 343 ScriptPromise BluetoothRemoteGATTCharacteristic::getDescriptorsImpl( | 344 ScriptPromise BluetoothRemoteGATTCharacteristic::getDescriptorsImpl( |
| 344 ScriptState* scriptState, | 345 ScriptState* scriptState, |
| 345 mojom::blink::WebBluetoothGATTQueryQuantity quantity, | 346 mojom::blink::WebBluetoothGATTQueryQuantity quantity, |
| 346 const String& descriptorsUUID) { | 347 const String& descriptorsUUID) { |
| 347 if (!getGatt()->connected()) { | 348 if (!getGatt()->connected()) { |
| 348 return ScriptPromise::rejectWithDOMException( | 349 return ScriptPromise::rejectWithDOMException( |
| 349 scriptState, | 350 scriptState, |
| 350 BluetoothRemoteGATTUtils::CreateDOMException( | 351 BluetoothError::CreateDOMException( |
| 351 BluetoothRemoteGATTUtils::ExceptionType::kGATTServerNotConnected)); | 352 blink::mojom::WebBluetoothResult::GATT_SERVER_NOT_CONNECTED)); |
| 352 } | 353 } |
| 353 | 354 |
| 354 if (!getGatt()->device()->isValidCharacteristic( | 355 if (!getGatt()->device()->isValidCharacteristic( |
| 355 m_characteristic->instance_id)) { | 356 m_characteristic->instance_id)) { |
| 356 return ScriptPromise::rejectWithDOMException( | 357 return ScriptPromise::rejectWithDOMException( |
| 357 scriptState, | 358 scriptState, |
| 358 BluetoothRemoteGATTUtils::CreateDOMException( | 359 BluetoothError::CreateDOMException( |
| 359 BluetoothRemoteGATTUtils::ExceptionType::kInvalidCharacteristic)); | 360 blink::mojom::WebBluetoothResult::INVALID_CHARACTERISTIC)); |
| 360 } | 361 } |
| 361 | 362 |
| 362 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 363 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 363 ScriptPromise promise = resolver->promise(); | 364 ScriptPromise promise = resolver->promise(); |
| 364 getGatt()->AddToActiveAlgorithms(resolver); | 365 getGatt()->AddToActiveAlgorithms(resolver); |
| 365 | 366 |
| 366 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); | 367 mojom::blink::WebBluetoothService* service = m_device->bluetooth()->service(); |
| 367 service->RemoteCharacteristicGetDescriptors( | 368 service->RemoteCharacteristicGetDescriptors( |
| 368 m_characteristic->instance_id, quantity, descriptorsUUID, | 369 m_characteristic->instance_id, quantity, descriptorsUUID, |
| 369 convertToBaseCallback( | 370 convertToBaseCallback( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 382 ScriptPromiseResolver* resolver, | 383 ScriptPromiseResolver* resolver, |
| 383 mojom::blink::WebBluetoothResult result, | 384 mojom::blink::WebBluetoothResult result, |
| 384 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTDescriptorPtr>> | 385 Optional<Vector<mojom::blink::WebBluetoothRemoteGATTDescriptorPtr>> |
| 385 descriptors) { | 386 descriptors) { |
| 386 if (!resolver->getExecutionContext() || | 387 if (!resolver->getExecutionContext() || |
| 387 resolver->getExecutionContext()->isContextDestroyed()) | 388 resolver->getExecutionContext()->isContextDestroyed()) |
| 388 return; | 389 return; |
| 389 | 390 |
| 390 // If the device is disconnected, reject. | 391 // If the device is disconnected, reject. |
| 391 if (!service()->device()->gatt()->RemoveFromActiveAlgorithms(resolver)) { | 392 if (!service()->device()->gatt()->RemoveFromActiveAlgorithms(resolver)) { |
| 392 resolver->reject(BluetoothRemoteGATTUtils::CreateDOMException( | 393 resolver->reject(BluetoothError::CreateDOMException( |
| 393 BluetoothRemoteGATTUtils::ExceptionType::kGATTServerDisconnected)); | 394 blink::mojom::WebBluetoothResult::GATT_SERVER_DISCONNECTED)); |
| 394 return; | 395 return; |
| 395 } | 396 } |
| 396 | 397 |
| 397 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { | 398 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { |
| 398 DCHECK(descriptors); | 399 DCHECK(descriptors); |
| 399 | 400 |
| 400 if (quantity == mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE) { | 401 if (quantity == mojom::blink::WebBluetoothGATTQueryQuantity::SINGLE) { |
| 401 DCHECK_EQ(1u, descriptors->size()); | 402 DCHECK_EQ(1u, descriptors->size()); |
| 402 resolver->resolve( | 403 resolver->resolve( |
| 403 service()->device()->getOrCreateBluetoothRemoteGATTDescriptor( | 404 service()->device()->getOrCreateBluetoothRemoteGATTDescriptor( |
| 404 std::move(descriptors.value()[0]), this)); | 405 std::move(descriptors.value()[0]), this)); |
| 405 return; | 406 return; |
| 406 } | 407 } |
| 407 | 408 |
| 408 HeapVector<Member<BluetoothRemoteGATTDescriptor>> gattDescriptors; | 409 HeapVector<Member<BluetoothRemoteGATTDescriptor>> gattDescriptors; |
| 409 gattDescriptors.reserveInitialCapacity(descriptors->size()); | 410 gattDescriptors.reserveInitialCapacity(descriptors->size()); |
| 410 for (auto& descriptor : descriptors.value()) { | 411 for (auto& descriptor : descriptors.value()) { |
| 411 gattDescriptors.push_back( | 412 gattDescriptors.push_back( |
| 412 service()->device()->getOrCreateBluetoothRemoteGATTDescriptor( | 413 service()->device()->getOrCreateBluetoothRemoteGATTDescriptor( |
| 413 std::move(descriptor), this)); | 414 std::move(descriptor), this)); |
| 414 } | 415 } |
| 415 resolver->resolve(gattDescriptors); | 416 resolver->resolve(gattDescriptors); |
| 416 } else { | 417 } else { |
| 417 resolver->reject(BluetoothError::take(resolver, result)); | 418 resolver->reject(BluetoothError::CreateDOMException(result)); |
| 418 } | 419 } |
| 419 } | 420 } |
| 420 | 421 |
| 421 DEFINE_TRACE(BluetoothRemoteGATTCharacteristic) { | 422 DEFINE_TRACE(BluetoothRemoteGATTCharacteristic) { |
| 422 visitor->trace(m_service); | 423 visitor->trace(m_service); |
| 423 visitor->trace(m_properties); | 424 visitor->trace(m_properties); |
| 424 visitor->trace(m_value); | 425 visitor->trace(m_value); |
| 425 visitor->trace(m_device); | 426 visitor->trace(m_device); |
| 426 EventTargetWithInlineData::trace(visitor); | 427 EventTargetWithInlineData::trace(visitor); |
| 427 ContextLifecycleObserver::trace(visitor); | 428 ContextLifecycleObserver::trace(visitor); |
| 428 } | 429 } |
| 429 | 430 |
| 430 } // namespace blink | 431 } // namespace blink |
| OLD | NEW |