OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // NETWORK_ERROR Note: | 5 // NETWORK_ERROR Note: |
6 // When a device can't be found in the BluetoothAdapter, that generally | 6 // When a device can't be found in the BluetoothAdapter, that generally |
7 // indicates that it's gone out of range. We reject with a NetworkError in that | 7 // indicates that it's gone out of range. We reject with a NetworkError in that |
8 // case. | 8 // case. |
9 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-conne ctgatt | 9 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-conne ctgatt |
10 | 10 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) { | 192 bool BluetoothDispatcherHost::OnMessageReceived(const IPC::Message& message) { |
193 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 193 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
194 bool handled = true; | 194 bool handled = true; |
195 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcherHost, message) | 195 IPC_BEGIN_MESSAGE_MAP(BluetoothDispatcherHost, message) |
196 IPC_MESSAGE_HANDLER(BluetoothHostMsg_RequestDevice, OnRequestDevice) | 196 IPC_MESSAGE_HANDLER(BluetoothHostMsg_RequestDevice, OnRequestDevice) |
197 IPC_MESSAGE_HANDLER(BluetoothHostMsg_ConnectGATT, OnConnectGATT) | 197 IPC_MESSAGE_HANDLER(BluetoothHostMsg_ConnectGATT, OnConnectGATT) |
198 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetPrimaryService, OnGetPrimaryService) | 198 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetPrimaryService, OnGetPrimaryService) |
199 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetCharacteristic, OnGetCharacteristic) | 199 IPC_MESSAGE_HANDLER(BluetoothHostMsg_GetCharacteristic, OnGetCharacteristic) |
200 IPC_MESSAGE_HANDLER(BluetoothHostMsg_ReadValue, OnReadValue) | 200 IPC_MESSAGE_HANDLER(BluetoothHostMsg_ReadValue, OnReadValue) |
201 IPC_MESSAGE_HANDLER(BluetoothHostMsg_WriteValue, OnWriteValue) | 201 IPC_MESSAGE_HANDLER(BluetoothHostMsg_WriteValue, OnWriteValue) |
202 IPC_MESSAGE_HANDLER(BluetoothHostMsg_StartNotifications, OnStartNotifications) | |
203 IPC_MESSAGE_HANDLER(BluetoothHostMsg_StopNotifications, OnStopNotifications) | |
202 IPC_MESSAGE_UNHANDLED(handled = false) | 204 IPC_MESSAGE_UNHANDLED(handled = false) |
203 IPC_END_MESSAGE_MAP() | 205 IPC_END_MESSAGE_MAP() |
204 return handled; | 206 return handled; |
205 } | 207 } |
206 | 208 |
207 void BluetoothDispatcherHost::SetBluetoothAdapterForTesting( | 209 void BluetoothDispatcherHost::SetBluetoothAdapterForTesting( |
208 scoped_refptr<device::BluetoothAdapter> mock_adapter) { | 210 scoped_refptr<device::BluetoothAdapter> mock_adapter) { |
209 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 211 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
210 current_delay_time_ = kTestingDelayTime; | 212 current_delay_time_ = kTestingDelayTime; |
211 // Reset the discovery session timer to use the new delay time. | 213 // Reset the discovery session timer to use the new delay time. |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter( | 342 for (IDMap<RequestDeviceSession, IDMapOwnPointer>::iterator iter( |
341 &request_device_sessions_); | 343 &request_device_sessions_); |
342 !iter.IsAtEnd(); iter.Advance()) { | 344 !iter.IsAtEnd(); iter.Advance()) { |
343 RequestDeviceSession* session = iter.GetCurrentValue(); | 345 RequestDeviceSession* session = iter.GetCurrentValue(); |
344 if (session->chooser) { | 346 if (session->chooser) { |
345 session->chooser->RemoveDevice(device->GetAddress()); | 347 session->chooser->RemoveDevice(device->GetAddress()); |
346 } | 348 } |
347 } | 349 } |
348 } | 350 } |
349 | 351 |
352 void BluetoothDispatcherHost::GattCharacteristicValueChanged( | |
353 device::BluetoothAdapter* adapter, | |
354 device::BluetoothGattCharacteristic* characteristic, | |
355 const std::vector<uint8>& value) { | |
356 // TODO(ortuno): Notify renderer the characteristic changed. | |
357 // http://crbug.com/529560 | |
358 VLOG(1) << "Characteristic updated."; | |
359 } | |
360 | |
350 void BluetoothDispatcherHost::OnRequestDevice( | 361 void BluetoothDispatcherHost::OnRequestDevice( |
351 int thread_id, | 362 int thread_id, |
352 int request_id, | 363 int request_id, |
353 int frame_routing_id, | 364 int frame_routing_id, |
354 const std::vector<BluetoothScanFilter>& filters, | 365 const std::vector<BluetoothScanFilter>& filters, |
355 const std::vector<BluetoothUUID>& optional_services) { | 366 const std::vector<BluetoothUUID>& optional_services) { |
356 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 367 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
357 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE); | 368 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE); |
358 RecordRequestDeviceArguments(filters, optional_services); | 369 RecordRequestDeviceArguments(filters, optional_services); |
359 | 370 |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
687 WebBluetoothError::CharacteristicNoLongerExists)); | 698 WebBluetoothError::CharacteristicNoLongerExists)); |
688 return; | 699 return; |
689 } | 700 } |
690 characteristic->WriteRemoteCharacteristic( | 701 characteristic->WriteRemoteCharacteristic( |
691 value, base::Bind(&BluetoothDispatcherHost::OnWriteValueSuccess, | 702 value, base::Bind(&BluetoothDispatcherHost::OnWriteValueSuccess, |
692 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id), | 703 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id), |
693 base::Bind(&BluetoothDispatcherHost::OnWriteValueFailed, | 704 base::Bind(&BluetoothDispatcherHost::OnWriteValueFailed, |
694 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id)); | 705 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id)); |
695 } | 706 } |
696 | 707 |
708 void BluetoothDispatcherHost::OnStartNotifications( | |
709 int thread_id, | |
710 int request_id, | |
711 const std::string& characteristic_instance_id) { | |
712 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
713 RecordWebBluetoothFunctionCall( | |
714 UMAWebBluetoothFunction::CHARACTERISTIC_START_NOTIFICATIONS); | |
715 | |
716 // BluetoothDispatcher will never send a request for a characteristic | |
717 // already subscribed to notifications. | |
718 DCHECK( | |
scheib
2015/10/01 22:05:22
It's a compromised renderer then, right? So this s
ortuno
2015/10/03 04:03:03
Done.
| |
719 characteristic_id_to_notify_session_.find(characteristic_instance_id) == | |
720 characteristic_id_to_notify_session_.end()); | |
721 | |
722 // TODO(ortuno): Check if notify/indicate bit is set. | |
scheib
2015/10/01 22:05:22
Have an issue so we track to follow up on this.
ortuno
2015/10/03 04:03:03
Done.
| |
723 | |
724 auto characteristic_iter = | |
725 characteristic_to_service_.find(characteristic_instance_id); | |
726 // A characteristic_instance_id not in the map implies a hostile renderer | |
scheib
2015/10/01 22:05:22
3rd time we're copying this block, so let's move e
ortuno
2015/10/03 04:03:03
Done.
| |
727 // because a renderer obtains the characteristic id from this class and | |
728 // it will be added to the map at that time. | |
729 if (characteristic_iter == characteristic_to_service_.end()) { | |
730 // Kill the renderer | |
731 bad_message::ReceivedBadMessage(this, | |
732 bad_message::BDH_INVALID_CHARACTERISTIC_ID); | |
733 return; | |
734 } | |
735 | |
736 const std::string& service_instance_id = characteristic_iter->second; | |
737 auto device_iter = service_to_device_.find(service_instance_id); | |
738 CHECK(device_iter != service_to_device_.end()); | |
739 | |
740 device::BluetoothDevice* device = | |
scheib
2015/10/01 22:05:22
In a later clean up patch we should refactor out t
ortuno
2015/10/03 04:03:03
I already have a patch :P
https://codereview.chro
| |
741 adapter_->GetDevice(device_iter->second /* device_instance_id */); | |
742 if (device == nullptr) { // See "NETWORK_ERROR Note" above. | |
743 RecordStartNotificationsOutcome(UMAGATTOperationOutcome::NO_DEVICE); | |
744 Send(new BluetoothMsg_StartNotificationsError( | |
745 thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange)); | |
746 return; | |
747 } | |
748 | |
749 BluetoothGattService* service = device->GetGattService(service_instance_id); | |
750 if (service == nullptr) { | |
751 RecordStartNotificationsOutcome(UMAGATTOperationOutcome::NO_SERVICE); | |
752 Send(new BluetoothMsg_StartNotificationsError( | |
753 thread_id, request_id, WebBluetoothError::ServiceNoLongerExists)); | |
754 return; | |
755 } | |
756 | |
757 BluetoothGattCharacteristic* characteristic = | |
758 service->GetCharacteristic(characteristic_instance_id); | |
759 if (characteristic == nullptr) { | |
760 RecordStartNotificationsOutcome(UMAGATTOperationOutcome::NO_CHARACTERISTIC); | |
761 Send(new BluetoothMsg_StartNotificationsError( | |
762 thread_id, request_id, | |
763 WebBluetoothError::CharacteristicNoLongerExists)); | |
764 return; | |
765 } | |
766 | |
767 characteristic->StartNotifySession( | |
768 base::Bind(&BluetoothDispatcherHost::OnStartNotifySessionSuccess, | |
769 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id), | |
770 base::Bind(&BluetoothDispatcherHost::OnStartNotifySessionFailed, | |
771 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id)); | |
772 } | |
773 void BluetoothDispatcherHost::OnStopNotifications( | |
774 int thread_id, | |
775 int request_id, | |
776 const std::string& characteristic_instance_id) { | |
777 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
778 RecordWebBluetoothFunctionCall( | |
779 UMAWebBluetoothFunction::CHARACTERISTIC_STOP_NOTIFICATIONS); | |
780 | |
781 auto notify_session_iter = | |
782 characteristic_id_to_notify_session_.find(characteristic_instance_id); | |
783 if (notify_session_iter == characteristic_id_to_notify_session_.end()) { | |
784 Send(new BluetoothMsg_StopNotificationsSuccess(thread_id, request_id)); | |
785 return; | |
786 } | |
787 notify_session_iter->second->Stop( | |
788 base::Bind(&BluetoothDispatcherHost::OnStopNotifySession, | |
789 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, | |
790 characteristic_instance_id)); | |
791 } | |
792 | |
697 void BluetoothDispatcherHost::OnDiscoverySessionStarted( | 793 void BluetoothDispatcherHost::OnDiscoverySessionStarted( |
698 int chooser_id, | 794 int chooser_id, |
699 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { | 795 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { |
700 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 796 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
701 VLOG(1) << "Started discovery session for " << chooser_id; | 797 VLOG(1) << "Started discovery session for " << chooser_id; |
702 if (RequestDeviceSession* session = | 798 if (RequestDeviceSession* session = |
703 request_device_sessions_.Lookup(chooser_id)) { | 799 request_device_sessions_.Lookup(chooser_id)) { |
704 session->discovery_session = discovery_session.Pass(); | 800 session->discovery_session = discovery_session.Pass(); |
705 | 801 |
706 // Arrange to stop discovery later. | 802 // Arrange to stop discovery later. |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
916 void BluetoothDispatcherHost::OnWriteValueFailed( | 1012 void BluetoothDispatcherHost::OnWriteValueFailed( |
917 int thread_id, | 1013 int thread_id, |
918 int request_id, | 1014 int request_id, |
919 device::BluetoothGattService::GattErrorCode error_code) { | 1015 device::BluetoothGattService::GattErrorCode error_code) { |
920 // TranslateGATTError calls RecordGATTOperationOutcome. | 1016 // TranslateGATTError calls RecordGATTOperationOutcome. |
921 Send(new BluetoothMsg_WriteCharacteristicValueError( | 1017 Send(new BluetoothMsg_WriteCharacteristicValueError( |
922 thread_id, request_id, | 1018 thread_id, request_id, |
923 TranslateGATTError(error_code, UMAGATTOperation::CHARACTERISTIC_WRITE))); | 1019 TranslateGATTError(error_code, UMAGATTOperation::CHARACTERISTIC_WRITE))); |
924 } | 1020 } |
925 | 1021 |
1022 void BluetoothDispatcherHost::OnStartNotifySessionSuccess( | |
1023 int thread_id, | |
1024 int request_id, | |
1025 scoped_ptr<device::BluetoothGattNotifySession> notify_session) { | |
1026 RecordStartNotificationsOutcome(UMAGATTOperationOutcome::SUCCESS); | |
1027 | |
1028 characteristic_id_to_notify_session_.insert( | |
1029 notify_session->GetCharacteristicIdentifier(), notify_session.Pass()); | |
1030 Send(new BluetoothMsg_StartNotificationsSuccess(thread_id, request_id)); | |
1031 } | |
1032 | |
1033 void BluetoothDispatcherHost::OnStartNotifySessionFailed( | |
1034 int thread_id, | |
1035 int request_id, | |
1036 device::BluetoothGattService::GattErrorCode error_code) { | |
1037 // TranslateGATTError calls RecordGATTOperationOutcome. | |
scheib
2015/10/01 22:05:22
In a clean up CL we should remove comments and ren
ortuno
2015/10/03 04:03:03
http://crbug.com/538876
| |
1038 Send(new BluetoothMsg_StartNotificationsError( | |
1039 thread_id, request_id, | |
1040 TranslateGATTError(error_code, UMAGATTOperation::START_NOTIFICATIONS))); | |
1041 } | |
1042 | |
1043 void BluetoothDispatcherHost::OnStopNotifySession( | |
1044 int thread_id, | |
1045 int request_id, | |
1046 const std::string& characteristic_instance_id) { | |
1047 characteristic_id_to_notify_session_.erase(characteristic_instance_id); | |
1048 Send(new BluetoothMsg_StopNotificationsSuccess(thread_id, request_id)); | |
1049 } | |
1050 | |
926 void BluetoothDispatcherHost::ShowBluetoothOverviewLink() { | 1051 void BluetoothDispatcherHost::ShowBluetoothOverviewLink() { |
927 NOTIMPLEMENTED(); | 1052 NOTIMPLEMENTED(); |
928 } | 1053 } |
929 | 1054 |
930 void BluetoothDispatcherHost::ShowBluetoothPairingLink() { | 1055 void BluetoothDispatcherHost::ShowBluetoothPairingLink() { |
931 NOTIMPLEMENTED(); | 1056 NOTIMPLEMENTED(); |
932 } | 1057 } |
933 | 1058 |
934 void BluetoothDispatcherHost::ShowBluetoothAdapterOffLink() { | 1059 void BluetoothDispatcherHost::ShowBluetoothAdapterOffLink() { |
935 NOTIMPLEMENTED(); | 1060 NOTIMPLEMENTED(); |
936 } | 1061 } |
937 | 1062 |
938 } // namespace content | 1063 } // namespace content |
OLD | NEW |