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

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

Issue 2216623002: bluetooth: {start,stop}Notifications() return the characteristic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change WeakPersistent to Persistent Created 4 years, 4 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/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/DOMDataView.h" 10 #include "core/dom/DOMDataView.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 WebVector<uint8_t> valueVector(value.bytes(), value.byteLength()); 188 WebVector<uint8_t> valueVector(value.bytes(), value.byteLength());
189 189
190 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 190 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
191 191
192 ScriptPromise promise = resolver->promise(); 192 ScriptPromise promise = resolver->promise();
193 webbluetooth->writeValue(m_webCharacteristic->characteristicInstanceID, valu eVector, new WriteValueCallback(this, resolver)); 193 webbluetooth->writeValue(m_webCharacteristic->characteristicInstanceID, valu eVector, new WriteValueCallback(this, resolver));
194 194
195 return promise; 195 return promise;
196 } 196 }
197 197
198 class NotificationsCallback : public WebBluetoothNotificationsCallbacks {
199 public:
200 NotificationsCallback(BluetoothRemoteGATTCharacteristic* characteristic, Scr iptPromiseResolver* resolver) : m_webCharacteristic(characteristic), m_resolver( resolver) {}
201
202 void onSuccess() override
203 {
204 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped())
205 return;
206
207 m_resolver->resolve(m_webCharacteristic);
208 }
209
210 void onError(int32_t error /* Corresponds to WebBluetoothError in web_blueto oth.mojom */) override
211 {
212 if (!m_resolver->getExecutionContext() || m_resolver->getExecutionContex t()->activeDOMObjectsAreStopped())
213 return;
214 m_resolver->reject(BluetoothError::take(m_resolver, error));
215 }
216
217 private:
218 Persistent<BluetoothRemoteGATTCharacteristic> m_webCharacteristic;
219 Persistent<ScriptPromiseResolver> m_resolver;
220 };
221
198 ScriptPromise BluetoothRemoteGATTCharacteristic::startNotifications(ScriptState* scriptState) 222 ScriptPromise BluetoothRemoteGATTCharacteristic::startNotifications(ScriptState* scriptState)
199 { 223 {
200 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e); 224 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e);
201 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 225 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
202 ScriptPromise promise = resolver->promise(); 226 ScriptPromise promise = resolver->promise();
203 webbluetooth->startNotifications(m_webCharacteristic->characteristicInstance ID, new CallbackPromiseAdapter<void, BluetoothError>(resolver)); 227 webbluetooth->startNotifications(m_webCharacteristic->characteristicInstance ID, new NotificationsCallback(this, resolver));
204 return promise; 228 return promise;
205 } 229 }
206 230
207 ScriptPromise BluetoothRemoteGATTCharacteristic::stopNotifications(ScriptState* scriptState) 231 ScriptPromise BluetoothRemoteGATTCharacteristic::stopNotifications(ScriptState* scriptState)
208 { 232 {
209 #if OS(MACOSX) || OS(ANDROID) 233 #if OS(MACOSX) || OS(ANDROID)
210 // TODO(jlebel): Remove when stopNotifications is implemented. 234 // TODO(jlebel): Remove when stopNotifications is implemented.
211 // TODO(scheib): Remove when stopNotifications is implemented. 235 // TODO(scheib): Remove when stopNotifications is implemented.
212 return ScriptPromise::rejectWithDOMException(scriptState, 236 return ScriptPromise::rejectWithDOMException(scriptState,
213 DOMException::create(NotSupportedError, 237 DOMException::create(NotSupportedError,
214 "stopNotifications is not implemented yet. See https://goo.gl/J6ASzs ")); 238 "stopNotifications is not implemented yet. See https://goo.gl/J6ASzs "));
215 #endif // OS(MACOSX) || OS(ANDROID) 239 #endif // OS(MACOSX) || OS(ANDROID)
216 240
217 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e); 241 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e);
218 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 242 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
219 ScriptPromise promise = resolver->promise(); 243 ScriptPromise promise = resolver->promise();
220 webbluetooth->stopNotifications(m_webCharacteristic->characteristicInstanceI D, new CallbackPromiseAdapter<void, BluetoothError>(resolver)); 244 webbluetooth->stopNotifications(m_webCharacteristic->characteristicInstanceI D, new NotificationsCallback(this, resolver));
221 return promise; 245 return promise;
222 } 246 }
223 247
224 DEFINE_TRACE(BluetoothRemoteGATTCharacteristic) 248 DEFINE_TRACE(BluetoothRemoteGATTCharacteristic)
225 { 249 {
226 visitor->trace(m_service); 250 visitor->trace(m_service);
227 visitor->trace(m_properties); 251 visitor->trace(m_properties);
228 visitor->trace(m_value); 252 visitor->trace(m_value);
229 EventTargetWithInlineData::trace(visitor); 253 EventTargetWithInlineData::trace(visitor);
230 ActiveDOMObject::trace(visitor); 254 ActiveDOMObject::trace(visitor);
231 } 255 }
232 256
233 } // namespace blink 257 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698