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 // ID Not In Map Note: | 5 // ID Not In Map Note: |
6 // A service, characteristic, or descriptor ID not in the corresponding | 6 // A service, characteristic, or descriptor ID not in the corresponding |
7 // BluetoothDispatcherHost map [service_to_device_, characteristic_to_service_, | 7 // BluetoothDispatcherHost map [service_to_device_, characteristic_to_service_, |
8 // descriptor_to_characteristic_] implies a hostile renderer because a renderer | 8 // descriptor_to_characteristic_] implies a hostile renderer because a renderer |
9 // obtains the corresponding ID from this class and it will be added to the map | 9 // obtains the corresponding ID from this class and it will be added to the map |
10 // at that time. | 10 // at that time. |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "content/browser/bluetooth/first_device_bluetooth_chooser.h" | 24 #include "content/browser/bluetooth/first_device_bluetooth_chooser.h" |
25 #include "content/browser/frame_host/render_frame_host_impl.h" | 25 #include "content/browser/frame_host/render_frame_host_impl.h" |
26 #include "content/browser/web_contents/web_contents_impl.h" | 26 #include "content/browser/web_contents/web_contents_impl.h" |
27 #include "content/public/browser/content_browser_client.h" | 27 #include "content/public/browser/content_browser_client.h" |
28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
29 #include "content/public/browser/web_contents_delegate.h" | 29 #include "content/public/browser/web_contents_delegate.h" |
30 #include "device/bluetooth/bluetooth_adapter.h" | 30 #include "device/bluetooth/bluetooth_adapter.h" |
31 #include "device/bluetooth/bluetooth_adapter_factory.h" | 31 #include "device/bluetooth/bluetooth_adapter_factory.h" |
32 #include "device/bluetooth/bluetooth_device.h" | 32 #include "device/bluetooth/bluetooth_device.h" |
33 #include "device/bluetooth/bluetooth_discovery_session.h" | 33 #include "device/bluetooth/bluetooth_discovery_session.h" |
34 #include "device/bluetooth/bluetooth_gatt_characteristic.h" | 34 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
35 #include "device/bluetooth/bluetooth_gatt_service.h" | 35 #include "device/bluetooth/bluetooth_remote_gatt_service.h" |
36 | 36 |
37 using blink::WebBluetoothError; | 37 using blink::WebBluetoothError; |
38 using device::BluetoothAdapter; | 38 using device::BluetoothAdapter; |
39 using device::BluetoothAdapterFactory; | 39 using device::BluetoothAdapterFactory; |
40 using device::BluetoothGattCharacteristic; | 40 using device::BluetoothRemoteGattCharacteristic; |
41 using device::BluetoothGattService; | 41 using device::BluetoothRemoteGattService; |
42 using device::BluetoothUUID; | 42 using device::BluetoothUUID; |
43 | 43 |
44 namespace content { | 44 namespace content { |
45 | 45 |
46 namespace { | 46 namespace { |
47 | 47 |
48 // TODO(ortuno): Once we have a chooser for scanning, a way to control that | 48 // TODO(ortuno): Once we have a chooser for scanning, a way to control that |
49 // chooser from tests, and the right callback for discovered services we should | 49 // chooser from tests, and the right callback for discovered services we should |
50 // delete these constants. | 50 // delete these constants. |
51 // https://crbug.com/436280 and https://crbug.com/484504 | 51 // https://crbug.com/436280 and https://crbug.com/484504 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session) { | 172 std::unique_ptr<device::BluetoothDiscoverySession> discovery_session) { |
173 // Nothing goes wrong if the discovery session fails to stop, and we don't | 173 // Nothing goes wrong if the discovery session fails to stop, and we don't |
174 // need to wait for it before letting the user's script proceed, so we ignore | 174 // need to wait for it before letting the user's script proceed, so we ignore |
175 // the results here. | 175 // the results here. |
176 discovery_session->Stop(base::Bind(&base::DoNothing), | 176 discovery_session->Stop(base::Bind(&base::DoNothing), |
177 base::Bind(&base::DoNothing)); | 177 base::Bind(&base::DoNothing)); |
178 } | 178 } |
179 | 179 |
180 // TODO(ortuno): This should really be a BluetoothDevice method. | 180 // TODO(ortuno): This should really be a BluetoothDevice method. |
181 // Replace when implemented. http://crbug.com/552022 | 181 // Replace when implemented. http://crbug.com/552022 |
182 std::vector<BluetoothGattService*> GetPrimaryServicesByUUID( | 182 std::vector<BluetoothRemoteGattService*> GetPrimaryServicesByUUID( |
183 device::BluetoothDevice* device, | 183 device::BluetoothDevice* device, |
184 const std::string& service_uuid) { | 184 const std::string& service_uuid) { |
185 std::vector<BluetoothGattService*> services; | 185 std::vector<BluetoothRemoteGattService*> services; |
186 VLOG(1) << "Looking for service: " << service_uuid; | 186 VLOG(1) << "Looking for service: " << service_uuid; |
187 for (BluetoothGattService* service : device->GetGattServices()) { | 187 for (BluetoothRemoteGattService* service : device->GetGattServices()) { |
188 VLOG(1) << "Service in cache: " << service->GetUUID().canonical_value(); | 188 VLOG(1) << "Service in cache: " << service->GetUUID().canonical_value(); |
189 if (service->GetUUID().canonical_value() == service_uuid && | 189 if (service->GetUUID().canonical_value() == service_uuid && |
190 service->IsPrimary()) { | 190 service->IsPrimary()) { |
191 services.push_back(service); | 191 services.push_back(service); |
192 } | 192 } |
193 } | 193 } |
194 return services; | 194 return services; |
195 } | 195 } |
196 | 196 |
197 UMARequestDeviceOutcome OutcomeFromChooserEvent(BluetoothChooser::Event event) { | 197 UMARequestDeviceOutcome OutcomeFromChooserEvent(BluetoothChooser::Event event) { |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 | 590 |
591 auto iter = pending_primary_services_requests_.find(device_address); | 591 auto iter = pending_primary_services_requests_.find(device_address); |
592 if (iter == pending_primary_services_requests_.end()) { | 592 if (iter == pending_primary_services_requests_.end()) { |
593 return; | 593 return; |
594 } | 594 } |
595 std::vector<PrimaryServicesRequest> requests; | 595 std::vector<PrimaryServicesRequest> requests; |
596 requests.swap(iter->second); | 596 requests.swap(iter->second); |
597 pending_primary_services_requests_.erase(iter); | 597 pending_primary_services_requests_.erase(iter); |
598 | 598 |
599 for (const PrimaryServicesRequest& request : requests) { | 599 for (const PrimaryServicesRequest& request : requests) { |
600 std::vector<BluetoothGattService*> services = | 600 std::vector<BluetoothRemoteGattService*> services = |
601 GetPrimaryServicesByUUID(device, request.service_uuid); | 601 GetPrimaryServicesByUUID(device, request.service_uuid); |
602 switch (request.func) { | 602 switch (request.func) { |
603 case PrimaryServicesRequest::GET_PRIMARY_SERVICE: | 603 case PrimaryServicesRequest::GET_PRIMARY_SERVICE: |
604 if (!services.empty()) { | 604 if (!services.empty()) { |
605 AddToServicesMapAndSendGetPrimaryServiceSuccess( | 605 AddToServicesMapAndSendGetPrimaryServiceSuccess( |
606 *services[0], request.thread_id, request.request_id); | 606 *services[0], request.thread_id, request.request_id); |
607 } else { | 607 } else { |
608 VLOG(1) << "No service found"; | 608 VLOG(1) << "No service found"; |
609 RecordGetPrimaryServiceOutcome( | 609 RecordGetPrimaryServiceOutcome( |
610 UMAGetPrimaryServiceOutcome::NOT_FOUND); | 610 UMAGetPrimaryServiceOutcome::NOT_FOUND); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 // There are four possibilities here: | 742 // There are four possibilities here: |
743 // 1. Services not discovered and service present in |device|: Send back the | 743 // 1. Services not discovered and service present in |device|: Send back the |
744 // service to the renderer. | 744 // service to the renderer. |
745 // 2. Services discovered and service present in |device|: Send back the | 745 // 2. Services discovered and service present in |device|: Send back the |
746 // service to the renderer. | 746 // service to the renderer. |
747 // 3. Services discovered and service not present in |device|: Send back not | 747 // 3. Services discovered and service not present in |device|: Send back not |
748 // found error. | 748 // found error. |
749 // 4. Services not discovered and service not present in |device|: Add request | 749 // 4. Services not discovered and service not present in |device|: Add request |
750 // to map of pending getPrimaryService requests. | 750 // to map of pending getPrimaryService requests. |
751 | 751 |
752 std::vector<BluetoothGattService*> services = | 752 std::vector<BluetoothRemoteGattService*> services = |
753 GetPrimaryServicesByUUID(query_result.device, service_uuid); | 753 GetPrimaryServicesByUUID(query_result.device, service_uuid); |
754 | 754 |
755 // 1. & 2. | 755 // 1. & 2. |
756 if (!services.empty()) { | 756 if (!services.empty()) { |
757 VLOG(1) << "Service found in device."; | 757 VLOG(1) << "Service found in device."; |
758 const BluetoothGattService& service = *services[0]; | 758 const BluetoothRemoteGattService& service = *services[0]; |
759 DCHECK(service.IsPrimary()); | 759 DCHECK(service.IsPrimary()); |
760 AddToServicesMapAndSendGetPrimaryServiceSuccess(service, thread_id, | 760 AddToServicesMapAndSendGetPrimaryServiceSuccess(service, thread_id, |
761 request_id); | 761 request_id); |
762 return; | 762 return; |
763 } | 763 } |
764 | 764 |
765 // 3. | 765 // 3. |
766 if (query_result.device->IsGattServicesDiscoveryComplete()) { | 766 if (query_result.device->IsGattServicesDiscoveryComplete()) { |
767 VLOG(1) << "Service not found in device."; | 767 VLOG(1) << "Service not found in device."; |
768 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NOT_FOUND); | 768 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NOT_FOUND); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 return; | 806 return; |
807 } | 807 } |
808 | 808 |
809 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 809 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
810 RecordGetCharacteristicOutcome(query_result.outcome); | 810 RecordGetCharacteristicOutcome(query_result.outcome); |
811 Send(new BluetoothMsg_GetCharacteristicError(thread_id, request_id, | 811 Send(new BluetoothMsg_GetCharacteristicError(thread_id, request_id, |
812 query_result.GetWebError())); | 812 query_result.GetWebError())); |
813 return; | 813 return; |
814 } | 814 } |
815 | 815 |
816 for (BluetoothGattCharacteristic* characteristic : | 816 for (BluetoothRemoteGattCharacteristic* characteristic : |
817 query_result.service->GetCharacteristics()) { | 817 query_result.service->GetCharacteristics()) { |
818 if (characteristic->GetUUID().canonical_value() == characteristic_uuid) { | 818 if (characteristic->GetUUID().canonical_value() == characteristic_uuid) { |
819 const std::string& characteristic_instance_id = | 819 const std::string& characteristic_instance_id = |
820 characteristic->GetIdentifier(); | 820 characteristic->GetIdentifier(); |
821 | 821 |
822 auto insert_result = characteristic_to_service_.insert( | 822 auto insert_result = characteristic_to_service_.insert( |
823 make_pair(characteristic_instance_id, service_instance_id)); | 823 make_pair(characteristic_instance_id, service_instance_id)); |
824 | 824 |
825 // If value is already in map, DCHECK it's valid. | 825 // If value is already in map, DCHECK it's valid. |
826 if (!insert_result.second) | 826 if (!insert_result.second) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 RecordGetCharacteristicsOutcome(query_result.outcome); | 873 RecordGetCharacteristicsOutcome(query_result.outcome); |
874 Send(new BluetoothMsg_GetCharacteristicsError(thread_id, request_id, | 874 Send(new BluetoothMsg_GetCharacteristicsError(thread_id, request_id, |
875 query_result.GetWebError())); | 875 query_result.GetWebError())); |
876 return; | 876 return; |
877 } | 877 } |
878 | 878 |
879 std::vector<std::string> characteristics_instance_ids; | 879 std::vector<std::string> characteristics_instance_ids; |
880 std::vector<std::string> characteristics_uuids; | 880 std::vector<std::string> characteristics_uuids; |
881 std::vector<uint32_t> characteristics_properties; | 881 std::vector<uint32_t> characteristics_properties; |
882 | 882 |
883 for (BluetoothGattCharacteristic* characteristic : | 883 for (BluetoothRemoteGattCharacteristic* characteristic : |
884 query_result.service->GetCharacteristics()) { | 884 query_result.service->GetCharacteristics()) { |
885 if (!BluetoothBlacklist::Get().IsExcluded(characteristic->GetUUID()) && | 885 if (!BluetoothBlacklist::Get().IsExcluded(characteristic->GetUUID()) && |
886 (characteristics_uuid.empty() || | 886 (characteristics_uuid.empty() || |
887 characteristics_uuid == characteristic->GetUUID().canonical_value())) { | 887 characteristics_uuid == characteristic->GetUUID().canonical_value())) { |
888 const std::string& characteristic_instance_id = | 888 const std::string& characteristic_instance_id = |
889 characteristic->GetIdentifier(); | 889 characteristic->GetIdentifier(); |
890 | 890 |
891 characteristics_instance_ids.push_back(characteristic_instance_id); | 891 characteristics_instance_ids.push_back(characteristic_instance_id); |
892 characteristics_uuids.push_back( | 892 characteristics_uuids.push_back( |
893 characteristic->GetUUID().canonical_value()); | 893 characteristic->GetUUID().canonical_value()); |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1279 // There was an error creating the ATT Bearer so we reject with | 1279 // There was an error creating the ATT Bearer so we reject with |
1280 // NetworkError. | 1280 // NetworkError. |
1281 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-con
nectgatt | 1281 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-con
nectgatt |
1282 RecordConnectGATTTimeFailed(base::TimeTicks::Now() - start_time); | 1282 RecordConnectGATTTimeFailed(base::TimeTicks::Now() - start_time); |
1283 // RecordConnectGATTOutcome is called by TranslateConnectError. | 1283 // RecordConnectGATTOutcome is called by TranslateConnectError. |
1284 Send(new BluetoothMsg_GATTServerConnectError( | 1284 Send(new BluetoothMsg_GATTServerConnectError( |
1285 thread_id, request_id, TranslateConnectError(error_code))); | 1285 thread_id, request_id, TranslateConnectError(error_code))); |
1286 } | 1286 } |
1287 | 1287 |
1288 void BluetoothDispatcherHost::AddToServicesMapAndSendGetPrimaryServiceSuccess( | 1288 void BluetoothDispatcherHost::AddToServicesMapAndSendGetPrimaryServiceSuccess( |
1289 const device::BluetoothGattService& service, | 1289 const device::BluetoothRemoteGattService& service, |
1290 int thread_id, | 1290 int thread_id, |
1291 int request_id) { | 1291 int request_id) { |
1292 const std::string& service_identifier = service.GetIdentifier(); | 1292 const std::string& service_identifier = service.GetIdentifier(); |
1293 const std::string& device_address = service.GetDevice()->GetAddress(); | 1293 const std::string& device_address = service.GetDevice()->GetAddress(); |
1294 auto insert_result = | 1294 auto insert_result = |
1295 service_to_device_.insert(make_pair(service_identifier, device_address)); | 1295 service_to_device_.insert(make_pair(service_identifier, device_address)); |
1296 | 1296 |
1297 // If a value is already in map, DCHECK it's valid. | 1297 // If a value is already in map, DCHECK it's valid. |
1298 if (!insert_result.second) | 1298 if (!insert_result.second) |
1299 DCHECK_EQ(insert_result.first->second, device_address); | 1299 DCHECK_EQ(insert_result.first->second, device_address); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1418 const PrimaryServicesRequest& request) { | 1418 const PrimaryServicesRequest& request) { |
1419 pending_primary_services_requests_[device_address].push_back(request); | 1419 pending_primary_services_requests_[device_address].push_back(request); |
1420 } | 1420 } |
1421 | 1421 |
1422 url::Origin BluetoothDispatcherHost::GetOrigin(int frame_routing_id) { | 1422 url::Origin BluetoothDispatcherHost::GetOrigin(int frame_routing_id) { |
1423 return RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id) | 1423 return RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id) |
1424 ->GetLastCommittedOrigin(); | 1424 ->GetLastCommittedOrigin(); |
1425 } | 1425 } |
1426 | 1426 |
1427 } // namespace content | 1427 } // namespace content |
OLD | NEW |