| Index: content/browser/bluetooth/bluetooth_device_chooser_controller.cc
|
| diff --git a/content/browser/bluetooth/bluetooth_device_chooser_controller.cc b/content/browser/bluetooth/bluetooth_device_chooser_controller.cc
|
| index 1128fb80d4c8825cf9894ad18093c32399660298..aa19abc6fc11748cd216fb1148ef32f0c04fadcc 100644
|
| --- a/content/browser/bluetooth/bluetooth_device_chooser_controller.cc
|
| +++ b/content/browser/bluetooth/bluetooth_device_chooser_controller.cc
|
| @@ -62,6 +62,11 @@ void LogRequestDeviceOptions(
|
| const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options) {
|
| VLOG(1) << "requestDevice called with the following filters: ";
|
| int i = 0;
|
| + VLOG(1) << "acceptAllDevices: " << options->accept_all_devices;
|
| +
|
| + if (options->filters.is_null())
|
| + return;
|
| +
|
| for (const auto& filter : options->filters) {
|
| VLOG(1) << "Filter #" << ++i;
|
| if (!filter->name.is_null())
|
| @@ -102,12 +107,25 @@ bool IsEmptyOrInvalidFilter(
|
|
|
| bool HasEmptyOrInvalidFilter(
|
| const mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>& filters) {
|
| + if (filters.is_null()) {
|
| + return true;
|
| + }
|
| +
|
| return filters.empty()
|
| ? true
|
| : filters.end() != std::find_if(filters.begin(), filters.end(),
|
| IsEmptyOrInvalidFilter);
|
| }
|
|
|
| +bool IsOptionsInvalid(
|
| + const blink::mojom::WebBluetoothRequestDeviceOptionsPtr& options) {
|
| + if (options->accept_all_devices) {
|
| + return !options->filters.is_null();
|
| + } else {
|
| + return HasEmptyOrInvalidFilter(options->filters);
|
| + }
|
| +}
|
| +
|
| bool MatchesFilter(const std::string* device_name,
|
| const UUIDSet& device_uuids,
|
| const blink::mojom::WebBluetoothScanFilterPtr& filter) {
|
| @@ -153,11 +171,14 @@ bool MatchesFilters(
|
| std::unique_ptr<device::BluetoothDiscoveryFilter> ComputeScanFilter(
|
| const mojo::Array<blink::mojom::WebBluetoothScanFilterPtr>& filters) {
|
| std::unordered_set<BluetoothUUID, device::BluetoothUUIDHash> services;
|
| - for (const auto& filter : filters) {
|
| - for (const base::Optional<BluetoothUUID>& service : filter->services) {
|
| - services.insert(service.value());
|
| + if (!filters.is_null()) {
|
| + for (const auto& filter : filters) {
|
| + for (const base::Optional<BluetoothUUID>& service : filter->services) {
|
| + services.insert(service.value());
|
| + }
|
| }
|
| }
|
| +
|
| // There isn't much support for GATT over BR/EDR from neither platforms nor
|
| // devices so performing a Dual scan will find devices that the API is not
|
| // able to interact with. To avoid wasting power and confusing users with
|
| @@ -259,17 +280,18 @@ void BluetoothDeviceChooserController::GetDevice(
|
| success_callback_ = success_callback;
|
| error_callback_ = error_callback;
|
|
|
| - // The renderer should never send empty filters.
|
| - if (HasEmptyOrInvalidFilter(options->filters)) {
|
| + // The renderer should never send invalid options.
|
| + if (IsOptionsInvalid(options)) {
|
| web_bluetooth_service_->CrashRendererAndClosePipe(
|
| - bad_message::BDH_EMPTY_OR_INVALID_FILTERS);
|
| + bad_message::BDH_INVALID_OPTIONS);
|
| return;
|
| }
|
| options_ = std::move(options);
|
| LogRequestDeviceOptions(options_);
|
|
|
| // Check blocklist to reject invalid filters and adjust optional_services.
|
| - if (BluetoothBlocklist::Get().IsExcluded(options_->filters)) {
|
| + if (!options_->filters.is_null() &&
|
| + BluetoothBlocklist::Get().IsExcluded(options_->filters)) {
|
| RecordRequestDeviceOutcome(
|
| UMARequestDeviceOutcome::BLOCKLISTED_SERVICE_IN_FILTER);
|
| PostErrorCallback(
|
| @@ -370,15 +392,17 @@ void BluetoothDeviceChooserController::GetDevice(
|
| void BluetoothDeviceChooserController::AddFilteredDevice(
|
| const device::BluetoothDevice& device) {
|
| base::Optional<std::string> device_name = device.GetName();
|
| - if (chooser_.get() &&
|
| - MatchesFilters(device_name ? &device_name.value() : nullptr,
|
| - device.GetUUIDs(), options_->filters)) {
|
| - base::Optional<int8_t> rssi = device.GetInquiryRSSI();
|
| - chooser_->AddOrUpdateDevice(
|
| - device.GetAddress(), !!device.GetName() /* should_update_name */,
|
| - device.GetNameForDisplay(), device.IsGattConnected(),
|
| - web_bluetooth_service_->IsDevicePaired(device.GetAddress()),
|
| - rssi ? CalculateSignalStrengthLevel(rssi.value()) : -1);
|
| + if (chooser_.get()) {
|
| + if (options_->accept_all_devices ||
|
| + MatchesFilters(device_name ? &device_name.value() : nullptr,
|
| + device.GetUUIDs(), options_->filters)) {
|
| + base::Optional<int8_t> rssi = device.GetInquiryRSSI();
|
| + chooser_->AddOrUpdateDevice(
|
| + device.GetAddress(), !!device.GetName() /* should_update_name */,
|
| + device.GetNameForDisplay(), device.IsGattConnected(),
|
| + web_bluetooth_service_->IsDevicePaired(device.GetAddress()),
|
| + rssi ? CalculateSignalStrengthLevel(rssi.value()) : -1);
|
| + }
|
| }
|
| }
|
|
|
|
|