Chromium Code Reviews| Index: third_party/WebKit/Source/modules/bluetooth/Bluetooth.cpp |
| diff --git a/third_party/WebKit/Source/modules/bluetooth/Bluetooth.cpp b/third_party/WebKit/Source/modules/bluetooth/Bluetooth.cpp |
| index 3ec59ad24fa62b79479b2f35d17c5f8875e9660d..ce8b80b2696787790f5a03a7a914abaed7dbc845 100644 |
| --- a/third_party/WebKit/Source/modules/bluetooth/Bluetooth.cpp |
| +++ b/third_party/WebKit/Source/modules/bluetooth/Bluetooth.cpp |
| @@ -100,26 +100,39 @@ static void canonicalizeFilter(const BluetoothScanFilter& filter, |
| static void convertRequestDeviceOptions(const RequestDeviceOptions& options, |
| WebRequestDeviceOptions& result, |
| ExceptionState& exceptionState) { |
| - ASSERT(options.hasFilters()); |
| - |
| - if (options.filters().isEmpty()) { |
| + if ((options.hasFilters() && options.acceptAllDevices()) || |
|
scheib
2016/11/22 21:22:44
Do you find either of these easier to read?
if
ortuno
2016/11/23 06:03:08
Went with the first one. Done.
|
| + (!options.hasFilters() && !options.acceptAllDevices())) { |
| exceptionState.throwTypeError( |
| - "'filters' member must be non-empty to find any devices."); |
| + "Either 'filters' should be present or 'acceptAllDevices' should be " |
| + "true, but not both."); |
| + return; |
| } |
| - Vector<WebBluetoothScanFilter> filters; |
| - for (const BluetoothScanFilter& filter : options.filters()) { |
| - WebBluetoothScanFilter canonicalizedFilter = WebBluetoothScanFilter(); |
| + result.acceptAllDevices = options.acceptAllDevices(); |
| - canonicalizeFilter(filter, canonicalizedFilter, exceptionState); |
| - |
| - if (exceptionState.hadException()) |
| + if (options.hasFilters()) { |
| + if (options.filters().isEmpty()) { |
|
haraken
2016/11/22 03:58:42
Is it possible that isEmpty returns true while has
ortuno
2016/11/22 04:00:12
Yup:
navigator.bluetooth.requestDevice({filters:
|
| + exceptionState.throwTypeError( |
| + "'filters' member must be non-empty to find any devices."); |
| return; |
| + } |
| - filters.append(canonicalizedFilter); |
| - } |
| + Vector<WebBluetoothScanFilter> filters; |
| + for (const BluetoothScanFilter& filter : options.filters()) { |
| + WebBluetoothScanFilter canonicalizedFilter = WebBluetoothScanFilter(); |
| + |
| + canonicalizeFilter(filter, canonicalizedFilter, exceptionState); |
| - result.filters.assign(filters); |
| + if (exceptionState.hadException()) |
| + return; |
| + |
| + filters.append(canonicalizedFilter); |
| + } |
| + |
| + result.filters.assign(filters); |
| + } else { |
| + result.hasFilters = false; |
| + } |
| if (options.hasOptionalServices()) { |
| Vector<WebString> optionalServices; |
| @@ -166,22 +179,17 @@ class RequestDeviceCallback : public WebBluetoothRequestDeviceCallbacks { |
| Persistent<ScriptPromiseResolver> m_resolver; |
| }; |
| -// https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetooth-requestdevice |
| ScriptPromise Bluetooth::requestDevice(ScriptState* scriptState, |
| const RequestDeviceOptions& options, |
| ExceptionState& exceptionState) { |
| ExecutionContext* context = scriptState->getExecutionContext(); |
| - // 1. If the incumbent settings object is not a secure context, reject promise |
| - // with a SecurityError and abort these steps. |
| String errorMessage; |
| if (!context->isSecureContext(errorMessage)) { |
| return ScriptPromise::rejectWithDOMException( |
| scriptState, DOMException::create(SecurityError, errorMessage)); |
| } |
| - // 2. If the algorithm is not allowed to show a popup, reject promise with a |
| - // SecurityError and abort these steps. |
| if (!UserGestureIndicator::consumeUserGesture()) { |
| return ScriptPromise::rejectWithDOMException( |
| scriptState, |
| @@ -196,14 +204,11 @@ ScriptPromise Bluetooth::requestDevice(ScriptState* scriptState, |
| return ScriptPromise::rejectWithDOMException( |
| scriptState, DOMException::create(NotSupportedError)); |
| - // 3. In order to convert the arguments from service names and aliases to just |
| - // UUIDs, do the following substeps: |
| WebRequestDeviceOptions webOptions; |
|
scheib
2016/11/22 21:22:44
Some of these comments helped explain why these st
ortuno
2016/11/23 06:03:08
hmm I think the code is pretty clear already but e
|
| convertRequestDeviceOptions(options, webOptions, exceptionState); |
| if (exceptionState.hadException()) |
| return exceptionState.reject(scriptState); |
| - // Subsequent steps are handled in the browser process. |
| ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| ScriptPromise promise = resolver->promise(); |
| webbluetooth->requestDevice(webOptions, |