diff options
author | ortuno <ortuno@chromium.org> | 2016-01-15 14:41:34 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-15 22:42:38 +0000 |
commit | 154400787a01efedca9063d98a4b0d06ebf39089 (patch) | |
tree | 06d0b0ec7da40552ac4a61dd2a6c7c20447e80df /content/renderer/bluetooth | |
parent | d5f3688818eaca5f93587f4e2753d4bef4c0ab5c (diff) | |
download | chromium_src-154400787a01efedca9063d98a4b0d06ebf39089.zip chromium_src-154400787a01efedca9063d98a4b0d06ebf39089.tar.gz chromium_src-154400787a01efedca9063d98a4b0d06ebf39089.tar.bz2 |
bluetooth: Implement allowed devices map
Add a selected device to the list of allowed devices map and, before
interacting with the device, check that the origin is allowed to
access that device.
BUG=493459
Review URL: https://codereview.chromium.org/1502663003
Cr-Commit-Position: refs/heads/master@{#369870}
Diffstat (limited to 'content/renderer/bluetooth')
-rw-r--r-- | content/renderer/bluetooth/bluetooth_dispatcher.cc | 64 | ||||
-rw-r--r-- | content/renderer/bluetooth/bluetooth_dispatcher.h | 21 | ||||
-rw-r--r-- | content/renderer/bluetooth/web_bluetooth_impl.cc | 31 |
3 files changed, 77 insertions, 39 deletions
diff --git a/content/renderer/bluetooth/bluetooth_dispatcher.cc b/content/renderer/bluetooth/bluetooth_dispatcher.cc index 82bad22..bc91cc6 100644 --- a/content/renderer/bluetooth/bluetooth_dispatcher.cc +++ b/content/renderer/bluetooth/bluetooth_dispatcher.cc @@ -70,16 +70,19 @@ struct BluetoothCharacteristicRequest { // Struct that holds a pending Start/StopNotifications request. struct BluetoothNotificationsRequest { BluetoothNotificationsRequest( + int frame_routing_id, const std::string characteristic_instance_id, blink::WebBluetoothGATTCharacteristic* characteristic, blink::WebBluetoothNotificationsCallbacks* callbacks, NotificationsRequestType type) - : characteristic_instance_id(characteristic_instance_id), + : frame_routing_id(frame_routing_id), + characteristic_instance_id(characteristic_instance_id), characteristic(characteristic), callbacks(callbacks), type(type) {} ~BluetoothNotificationsRequest() {} + const int frame_routing_id; const std::string characteristic_instance_id; // The characteristic object is owned by the execution context on // the blink side which can destroy the object at any point. Since the @@ -216,61 +219,70 @@ void BluetoothDispatcher::requestDevice( } void BluetoothDispatcher::connectGATT( + int frame_routing_id, const blink::WebString& device_id, blink::WebBluetoothConnectGATTCallbacks* callbacks) { int request_id = pending_connect_requests_.Add(callbacks); Send(new BluetoothHostMsg_ConnectGATT(CurrentWorkerId(), request_id, - device_id.utf8())); + frame_routing_id, device_id.utf8())); } void BluetoothDispatcher::getPrimaryService( + int frame_routing_id, const blink::WebString& device_id, const blink::WebString& service_uuid, blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) { int request_id = pending_primary_service_requests_.Add( new BluetoothPrimaryServiceRequest(device_id, service_uuid, callbacks)); Send(new BluetoothHostMsg_GetPrimaryService( - CurrentWorkerId(), request_id, device_id.utf8(), service_uuid.utf8())); + CurrentWorkerId(), request_id, frame_routing_id, device_id.utf8(), + service_uuid.utf8())); } void BluetoothDispatcher::getCharacteristic( + int frame_routing_id, const blink::WebString& service_instance_id, const blink::WebString& characteristic_uuid, blink::WebBluetoothGetCharacteristicCallbacks* callbacks) { int request_id = pending_characteristic_requests_.Add(new BluetoothCharacteristicRequest( service_instance_id, characteristic_uuid, callbacks)); - Send(new BluetoothHostMsg_GetCharacteristic(CurrentWorkerId(), request_id, - service_instance_id.utf8(), - characteristic_uuid.utf8())); + Send(new BluetoothHostMsg_GetCharacteristic( + CurrentWorkerId(), request_id, frame_routing_id, + service_instance_id.utf8(), characteristic_uuid.utf8())); } void BluetoothDispatcher::readValue( + int frame_routing_id, const blink::WebString& characteristic_instance_id, blink::WebBluetoothReadValueCallbacks* callbacks) { int request_id = pending_read_value_requests_.Add(callbacks); Send(new BluetoothHostMsg_ReadValue(CurrentWorkerId(), request_id, + frame_routing_id, characteristic_instance_id.utf8())); } void BluetoothDispatcher::writeValue( + int frame_routing_id, const blink::WebString& characteristic_instance_id, const blink::WebVector<uint8_t>& value, blink::WebBluetoothWriteValueCallbacks* callbacks) { int request_id = pending_write_value_requests_.Add(callbacks); Send(new BluetoothHostMsg_WriteValue( - CurrentWorkerId(), request_id, characteristic_instance_id.utf8(), + CurrentWorkerId(), request_id, frame_routing_id, + characteristic_instance_id.utf8(), std::vector<uint8_t>(value.begin(), value.end()))); } void BluetoothDispatcher::startNotifications( + int frame_routing_id, const blink::WebString& characteristic_instance_id, blink::WebBluetoothGATTCharacteristic* characteristic, blink::WebBluetoothNotificationsCallbacks* callbacks) { - int request_id = QueueNotificationRequest(characteristic_instance_id.utf8(), - characteristic, callbacks, - NotificationsRequestType::START); + int request_id = QueueNotificationRequest( + frame_routing_id, characteristic_instance_id.utf8(), characteristic, + callbacks, NotificationsRequestType::START); // The Notification subscription's state can change after a request // finishes. To avoid resolving with a soon-to-be-invalid state we queue // requests. @@ -283,12 +295,13 @@ void BluetoothDispatcher::startNotifications( } void BluetoothDispatcher::stopNotifications( + int frame_routing_id, const blink::WebString& characteristic_instance_id, blink::WebBluetoothGATTCharacteristic* characteristic, blink::WebBluetoothNotificationsCallbacks* callbacks) { - int request_id = QueueNotificationRequest(characteristic_instance_id.utf8(), - characteristic, callbacks, - NotificationsRequestType::STOP); + int request_id = QueueNotificationRequest( + frame_routing_id, characteristic_instance_id.utf8(), characteristic, + callbacks, NotificationsRequestType::STOP); if (HasNotificationRequestResponsePending( characteristic_instance_id.utf8())) { return; @@ -298,6 +311,7 @@ void BluetoothDispatcher::stopNotifications( } void BluetoothDispatcher::characteristicObjectRemoved( + int frame_routing_id, const blink::WebString& characteristic_instance_id, blink::WebBluetoothGATTCharacteristic* characteristic) { // We need to remove references to the object from the following: @@ -309,7 +323,7 @@ void BluetoothDispatcher::characteristicObjectRemoved( // TODO(ortuno): We should only unregister a characteristic once // there are no characteristic objects that have listeners attached. // https://crbug.com/541388 - UnregisterCharacteristicObject(characteristic_instance_id); + UnregisterCharacteristicObject(frame_routing_id, characteristic_instance_id); // 2 // If the object is in the queue we null the characteristic. If this is the @@ -356,11 +370,12 @@ void BluetoothDispatcher::characteristicObjectRemoved( // We pass in the characteristic so that ResolveOrSendStopNotificationsRequest // can remove the characteristic from ActiveNotificationSubscriptions. ResolveOrSendStopNotificationsRequest(QueueNotificationRequest( - characteristic_instance_id.utf8(), characteristic, + frame_routing_id, characteristic_instance_id.utf8(), characteristic, nullptr /* callbacks */, NotificationsRequestType::STOP)); } void BluetoothDispatcher::registerCharacteristicObject( + int frame_routing_id, const blink::WebString& characteristic_instance_id, blink::WebBluetoothGATTCharacteristic* characteristic) { // TODO(ortuno): After the Object manager is implemented, there will @@ -373,7 +388,7 @@ void BluetoothDispatcher::registerCharacteristicObject( std::make_pair(characteristic_instance_id.utf8(), characteristic)); Send(new BluetoothHostMsg_RegisterCharacteristic( - CurrentWorkerId(), characteristic_instance_id.utf8())); + CurrentWorkerId(), frame_routing_id, characteristic_instance_id.utf8())); } void BluetoothDispatcher::WillStopCurrentWorkerThread() { @@ -381,13 +396,15 @@ void BluetoothDispatcher::WillStopCurrentWorkerThread() { } int BluetoothDispatcher::QueueNotificationRequest( + int frame_routing_id, const std::string& characteristic_instance_id, blink::WebBluetoothGATTCharacteristic* characteristic, blink::WebBluetoothNotificationsCallbacks* callbacks, NotificationsRequestType type) { int request_id = pending_notifications_requests_.Add(new BluetoothNotificationsRequest( - characteristic_instance_id, characteristic, callbacks, type)); + frame_routing_id, characteristic_instance_id, characteristic, + callbacks, type)); notification_requests_queues_[characteristic_instance_id].push(request_id); return request_id; @@ -473,6 +490,7 @@ void BluetoothDispatcher::ResolveOrSendStartNotificationRequest( int request_id) { BluetoothNotificationsRequest* request = pending_notifications_requests_.Lookup(request_id); + const int frame_routing_id = request->frame_routing_id; const std::string& characteristic_instance_id = request->characteristic_instance_id; blink::WebBluetoothGATTCharacteristic* characteristic = @@ -495,6 +513,7 @@ void BluetoothDispatcher::ResolveOrSendStartNotificationRequest( } Send(new BluetoothHostMsg_StartNotifications(CurrentWorkerId(), request_id, + frame_routing_id, characteristic_instance_id)); } @@ -505,6 +524,7 @@ void BluetoothDispatcher::ResolveOrSendStopNotificationsRequest( // requests. BluetoothNotificationsRequest* request = pending_notifications_requests_.Lookup(request_id); + const int frame_routing_id = request->frame_routing_id; const std::string& characteristic_instance_id = request->characteristic_instance_id; blink::WebBluetoothGATTCharacteristic* characteristic = @@ -516,6 +536,7 @@ void BluetoothDispatcher::ResolveOrSendStopNotificationsRequest( if (RemoveFromActiveNotificationSubscriptions(characteristic_instance_id, characteristic)) { Send(new BluetoothHostMsg_StopNotifications(CurrentWorkerId(), request_id, + frame_routing_id, characteristic_instance_id)); return; } @@ -532,12 +553,14 @@ void BluetoothDispatcher::ResolveOrSendStopNotificationsRequest( } void BluetoothDispatcher::UnregisterCharacteristicObject( + int frame_routing_id, const blink::WebString& characteristic_instance_id) { int removed = active_characteristics_.erase(characteristic_instance_id.utf8()); if (removed != 0) { Send(new BluetoothHostMsg_UnregisterCharacteristic( - CurrentWorkerId(), characteristic_instance_id.utf8())); + CurrentWorkerId(), frame_routing_id, + characteristic_instance_id.utf8())); } } @@ -708,8 +731,9 @@ void BluetoothDispatcher::OnStartNotificationsSuccess(int thread_id, // which would result in the subscription continuing. if (request->characteristic == nullptr) { QueueNotificationRequest( - request->characteristic_instance_id, nullptr /* characteristic */, - nullptr /* callbacks */, NotificationsRequestType::STOP); + request->frame_routing_id, request->characteristic_instance_id, + nullptr /* characteristic */, nullptr /* callbacks */, + NotificationsRequestType::STOP); } request->callbacks->onSuccess(); diff --git a/content/renderer/bluetooth/bluetooth_dispatcher.h b/content/renderer/bluetooth/bluetooth_dispatcher.h index 6dbd5ea..1d978e1 100644 --- a/content/renderer/bluetooth/bluetooth_dispatcher.h +++ b/content/renderer/bluetooth/bluetooth_dispatcher.h @@ -64,32 +64,41 @@ class BluetoothDispatcher : public WorkerThread::Observer { void requestDevice(int frame_routing_id, const blink::WebRequestDeviceOptions& options, blink::WebBluetoothRequestDeviceCallbacks* callbacks); - void connectGATT(const blink::WebString& device_id, + void connectGATT(int frame_routing_id, + const blink::WebString& device_id, blink::WebBluetoothConnectGATTCallbacks* callbacks); void getPrimaryService( + int frame_routing_id, const blink::WebString& device_id, const blink::WebString& service_uuid, blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks); void getCharacteristic( + int frame_routing_id, const blink::WebString& service_instance_id, const blink::WebString& characteristic_uuid, blink::WebBluetoothGetCharacteristicCallbacks* callbacks); - void readValue(const blink::WebString& characteristic_instance_id, + void readValue(int frame_routing_id, + const blink::WebString& characteristic_instance_id, blink::WebBluetoothReadValueCallbacks* callbacks); - void writeValue(const blink::WebString& characteristic_instance_id, + void writeValue(int frame_routing_id, + const blink::WebString& characteristic_instance_id, const blink::WebVector<uint8_t>& value, blink::WebBluetoothWriteValueCallbacks*); - void startNotifications(const blink::WebString& characteristic_instance_id, + void startNotifications(int frame_routing_id, + const blink::WebString& characteristic_instance_id, blink::WebBluetoothGATTCharacteristic* delegate, blink::WebBluetoothNotificationsCallbacks*); - void stopNotifications(const blink::WebString& characteristic_instance_id, + void stopNotifications(int frame_routing_id, + const blink::WebString& characteristic_instance_id, blink::WebBluetoothGATTCharacteristic* delegate, blink::WebBluetoothNotificationsCallbacks*); void characteristicObjectRemoved( + int frame_routing_id, const blink::WebString& characteristic_instance_id, blink::WebBluetoothGATTCharacteristic* delegate); void registerCharacteristicObject( + int frame_routing_id, const blink::WebString& characteristic_instance_id, blink::WebBluetoothGATTCharacteristic* characteristic); @@ -113,6 +122,7 @@ class BluetoothDispatcher : public WorkerThread::Observer { // Creates a notification request and queues it. int QueueNotificationRequest( + int frame_routing_id, const std::string& characteristic_instance_id, blink::WebBluetoothGATTCharacteristic* characteristic, blink::WebBluetoothNotificationsCallbacks* callbacks, @@ -157,6 +167,7 @@ class BluetoothDispatcher : public WorkerThread::Observer { // receiving notifications. // https://crbug.com/541388 void UnregisterCharacteristicObject( + int frame_routing_id, const blink::WebString& characteristic_instance_id); // IPC Handlers, see definitions in bluetooth_messages.h. diff --git a/content/renderer/bluetooth/web_bluetooth_impl.cc b/content/renderer/bluetooth/web_bluetooth_impl.cc index 92d035b..8e3039d 100644 --- a/content/renderer/bluetooth/web_bluetooth_impl.cc +++ b/content/renderer/bluetooth/web_bluetooth_impl.cc @@ -30,65 +30,68 @@ void WebBluetoothImpl::requestDevice( void WebBluetoothImpl::connectGATT( const blink::WebString& device_id, blink::WebBluetoothConnectGATTCallbacks* callbacks) { - GetDispatcher()->connectGATT(device_id, callbacks); + GetDispatcher()->connectGATT(frame_routing_id_, device_id, callbacks); } void WebBluetoothImpl::getPrimaryService( const blink::WebString& device_id, const blink::WebString& service_uuid, blink::WebBluetoothGetPrimaryServiceCallbacks* callbacks) { - GetDispatcher()->getPrimaryService(device_id, service_uuid, callbacks); + GetDispatcher()->getPrimaryService(frame_routing_id_, device_id, service_uuid, + callbacks); } void WebBluetoothImpl::getCharacteristic( const blink::WebString& service_instance_id, const blink::WebString& characteristic_uuid, blink::WebBluetoothGetCharacteristicCallbacks* callbacks) { - GetDispatcher()->getCharacteristic(service_instance_id, characteristic_uuid, - callbacks); + GetDispatcher()->getCharacteristic(frame_routing_id_, service_instance_id, + characteristic_uuid, callbacks); } void WebBluetoothImpl::readValue( const blink::WebString& characteristic_instance_id, blink::WebBluetoothReadValueCallbacks* callbacks) { - GetDispatcher()->readValue(characteristic_instance_id, callbacks); + GetDispatcher()->readValue(frame_routing_id_, characteristic_instance_id, + callbacks); } void WebBluetoothImpl::writeValue( const blink::WebString& characteristic_instance_id, const blink::WebVector<uint8_t>& value, blink::WebBluetoothWriteValueCallbacks* callbacks) { - GetDispatcher()->writeValue(characteristic_instance_id, value, callbacks); + GetDispatcher()->writeValue(frame_routing_id_, characteristic_instance_id, + value, callbacks); } void WebBluetoothImpl::startNotifications( const blink::WebString& characteristic_instance_id, blink::WebBluetoothGATTCharacteristic* characteristic, blink::WebBluetoothNotificationsCallbacks* callbacks) { - GetDispatcher()->startNotifications(characteristic_instance_id, - characteristic, callbacks); + GetDispatcher()->startNotifications( + frame_routing_id_, characteristic_instance_id, characteristic, callbacks); } void WebBluetoothImpl::stopNotifications( const blink::WebString& characteristic_instance_id, blink::WebBluetoothGATTCharacteristic* characteristic, blink::WebBluetoothNotificationsCallbacks* callbacks) { - GetDispatcher()->stopNotifications(characteristic_instance_id, characteristic, - callbacks); + GetDispatcher()->stopNotifications( + frame_routing_id_, characteristic_instance_id, characteristic, callbacks); } void WebBluetoothImpl::characteristicObjectRemoved( const blink::WebString& characteristic_instance_id, blink::WebBluetoothGATTCharacteristic* characteristic) { - GetDispatcher()->characteristicObjectRemoved(characteristic_instance_id, - characteristic); + GetDispatcher()->characteristicObjectRemoved( + frame_routing_id_, characteristic_instance_id, characteristic); } void WebBluetoothImpl::registerCharacteristicObject( const blink::WebString& characteristic_instance_id, blink::WebBluetoothGATTCharacteristic* characteristic) { - GetDispatcher()->registerCharacteristicObject(characteristic_instance_id, - characteristic); + GetDispatcher()->registerCharacteristicObject( + frame_routing_id_, characteristic_instance_id, characteristic); } BluetoothDispatcher* WebBluetoothImpl::GetDispatcher() { |