| 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" |
| 11 #include "core/dom/Document.h" | 11 #include "core/dom/Document.h" |
| 12 #include "core/dom/ExceptionCode.h" | 12 #include "core/dom/ExceptionCode.h" |
| 13 #include "core/dom/ExecutionContext.h" | 13 #include "core/dom/ExecutionContext.h" |
| 14 #include "core/frame/LocalFrame.h" | 14 #include "core/frame/LocalFrame.h" |
| 15 #include "modules/bluetooth/BluetoothDevice.h" | 15 #include "modules/bluetooth/BluetoothDevice.h" |
| 16 #include "modules/bluetooth/BluetoothError.h" | 16 #include "modules/bluetooth/BluetoothError.h" |
| 17 #include "modules/bluetooth/BluetoothRemoteGATTCharacteristic.h" | 17 #include "modules/bluetooth/BluetoothRemoteGATTCharacteristic.h" |
| 18 #include "modules/bluetooth/BluetoothUUID.h" | 18 #include "modules/bluetooth/BluetoothUUID.h" |
| 19 #include "modules/bluetooth/RequestDeviceOptions.h" | 19 #include "modules/bluetooth/RequestDeviceOptions.h" |
| 20 #include "platform/UserGestureIndicator.h" | 20 #include "platform/UserGestureIndicator.h" |
| 21 #include "public/platform/InterfaceProvider.h" | 21 #include "public/platform/InterfaceProvider.h" |
| 22 #include <memory> | 22 #include <memory> |
| 23 #include <utility> | 23 #include <utility> |
| 24 | 24 |
| 25 namespace blink { | 25 namespace blink { |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 // A name coming from an adv packet is max 29 bytes (adv packet max size | |
| 29 // 31 bytes - 2 byte length field), but the name can also be acquired via | |
| 30 // gap.device_name, so it is limited to the max EIR packet size of 240 bytes. | |
| 31 // See Core Spec 5.0, vol 3, C, 8.1.2. | |
| 32 const size_t kMaxFilterNameLength = 240; | |
| 33 const char kFilterNameTooLong[] = | |
| 34 "A 'name' or 'namePrefix' longer than 240 bytes results in no devices " | |
| 35 "being found, because a device can't acquire a name longer than 240 bytes."; | |
| 36 // Per the Bluetooth Spec: The name is a user-friendly name associated with the | 28 // Per the Bluetooth Spec: The name is a user-friendly name associated with the |
| 37 // device and consists of a maximum of 248 bytes coded according to the UTF-8 | 29 // device and consists of a maximum of 248 bytes coded according to the UTF-8 |
| 38 // standard. | 30 // standard. |
| 39 const size_t kMaxDeviceNameLength = 248; | 31 const size_t kMaxDeviceNameLength = 248; |
| 40 const char kDeviceNameTooLong[] = | 32 const char kDeviceNameTooLong[] = |
| 41 "A device name can't be longer than 248 bytes."; | 33 "A device name can't be longer than 248 bytes."; |
| 42 } // namespace | 34 } // namespace |
| 43 | 35 |
| 44 static void canonicalizeFilter( | 36 static void canonicalizeFilter( |
| 45 const BluetoothScanFilterInit& filter, | 37 const BluetoothScanFilterInit& filter, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 66 canonicalizedFilter->services->push_back(validatedService); | 58 canonicalizedFilter->services->push_back(validatedService); |
| 67 } | 59 } |
| 68 } | 60 } |
| 69 | 61 |
| 70 if (filter.hasName()) { | 62 if (filter.hasName()) { |
| 71 size_t nameLength = filter.name().utf8().length(); | 63 size_t nameLength = filter.name().utf8().length(); |
| 72 if (nameLength > kMaxDeviceNameLength) { | 64 if (nameLength > kMaxDeviceNameLength) { |
| 73 exceptionState.throwTypeError(kDeviceNameTooLong); | 65 exceptionState.throwTypeError(kDeviceNameTooLong); |
| 74 return; | 66 return; |
| 75 } | 67 } |
| 76 if (nameLength > kMaxFilterNameLength) { | |
| 77 exceptionState.throwDOMException(NotFoundError, kFilterNameTooLong); | |
| 78 return; | |
| 79 } | |
| 80 canonicalizedFilter->name = filter.name(); | 68 canonicalizedFilter->name = filter.name(); |
| 81 } | 69 } |
| 82 | 70 |
| 83 if (filter.hasNamePrefix()) { | 71 if (filter.hasNamePrefix()) { |
| 84 size_t namePrefixLength = filter.namePrefix().utf8().length(); | 72 size_t namePrefixLength = filter.namePrefix().utf8().length(); |
| 85 if (namePrefixLength > kMaxDeviceNameLength) { | 73 if (namePrefixLength > kMaxDeviceNameLength) { |
| 86 exceptionState.throwTypeError(kDeviceNameTooLong); | 74 exceptionState.throwTypeError(kDeviceNameTooLong); |
| 87 return; | 75 return; |
| 88 } | 76 } |
| 89 if (namePrefixLength > kMaxFilterNameLength) { | |
| 90 exceptionState.throwDOMException(NotFoundError, kFilterNameTooLong); | |
| 91 return; | |
| 92 } | |
| 93 if (filter.namePrefix().length() == 0) { | 77 if (filter.namePrefix().length() == 0) { |
| 94 exceptionState.throwTypeError( | 78 exceptionState.throwTypeError( |
| 95 "'namePrefix', if present, must me non-empty."); | 79 "'namePrefix', if present, must me non-empty."); |
| 96 return; | 80 return; |
| 97 } | 81 } |
| 98 canonicalizedFilter->name_prefix = filter.namePrefix(); | 82 canonicalizedFilter->name_prefix = filter.namePrefix(); |
| 99 } | 83 } |
| 100 } | 84 } |
| 101 | 85 |
| 102 static void convertRequestDeviceOptions( | 86 static void convertRequestDeviceOptions( |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 BluetoothDevice* device = m_deviceInstanceMap.get(id); | 279 BluetoothDevice* device = m_deviceInstanceMap.get(id); |
| 296 if (!device) { | 280 if (!device) { |
| 297 device = BluetoothDevice::take(resolver, std::move(devicePtr), this); | 281 device = BluetoothDevice::take(resolver, std::move(devicePtr), this); |
| 298 auto result = m_deviceInstanceMap.add(id, device); | 282 auto result = m_deviceInstanceMap.add(id, device); |
| 299 DCHECK(result.isNewEntry); | 283 DCHECK(result.isNewEntry); |
| 300 } | 284 } |
| 301 return device; | 285 return device; |
| 302 } | 286 } |
| 303 | 287 |
| 304 } // namespace blink | 288 } // namespace blink |
| OLD | NEW |