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 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 | 587 |
588 auto iter = pending_primary_services_requests_.find(device_address); | 588 auto iter = pending_primary_services_requests_.find(device_address); |
589 if (iter == pending_primary_services_requests_.end()) { | 589 if (iter == pending_primary_services_requests_.end()) { |
590 return; | 590 return; |
591 } | 591 } |
592 std::vector<PrimaryServicesRequest> requests; | 592 std::vector<PrimaryServicesRequest> requests; |
593 requests.swap(iter->second); | 593 requests.swap(iter->second); |
594 pending_primary_services_requests_.erase(iter); | 594 pending_primary_services_requests_.erase(iter); |
595 | 595 |
596 for (const PrimaryServicesRequest& request : requests) { | 596 for (const PrimaryServicesRequest& request : requests) { |
597 std::vector<BluetoothGattService*> services = | 597 std::vector<BluetoothRemoteGattService*> services = |
598 GetPrimaryServicesByUUID(device, request.service_uuid); | 598 GetPrimaryServicesByUUID(device, request.service_uuid); |
599 switch (request.func) { | 599 switch (request.func) { |
600 case PrimaryServicesRequest::GET_PRIMARY_SERVICE: | 600 case PrimaryServicesRequest::GET_PRIMARY_SERVICE: |
601 if (!services.empty()) { | 601 if (!services.empty()) { |
602 AddToServicesMapAndSendGetPrimaryServiceSuccess( | 602 AddToServicesMapAndSendGetPrimaryServiceSuccess( |
603 *services[0], request.thread_id, request.request_id); | 603 *services[0], request.thread_id, request.request_id); |
604 } else { | 604 } else { |
605 VLOG(1) << "No service found"; | 605 VLOG(1) << "No service found"; |
606 RecordGetPrimaryServiceOutcome( | 606 RecordGetPrimaryServiceOutcome( |
607 UMAGetPrimaryServiceOutcome::NOT_FOUND); | 607 UMAGetPrimaryServiceOutcome::NOT_FOUND); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 // There are four possibilities here: | 739 // There are four possibilities here: |
740 // 1. Services not discovered and service present in |device|: Send back the | 740 // 1. Services not discovered and service present in |device|: Send back the |
741 // service to the renderer. | 741 // service to the renderer. |
742 // 2. Services discovered and service present in |device|: Send back the | 742 // 2. Services discovered and service present in |device|: Send back the |
743 // service to the renderer. | 743 // service to the renderer. |
744 // 3. Services discovered and service not present in |device|: Send back not | 744 // 3. Services discovered and service not present in |device|: Send back not |
745 // found error. | 745 // found error. |
746 // 4. Services not discovered and service not present in |device|: Add request | 746 // 4. Services not discovered and service not present in |device|: Add request |
747 // to map of pending getPrimaryService requests. | 747 // to map of pending getPrimaryService requests. |
748 | 748 |
749 std::vector<BluetoothGattService*> services = | 749 std::vector<BluetoothRemoteGattService*> services = |
750 GetPrimaryServicesByUUID(query_result.device, service_uuid); | 750 GetPrimaryServicesByUUID(query_result.device, service_uuid); |
751 | 751 |
752 // 1. & 2. | 752 // 1. & 2. |
753 if (!services.empty()) { | 753 if (!services.empty()) { |
754 VLOG(1) << "Service found in device."; | 754 VLOG(1) << "Service found in device."; |
755 const BluetoothGattService& service = *services[0]; | 755 const BluetoothRemoteGattService& service = *services[0]; |
756 DCHECK(service.IsPrimary()); | 756 DCHECK(service.IsPrimary()); |
757 AddToServicesMapAndSendGetPrimaryServiceSuccess(service, thread_id, | 757 AddToServicesMapAndSendGetPrimaryServiceSuccess(service, thread_id, |
758 request_id); | 758 request_id); |
759 return; | 759 return; |
760 } | 760 } |
761 | 761 |
762 // 3. | 762 // 3. |
763 if (query_result.device->IsGattServicesDiscoveryComplete()) { | 763 if (query_result.device->IsGattServicesDiscoveryComplete()) { |
764 VLOG(1) << "Service not found in device."; | 764 VLOG(1) << "Service not found in device."; |
765 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NOT_FOUND); | 765 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NOT_FOUND); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 return; | 803 return; |
804 } | 804 } |
805 | 805 |
806 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 806 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
807 RecordGetCharacteristicOutcome(query_result.outcome); | 807 RecordGetCharacteristicOutcome(query_result.outcome); |
808 Send(new BluetoothMsg_GetCharacteristicError(thread_id, request_id, | 808 Send(new BluetoothMsg_GetCharacteristicError(thread_id, request_id, |
809 query_result.GetWebError())); | 809 query_result.GetWebError())); |
810 return; | 810 return; |
811 } | 811 } |
812 | 812 |
813 for (BluetoothGattCharacteristic* characteristic : | 813 for (BluetoothRemoteGattCharacteristic* characteristic : |
814 query_result.service->GetCharacteristics()) { | 814 query_result.service->GetCharacteristics()) { |
815 if (characteristic->GetUUID().canonical_value() == characteristic_uuid) { | 815 if (characteristic->GetUUID().canonical_value() == characteristic_uuid) { |
816 const std::string& characteristic_instance_id = | 816 const std::string& characteristic_instance_id = |
817 characteristic->GetIdentifier(); | 817 characteristic->GetIdentifier(); |
818 | 818 |
819 auto insert_result = characteristic_to_service_.insert( | 819 auto insert_result = characteristic_to_service_.insert( |
820 make_pair(characteristic_instance_id, service_instance_id)); | 820 make_pair(characteristic_instance_id, service_instance_id)); |
821 | 821 |
822 // If value is already in map, DCHECK it's valid. | 822 // If value is already in map, DCHECK it's valid. |
823 if (!insert_result.second) | 823 if (!insert_result.second) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 RecordGetCharacteristicsOutcome(query_result.outcome); | 870 RecordGetCharacteristicsOutcome(query_result.outcome); |
871 Send(new BluetoothMsg_GetCharacteristicsError(thread_id, request_id, | 871 Send(new BluetoothMsg_GetCharacteristicsError(thread_id, request_id, |
872 query_result.GetWebError())); | 872 query_result.GetWebError())); |
873 return; | 873 return; |
874 } | 874 } |
875 | 875 |
876 std::vector<std::string> characteristics_instance_ids; | 876 std::vector<std::string> characteristics_instance_ids; |
877 std::vector<std::string> characteristics_uuids; | 877 std::vector<std::string> characteristics_uuids; |
878 std::vector<uint32_t> characteristics_properties; | 878 std::vector<uint32_t> characteristics_properties; |
879 | 879 |
880 for (BluetoothGattCharacteristic* characteristic : | 880 for (BluetoothRemoteGattCharacteristic* characteristic : |
881 query_result.service->GetCharacteristics()) { | 881 query_result.service->GetCharacteristics()) { |
882 if (!BluetoothBlacklist::Get().IsExcluded(characteristic->GetUUID()) && | 882 if (!BluetoothBlacklist::Get().IsExcluded(characteristic->GetUUID()) && |
883 (characteristics_uuid.empty() || | 883 (characteristics_uuid.empty() || |
884 characteristics_uuid == characteristic->GetUUID().canonical_value())) { | 884 characteristics_uuid == characteristic->GetUUID().canonical_value())) { |
885 const std::string& characteristic_instance_id = | 885 const std::string& characteristic_instance_id = |
886 characteristic->GetIdentifier(); | 886 characteristic->GetIdentifier(); |
887 | 887 |
888 characteristics_instance_ids.push_back(characteristic_instance_id); | 888 characteristics_instance_ids.push_back(characteristic_instance_id); |
889 characteristics_uuids.push_back( | 889 characteristics_uuids.push_back( |
890 characteristic->GetUUID().canonical_value()); | 890 characteristic->GetUUID().canonical_value()); |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1276 // There was an error creating the ATT Bearer so we reject with | 1276 // There was an error creating the ATT Bearer so we reject with |
1277 // NetworkError. | 1277 // NetworkError. |
1278 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-con
nectgatt | 1278 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-con
nectgatt |
1279 RecordConnectGATTTimeFailed(base::TimeTicks::Now() - start_time); | 1279 RecordConnectGATTTimeFailed(base::TimeTicks::Now() - start_time); |
1280 // RecordConnectGATTOutcome is called by TranslateConnectError. | 1280 // RecordConnectGATTOutcome is called by TranslateConnectError. |
1281 Send(new BluetoothMsg_GATTServerConnectError( | 1281 Send(new BluetoothMsg_GATTServerConnectError( |
1282 thread_id, request_id, TranslateConnectError(error_code))); | 1282 thread_id, request_id, TranslateConnectError(error_code))); |
1283 } | 1283 } |
1284 | 1284 |
1285 void BluetoothDispatcherHost::AddToServicesMapAndSendGetPrimaryServiceSuccess( | 1285 void BluetoothDispatcherHost::AddToServicesMapAndSendGetPrimaryServiceSuccess( |
1286 const device::BluetoothGattService& service, | 1286 const device::BluetoothRemoteGattService& service, |
1287 int thread_id, | 1287 int thread_id, |
1288 int request_id) { | 1288 int request_id) { |
1289 const std::string& service_identifier = service.GetIdentifier(); | 1289 const std::string& service_identifier = service.GetIdentifier(); |
1290 const std::string& device_address = service.GetDevice()->GetAddress(); | 1290 const std::string& device_address = service.GetDevice()->GetAddress(); |
1291 auto insert_result = | 1291 auto insert_result = |
1292 service_to_device_.insert(make_pair(service_identifier, device_address)); | 1292 service_to_device_.insert(make_pair(service_identifier, device_address)); |
1293 | 1293 |
1294 // If a value is already in map, DCHECK it's valid. | 1294 // If a value is already in map, DCHECK it's valid. |
1295 if (!insert_result.second) | 1295 if (!insert_result.second) |
1296 DCHECK_EQ(insert_result.first->second, device_address); | 1296 DCHECK_EQ(insert_result.first->second, device_address); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1415 const PrimaryServicesRequest& request) { | 1415 const PrimaryServicesRequest& request) { |
1416 pending_primary_services_requests_[device_address].push_back(request); | 1416 pending_primary_services_requests_[device_address].push_back(request); |
1417 } | 1417 } |
1418 | 1418 |
1419 url::Origin BluetoothDispatcherHost::GetOrigin(int frame_routing_id) { | 1419 url::Origin BluetoothDispatcherHost::GetOrigin(int frame_routing_id) { |
1420 return RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id) | 1420 return RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id) |
1421 ->GetLastCommittedOrigin(); | 1421 ->GetLastCommittedOrigin(); |
1422 } | 1422 } |
1423 | 1423 |
1424 } // namespace content | 1424 } // namespace content |
OLD | NEW |