Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: third_party/WebKit/Source/modules/bluetooth/Bluetooth.cpp

Issue 2642123003: Bluetooth: Make maximum possible name filter 248 bytes, not 240 (Closed)
Patch Set: Correct 249->248 bytes in layout test Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 }
jeffcarp 2017/01/21 00:14:05 Because of this change and the one below, the layo
jeffcarp 2017/01/21 00:20:34 The WebBluetooth spec doesn't seem to explicitly m
Jeffrey Yasskin 2017/01/23 17:16:14 Yep, as discussed in https://github.com/WebBluetoo
scheib 2017/01/23 18:31:47 Thanks Jeffrey. So Jeff, please just update these
scheib 2017/01/23 18:31:47 Switching the expectations to TypeError looks corr
Jeffrey Yasskin 2017/01/23 18:55:21 I think TypeError is correct when nameLength > kMa
scheib 2017/01/23 20:10:25 Jeffrey, I'm left confused by what you think is be
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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 BluetoothDevice* device = m_deviceInstanceMap.get(id); 278 BluetoothDevice* device = m_deviceInstanceMap.get(id);
295 if (!device) { 279 if (!device) {
296 device = BluetoothDevice::take(resolver, std::move(devicePtr), this); 280 device = BluetoothDevice::take(resolver, std::move(devicePtr), this);
297 auto result = m_deviceInstanceMap.add(id, device); 281 auto result = m_deviceInstanceMap.add(id, device);
298 DCHECK(result.isNewEntry); 282 DCHECK(result.isNewEntry);
299 } 283 }
300 return device; 284 return device;
301 } 285 }
302 286
303 } // namespace blink 287 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698