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 2a0bee72f892edaa8c5efc9123b3ecd4e13d742b..08e591eaffb37d6ac2ff8042c96701a3ded7351e 100644 |
| --- a/third_party/WebKit/Source/modules/bluetooth/Bluetooth.cpp |
| +++ b/third_party/WebKit/Source/modules/bluetooth/Bluetooth.cpp |
| @@ -21,23 +21,62 @@ |
| namespace blink { |
| -// Returns a DOMException if the conversion fails, or null if it succeeds. |
| -static void convertRequestDeviceOptions(const RequestDeviceOptions& options, WebRequestDeviceOptions& result, ExceptionState& exceptionState) |
| +static void canonicalizeFilter(const BluetoothScanFilter& filter, WebBluetoothScanFilter& canonicalizedFilter, ExceptionState& exceptionState) |
| { |
| - if (options.hasFilters()) { |
| - Vector<WebBluetoothScanFilter> filters; |
| - for (const BluetoothScanFilter& filter : options.filters()) { |
| - Vector<WebString> services; |
| - for (const StringOrUnsignedLong& service : filter.services()) { |
| - const String& validatedService = BluetoothUUID::getService(service, exceptionState); |
| - if (exceptionState.hadException()) |
| - return; |
| - services.append(validatedService); |
| - } |
| - filters.append(WebBluetoothScanFilter(services)); |
| + if (!(filter.hasServices() || filter.hasName() || filter.hasNamePrefix())) { |
| + exceptionState.throwTypeError( |
| + "A filter must restrict the devices in some way."); |
| + return; |
| + } |
| + |
| + if (filter.hasServices()) { |
| + if (filter.services().size() == 0) { |
| + exceptionState.throwTypeError( |
| + "The services member must contain at least one service"); |
|
scheib
2015/10/22 04:58:42
'services', if present, must contain ...
ortuno
2015/10/22 16:21:31
Done.
|
| + return; |
| + } |
| + Vector<WebString> services; |
| + for (const StringOrUnsignedLong& service : filter.services()) { |
| + const String& validatedService = BluetoothUUID::getService(service, exceptionState); |
| + if (exceptionState.hadException()) |
| + return; |
| + services.append(validatedService); |
| + } |
| + canonicalizedFilter.services.assign(services); |
| + } |
| + |
| + if (filter.hasName()) { |
| + canonicalizedFilter.name = filter.name(); |
|
scheib
2015/10/22 04:58:42
Shouldn't this also test for empty string ""?
ortuno
2015/10/22 16:21:31
The spec doesn't say anything about empty name. Al
scheib
2015/10/22 18:35:52
Hmm, I was distracted by the empty prefix. OK.
|
| + } |
| + |
| + if (filter.hasNamePrefix()) { |
| + if (filter.namePrefix().length() == 0) { |
| + exceptionState.throwTypeError( |
| + "A filter must restrict the devices in some way."); |
|
scheib
2015/10/22 04:58:42
'namePrefix', if present, must be non-empty.
ortuno
2015/10/22 16:21:31
Done. This message was copied from the spec. Can y
scheib
2015/10/22 18:35:52
Done.
|
| + return; |
| } |
| - result.filters.assign(filters); |
| + canonicalizedFilter.namePrefix = filter.namePrefix(); |
| } |
| +} |
| + |
| +static void convertRequestDeviceOptions(const RequestDeviceOptions& options, WebRequestDeviceOptions& result, ExceptionState& exceptionState) |
| +{ |
| + ASSERT(options.hasFilters()); |
| + |
| + Vector<WebBluetoothScanFilter> filters; |
| + for (const BluetoothScanFilter& filter : options.filters()) { |
| + WebBluetoothScanFilter canonicalizedFilter = WebBluetoothScanFilter(); |
| + |
| + canonicalizeFilter(filter, canonicalizedFilter, exceptionState); |
| + |
| + if (exceptionState.hadException()) |
| + return; |
| + |
| + filters.append(canonicalizedFilter); |
| + } |
| + |
| + result.filters.assign(filters); |
| + |
| if (options.hasOptionalServices()) { |
| Vector<WebString> optionalServices; |
| for (const StringOrUnsignedLong& optionalService : options.optionalServices()) { |