Commit c3adec27 authored by Ovidio Henriquez's avatar Ovidio Henriquez Committed by Commit Bot

bluetooth: Fix permissions flag check in service

This change fixes the checks for the WebBluetoothNewPermissionsBackend
feature flag. Previously, it was checking if the BluetoothDelegate* was
not null and if the flag was enabled in the same statement. This is
incorrect because it falls back to using the original permissions system
if the delegate is null, which shouldn't happen if the feature flag is
enabled. With this change, the feature flag is checked first, then the
delegate pointer. If the delegate pointer is null, then the current Web
Bluetooth operation fails.

Design doc:
https://docs.google.com/document/d/1h3uAVXJARHrNWaNACUPiQhLt7XI-fFFQoARSs1WgMDM

Bug: 589228
Change-Id: Ib01e90b49924d7ba4e1dd03c8117eae9e21e795c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2081526
Commit-Queue: Ovidio de Jesús Ruiz-Henríquez <odejesush@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746482}
parent 5df5e8e1
......@@ -288,10 +288,12 @@ WebBluetoothServiceImpl::GetBluetoothAllowed() {
bool WebBluetoothServiceImpl::IsDevicePaired(
const std::string& device_address) {
BluetoothDelegate* delegate =
GetContentClient()->browser()->GetBluetoothDelegate();
if (delegate && base::FeatureList::IsEnabled(
features::kWebBluetoothNewPermissionsBackend)) {
if (base::FeatureList::IsEnabled(
features::kWebBluetoothNewPermissionsBackend)) {
BluetoothDelegate* delegate =
GetContentClient()->browser()->GetBluetoothDelegate();
if (!delegate)
return false;
return delegate->GetWebBluetoothDeviceId(render_frame_host_, device_address)
.IsValid();
}
......@@ -536,10 +538,12 @@ void WebBluetoothServiceImpl::DeviceAdvertisementReceived(
auto client = scanning_clients_.begin();
while (client != scanning_clients_.end()) {
auto device = blink::mojom::WebBluetoothDevice::New();
BluetoothDelegate* delegate =
GetContentClient()->browser()->GetBluetoothDelegate();
if (delegate && base::FeatureList::IsEnabled(
features::kWebBluetoothNewPermissionsBackend)) {
if (base::FeatureList::IsEnabled(
features::kWebBluetoothNewPermissionsBackend)) {
BluetoothDelegate* delegate =
GetContentClient()->browser()->GetBluetoothDelegate();
if (!delegate)
return;
device->id =
delegate->AddScannedDevice(render_frame_host_, device_address);
} else {
......@@ -707,13 +711,15 @@ void WebBluetoothServiceImpl::RemoteServerConnect(
RemoteServerConnectCallback callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
bool is_connect_allowed;
BluetoothDelegate* delegate =
GetContentClient()->browser()->GetBluetoothDelegate();
if (delegate && base::FeatureList::IsEnabled(
features::kWebBluetoothNewPermissionsBackend)) {
is_connect_allowed =
delegate->HasDevicePermission(render_frame_host_, device_id);
bool is_connect_allowed = false;
if (base::FeatureList::IsEnabled(
features::kWebBluetoothNewPermissionsBackend)) {
BluetoothDelegate* delegate =
GetContentClient()->browser()->GetBluetoothDelegate();
if (delegate) {
is_connect_allowed =
delegate->HasDevicePermission(render_frame_host_, device_id);
}
} else {
is_connect_allowed = allowed_devices().IsAllowedToGATTConnect(device_id);
}
......@@ -1502,10 +1508,16 @@ void WebBluetoothServiceImpl::OnGetDeviceSuccess(
DVLOG(1) << "Device: " << device->GetNameForDisplay();
auto web_bluetooth_device = blink::mojom::WebBluetoothDevice::New();
BluetoothDelegate* delegate =
GetContentClient()->browser()->GetBluetoothDelegate();
if (delegate && base::FeatureList::IsEnabled(
features::kWebBluetoothNewPermissionsBackend)) {
if (base::FeatureList::IsEnabled(
features::kWebBluetoothNewPermissionsBackend)) {
BluetoothDelegate* delegate =
GetContentClient()->browser()->GetBluetoothDelegate();
if (!delegate) {
std::move(callback).Run(
blink::mojom::WebBluetoothResult::WEB_BLUETOOTH_NOT_SUPPORTED,
/*device=*/nullptr);
return;
}
web_bluetooth_device->id = delegate->GrantServiceAccessPermission(
render_frame_host_, device, options.get());
} else {
......@@ -1660,12 +1672,15 @@ void WebBluetoothServiceImpl::OnDescriptorWriteValueFailed(
CacheQueryResult WebBluetoothServiceImpl::QueryCacheForDevice(
const blink::WebBluetoothDeviceId& device_id) {
std::string device_address;
BluetoothDelegate* delegate =
GetContentClient()->browser()->GetBluetoothDelegate();
if (delegate && base::FeatureList::IsEnabled(
features::kWebBluetoothNewPermissionsBackend)) {
device_address = delegate->GetDeviceAddress(render_frame_host_, device_id);
std::string device_address = "";
if (base::FeatureList::IsEnabled(
features::kWebBluetoothNewPermissionsBackend)) {
BluetoothDelegate* delegate =
GetContentClient()->browser()->GetBluetoothDelegate();
if (delegate) {
device_address =
delegate->GetDeviceAddress(render_frame_host_, device_id);
}
} else {
device_address = allowed_devices().GetDeviceAddress(device_id);
}
......@@ -1698,12 +1713,14 @@ CacheQueryResult WebBluetoothServiceImpl::QueryCacheForService(
}
blink::WebBluetoothDeviceId device_id;
BluetoothDelegate* delegate =
GetContentClient()->browser()->GetBluetoothDelegate();
if (delegate && base::FeatureList::IsEnabled(
features::kWebBluetoothNewPermissionsBackend)) {
device_id = delegate->GetWebBluetoothDeviceId(render_frame_host_,
device_iter->second);
if (base::FeatureList::IsEnabled(
features::kWebBluetoothNewPermissionsBackend)) {
BluetoothDelegate* delegate =
GetContentClient()->browser()->GetBluetoothDelegate();
if (delegate) {
device_id = delegate->GetWebBluetoothDeviceId(render_frame_host_,
device_iter->second);
}
} else {
const blink::WebBluetoothDeviceId* device_id_ptr =
allowed_devices().GetDeviceId(device_iter->second);
......@@ -1900,10 +1917,12 @@ void WebBluetoothServiceImpl::ClearState() {
bool WebBluetoothServiceImpl::IsAllowedToAccessAtLeastOneService(
const blink::WebBluetoothDeviceId& device_id) {
BluetoothDelegate* delegate =
GetContentClient()->browser()->GetBluetoothDelegate();
if (delegate && base::FeatureList::IsEnabled(
features::kWebBluetoothNewPermissionsBackend)) {
if (base::FeatureList::IsEnabled(
features::kWebBluetoothNewPermissionsBackend)) {
BluetoothDelegate* delegate =
GetContentClient()->browser()->GetBluetoothDelegate();
if (!delegate)
return false;
return delegate->IsAllowedToAccessAtLeastOneService(render_frame_host_,
device_id);
} else {
......@@ -1914,10 +1933,12 @@ bool WebBluetoothServiceImpl::IsAllowedToAccessAtLeastOneService(
bool WebBluetoothServiceImpl::IsAllowedToAccessService(
const blink::WebBluetoothDeviceId& device_id,
const device::BluetoothUUID& service) {
BluetoothDelegate* delegate =
GetContentClient()->browser()->GetBluetoothDelegate();
if (delegate && base::FeatureList::IsEnabled(
features::kWebBluetoothNewPermissionsBackend)) {
if (base::FeatureList::IsEnabled(
features::kWebBluetoothNewPermissionsBackend)) {
BluetoothDelegate* delegate =
GetContentClient()->browser()->GetBluetoothDelegate();
if (!delegate)
return false;
return delegate->IsAllowedToAccessService(render_frame_host_, device_id,
service);
} else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment