| 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/BluetoothRemoteGATTService.h" | 5 #include "modules/bluetooth/BluetoothRemoteGATTService.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" | 7 #include "bindings/core/v8/CallbackPromiseAdapter.h" |
| 8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
| 9 #include "bindings/core/v8/ScriptPromiseResolver.h" | 9 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 10 #include "core/dom/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 if (exceptionState.hadException()) | 39 if (exceptionState.hadException()) |
| 40 return exceptionState.reject(scriptState); | 40 return exceptionState.reject(scriptState); |
| 41 | 41 |
| 42 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 42 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 43 ScriptPromise promise = resolver->promise(); | 43 ScriptPromise promise = resolver->promise(); |
| 44 webbluetooth->getCharacteristic(m_webService->serviceInstanceID, characteris
ticUUID, new CallbackPromiseAdapter<BluetoothRemoteGATTCharacteristic, Bluetooth
Error>(resolver)); | 44 webbluetooth->getCharacteristic(m_webService->serviceInstanceID, characteris
ticUUID, new CallbackPromiseAdapter<BluetoothRemoteGATTCharacteristic, Bluetooth
Error>(resolver)); |
| 45 | 45 |
| 46 return promise; | 46 return promise; |
| 47 } | 47 } |
| 48 | 48 |
| 49 ScriptPromise BluetoothRemoteGATTService::getCharacteristics(ScriptState* script
State, ExceptionState&) |
| 50 { |
| 51 return getCharacteristicsImpl(scriptState, String()); |
| 52 } |
| 53 |
| 54 ScriptPromise BluetoothRemoteGATTService::getCharacteristics(ScriptState* script
State, const StringOrUnsignedLong& characteristic, ExceptionState& exceptionStat
e) |
| 55 { |
| 56 String characteristicUUID = BluetoothUUID::getCharacteristic(characteristic,
exceptionState); |
| 57 if (exceptionState.hadException()) |
| 58 return exceptionState.reject(scriptState); |
| 59 |
| 60 return getCharacteristicsImpl(scriptState, characteristicUUID); |
| 61 } |
| 62 |
| 63 // Class that allows us to use CallbackPromiseAdapter to resolve a promise with
a |
| 64 // vector owning BluetoothRemoteGATTCharacteristics. |
| 65 class RemoteCharacteristicArray { |
| 66 STATIC_ONLY(RemoteCharacteristicArray); |
| 67 public: |
| 68 using WebType = OwnPtr<WebVector<WebBluetoothRemoteGATTCharacteristicInit*>>
; |
| 69 static HeapVector<Member<BluetoothRemoteGATTCharacteristic>> take(ScriptProm
iseResolver* resolver, PassOwnPtr<WebVector<WebBluetoothRemoteGATTCharacteristic
Init*>> webCharacteristics) |
| 70 { |
| 71 HeapVector<Member<BluetoothRemoteGATTCharacteristic>> characteristics; |
| 72 characteristics.reserveInitialCapacity(webCharacteristics->size()); |
| 73 for (WebBluetoothRemoteGATTCharacteristicInit* webCharacteristic : *webC
haracteristics) { |
| 74 characteristics.append(BluetoothRemoteGATTCharacteristic::take(resol
ver, adoptPtr(webCharacteristic))); |
| 75 } |
| 76 return characteristics; |
| 77 } |
| 78 }; |
| 79 |
| 80 ScriptPromise BluetoothRemoteGATTService::getCharacteristicsImpl(ScriptState* sc
riptState, String characteristicsUUID) |
| 81 { |
| 82 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
| 83 ScriptPromise promise = resolver->promise(); |
| 84 |
| 85 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat
e); |
| 86 webbluetooth->getCharacteristics(m_webService->serviceInstanceID, characteri
sticsUUID, new CallbackPromiseAdapter<RemoteCharacteristicArray, BluetoothError>
(resolver)); |
| 87 |
| 88 return promise; |
| 89 } |
| 90 |
| 49 } // namespace blink | 91 } // namespace blink |
| OLD | NEW |