Chromium Code Reviews| Index: chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc |
| diff --git a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc |
| index 4b20720e6dcccdfd78ebdc3e221268544a7704b3..46336b14f3c97f4c188fe994bb865a6ebd2ac1a1 100644 |
| --- a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc |
| +++ b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_api.cc |
| @@ -180,6 +180,15 @@ bool HasProperty( |
| return false; |
| } |
| +bool HasPermission( |
| + const std::vector<apibtle::DescriptorPermission>& api_permissions, |
| + apibtle::DescriptorPermission permission) { |
| + if (find(api_permissions.begin(), api_permissions.end(), permission) != |
|
xiyuan
2016/05/12 19:25:37
nit: just a return ?
return find(api_permission
rkc
2016/05/12 20:32:53
Done.
|
| + api_permissions.end()) |
| + return true; |
| + return false; |
| +} |
| + |
| device::BluetoothGattCharacteristic::Properties GetBluetoothProperties( |
| const std::vector<apibtle::CharacteristicProperty>& api_properties) { |
| device::BluetoothGattCharacteristic::Properties properties = |
| @@ -194,10 +203,12 @@ device::BluetoothGattCharacteristic::Properties GetBluetoothProperties( |
| if (HasProperty(api_properties, apibtle::CHARACTERISTIC_PROPERTY_READ)) |
| properties |= device::BluetoothGattCharacteristic::PROPERTY_READ; |
| + |
| if (HasProperty(api_properties, |
| apibtle::CHARACTERISTIC_PROPERTY_WRITEWITHOUTRESPONSE)) |
| properties |= |
|
xiyuan
2016/05/12 19:25:37
nit: wrap with {} if condition and branch takes mo
rkc
2016/05/12 20:32:53
Done.
|
| device::BluetoothGattCharacteristic::PROPERTY_WRITE_WITHOUT_RESPONSE; |
| + |
| if (HasProperty(api_properties, apibtle::CHARACTERISTIC_PROPERTY_WRITE)) |
| properties |= device::BluetoothGattCharacteristic::PROPERTY_WRITE; |
| @@ -211,21 +222,79 @@ device::BluetoothGattCharacteristic::Properties GetBluetoothProperties( |
| apibtle::CHARACTERISTIC_PROPERTY_AUTHENTICATEDSIGNEDWRITES)) |
| properties |= device::BluetoothGattCharacteristic:: |
| PROPERTY_AUTHENTICATED_SIGNED_WRITES; |
| + |
| if (HasProperty(api_properties, |
| apibtle::CHARACTERISTIC_PROPERTY_EXTENDEDPROPERTIES)) |
| properties |= |
| device::BluetoothGattCharacteristic::PROPERTY_EXTENDED_PROPERTIES; |
| + |
| if (HasProperty(api_properties, |
| apibtle::CHARACTERISTIC_PROPERTY_RELIABLEWRITE)) |
| properties |= device::BluetoothGattCharacteristic::PROPERTY_RELIABLE_WRITE; |
| + |
| if (HasProperty(api_properties, |
| apibtle::CHARACTERISTIC_PROPERTY_WRITABLEAUXILIARIES)) |
| properties |= |
| device::BluetoothGattCharacteristic::PROPERTY_WRITABLE_AUXILIARIES; |
| + if (HasProperty(api_properties, apibtle::CHARACTERISTIC_PROPERTY_ENCRYPTREAD)) |
| + properties |= device::BluetoothGattCharacteristic::PROPERTY_READ_ENCRYPTED; |
| + |
| + if (HasProperty(api_properties, |
| + apibtle::CHARACTERISTIC_PROPERTY_ENCRYPTWRITE)) |
| + properties |= device::BluetoothGattCharacteristic::PROPERTY_WRITE_ENCRYPTED; |
| + |
| + if (HasProperty(api_properties, |
| + apibtle::CHARACTERISTIC_PROPERTY_ENCRYPTAUTHENTICATEDREAD)) |
| + properties |= device::BluetoothGattCharacteristic:: |
| + PROPERTY_READ_ENCRYPTED_AUTHENTICATED; |
| + |
| + if (HasProperty(api_properties, |
| + apibtle::CHARACTERISTIC_PROPERTY_ENCRYPTAUTHENTICATEDWRITE)) |
| + properties |= device::BluetoothGattCharacteristic:: |
| + PROPERTY_WRITE_ENCRYPTED_AUTHENTICATED; |
| + |
| return properties; |
| } |
| +device::BluetoothGattCharacteristic::Permissions GetBluetoothPermissions( |
| + const std::vector<apibtle::DescriptorPermission>& api_permissions) { |
| + device::BluetoothGattCharacteristic::Permissions permissions = |
| + device::BluetoothGattCharacteristic::PERMISSION_NONE; |
| + |
| + static_assert( |
| + apibtle::DESCRIPTOR_PERMISSION_LAST == 6, |
| + "Update required if the number of characteristic properties changes."); |
| + |
| + if (HasPermission(api_permissions, apibtle::DESCRIPTOR_PERMISSION_READ)) |
| + permissions |= device::BluetoothGattCharacteristic::PERMISSION_READ; |
| + |
| + if (HasPermission(api_permissions, apibtle::DESCRIPTOR_PERMISSION_WRITE)) |
| + permissions |= device::BluetoothGattCharacteristic::PERMISSION_WRITE; |
| + |
| + if (HasPermission(api_permissions, |
| + apibtle::DESCRIPTOR_PERMISSION_ENCRYPTEDREAD)) |
| + permissions |= |
| + device::BluetoothGattCharacteristic::PERMISSION_READ_ENCRYPTED; |
| + |
| + if (HasPermission(api_permissions, |
| + apibtle::DESCRIPTOR_PERMISSION_ENCRYPTEDWRITE)) |
| + permissions |= |
| + device::BluetoothGattCharacteristic::PERMISSION_WRITE_ENCRYPTED; |
| + |
| + if (HasPermission(api_permissions, |
| + apibtle::DESCRIPTOR_PERMISSION_ENCRYPTEDAUTHENTICATEDREAD)) |
| + permissions |= device::BluetoothGattCharacteristic:: |
| + PERMISSION_READ_ENCRYPTED_AUTHENTICATED; |
| + |
| + if (HasPermission(api_permissions, |
| + apibtle::DESCRIPTOR_PERMISSION_ENCRYPTEDAUTHENTICATEDWRITE)) |
| + permissions |= device::BluetoothGattCharacteristic:: |
| + PERMISSION_WRITE_ENCRYPTED_AUTHENTICATED; |
| + |
| + return permissions; |
| +} |
| + |
| } // namespace |
| @@ -1264,7 +1333,8 @@ void BluetoothLowEnergyCreateDescriptorFunction::DoWork() { |
| base::WeakPtr<device::BluetoothLocalGattDescriptor> descriptor = |
| device::BluetoothLocalGattDescriptor::Create( |
| device::BluetoothUUID(params_->descriptor.uuid), |
| - device::BluetoothGattCharacteristic::Permissions(), characteristic); |
| + GetBluetoothPermissions(params_->descriptor.permissions), |
| + characteristic); |
| Respond(ArgumentList( |
| apibtle::CreateDescriptor::Results::Create(descriptor->GetIdentifier()))); |
| @@ -1329,7 +1399,15 @@ void BluetoothLowEnergyNotifyCharacteristicValueChangedFunction::DoWork() { |
| template class BLEPeripheralExtensionFunction<apibtle::RemoveService::Params>; |
| void BluetoothLowEnergyRemoveServiceFunction::DoWork() { |
| - Respond(Error(kErrorPermissionDenied)); |
| + device::BluetoothLocalGattService* service = |
| + event_router_->adapter()->GetGattService(params_->service_id); |
| + if (!service) { |
| + Respond(Error(kErrorInvalidServiceId)); |
| + return; |
| + } |
| + event_router_->RemoveServiceFromApp(extension_id(), service->GetIdentifier()); |
| + service->Delete(); |
| + Respond(NoArguments()); |
| } |
| // sendRequestResponse: |