Chromium Code Reviews| Index: Source/modules/bluetooth/Bluetooth.cpp |
| diff --git a/Source/modules/bluetooth/Bluetooth.cpp b/Source/modules/bluetooth/Bluetooth.cpp |
| index 0548f38cd92107111552293081873a5f0049be44..fc81f2e58a3b6754c6530db935b02f870a7e07f3 100644 |
| --- a/Source/modules/bluetooth/Bluetooth.cpp |
| +++ b/Source/modules/bluetooth/Bluetooth.cpp |
| @@ -12,20 +12,59 @@ |
| #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); |
| + } |
| + WebBluetoothScanFilter webFilter; |
| + webFilter.services.assign(services); |
|
ortuno
2015/06/15 19:13:37
why do you use assign instead of the constructor?
Jeffrey Yasskin
2015/06/15 19:19:18
I hadn't added the constructor when I wrote this c
|
| + filters.append(webFilter); |
| + } |
| + 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; |
| } |