| 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..c776bb647f758bba007a75a4f2e37746b3051287 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(
|
| + "'services', if present, must contain at least one service.");
|
| + 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();
|
| + }
|
| +
|
| + if (filter.hasNamePrefix()) {
|
| + if (filter.namePrefix().length() == 0) {
|
| + exceptionState.throwTypeError(
|
| + "'namePrefix', if present, must me non-empty.");
|
| + 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()) {
|
|
|