| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/BluetoothRemoteGATTDescriptor.h" | 5 #include "modules/bluetooth/BluetoothRemoteGATTDescriptor.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 } | 124 } |
| 125 | 125 |
| 126 // Partial implementation of writeValue algorithm: | 126 // Partial implementation of writeValue algorithm: |
| 127 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdesc
riptor-writevalue | 127 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdesc
riptor-writevalue |
| 128 | 128 |
| 129 // If bytes is more than 512 bytes long (the maximum length of an attribute | 129 // If bytes is more than 512 bytes long (the maximum length of an attribute |
| 130 // value, per Long Attribute Values) return a promise rejected with an | 130 // value, per Long Attribute Values) return a promise rejected with an |
| 131 // InvalidModificationError and abort. | 131 // InvalidModificationError and abort. |
| 132 if (value.byteLength() > 512) { | 132 if (value.byteLength() > 512) { |
| 133 return ScriptPromise::rejectWithDOMException( | 133 return ScriptPromise::rejectWithDOMException( |
| 134 scriptState, DOMException::create(InvalidModificationError, | 134 scriptState, |
| 135 "Value can't exceed 512 bytes.")); | 135 DOMException::create(InvalidModificationError, |
| 136 "Value can't exceed 512 bytes.")); |
| 136 } | 137 } |
| 137 | 138 |
| 138 // Let valueVector be a copy of the bytes held by value. | 139 // Let valueVector be a copy of the bytes held by value. |
| 139 Vector<uint8_t> valueVector; | 140 Vector<uint8_t> valueVector; |
| 140 valueVector.append(value.bytes(), value.byteLength()); | 141 valueVector.append(value.bytes(), value.byteLength()); |
| 141 | 142 |
| 142 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 143 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 143 ScriptPromise promise = resolver->promise(); | 144 ScriptPromise promise = resolver->promise(); |
| 144 getGatt()->AddToActiveAlgorithms(resolver); | 145 getGatt()->AddToActiveAlgorithms(resolver); |
| 145 getService()->RemoteDescriptorWriteValue( | 146 getService()->RemoteDescriptorWriteValue( |
| 146 m_descriptor->instance_id, valueVector, | 147 m_descriptor->instance_id, valueVector, |
| 147 convertToBaseCallback(WTF::bind( | 148 convertToBaseCallback(WTF::bind( |
| 148 &BluetoothRemoteGATTDescriptor::WriteValueCallback, | 149 &BluetoothRemoteGATTDescriptor::WriteValueCallback, |
| 149 wrapPersistent(this), wrapPersistent(resolver), valueVector))); | 150 wrapPersistent(this), wrapPersistent(resolver), valueVector))); |
| 150 | 151 |
| 151 return promise; | 152 return promise; |
| 152 } | 153 } |
| 153 | 154 |
| 154 DEFINE_TRACE(BluetoothRemoteGATTDescriptor) { | 155 DEFINE_TRACE(BluetoothRemoteGATTDescriptor) { |
| 155 visitor->trace(m_characteristic); | 156 visitor->trace(m_characteristic); |
| 156 visitor->trace(m_value); | 157 visitor->trace(m_value); |
| 157 } | 158 } |
| 158 | 159 |
| 159 } // namespace blink | 160 } // namespace blink |
| OLD | NEW |