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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 return; | 64 return; |
65 m_resolver->reject(BluetoothError::take(m_resolver, e)); | 65 m_resolver->reject(BluetoothError::take(m_resolver, e)); |
66 } | 66 } |
67 private: | 67 private: |
68 Persistent<ScriptPromiseResolver> m_resolver; | 68 Persistent<ScriptPromiseResolver> m_resolver; |
69 mojom::WebBluetoothGATTQueryQuantity m_quantity; | 69 mojom::WebBluetoothGATTQueryQuantity m_quantity; |
70 }; | 70 }; |
71 | 71 |
72 ScriptPromise BluetoothRemoteGATTService::getCharacteristic(ScriptState* scriptS
tate, const StringOrUnsignedLong& characteristic, ExceptionState& exceptionState
) | 72 ScriptPromise BluetoothRemoteGATTService::getCharacteristic(ScriptState* scriptS
tate, const StringOrUnsignedLong& characteristic, ExceptionState& exceptionState
) |
73 { | 73 { |
74 #if OS(MACOSX) | |
75 // TODO(jlebel): Remove when getCharacteristic is implemented. | |
76 return ScriptPromise::rejectWithDOMException(scriptState, | |
77 DOMException::create(NotSupportedError, | |
78 "getCharacteristic is not implemented yet. See https://goo.gl/J6ASzs
")); | |
79 #endif // OS(MACOSX) | |
80 | |
81 String characteristicUUID = BluetoothUUID::getCharacteristic(characteristic,
exceptionState); | 74 String characteristicUUID = BluetoothUUID::getCharacteristic(characteristic,
exceptionState); |
82 if (exceptionState.hadException()) | 75 if (exceptionState.hadException()) |
83 return exceptionState.reject(scriptState); | 76 return exceptionState.reject(scriptState); |
84 | 77 |
85 return getCharacteristicsImpl(scriptState, mojom::WebBluetoothGATTQueryQuant
ity::SINGLE, characteristicUUID); | 78 return getCharacteristicsImpl(scriptState, mojom::WebBluetoothGATTQueryQuant
ity::SINGLE, characteristicUUID); |
86 } | 79 } |
87 | 80 |
88 ScriptPromise BluetoothRemoteGATTService::getCharacteristics(ScriptState* script
State, const StringOrUnsignedLong& characteristic, ExceptionState& exceptionStat
e) | 81 ScriptPromise BluetoothRemoteGATTService::getCharacteristics(ScriptState* script
State, const StringOrUnsignedLong& characteristic, ExceptionState& exceptionStat
e) |
89 { | 82 { |
90 String characteristicUUID = BluetoothUUID::getCharacteristic(characteristic,
exceptionState); | 83 String characteristicUUID = BluetoothUUID::getCharacteristic(characteristic,
exceptionState); |
91 if (exceptionState.hadException()) | 84 if (exceptionState.hadException()) |
92 return exceptionState.reject(scriptState); | 85 return exceptionState.reject(scriptState); |
93 | 86 |
94 return getCharacteristicsImpl(scriptState, mojom::WebBluetoothGATTQueryQuant
ity::MULTIPLE, characteristicUUID); | 87 return getCharacteristicsImpl(scriptState, mojom::WebBluetoothGATTQueryQuant
ity::MULTIPLE, characteristicUUID); |
95 } | 88 } |
96 | 89 |
97 ScriptPromise BluetoothRemoteGATTService::getCharacteristics(ScriptState* script
State, ExceptionState&) | 90 ScriptPromise BluetoothRemoteGATTService::getCharacteristics(ScriptState* script
State, ExceptionState&) |
98 { | 91 { |
99 return getCharacteristicsImpl(scriptState, mojom::WebBluetoothGATTQueryQuant
ity::MULTIPLE); | 92 return getCharacteristicsImpl(scriptState, mojom::WebBluetoothGATTQueryQuant
ity::MULTIPLE); |
100 } | 93 } |
101 | 94 |
102 ScriptPromise BluetoothRemoteGATTService::getCharacteristicsImpl(ScriptState* sc
riptState, mojom::WebBluetoothGATTQueryQuantity quantity, String characteristics
UUID) | 95 ScriptPromise BluetoothRemoteGATTService::getCharacteristicsImpl(ScriptState* sc
riptState, mojom::WebBluetoothGATTQueryQuantity quantity, String characteristics
UUID) |
103 { | 96 { |
104 #if OS(MACOSX) | |
105 // TODO(jlebel): Remove when getCharacteristics is implemented. | |
106 return ScriptPromise::rejectWithDOMException(scriptState, | |
107 DOMException::create(NotSupportedError, | |
108 "getCharacteristics is not implemented yet. See https://goo.gl/J6ASz
s")); | |
109 #endif // OS(MACOSX) | |
110 | |
111 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; | 97 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState)
; |
112 ScriptPromise promise = resolver->promise(); | 98 ScriptPromise promise = resolver->promise(); |
113 | 99 |
114 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat
e); | 100 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat
e); |
115 webbluetooth->getCharacteristics(m_webService->serviceInstanceID, quantity,
characteristicsUUID, new GetCharacteristicsCallback(quantity, resolver)); | 101 webbluetooth->getCharacteristics(m_webService->serviceInstanceID, quantity,
characteristicsUUID, new GetCharacteristicsCallback(quantity, resolver)); |
116 | 102 |
117 return promise; | 103 return promise; |
118 } | 104 } |
119 | 105 |
120 } // namespace blink | 106 } // namespace blink |
OLD | NEW |