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 29 matching lines...) Expand all Loading... | |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 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 bool EmptyFilter(const content::BluetoothScanFilter& filter) { | |
|
scheib
2015/10/22 18:35:52
IsEmptyFilter will be clearer that 'empty' is an a
ortuno
2015/10/22 20:47:22
Done.
| |
| 51 return filter.name.empty() && filter.namePrefix.empty() && | |
| 52 filter.services.empty(); | |
| 53 } | |
| 54 | |
| 55 bool EmptyFilters(const std::vector<content::BluetoothScanFilter>& filters) { | |
|
scheib
2015/10/22 18:35:52
IsEmptyFilters.... is sort of poor grammar. IsEmpt
ortuno
2015/10/22 20:47:22
Changed it to HasEmptyFilter.
| |
| 56 if (filters.empty()) { | |
| 57 return true; | |
| 58 } | |
| 59 for (const content::BluetoothScanFilter& filter : filters) { | |
| 60 if (EmptyFilter(filter)) { | |
| 61 return true; | |
| 62 } | |
| 63 } | |
| 64 return false; | |
| 65 } | |
| 66 | |
| 50 // Defined at | 67 // Defined at |
| 51 // https://webbluetoothchrome.github.io/web-bluetooth/#dfn-matches-a-filter | 68 // https://webbluetoothchrome.github.io/web-bluetooth/#dfn-matches-a-filter |
| 52 bool MatchesFilter(const std::set<BluetoothUUID>& device_uuids, | 69 bool MatchesFilter(const device::BluetoothDevice& device, |
| 53 const content::BluetoothScanFilter& filter) { | 70 const content::BluetoothScanFilter& filter) { |
| 54 if (filter.services.empty()) | 71 DCHECK(!EmptyFilter(filter)); |
| 55 return false; | 72 |
| 56 for (const BluetoothUUID& service : filter.services) { | 73 const std::string device_name = base::UTF16ToUTF8(device.GetName()); |
| 57 if (!ContainsKey(device_uuids, service)) { | 74 |
| 75 if (!filter.name.empty()) { | |
| 76 if (device_name != filter.name) { | |
| 58 return false; | 77 return false; |
| 59 } | 78 } |
| 60 } | 79 } |
| 80 | |
| 81 if (!filter.namePrefix.empty()) { | |
| 82 if (!base::StartsWith(device_name, filter.namePrefix, | |
| 83 base::CompareCase::SENSITIVE)) { | |
| 84 return false; | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 if (!filter.services.empty()) { | |
| 89 const std::vector<BluetoothUUID>& device_uuid_list = device.GetUUIDs(); | |
| 90 const std::set<BluetoothUUID> device_uuids(device_uuid_list.begin(), | |
| 91 device_uuid_list.end()); | |
| 92 for (const BluetoothUUID& service : filter.services) { | |
| 93 if (!ContainsKey(device_uuids, service)) { | |
| 94 return false; | |
| 95 } | |
| 96 } | |
| 97 } | |
| 98 | |
| 61 return true; | 99 return true; |
| 62 } | 100 } |
| 63 | 101 |
| 64 bool MatchesFilters(const device::BluetoothDevice& device, | 102 bool MatchesFilters(const device::BluetoothDevice& device, |
| 65 const std::vector<content::BluetoothScanFilter>& filters) { | 103 const std::vector<content::BluetoothScanFilter>& filters) { |
| 66 const std::vector<BluetoothUUID>& device_uuid_list = device.GetUUIDs(); | 104 DCHECK(!EmptyFilters(filters)); |
| 67 const std::set<BluetoothUUID> device_uuids(device_uuid_list.begin(), | |
| 68 device_uuid_list.end()); | |
| 69 for (const content::BluetoothScanFilter& filter : filters) { | 105 for (const content::BluetoothScanFilter& filter : filters) { |
| 70 if (MatchesFilter(device_uuids, filter)) { | 106 if (MatchesFilter(device, filter)) { |
| 71 return true; | 107 return true; |
| 72 } | 108 } |
| 73 } | 109 } |
| 74 return false; | 110 return false; |
| 75 } | 111 } |
| 76 | 112 |
| 77 WebBluetoothError TranslateConnectError( | 113 WebBluetoothError TranslateConnectError( |
| 78 device::BluetoothDevice::ConnectErrorCode error_code) { | 114 device::BluetoothDevice::ConnectErrorCode error_code) { |
| 79 switch (error_code) { | 115 switch (error_code) { |
| 80 case device::BluetoothDevice::ERROR_UNKNOWN: | 116 case device::BluetoothDevice::ERROR_UNKNOWN: |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 int request_id, | 472 int request_id, |
| 437 int frame_routing_id, | 473 int frame_routing_id, |
| 438 const std::vector<BluetoothScanFilter>& filters, | 474 const std::vector<BluetoothScanFilter>& filters, |
| 439 const std::vector<BluetoothUUID>& optional_services) { | 475 const std::vector<BluetoothUUID>& optional_services) { |
| 440 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 476 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 441 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE); | 477 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE); |
| 442 RecordRequestDeviceArguments(filters, optional_services); | 478 RecordRequestDeviceArguments(filters, optional_services); |
| 443 | 479 |
| 444 VLOG(1) << "requestDevice called with the following filters: "; | 480 VLOG(1) << "requestDevice called with the following filters: "; |
| 445 for (const BluetoothScanFilter& filter : filters) { | 481 for (const BluetoothScanFilter& filter : filters) { |
| 482 VLOG(1) << "Name: " << filter.name; | |
| 483 VLOG(1) << "Name Prefix: " << filter.namePrefix; | |
| 484 VLOG(1) << "Services:"; | |
| 446 VLOG(1) << "\t["; | 485 VLOG(1) << "\t["; |
| 447 for (const BluetoothUUID& service : filter.services) | 486 for (const BluetoothUUID& service : filter.services) |
| 448 VLOG(1) << "\t\t" << service.value(); | 487 VLOG(1) << "\t\t" << service.value(); |
| 449 VLOG(1) << "\t]"; | 488 VLOG(1) << "\t]"; |
| 450 } | 489 } |
| 451 | 490 |
| 452 VLOG(1) << "requestDevice called with the following optional services: "; | 491 VLOG(1) << "requestDevice called with the following optional services: "; |
| 453 for (const BluetoothUUID& service : optional_services) | 492 for (const BluetoothUUID& service : optional_services) |
| 454 VLOG(1) << "\t" << service.value(); | 493 VLOG(1) << "\t" << service.value(); |
| 455 | 494 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 476 | 515 |
| 477 if (!adapter_->IsPresent()) { | 516 if (!adapter_->IsPresent()) { |
| 478 VLOG(1) << "Bluetooth Adapter not present. Can't serve requestDevice."; | 517 VLOG(1) << "Bluetooth Adapter not present. Can't serve requestDevice."; |
| 479 RecordRequestDeviceOutcome( | 518 RecordRequestDeviceOutcome( |
| 480 UMARequestDeviceOutcome::BLUETOOTH_ADAPTER_NOT_PRESENT); | 519 UMARequestDeviceOutcome::BLUETOOTH_ADAPTER_NOT_PRESENT); |
| 481 Send(new BluetoothMsg_RequestDeviceError( | 520 Send(new BluetoothMsg_RequestDeviceError( |
| 482 thread_id, request_id, WebBluetoothError::NoBluetoothAdapter)); | 521 thread_id, request_id, WebBluetoothError::NoBluetoothAdapter)); |
| 483 return; | 522 return; |
| 484 } | 523 } |
| 485 | 524 |
| 525 // The renderer should never send empty filters. | |
| 526 if (EmptyFilters(filters)) { | |
| 527 bad_message::ReceivedBadMessage(this, bad_message::BDH_EMPTY_FILTERS); | |
| 528 } | |
|
scheib
2015/10/22 18:35:52
return; in this case instead of opening chooser.
ortuno
2015/10/22 20:47:22
Done.
| |
| 529 | |
| 486 // Create storage for the information that backs the chooser, and show the | 530 // Create storage for the information that backs the chooser, and show the |
| 487 // chooser. | 531 // chooser. |
| 488 RequestDeviceSession* const session = new RequestDeviceSession( | 532 RequestDeviceSession* const session = new RequestDeviceSession( |
| 489 thread_id, request_id, filters, optional_services); | 533 thread_id, request_id, filters, optional_services); |
| 490 int chooser_id = request_device_sessions_.Add(session); | 534 int chooser_id = request_device_sessions_.Add(session); |
| 491 | 535 |
| 492 BluetoothChooser::EventHandler chooser_event_handler = | 536 BluetoothChooser::EventHandler chooser_event_handler = |
| 493 base::Bind(&BluetoothDispatcherHost::OnBluetoothChooserEvent, | 537 base::Bind(&BluetoothDispatcherHost::OnBluetoothChooserEvent, |
| 494 weak_ptr_on_ui_thread_, chooser_id); | 538 weak_ptr_on_ui_thread_, chooser_id); |
| 495 if (WebContents* web_contents = | 539 if (WebContents* web_contents = |
| (...skipping 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1136 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1180 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1137 NOTIMPLEMENTED(); | 1181 NOTIMPLEMENTED(); |
| 1138 } | 1182 } |
| 1139 | 1183 |
| 1140 void BluetoothDispatcherHost::ShowBluetoothAdapterOffLink() { | 1184 void BluetoothDispatcherHost::ShowBluetoothAdapterOffLink() { |
| 1141 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1185 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1142 NOTIMPLEMENTED(); | 1186 NOTIMPLEMENTED(); |
| 1143 } | 1187 } |
| 1144 | 1188 |
| 1145 } // namespace content | 1189 } // namespace content |
| OLD | NEW |