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 c11c203b13ee8b60fef83d7ab6a95605b04b30db..924974f6be8bb395992a1bbd8a5de1721df12ae0 100644 |
--- a/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
+++ b/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
@@ -10,10 +10,12 @@ |
#include "device/bluetooth/bluetooth_adapter_factory.h" |
#include "device/bluetooth/bluetooth_device.h" |
#include "device/bluetooth/bluetooth_discovery_session.h" |
+#include "device/bluetooth/bluetooth_gatt_characteristic.h" |
#include "device/bluetooth/bluetooth_gatt_service.h" |
using device::BluetoothAdapter; |
using device::BluetoothAdapterFactory; |
+using device::BluetoothGattCharacteristic; |
using device::BluetoothGattService; |
namespace content { |
@@ -54,6 +56,7 @@ bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) { |
IPC_MESSAGE_HANDLER(BluetoothHostMsg_RequestDevice, OnRequestDevice) |
IPC_MESSAGE_HANDLER(BluetoothHostMsg_ConnectGATT, OnConnectGATT) |
IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetPrimaryService, OnGetPrimaryService) |
+ IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetCharacteristic, OnGetCharacteristic) |
IPC_MESSAGE_UNHANDLED(handled = false) |
IPC_END_MESSAGE_MAP() |
return handled; |
@@ -149,6 +152,57 @@ void BluetoothDispatcherHost::OnGetPrimaryService( |
base::TimeDelta::FromSeconds(current_delay_time_)); |
} |
+void BluetoothDispatcherHost::OnGetCharacteristic( |
+ int thread_id, |
+ int request_id, |
+ const std::string& service_instance_id, |
+ const std::string& characteristic_uuid) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ |
+ // There are no cases in which a normal renderer could pass |
scheib
2015/06/04 06:30:48
Move this comment either just above the 'if' line,
ortuno
2015/06/05 19:37:44
Done.
|
+ // a service_instance_id not in our map so we can assume |
+ // the renderer is hostile. |
+ auto device_iter = service_to_device_.find(service_instance_id); |
+ if (device_iter == service_to_device_.end()) { |
+ BadMessageReceived(); // Kill the renderer. |
+ return; |
+ } |
+ |
+ // TODO(ortuno): Check if domain has access to device. |
+ // https://crbug.com/493459 |
+ device::BluetoothDevice* device = |
+ adapter_->GetDevice(device_iter->second /* device_instance_id */); |
+ |
+ if (device == NULL) { |
+ Send(new BluetoothMsg_GetCharacteristicError( |
+ thread_id, request_id, BluetoothError::NETWORK_ERROR)); |
+ return; |
+ } |
+ |
+ // TODO(ortuno): Check if domain has access to service |
+ // http://crbug.com/493460 |
+ device::BluetoothGattService* service = |
+ device->GetGattService(service_instance_id); |
+ if (!service) { |
+ Send(new BluetoothMsg_GetCharacteristicError( |
+ thread_id, request_id, BluetoothError::NETWORK_ERROR)); |
+ return; |
+ } |
+ |
+ for (BluetoothGattCharacteristic* characteristic : |
+ service->GetCharacteristics()) { |
+ if (characteristic->GetUUID().canonical_value() == characteristic_uuid) { |
+ // TODO(ortuno): Use generated instance ID instead. |
+ // https://crbug.com/495379 |
+ Send(new BluetoothMsg_GetCharacteristicSuccess( |
+ thread_id, request_id, characteristic->GetIdentifier())); |
+ return; |
+ } |
+ } |
+ Send(new BluetoothMsg_GetCharacteristicError(thread_id, request_id, |
+ BluetoothError::NOT_FOUND)); |
+} |
+ |
void BluetoothDispatcherHost::OnDiscoverySessionStarted( |
int thread_id, |
int request_id, |
@@ -253,8 +307,13 @@ void BluetoothDispatcherHost::OnServicesDiscovered( |
} |
for (BluetoothGattService* service : device->GetGattServices()) { |
if (service->GetUUID().canonical_value() == service_uuid) { |
+ // TODO(ortuno): Use generated instance ID instead. |
+ // https://crbug.com/495379 |
+ const std::string& service_identifier = service->GetIdentifier(); |
+ service_to_device_.insert( |
scheib
2015/06/04 06:30:48
Maybe for paranoia:
auto insert_result = service_
ortuno
2015/06/05 19:37:44
If you call getPrimaryService("some uuid") twice t
scheib
2015/06/08 17:02:07
Whoops, overlooked this. Discussed in person too,
|
+ make_pair(service_identifier, device_instance_id)); |
Send(new BluetoothMsg_GetPrimaryServiceSuccess(thread_id, request_id, |
- service->GetIdentifier())); |
+ service_identifier)); |
return; |
} |
} |