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 f6042833937de7839ffda678c25e17d266716c0a..f7cf8109cdab2c4a5eb05f30934e58d90af6d14f 100644 |
| --- a/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| +++ b/content/browser/bluetooth/bluetooth_dispatcher_host.cc |
| @@ -100,10 +100,26 @@ void BluetoothDispatcherHost::OnConnectGATT( |
| int request_id, |
| const std::string& device_instance_id) { |
| DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| - // TODO(ortuno): Add actual implementation of connectGATT. This needs to be |
| - // done after the "allowed devices map" is implemented. |
| - Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id, |
| - device_instance_id)); |
| + // TODO(ortuno): Right now it's pointless to check if the domain has access to |
| + // the device, because any domain can connect to any device. But once |
| + // permissions are implemented we should check that the domain has access to |
| + // the device. https://crbug.com/484745 |
| + device::BluetoothDevice* device = adapter_->GetDevice(device_instance_id); |
| + if (device == NULL) { |
| + // Since we can't create a ATT Bearer without a device we reject with |
| + // NetworkError. |
|
Jeffrey Yasskin
2015/05/20 22:19:48
Is a device_instance_id that doesn't map to a devi
ortuno
2015/05/20 23:35:19
Yes, the renderer could send a device_instance_id
Jeffrey Yasskin
2015/05/21 00:12:00
And walking out of range is exactly when we'd want
|
| + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-connectgatt |
| + Send(new BluetoothMsg_ConnectGATTError(thread_id, request_id, |
| + BluetoothError::NETWORK_ERROR)); |
| + return; |
| + } |
| + device->CreateGattConnection( |
| + base::Bind(&BluetoothDispatcherHost::OnGATTConnectionCreated, |
| + weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, |
| + device_instance_id), |
| + base::Bind(&BluetoothDispatcherHost::OnCreateGATTConnectionError, |
| + weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, |
| + device_instance_id)); |
| } |
| void BluetoothDispatcherHost::OnDiscoverySessionStarted( |
| @@ -172,4 +188,27 @@ void BluetoothDispatcherHost::OnDiscoverySessionStoppedError(int thread_id, |
| BluetoothError::NOT_FOUND)); |
| } |
| +void BluetoothDispatcherHost::OnGATTConnectionCreated( |
| + int thread_id, |
| + int request_id, |
| + const std::string& device_instance_id, |
| + scoped_ptr<device::BluetoothGattConnection> connection) { |
| + // TODO(ortuno): Save the BluetoothGattConnection so we can disconnect |
| + // from it. |
| + Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id, |
| + device_instance_id)); |
| +} |
| + |
| +void BluetoothDispatcherHost::OnCreateGATTConnectionError( |
| + int thread_id, |
| + int request_id, |
| + const std::string& device_instance_id, |
| + device::BluetoothDevice::ConnectErrorCode error_code) { |
| + // There was an error creating the ATT Bearer so we reject with |
| + // NetworkError. |
|
Jeffrey Yasskin
2015/05/20 22:19:48
Please give the eventual Javascript error a descri
ortuno
2015/05/20 23:35:19
Added a todo and opened an issue: http://crbug.com
|
| + // https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothdevice-connectgatt |
| + Send(new BluetoothMsg_ConnectGATTError(thread_id, request_id, |
| + BluetoothError::NETWORK_ERROR)); |
| +} |
| + |
| } // namespace content |