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

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

Issue 1940923002: bluetooth: Add JS error messages for unimplemented features (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTServer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "core/dom/DOMException.h" 11 #include "core/dom/DOMException.h"
12 #include "core/dom/ExceptionCode.h" 12 #include "core/dom/ExceptionCode.h"
13 #include "core/events/Event.h" 13 #include "core/events/Event.h"
14 #include "core/inspector/ConsoleMessage.h"
14 #include "modules/bluetooth/BluetoothCharacteristicProperties.h" 15 #include "modules/bluetooth/BluetoothCharacteristicProperties.h"
15 #include "modules/bluetooth/BluetoothError.h" 16 #include "modules/bluetooth/BluetoothError.h"
16 #include "modules/bluetooth/BluetoothSupplement.h" 17 #include "modules/bluetooth/BluetoothSupplement.h"
17 #include "public/platform/modules/bluetooth/WebBluetooth.h" 18 #include "public/platform/modules/bluetooth/WebBluetooth.h"
18 19
19 namespace blink { 20 namespace blink {
20 21
21 namespace { 22 namespace {
22 23
23 DOMDataView* ConvertWebVectorToDataView(const WebVector<uint8_t>& webVector) 24 DOMDataView* ConvertWebVectorToDataView(const WebVector<uint8_t>& webVector)
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 m_resolver->reject(BluetoothError::take(m_resolver, e)); 126 m_resolver->reject(BluetoothError::take(m_resolver, e));
126 } 127 }
127 128
128 private: 129 private:
129 WeakPersistent<BluetoothRemoteGATTCharacteristic> m_webCharacteristic; 130 WeakPersistent<BluetoothRemoteGATTCharacteristic> m_webCharacteristic;
130 Persistent<ScriptPromiseResolver> m_resolver; 131 Persistent<ScriptPromiseResolver> m_resolver;
131 }; 132 };
132 133
133 ScriptPromise BluetoothRemoteGATTCharacteristic::readValue(ScriptState* scriptSt ate) 134 ScriptPromise BluetoothRemoteGATTCharacteristic::readValue(ScriptState* scriptSt ate)
134 { 135 {
136 #if OS(MACOSX)
137 // TODO(jlebel): Remove when readValue is implemented.
138 return ScriptPromise::rejectWithDOMException(scriptState,
139 DOMException::create(NotSupportedError,
140 "readValue is not implemented yet. See https://goo.gl/J6ASzs"));
141 #endif // OS(MACOSX)
142
135 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e); 143 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e);
136 144
137 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 145 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
138 ScriptPromise promise = resolver->promise(); 146 ScriptPromise promise = resolver->promise();
139 webbluetooth->readValue(m_webCharacteristic->characteristicInstanceID, new R eadValueCallback(this, resolver)); 147 webbluetooth->readValue(m_webCharacteristic->characteristicInstanceID, new R eadValueCallback(this, resolver));
140 148
141 return promise; 149 return promise;
142 } 150 }
143 151
144 class WriteValueCallback : public WebBluetoothWriteValueCallbacks { 152 class WriteValueCallback : public WebBluetoothWriteValueCallbacks {
(...skipping 18 matching lines...) Expand all
163 m_resolver->reject(BluetoothError::take(m_resolver, e)); 171 m_resolver->reject(BluetoothError::take(m_resolver, e));
164 } 172 }
165 173
166 private: 174 private:
167 WeakPersistent<BluetoothRemoteGATTCharacteristic> m_webCharacteristic; 175 WeakPersistent<BluetoothRemoteGATTCharacteristic> m_webCharacteristic;
168 Persistent<ScriptPromiseResolver> m_resolver; 176 Persistent<ScriptPromiseResolver> m_resolver;
169 }; 177 };
170 178
171 ScriptPromise BluetoothRemoteGATTCharacteristic::writeValue(ScriptState* scriptS tate, const DOMArrayPiece& value) 179 ScriptPromise BluetoothRemoteGATTCharacteristic::writeValue(ScriptState* scriptS tate, const DOMArrayPiece& value)
172 { 180 {
181 #if OS(MACOSX)
182 // TODO(jlebel): Remove when writeValue is implemented.
183 return ScriptPromise::rejectWithDOMException(scriptState,
184 DOMException::create(NotSupportedError,
185 "writeValue is not implemented yet. See https://goo.gl/J6ASzs"));
186 #endif // OS(MACOSX)
187
173 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e); 188 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e);
174 // Partial implementation of writeValue algorithm: 189 // Partial implementation of writeValue algorithm:
175 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothgattchar acteristic-writevalue 190 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothgattchar acteristic-writevalue
176 191
177 // If bytes is more than 512 bytes long (the maximum length of an attribute 192 // If bytes is more than 512 bytes long (the maximum length of an attribute
178 // value, per Long Attribute Values) return a promise rejected with an 193 // value, per Long Attribute Values) return a promise rejected with an
179 // InvalidModificationError and abort. 194 // InvalidModificationError and abort.
180 if (value.byteLength() > 512) 195 if (value.byteLength() > 512)
181 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidModificationError, "Value can't exceed 512 bytes.")); 196 return ScriptPromise::rejectWithDOMException(scriptState, DOMException:: create(InvalidModificationError, "Value can't exceed 512 bytes."));
182 197
183 // Let valueVector be a copy of the bytes held by value. 198 // Let valueVector be a copy of the bytes held by value.
184 WebVector<uint8_t> valueVector(value.bytes(), value.byteLength()); 199 WebVector<uint8_t> valueVector(value.bytes(), value.byteLength());
185 200
186 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 201 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
187 202
188 ScriptPromise promise = resolver->promise(); 203 ScriptPromise promise = resolver->promise();
189 webbluetooth->writeValue(m_webCharacteristic->characteristicInstanceID, valu eVector, new WriteValueCallback(this, resolver)); 204 webbluetooth->writeValue(m_webCharacteristic->characteristicInstanceID, valu eVector, new WriteValueCallback(this, resolver));
190 205
191 return promise; 206 return promise;
192 } 207 }
193 208
194 ScriptPromise BluetoothRemoteGATTCharacteristic::startNotifications(ScriptState* scriptState) 209 ScriptPromise BluetoothRemoteGATTCharacteristic::startNotifications(ScriptState* scriptState)
195 { 210 {
211 #if OS(MACOSX)
212 // TODO(jlebel): Remove when startNotifications is implemented.
213 return ScriptPromise::rejectWithDOMException(scriptState,
214 DOMException::create(NotSupportedError,
215 "startNotifications is not implemented yet. See https://goo.gl/J6ASz s"));
216 #endif // OS(MACOSX)
217
196 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e); 218 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e);
197 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 219 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
198 ScriptPromise promise = resolver->promise(); 220 ScriptPromise promise = resolver->promise();
199 webbluetooth->startNotifications(m_webCharacteristic->characteristicInstance ID, new CallbackPromiseAdapter<void, BluetoothError>(resolver)); 221 webbluetooth->startNotifications(m_webCharacteristic->characteristicInstance ID, new CallbackPromiseAdapter<void, BluetoothError>(resolver));
200 return promise; 222 return promise;
201 } 223 }
202 224
203 ScriptPromise BluetoothRemoteGATTCharacteristic::stopNotifications(ScriptState* scriptState) 225 ScriptPromise BluetoothRemoteGATTCharacteristic::stopNotifications(ScriptState* scriptState)
204 { 226 {
227 #if OS(MACOSX)
scheib 2016/05/02 17:12:28 Merge these instead of duplicating the code: if OS
228 // TODO(jlebel): Remove when stopNotifications is implemented.
229 return ScriptPromise::rejectWithDOMException(scriptState,
230 DOMException::create(NotSupportedError,
231 "stopNotifications is not implemented yet. See https://goo.gl/J6ASzs "));
232 #endif // OS(MACOSX)
233 #if OS(ANDROID)
234 // TODO(scheib): Remove when stopNotifications is implemented.
235 return ScriptPromise::rejectWithDOMException(scriptState,
236 DOMException::create(NotSupportedError,
237 "stopNotifications is not implemented yet. See https://goo.gl/J6ASzs "));
238 #endif // OS(ANDROID)
239
205 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e); 240 WebBluetooth* webbluetooth = BluetoothSupplement::fromScriptState(scriptStat e);
206 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ; 241 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState) ;
207 ScriptPromise promise = resolver->promise(); 242 ScriptPromise promise = resolver->promise();
208 webbluetooth->stopNotifications(m_webCharacteristic->characteristicInstanceI D, new CallbackPromiseAdapter<void, BluetoothError>(resolver)); 243 webbluetooth->stopNotifications(m_webCharacteristic->characteristicInstanceI D, new CallbackPromiseAdapter<void, BluetoothError>(resolver));
209 return promise; 244 return promise;
210 } 245 }
211 246
212 DEFINE_TRACE(BluetoothRemoteGATTCharacteristic) 247 DEFINE_TRACE(BluetoothRemoteGATTCharacteristic)
213 { 248 {
214 visitor->trace(m_properties); 249 visitor->trace(m_properties);
215 visitor->trace(m_value); 250 visitor->trace(m_value);
216 EventTargetWithInlineData::trace(visitor); 251 EventTargetWithInlineData::trace(visitor);
217 ActiveDOMObject::trace(visitor); 252 ActiveDOMObject::trace(visitor);
218 } 253 }
219 254
220 } // namespace blink 255 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/modules/bluetooth/BluetoothRemoteGATTServer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698