| 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 "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/dom/DOMException.h" |
| 10 #include "modules/bluetooth/BluetoothError.h" | 10 #include "modules/bluetooth/BluetoothError.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 ScriptPromiseResolver* resolver, | 32 ScriptPromiseResolver* resolver, |
| 33 mojom::blink::WebBluetoothResult result, | 33 mojom::blink::WebBluetoothResult result, |
| 34 const Optional<Vector<uint8_t>>& value) { | 34 const Optional<Vector<uint8_t>>& value) { |
| 35 if (!resolver->GetExecutionContext() || | 35 if (!resolver->GetExecutionContext() || |
| 36 resolver->GetExecutionContext()->IsContextDestroyed()) | 36 resolver->GetExecutionContext()->IsContextDestroyed()) |
| 37 return; | 37 return; |
| 38 | 38 |
| 39 // If the device is disconnected, reject. | 39 // If the device is disconnected, reject. |
| 40 if (!GetGatt()->RemoveFromActiveAlgorithms(resolver)) { | 40 if (!GetGatt()->RemoveFromActiveAlgorithms(resolver)) { |
| 41 resolver->Reject( | 41 resolver->Reject( |
| 42 BluetoothError::CreateNotConnectedException(BluetoothOperation::GATT)); | 42 BluetoothError::CreateNotConnectedException(BluetoothOperation::kGATT)); |
| 43 return; | 43 return; |
| 44 } | 44 } |
| 45 | 45 |
| 46 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { | 46 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { |
| 47 DCHECK(value); | 47 DCHECK(value); |
| 48 DOMDataView* dom_data_view = | 48 DOMDataView* dom_data_view = |
| 49 BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value.value()); | 49 BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value.value()); |
| 50 value_ = dom_data_view; | 50 value_ = dom_data_view; |
| 51 resolver->Resolve(dom_data_view); | 51 resolver->Resolve(dom_data_view); |
| 52 } else { | 52 } else { |
| 53 resolver->Reject(BluetoothError::CreateDOMException(result)); | 53 resolver->Reject(BluetoothError::CreateDOMException(result)); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 57 ScriptPromise BluetoothRemoteGATTDescriptor::readValue( | 57 ScriptPromise BluetoothRemoteGATTDescriptor::readValue( |
| 58 ScriptState* script_state) { | 58 ScriptState* script_state) { |
| 59 if (!GetGatt()->connected()) { | 59 if (!GetGatt()->connected()) { |
| 60 return ScriptPromise::RejectWithDOMException( | 60 return ScriptPromise::RejectWithDOMException( |
| 61 script_state, | 61 script_state, |
| 62 BluetoothError::CreateNotConnectedException(BluetoothOperation::GATT)); | 62 BluetoothError::CreateNotConnectedException(BluetoothOperation::kGATT)); |
| 63 } | 63 } |
| 64 | 64 |
| 65 if (!GetGatt()->device()->IsValidDescriptor(descriptor_->instance_id)) { | 65 if (!GetGatt()->device()->IsValidDescriptor(descriptor_->instance_id)) { |
| 66 return ScriptPromise::RejectWithDOMException( | 66 return ScriptPromise::RejectWithDOMException( |
| 67 script_state, CreateInvalidDescriptorError()); | 67 script_state, CreateInvalidDescriptorError()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); | 70 ScriptPromiseResolver* resolver = ScriptPromiseResolver::Create(script_state); |
| 71 ScriptPromise promise = resolver->Promise(); | 71 ScriptPromise promise = resolver->Promise(); |
| 72 GetGatt()->AddToActiveAlgorithms(resolver); | 72 GetGatt()->AddToActiveAlgorithms(resolver); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 84 const Vector<uint8_t>& value, | 84 const Vector<uint8_t>& value, |
| 85 mojom::blink::WebBluetoothResult result) { | 85 mojom::blink::WebBluetoothResult result) { |
| 86 if (!resolver->GetExecutionContext() || | 86 if (!resolver->GetExecutionContext() || |
| 87 resolver->GetExecutionContext()->IsContextDestroyed()) | 87 resolver->GetExecutionContext()->IsContextDestroyed()) |
| 88 return; | 88 return; |
| 89 | 89 |
| 90 // If the resolver is not in the set of ActiveAlgorithms then the frame | 90 // If the resolver is not in the set of ActiveAlgorithms then the frame |
| 91 // disconnected so we reject. | 91 // disconnected so we reject. |
| 92 if (!GetGatt()->RemoveFromActiveAlgorithms(resolver)) { | 92 if (!GetGatt()->RemoveFromActiveAlgorithms(resolver)) { |
| 93 resolver->Reject( | 93 resolver->Reject( |
| 94 BluetoothError::CreateNotConnectedException(BluetoothOperation::GATT)); | 94 BluetoothError::CreateNotConnectedException(BluetoothOperation::kGATT)); |
| 95 return; | 95 return; |
| 96 } | 96 } |
| 97 | 97 |
| 98 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { | 98 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { |
| 99 value_ = BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value); | 99 value_ = BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value); |
| 100 resolver->Resolve(); | 100 resolver->Resolve(); |
| 101 } else { | 101 } else { |
| 102 resolver->Reject(BluetoothError::CreateDOMException(result)); | 102 resolver->Reject(BluetoothError::CreateDOMException(result)); |
| 103 } | 103 } |
| 104 } | 104 } |
| 105 | 105 |
| 106 ScriptPromise BluetoothRemoteGATTDescriptor::writeValue( | 106 ScriptPromise BluetoothRemoteGATTDescriptor::writeValue( |
| 107 ScriptState* script_state, | 107 ScriptState* script_state, |
| 108 const DOMArrayPiece& value) { | 108 const DOMArrayPiece& value) { |
| 109 if (!GetGatt()->connected()) { | 109 if (!GetGatt()->connected()) { |
| 110 return ScriptPromise::RejectWithDOMException( | 110 return ScriptPromise::RejectWithDOMException( |
| 111 script_state, | 111 script_state, |
| 112 BluetoothError::CreateNotConnectedException(BluetoothOperation::GATT)); | 112 BluetoothError::CreateNotConnectedException(BluetoothOperation::kGATT)); |
| 113 } | 113 } |
| 114 | 114 |
| 115 if (!GetGatt()->device()->IsValidDescriptor(descriptor_->instance_id)) { | 115 if (!GetGatt()->device()->IsValidDescriptor(descriptor_->instance_id)) { |
| 116 return ScriptPromise::RejectWithDOMException( | 116 return ScriptPromise::RejectWithDOMException( |
| 117 script_state, CreateInvalidDescriptorError()); | 117 script_state, CreateInvalidDescriptorError()); |
| 118 } | 118 } |
| 119 | 119 |
| 120 // Partial implementation of writeValue algorithm: | 120 // Partial implementation of writeValue algorithm: |
| 121 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdesc
riptor-writevalue | 121 // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattdesc
riptor-writevalue |
| 122 | 122 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 152 " is no longer valid. Remember to retrieve the Descriptor again " | 152 " is no longer valid. Remember to retrieve the Descriptor again " |
| 153 "after reconnecting."); | 153 "after reconnecting."); |
| 154 } | 154 } |
| 155 | 155 |
| 156 DEFINE_TRACE(BluetoothRemoteGATTDescriptor) { | 156 DEFINE_TRACE(BluetoothRemoteGATTDescriptor) { |
| 157 visitor->Trace(characteristic_); | 157 visitor->Trace(characteristic_); |
| 158 visitor->Trace(value_); | 158 visitor->Trace(value_); |
| 159 } | 159 } |
| 160 | 160 |
| 161 } // namespace blink | 161 } // namespace blink |
| OLD | NEW |