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