Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/Bluetooth.h" | 5 #include "modules/bluetooth/Bluetooth.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/DOMException.h" | 10 #include "core/dom/DOMException.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 "'namePrefix', if present, must me non-empty."); | 95 "'namePrefix', if present, must me non-empty."); |
| 96 return; | 96 return; |
| 97 } | 97 } |
| 98 canonicalizedFilter.namePrefix = filter.namePrefix(); | 98 canonicalizedFilter.namePrefix = filter.namePrefix(); |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 | 101 |
| 102 static void convertRequestDeviceOptions(const RequestDeviceOptions& options, | 102 static void convertRequestDeviceOptions(const RequestDeviceOptions& options, |
| 103 WebRequestDeviceOptions& result, | 103 WebRequestDeviceOptions& result, |
| 104 ExceptionState& exceptionState) { | 104 ExceptionState& exceptionState) { |
| 105 ASSERT(options.hasFilters()); | 105 result.acceptAllDevices = options.acceptAllDevices(); |
|
ortuno
2016/10/31 00:00:02
In order to debug the spec and make the implementa
| |
| 106 if (!result.acceptAllDevices) { | |
| 107 if (!options.hasFilters() || options.filters().isEmpty()) { | |
| 108 exceptionState.throwTypeError( | |
| 109 "'filters' member must be non-empty to find any devices when " | |
| 110 "'acceptAllDevices' is false."); | |
| 111 return; | |
| 112 } | |
| 106 | 113 |
| 107 if (options.filters().isEmpty()) { | 114 Vector<WebBluetoothScanFilter> filters; |
| 108 exceptionState.throwTypeError( | 115 for (const BluetoothScanFilter& filter : options.filters()) { |
| 109 "'filters' member must be non-empty to find any devices."); | 116 WebBluetoothScanFilter canonicalizedFilter = WebBluetoothScanFilter(); |
| 117 | |
| 118 canonicalizeFilter(filter, canonicalizedFilter, exceptionState); | |
| 119 | |
| 120 if (exceptionState.hadException()) | |
| 121 return; | |
| 122 | |
| 123 filters.append(canonicalizedFilter); | |
| 124 } | |
| 125 | |
| 126 result.filters.assign(filters); | |
| 110 } | 127 } |
| 111 | 128 |
| 112 Vector<WebBluetoothScanFilter> filters; | |
| 113 for (const BluetoothScanFilter& filter : options.filters()) { | |
| 114 WebBluetoothScanFilter canonicalizedFilter = WebBluetoothScanFilter(); | |
| 115 | |
| 116 canonicalizeFilter(filter, canonicalizedFilter, exceptionState); | |
| 117 | |
| 118 if (exceptionState.hadException()) | |
| 119 return; | |
| 120 | |
| 121 filters.append(canonicalizedFilter); | |
| 122 } | |
| 123 | |
| 124 result.filters.assign(filters); | |
| 125 | |
| 126 if (options.hasOptionalServices()) { | 129 if (options.hasOptionalServices()) { |
| 127 Vector<WebString> optionalServices; | 130 Vector<WebString> optionalServices; |
| 128 for (const StringOrUnsignedLong& optionalService : | 131 for (const StringOrUnsignedLong& optionalService : |
| 129 options.optionalServices()) { | 132 options.optionalServices()) { |
| 130 const String& validatedOptionalService = | 133 const String& validatedOptionalService = |
| 131 BluetoothUUID::getService(optionalService, exceptionState); | 134 BluetoothUUID::getService(optionalService, exceptionState); |
| 132 if (exceptionState.hadException()) | 135 if (exceptionState.hadException()) |
| 133 return; | 136 return; |
| 134 optionalServices.append(validatedOptionalService); | 137 optionalServices.append(validatedOptionalService); |
| 135 } | 138 } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 210 // Subsequent steps are handled in the browser process. | 213 // Subsequent steps are handled in the browser process. |
| 211 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); | 214 ScriptPromiseResolver* resolver = ScriptPromiseResolver::create(scriptState); |
| 212 ScriptPromise promise = resolver->promise(); | 215 ScriptPromise promise = resolver->promise(); |
| 213 webbluetooth->requestDevice( | 216 webbluetooth->requestDevice( |
| 214 webOptions, | 217 webOptions, |
| 215 new CallbackPromiseAdapter<BluetoothDevice, BluetoothError>(resolver)); | 218 new CallbackPromiseAdapter<BluetoothDevice, BluetoothError>(resolver)); |
| 216 return promise; | 219 return promise; |
| 217 } | 220 } |
| 218 | 221 |
| 219 } // namespace blink | 222 } // namespace blink |
| OLD | NEW |