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

Unified Diff: Source/modules/bluetooth/Bluetooth.cpp

Issue 1182973002: Implement the Blink side of RequestDeviceOptions. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@pinned
Patch Set: Prepare readValue.html for a mock data change Created 5 years, 6 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
Index: Source/modules/bluetooth/Bluetooth.cpp
diff --git a/Source/modules/bluetooth/Bluetooth.cpp b/Source/modules/bluetooth/Bluetooth.cpp
index 0548f38cd92107111552293081873a5f0049be44..9b9d6c2e152967f56084ff0145d61bcd9e254575 100644
--- a/Source/modules/bluetooth/Bluetooth.cpp
+++ b/Source/modules/bluetooth/Bluetooth.cpp
@@ -12,20 +12,57 @@
#include "core/dom/ExceptionCode.h"
#include "modules/bluetooth/BluetoothDevice.h"
#include "modules/bluetooth/BluetoothError.h"
+#include "modules/bluetooth/RequestDeviceOptions.h"
#include "public/platform/Platform.h"
#include "public/platform/modules/bluetooth/WebBluetooth.h"
+#include "public/platform/modules/bluetooth/WebRequestDeviceOptions.h"
namespace blink {
-ScriptPromise Bluetooth::requestDevice(ScriptState* scriptState)
+// Returns a DOMException if the conversion fails, or null if it succeeds.
+static DOMException* convertRequestDeviceOptions(const RequestDeviceOptions& options, WebRequestDeviceOptions& result)
+{
+ if (options.hasFilters()) {
+ Vector<WebBluetoothScanFilter> filters;
+ for (const BluetoothScanFilter& filter : options.filters()) {
+ Vector<WebString> services;
+ for (const String& service : filter.services()) {
+ // TODO(jyasskin): https://crbug.com/500630: Pass the services
+ // through BluetoothUUID.getService() per
+ // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice
+ services.append(service);
+ }
+ filters.append(WebBluetoothScanFilter(services));
+ }
+ result.filters.assign(filters);
+ }
+ if (options.hasOptionalServices()) {
+ Vector<WebString> optionalServices;
+ for (const String& optionalService : options.optionalServices()) {
+ // TODO(jyasskin): https://crbug.com/500630: Pass the services
+ // through BluetoothUUID.getService() per
+ // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetooth-requestdevice
+ optionalServices.append(optionalService);
+ }
+ result.optionalServices.assign(optionalServices);
+ }
+ return 0;
+}
+
+ScriptPromise Bluetooth::requestDevice(ScriptState* scriptState, const RequestDeviceOptions& options)
{
WebBluetooth* webbluetooth = Platform::current()->bluetooth();
if (!webbluetooth)
return ScriptPromise::rejectWithDOMException(scriptState, DOMException::create(NotSupportedError));
+ WebRequestDeviceOptions webOptions;
+ DOMException* exception = convertRequestDeviceOptions(options, webOptions);
+ if (exception)
+ return ScriptPromise::rejectWithDOMException(scriptState, exception);
+
RefPtrWillBeRawPtr<ScriptPromiseResolver> resolver = ScriptPromiseResolver::create(scriptState);
ScriptPromise promise = resolver->promise();
- webbluetooth->requestDevice(new CallbackPromiseAdapter<BluetoothDevice, BluetoothError>(resolver));
+ webbluetooth->requestDevice(webOptions, new CallbackPromiseAdapter<BluetoothDevice, BluetoothError>(resolver));
return promise;
}

Powered by Google App Engine
This is Rietveld 408576698