Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // ID Not In Map Note: | 5 // ID Not In Map Note: |
| 6 // A service, characteristic, or descriptor ID not in the corresponding | 6 // A service, characteristic, or descriptor ID not in the corresponding |
| 7 // BluetoothDispatcherHost map [service_to_device_, characteristic_to_service_, | 7 // BluetoothDispatcherHost map [service_to_device_, characteristic_to_service_, |
| 8 // descriptor_to_characteristic_] implies a hostile renderer because a renderer | 8 // descriptor_to_characteristic_] implies a hostile renderer because a renderer |
| 9 // obtains the corresponding ID from this class and it will be added to the map | 9 // obtains the corresponding ID from this class and it will be added to the map |
| 10 // at that time. | 10 // at that time. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 42 | 42 |
| 43 // TODO(ortuno): Once we have a chooser for scanning, a way to control that | 43 // TODO(ortuno): Once we have a chooser for scanning, a way to control that |
| 44 // chooser from tests, and the right callback for discovered services we should | 44 // chooser from tests, and the right callback for discovered services we should |
| 45 // delete these constants. | 45 // delete these constants. |
| 46 // https://crbug.com/436280 and https://crbug.com/484504 | 46 // https://crbug.com/436280 and https://crbug.com/484504 |
| 47 const int kDelayTime = 5; // 5 seconds for scanning and discovering | 47 const int kDelayTime = 5; // 5 seconds for scanning and discovering |
| 48 const int kTestingDelayTime = 0; // No need to wait during tests | 48 const int kTestingDelayTime = 0; // No need to wait during tests |
| 49 | 49 |
| 50 // Defined at | 50 // Defined at |
| 51 // https://webbluetoothchrome.github.io/web-bluetooth/#dfn-matches-a-filter | 51 // https://webbluetoothchrome.github.io/web-bluetooth/#dfn-matches-a-filter |
| 52 bool MatchesFilter(const std::set<BluetoothUUID>& device_uuids, | 52 bool MatchesFilter(const device::BluetoothDevice& device, |
| 53 const content::BluetoothScanFilter& filter) { | 53 const content::BluetoothScanFilter& filter) { |
| 54 if (filter.services.empty()) | 54 DCHECK(!(filter.name.empty() && filter.namePrefix.empty() && |
|
scheib
2015/10/22 04:58:42
Malformed data from a renderer should kill it. Tha
ortuno
2015/10/22 16:21:31
Done.
| |
| 55 return false; | 55 filter.services.empty())); |
| 56 for (const BluetoothUUID& service : filter.services) { | 56 |
| 57 if (!ContainsKey(device_uuids, service)) { | 57 const std::string device_name = base::UTF16ToUTF8(device.GetName()); |
| 58 | |
| 59 if (!filter.name.empty()) { | |
| 60 if (device_name != filter.name) { | |
| 58 return false; | 61 return false; |
| 59 } | 62 } |
| 60 } | 63 } |
| 64 | |
| 65 if (!filter.namePrefix.empty()) { | |
| 66 if (!base::StartsWith(device_name, filter.namePrefix, | |
| 67 base::CompareCase::SENSITIVE)) { | |
| 68 return false; | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 if (!filter.services.empty()) { | |
| 73 const std::vector<BluetoothUUID>& device_uuid_list = device.GetUUIDs(); | |
| 74 const std::set<BluetoothUUID> device_uuids(device_uuid_list.begin(), | |
| 75 device_uuid_list.end()); | |
| 76 for (const BluetoothUUID& service : filter.services) { | |
| 77 if (!ContainsKey(device_uuids, service)) { | |
| 78 return false; | |
| 79 } | |
| 80 } | |
| 81 } | |
| 82 | |
| 61 return true; | 83 return true; |
| 62 } | 84 } |
| 63 | 85 |
| 64 bool MatchesFilters(const device::BluetoothDevice& device, | 86 bool MatchesFilters(const device::BluetoothDevice& device, |
| 65 const std::vector<content::BluetoothScanFilter>& filters) { | 87 const std::vector<content::BluetoothScanFilter>& filters) { |
| 66 const std::vector<BluetoothUUID>& device_uuid_list = device.GetUUIDs(); | |
| 67 const std::set<BluetoothUUID> device_uuids(device_uuid_list.begin(), | |
| 68 device_uuid_list.end()); | |
| 69 for (const content::BluetoothScanFilter& filter : filters) { | 88 for (const content::BluetoothScanFilter& filter : filters) { |
| 70 if (MatchesFilter(device_uuids, filter)) { | 89 if (MatchesFilter(device, filter)) { |
| 71 return true; | 90 return true; |
| 72 } | 91 } |
| 73 } | 92 } |
| 74 return false; | 93 return false; |
| 75 } | 94 } |
| 76 | 95 |
| 77 WebBluetoothError TranslateConnectError( | 96 WebBluetoothError TranslateConnectError( |
| 78 device::BluetoothDevice::ConnectErrorCode error_code) { | 97 device::BluetoothDevice::ConnectErrorCode error_code) { |
| 79 switch (error_code) { | 98 switch (error_code) { |
| 80 case device::BluetoothDevice::ERROR_UNKNOWN: | 99 case device::BluetoothDevice::ERROR_UNKNOWN: |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 int request_id, | 455 int request_id, |
| 437 int frame_routing_id, | 456 int frame_routing_id, |
| 438 const std::vector<BluetoothScanFilter>& filters, | 457 const std::vector<BluetoothScanFilter>& filters, |
| 439 const std::vector<BluetoothUUID>& optional_services) { | 458 const std::vector<BluetoothUUID>& optional_services) { |
| 440 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 459 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 441 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE); | 460 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE); |
| 442 RecordRequestDeviceArguments(filters, optional_services); | 461 RecordRequestDeviceArguments(filters, optional_services); |
| 443 | 462 |
| 444 VLOG(1) << "requestDevice called with the following filters: "; | 463 VLOG(1) << "requestDevice called with the following filters: "; |
| 445 for (const BluetoothScanFilter& filter : filters) { | 464 for (const BluetoothScanFilter& filter : filters) { |
| 465 VLOG(1) << "Name: " << filter.name; | |
| 466 VLOG(1) << "Name Prefix: " << filter.namePrefix; | |
| 467 VLOG(1) << "Services:"; | |
| 446 VLOG(1) << "\t["; | 468 VLOG(1) << "\t["; |
| 447 for (const BluetoothUUID& service : filter.services) | 469 for (const BluetoothUUID& service : filter.services) |
| 448 VLOG(1) << "\t\t" << service.value(); | 470 VLOG(1) << "\t\t" << service.value(); |
| 449 VLOG(1) << "\t]"; | 471 VLOG(1) << "\t]"; |
| 450 } | 472 } |
| 451 | 473 |
| 452 VLOG(1) << "requestDevice called with the following optional services: "; | 474 VLOG(1) << "requestDevice called with the following optional services: "; |
| 453 for (const BluetoothUUID& service : optional_services) | 475 for (const BluetoothUUID& service : optional_services) |
| 454 VLOG(1) << "\t" << service.value(); | 476 VLOG(1) << "\t" << service.value(); |
| 455 | 477 |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1136 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1158 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1137 NOTIMPLEMENTED(); | 1159 NOTIMPLEMENTED(); |
| 1138 } | 1160 } |
| 1139 | 1161 |
| 1140 void BluetoothDispatcherHost::ShowBluetoothAdapterOffLink() { | 1162 void BluetoothDispatcherHost::ShowBluetoothAdapterOffLink() { |
| 1141 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1163 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1142 NOTIMPLEMENTED(); | 1164 NOTIMPLEMENTED(); |
| 1143 } | 1165 } |
| 1144 | 1166 |
| 1145 } // namespace content | 1167 } // namespace content |
| OLD | NEW |