Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(532)

Side by Side Diff: third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.cpp

Issue 2637343002: Implement WebBluetooth descriptor.readValue() (Closed)
Patch Set: #3 Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/BluetoothRemoteGATTCharacteristic.h" 5 #include "modules/bluetooth/BluetoothRemoteGATTCharacteristic.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/events/Event.h" 9 #include "core/events/Event.h"
10 #include "core/inspector/ConsoleMessage.h" 10 #include "core/inspector/ConsoleMessage.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value.value()); 115 BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value.value());
116 setValue(domDataView); 116 setValue(domDataView);
117 resolver->resolve(domDataView); 117 resolver->resolve(domDataView);
118 } else { 118 } else {
119 resolver->reject(BluetoothError::take(resolver, result)); 119 resolver->reject(BluetoothError::take(resolver, result));
120 } 120 }
121 } 121 }
122 122
123 ScriptPromise BluetoothRemoteGATTCharacteristic::readValue( 123 ScriptPromise BluetoothRemoteGATTCharacteristic::readValue(
124 ScriptState* scriptState) { 124 ScriptState* scriptState) {
125 // We always check that the device is connected.
126 if (!getGatt()->connected()) { 125 if (!getGatt()->connected()) {
127 return ScriptPromise::rejectWithDOMException( 126 return ScriptPromise::rejectWithDOMException(
128 scriptState, 127 scriptState,
129 BluetoothRemoteGATTUtils::CreateDOMException( 128 BluetoothRemoteGATTUtils::CreateDOMException(
130 BluetoothRemoteGATTUtils::ExceptionType::kGATTServerNotConnected)); 129 BluetoothRemoteGATTUtils::ExceptionType::kGATTServerNotConnected));
131 } 130 }
132 131
133 if (!getGatt()->device()->isValidCharacteristic( 132 if (!getGatt()->device()->isValidCharacteristic(
134 m_characteristic->instance_id)) { 133 m_characteristic->instance_id)) {
135 return ScriptPromise::rejectWithDOMException( 134 return ScriptPromise::rejectWithDOMException(
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 setValue(BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value)); 171 setValue(BluetoothRemoteGATTUtils::ConvertWTFVectorToDataView(value));
173 resolver->resolve(); 172 resolver->resolve();
174 } else { 173 } else {
175 resolver->reject(BluetoothError::take(resolver, result)); 174 resolver->reject(BluetoothError::take(resolver, result));
176 } 175 }
177 } 176 }
178 177
179 ScriptPromise BluetoothRemoteGATTCharacteristic::writeValue( 178 ScriptPromise BluetoothRemoteGATTCharacteristic::writeValue(
180 ScriptState* scriptState, 179 ScriptState* scriptState,
181 const DOMArrayPiece& value) { 180 const DOMArrayPiece& value) {
182 // We always check that the device is connected.
183 if (!getGatt()->connected()) { 181 if (!getGatt()->connected()) {
184 return ScriptPromise::rejectWithDOMException( 182 return ScriptPromise::rejectWithDOMException(
185 scriptState, 183 scriptState,
186 BluetoothRemoteGATTUtils::CreateDOMException( 184 BluetoothRemoteGATTUtils::CreateDOMException(
187 BluetoothRemoteGATTUtils::ExceptionType::kGATTServerNotConnected)); 185 BluetoothRemoteGATTUtils::ExceptionType::kGATTServerNotConnected));
188 } 186 }
189 187
190 if (!getGatt()->device()->isValidCharacteristic( 188 if (!getGatt()->device()->isValidCharacteristic(
191 m_characteristic->instance_id)) { 189 m_characteristic->instance_id)) {
192 return ScriptPromise::rejectWithDOMException( 190 return ScriptPromise::rejectWithDOMException(
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 239
242 if (result == mojom::blink::WebBluetoothResult::SUCCESS) { 240 if (result == mojom::blink::WebBluetoothResult::SUCCESS) {
243 resolver->resolve(this); 241 resolver->resolve(this);
244 } else { 242 } else {
245 resolver->reject(BluetoothError::take(resolver, result)); 243 resolver->reject(BluetoothError::take(resolver, result));
246 } 244 }
247 } 245 }
248 246
249 ScriptPromise BluetoothRemoteGATTCharacteristic::startNotifications( 247 ScriptPromise BluetoothRemoteGATTCharacteristic::startNotifications(
250 ScriptState* scriptState) { 248 ScriptState* scriptState) {
251 // We always check that the device is connected.
252 if (!getGatt()->connected()) { 249 if (!getGatt()->connected()) {
253 return ScriptPromise::rejectWithDOMException( 250 return ScriptPromise::rejectWithDOMException(
254 scriptState, 251 scriptState,
255 BluetoothRemoteGATTUtils::CreateDOMException( 252 BluetoothRemoteGATTUtils::CreateDOMException(
256 BluetoothRemoteGATTUtils::ExceptionType::kGATTServerNotConnected)); 253 BluetoothRemoteGATTUtils::ExceptionType::kGATTServerNotConnected));
257 } 254 }
258 255
259 if (!getGatt()->device()->isValidCharacteristic( 256 if (!getGatt()->device()->isValidCharacteristic(
260 m_characteristic->instance_id)) { 257 m_characteristic->instance_id)) {
261 return ScriptPromise::rejectWithDOMException( 258 return ScriptPromise::rejectWithDOMException(
(...skipping 11 matching lines...) Expand all
273 m_characteristic->instance_id, 270 m_characteristic->instance_id,
274 convertToBaseCallback( 271 convertToBaseCallback(
275 WTF::bind(&BluetoothRemoteGATTCharacteristic::NotificationsCallback, 272 WTF::bind(&BluetoothRemoteGATTCharacteristic::NotificationsCallback,
276 wrapPersistent(this), wrapPersistent(resolver)))); 273 wrapPersistent(this), wrapPersistent(resolver))));
277 274
278 return promise; 275 return promise;
279 } 276 }
280 277
281 ScriptPromise BluetoothRemoteGATTCharacteristic::stopNotifications( 278 ScriptPromise BluetoothRemoteGATTCharacteristic::stopNotifications(
282 ScriptState* scriptState) { 279 ScriptState* scriptState) {
283 // We always check that the device is connected.
284 if (!getGatt()->connected()) { 280 if (!getGatt()->connected()) {
285 return ScriptPromise::rejectWithDOMException( 281 return ScriptPromise::rejectWithDOMException(
286 scriptState, 282 scriptState,
287 BluetoothRemoteGATTUtils::CreateDOMException( 283 BluetoothRemoteGATTUtils::CreateDOMException(
288 BluetoothRemoteGATTUtils::ExceptionType::kGATTServerNotConnected)); 284 BluetoothRemoteGATTUtils::ExceptionType::kGATTServerNotConnected));
289 } 285 }
290 286
291 if (!getGatt()->device()->isValidCharacteristic( 287 if (!getGatt()->device()->isValidCharacteristic(
292 m_characteristic->instance_id)) { 288 m_characteristic->instance_id)) {
293 return ScriptPromise::rejectWithDOMException( 289 return ScriptPromise::rejectWithDOMException(
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 DEFINE_TRACE(BluetoothRemoteGATTCharacteristic) { 426 DEFINE_TRACE(BluetoothRemoteGATTCharacteristic) {
431 visitor->trace(m_service); 427 visitor->trace(m_service);
432 visitor->trace(m_properties); 428 visitor->trace(m_properties);
433 visitor->trace(m_value); 429 visitor->trace(m_value);
434 visitor->trace(m_device); 430 visitor->trace(m_device);
435 EventTargetWithInlineData::trace(visitor); 431 EventTargetWithInlineData::trace(visitor);
436 ContextLifecycleObserver::trace(visitor); 432 ContextLifecycleObserver::trace(visitor);
437 } 433 }
438 434
439 } // namespace blink 435 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698