Chromium Code Reviews| Index: content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| diff --git a/content/browser/bluetooth/bluetooth_dispatcher_host.cc b/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| index d10d56e1266d48b1f242041cffe9db05d790b299..c60ae5e9eadc3830839b8835b6d2dfa234ef4adc 100644 |
| --- a/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| +++ b/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| @@ -47,27 +47,63 @@ namespace { |
| const int kDelayTime = 5; // 5 seconds for scanning and discovering |
| const int kTestingDelayTime = 0; // No need to wait during tests |
| +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.
|
| + return filter.name.empty() && filter.namePrefix.empty() && |
| + filter.services.empty(); |
| +} |
| + |
| +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.
|
| + if (filters.empty()) { |
| + return true; |
| + } |
| + for (const content::BluetoothScanFilter& filter : filters) { |
| + if (EmptyFilter(filter)) { |
| + return true; |
| + } |
| + } |
| + return false; |
| +} |
| + |
| // Defined at |
| // https://webbluetoothchrome.github.io/web-bluetooth/#dfn-matches-a-filter |
| -bool MatchesFilter(const std::set<BluetoothUUID>& device_uuids, |
| +bool MatchesFilter(const device::BluetoothDevice& device, |
| const content::BluetoothScanFilter& filter) { |
| - if (filter.services.empty()) |
| - return false; |
| - for (const BluetoothUUID& service : filter.services) { |
| - if (!ContainsKey(device_uuids, service)) { |
| + DCHECK(!EmptyFilter(filter)); |
| + |
| + const std::string device_name = base::UTF16ToUTF8(device.GetName()); |
| + |
| + if (!filter.name.empty()) { |
| + if (device_name != filter.name) { |
| return false; |
| } |
| } |
| + |
| + if (!filter.namePrefix.empty()) { |
| + if (!base::StartsWith(device_name, filter.namePrefix, |
| + base::CompareCase::SENSITIVE)) { |
| + return false; |
| + } |
| + } |
| + |
| + if (!filter.services.empty()) { |
| + const std::vector<BluetoothUUID>& device_uuid_list = device.GetUUIDs(); |
| + const std::set<BluetoothUUID> device_uuids(device_uuid_list.begin(), |
| + device_uuid_list.end()); |
| + for (const BluetoothUUID& service : filter.services) { |
| + if (!ContainsKey(device_uuids, service)) { |
| + return false; |
| + } |
| + } |
| + } |
| + |
| return true; |
| } |
| bool MatchesFilters(const device::BluetoothDevice& device, |
| const std::vector<content::BluetoothScanFilter>& filters) { |
| - const std::vector<BluetoothUUID>& device_uuid_list = device.GetUUIDs(); |
| - const std::set<BluetoothUUID> device_uuids(device_uuid_list.begin(), |
| - device_uuid_list.end()); |
| + DCHECK(!EmptyFilters(filters)); |
| for (const content::BluetoothScanFilter& filter : filters) { |
| - if (MatchesFilter(device_uuids, filter)) { |
| + if (MatchesFilter(device, filter)) { |
| return true; |
| } |
| } |
| @@ -443,6 +479,9 @@ void BluetoothDispatcherHost::OnRequestDevice( |
| VLOG(1) << "requestDevice called with the following filters: "; |
| for (const BluetoothScanFilter& filter : filters) { |
| + VLOG(1) << "Name: " << filter.name; |
| + VLOG(1) << "Name Prefix: " << filter.namePrefix; |
| + VLOG(1) << "Services:"; |
| VLOG(1) << "\t["; |
| for (const BluetoothUUID& service : filter.services) |
| VLOG(1) << "\t\t" << service.value(); |
| @@ -483,6 +522,11 @@ void BluetoothDispatcherHost::OnRequestDevice( |
| return; |
| } |
| + // The renderer should never send empty filters. |
| + if (EmptyFilters(filters)) { |
| + bad_message::ReceivedBadMessage(this, bad_message::BDH_EMPTY_FILTERS); |
| + } |
|
scheib
2015/10/22 18:35:52
return; in this case instead of opening chooser.
ortuno
2015/10/22 20:47:22
Done.
|
| + |
| // Create storage for the information that backs the chooser, and show the |
| // chooser. |
| RequestDeviceSession* const session = new RequestDeviceSession( |