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

Unified Diff: third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.cpp

Issue 2443473003: bluetooth: Require frame to be connected for characteristic.readValue to succeed (Closed)
Patch Set: Fix typo Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.cpp
diff --git a/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.cpp b/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.cpp
index c92a061a325740853622742149e7dd9f1518653e..634b516a9f26151340e76a6bcffeab4fabe62d5b 100644
--- a/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.cpp
+++ b/third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.cpp
@@ -23,6 +23,11 @@ namespace blink {
namespace {
+const char kGATTServerDisconnected[] =
+ "GATT Server disconnected while performing a GATT operation.";
+const char kGATTServerNotConnected[] =
+ "GATT Server is disconnected. Cannot perform GATT operations.";
+
DOMDataView* ConvertWebVectorToDataView(const WebVector<uint8_t>& webVector) {
static_assert(sizeof(*webVector.data()) == 1,
"uint8_t should be a single byte");
@@ -119,16 +124,28 @@ class ReadValueCallback : public WebBluetoothReadValueCallbacks {
public:
ReadValueCallback(BluetoothRemoteGATTCharacteristic* characteristic,
ScriptPromiseResolver* resolver)
- : m_webCharacteristic(characteristic), m_resolver(resolver) {}
+ : m_characteristic(characteristic), m_resolver(resolver) {
+ // We always check that the device is connected before constructing this
+ // object.
+ CHECK(m_characteristic->gatt()->connected());
+ m_characteristic->gatt()->AddToActiveAlgorithms(m_resolver.get());
+ }
void onSuccess(const WebVector<uint8_t>& value) override {
if (!m_resolver->getExecutionContext() ||
m_resolver->getExecutionContext()->activeDOMObjectsAreStopped())
return;
+ if (!m_characteristic->gatt()->RemoveFromActiveAlgorithms(
+ m_resolver.get())) {
+ m_resolver->reject(
+ DOMException::create(NetworkError, kGATTServerDisconnected));
+ return;
+ }
+
DOMDataView* domDataView = ConvertWebVectorToDataView(value);
- if (m_webCharacteristic)
- m_webCharacteristic->setValue(domDataView);
+ if (m_characteristic)
+ m_characteristic->setValue(domDataView);
m_resolver->resolve(domDataView);
}
@@ -140,16 +157,30 @@ class ReadValueCallback : public WebBluetoothReadValueCallbacks {
if (!m_resolver->getExecutionContext() ||
m_resolver->getExecutionContext()->activeDOMObjectsAreStopped())
return;
+
+ if (!m_characteristic->gatt()->RemoveFromActiveAlgorithms(
+ m_resolver.get())) {
+ m_resolver->reject(
+ DOMException::create(NetworkError, kGATTServerDisconnected));
+ return;
+ }
+
m_resolver->reject(BluetoothError::take(m_resolver, error));
}
private:
- WeakPersistent<BluetoothRemoteGATTCharacteristic> m_webCharacteristic;
+ WeakPersistent<BluetoothRemoteGATTCharacteristic> m_characteristic;
Persistent<ScriptPromiseResolver> m_resolver;
};
ScriptPromise BluetoothRemoteGATTCharacteristic::readValue(
ScriptState* scriptState) {
+ if (!gatt()->connected()) {
+ return ScriptPromise::rejectWithDOMException(
+ scriptState,
+ DOMException::create(NetworkError, kGATTServerNotConnected));
+ }
+
WebBluetooth* webbluetooth =
BluetoothSupplement::fromScriptState(scriptState);
« no previous file with comments | « third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTCharacteristic.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698