| Index: third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTService.cpp
|
| diff --git a/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTService.cpp b/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTService.cpp
|
| index 9c71c576a5e39790a107066048aee00d708fb3a8..721686281ebb400495580c620e3e57acee9f1781 100644
|
| --- a/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTService.cpp
|
| +++ b/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTService.cpp
|
| @@ -46,4 +46,46 @@ ScriptPromise BluetoothRemoteGATTService::getCharacteristic(ScriptState* scriptS
|
| return promise;
|
| }
|
|
|
| +ScriptPromise BluetoothRemoteGATTService::getCharacteristics(ScriptState* scriptState, ExceptionState&)
|
| +{
|
| + return getCharacteristicsImpl(scriptState, String());
|
| +}
|
| +
|
| +ScriptPromise BluetoothRemoteGATTService::getCharacteristics(ScriptState* scriptState, const StringOrUnsignedLong& characteristic, ExceptionState& exceptionState)
|
| +{
|
| + String characteristicUUID = BluetoothUUID::getCharacteristic(characteristic, exceptionState);
|
| + if (exceptionState.hadException())
|
| + return exceptionState.reject(scriptState);
|
| +
|
| + return getCharacteristicsImpl(scriptState, characteristicUUID);
|
| +}
|
| +
|
| +// Class that allows us to use CallbackPromiseAdapter to resolve a promise with a
|
| +// vector owning BluetoothRemoteGATTCharacteristics.
|
| +class RemoteCharacteristicArray {
|
| + STATIC_ONLY(RemoteCharacteristicArray);
|
| +public:
|
| + using WebType = OwnPtr<WebVector<WebBluetoothRemoteGATTCharacteristicInit*>>;
|
| + static HeapVector<Member<BluetoothRemoteGATTCharacteristic>> take(ScriptPromiseResolver* resolver, PassOwnPtr<WebVector<WebBluetoothRemoteGATTCharacteristicInit*>> webCharacteristics)
|
| + {
|
| + HeapVector<Member<BluetoothRemoteGATTCharacteristic>> characteristics;
|
| + characteristics.reserveInitialCapacity(webCharacteristics->size());
|
| + for (WebBluetoothRemoteGATTCharacteristicInit* webCharacteristic : *webCharacteristics) {
|
| + characteristics.append(BluetoothRemoteGATTCharacteristic::take(resolver, adoptPtr(webCharacteristic)));
|
| + }
|
| + return characteristics;
|
| + }
|
| +};
|
| +
|
| +ScriptPromise BluetoothRemoteGATTService::getCharacteristicsImpl(ScriptState* scriptState, String characteristicsUUID)
|
| +{
|
| + ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState);
|
| + ScriptPromise promise = resolver->promise();
|
| +
|
| + WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptState);
|
| + webbluetooth->getCharacteristics(m_webService->serviceInstanceID, characteristicsUUID, new CallbackPromiseAdapter<RemoteCharacteristicArray, BluetoothError>(resolver));
|
| +
|
| + return promise;
|
| +}
|
| +
|
| } // namespace blink
|
|
|