| 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;
|
|
|
| }
|
|
|