OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 // WebBluetoothServiceImpl map [service_id_to_device_address_, | 7 // WebBluetoothServiceImpl map [service_id_to_device_address_, |
8 // characteristic_id_to_service_id_, descriptor_to_characteristic_] implies a | 8 // characteristic_id_to_service_id_, descriptor_to_characteristic_] implies a |
9 // hostile renderer because a renderer obtains the corresponding ID from this | 9 // hostile renderer because a renderer obtains the corresponding ID from this |
10 // class and it will be added to the map at that time. | 10 // class and it will be added to the map at that time. |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 return blink::mojom::WebBluetoothResult::GATT_NOT_PAIRED; | 123 return blink::mojom::WebBluetoothResult::GATT_NOT_PAIRED; |
124 case device::BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED: | 124 case device::BluetoothRemoteGattService::GATT_ERROR_NOT_SUPPORTED: |
125 RecordGATTOperationOutcome(operation, | 125 RecordGATTOperationOutcome(operation, |
126 UMAGATTOperationOutcome::NOT_SUPPORTED); | 126 UMAGATTOperationOutcome::NOT_SUPPORTED); |
127 return blink::mojom::WebBluetoothResult::GATT_NOT_SUPPORTED; | 127 return blink::mojom::WebBluetoothResult::GATT_NOT_SUPPORTED; |
128 } | 128 } |
129 NOTREACHED(); | 129 NOTREACHED(); |
130 return blink::mojom::WebBluetoothResult::GATT_UNTRANSLATED_ERROR_CODE; | 130 return blink::mojom::WebBluetoothResult::GATT_UNTRANSLATED_ERROR_CODE; |
131 } | 131 } |
132 | 132 |
133 // TODO(ortuno): This should really be a BluetoothDevice method. | |
134 // Replace when implemented. http://crbug.com/552022 | |
135 std::vector<device::BluetoothRemoteGattCharacteristic*> | |
136 GetCharacteristicsByUUID(device::BluetoothRemoteGattService* service, | |
137 const BluetoothUUID& characteristic_uuid) { | |
138 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics; | |
139 VLOG(1) << "Looking for characteristic: " | |
140 << characteristic_uuid.canonical_value(); | |
141 for (device::BluetoothRemoteGattCharacteristic* characteristic : | |
142 service->GetCharacteristics()) { | |
143 VLOG(1) << "Characteristic in cache: " | |
144 << characteristic->GetUUID().canonical_value(); | |
145 if (characteristic->GetUUID() == characteristic_uuid) { | |
146 characteristics.push_back(characteristic); | |
147 } | |
148 } | |
149 return characteristics; | |
150 } | |
151 | |
152 // TODO(ortuno): This should really be a BluetoothDevice method. | |
153 // Replace when implemented. http://crbug.com/552022 | |
154 std::vector<device::BluetoothRemoteGattService*> GetPrimaryServicesByUUID( | |
155 device::BluetoothDevice* device, | |
156 const BluetoothUUID& service_uuid) { | |
157 std::vector<device::BluetoothRemoteGattService*> services; | |
158 VLOG(1) << "Looking for service: " << service_uuid.canonical_value(); | |
159 for (device::BluetoothRemoteGattService* service : | |
160 device->GetGattServices()) { | |
161 VLOG(1) << "Service in cache: " << service->GetUUID().canonical_value(); | |
162 if (service->GetUUID() == service_uuid && service->IsPrimary()) { | |
163 services.push_back(service); | |
164 } | |
165 } | |
166 return services; | |
167 } | |
168 | |
169 // TODO(ortuno): This should really be a BluetoothDevice method. | |
170 // Replace when implemented. http://crbug.com/552022 | |
171 std::vector<device::BluetoothRemoteGattService*> GetPrimaryServices( | |
172 device::BluetoothDevice* device) { | |
173 std::vector<device::BluetoothRemoteGattService*> services; | |
174 VLOG(1) << "Looking for services."; | |
175 for (device::BluetoothRemoteGattService* service : | |
176 device->GetGattServices()) { | |
177 VLOG(1) << "Service in cache: " << service->GetUUID().canonical_value(); | |
178 if (service->IsPrimary()) { | |
179 services.push_back(service); | |
180 } | |
181 } | |
182 return services; | |
183 } | |
184 | |
185 } // namespace | 133 } // namespace |
186 | 134 |
187 // Struct that holds the result of a cache query. | 135 // Struct that holds the result of a cache query. |
188 struct CacheQueryResult { | 136 struct CacheQueryResult { |
189 CacheQueryResult() : outcome(CacheQueryOutcome::SUCCESS) {} | 137 CacheQueryResult() : outcome(CacheQueryOutcome::SUCCESS) {} |
190 | 138 |
191 explicit CacheQueryResult(CacheQueryOutcome outcome) : outcome(outcome) {} | 139 explicit CacheQueryResult(CacheQueryOutcome outcome) : outcome(outcome) {} |
192 | 140 |
193 ~CacheQueryResult() {} | 141 ~CacheQueryResult() {} |
194 | 142 |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 | 464 |
517 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 465 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
518 RecordGetCharacteristicsOutcome(quantity, query_result.outcome); | 466 RecordGetCharacteristicsOutcome(quantity, query_result.outcome); |
519 callback.Run(query_result.GetWebResult(), | 467 callback.Run(query_result.GetWebResult(), |
520 base::nullopt /* characteristics */); | 468 base::nullopt /* characteristics */); |
521 return; | 469 return; |
522 } | 470 } |
523 | 471 |
524 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics = | 472 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics = |
525 characteristics_uuid | 473 characteristics_uuid |
526 ? GetCharacteristicsByUUID(query_result.service, | 474 ? query_result.device->GetCharacteristicsByUUID( |
527 characteristics_uuid.value()) | 475 service_instance_id, characteristics_uuid.value()) |
528 : query_result.service->GetCharacteristics(); | 476 : query_result.service->GetCharacteristics(); |
529 | 477 |
530 std::vector<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr> | 478 std::vector<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr> |
531 response_characteristics; | 479 response_characteristics; |
532 for (device::BluetoothRemoteGattCharacteristic* characteristic : | 480 for (device::BluetoothRemoteGattCharacteristic* characteristic : |
533 characteristics) { | 481 characteristics) { |
534 if (BluetoothBlocklist::Get().IsExcluded(characteristic->GetUUID())) { | 482 if (BluetoothBlocklist::Get().IsExcluded(characteristic->GetUUID())) { |
535 continue; | 483 continue; |
536 } | 484 } |
537 std::string characteristic_instance_id = characteristic->GetIdentifier(); | 485 std::string characteristic_instance_id = characteristic->GetIdentifier(); |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 void WebBluetoothServiceImpl::RemoteServerGetPrimaryServicesImpl( | 696 void WebBluetoothServiceImpl::RemoteServerGetPrimaryServicesImpl( |
749 const WebBluetoothDeviceId& device_id, | 697 const WebBluetoothDeviceId& device_id, |
750 blink::mojom::WebBluetoothGATTQueryQuantity quantity, | 698 blink::mojom::WebBluetoothGATTQueryQuantity quantity, |
751 const base::Optional<BluetoothUUID>& services_uuid, | 699 const base::Optional<BluetoothUUID>& services_uuid, |
752 const RemoteServerGetPrimaryServicesCallback& callback, | 700 const RemoteServerGetPrimaryServicesCallback& callback, |
753 device::BluetoothDevice* device) { | 701 device::BluetoothDevice* device) { |
754 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 702 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
755 DCHECK(device->IsGattServicesDiscoveryComplete()); | 703 DCHECK(device->IsGattServicesDiscoveryComplete()); |
756 | 704 |
757 std::vector<device::BluetoothRemoteGattService*> services = | 705 std::vector<device::BluetoothRemoteGattService*> services = |
758 services_uuid ? GetPrimaryServicesByUUID(device, services_uuid.value()) | 706 services_uuid ? device->GetPrimaryServicesByUUID(services_uuid.value()) |
759 : GetPrimaryServices(device); | 707 : device->GetPrimaryServices(); |
760 | 708 |
761 std::vector<blink::mojom::WebBluetoothRemoteGATTServicePtr> response_services; | 709 std::vector<blink::mojom::WebBluetoothRemoteGATTServicePtr> response_services; |
762 for (device::BluetoothRemoteGattService* service : services) { | 710 for (device::BluetoothRemoteGattService* service : services) { |
763 if (!allowed_devices_map_.IsOriginAllowedToAccessService( | 711 if (!allowed_devices_map_.IsOriginAllowedToAccessService( |
764 GetOrigin(), device_id, service->GetUUID())) { | 712 GetOrigin(), device_id, service->GetUUID())) { |
765 continue; | 713 continue; |
766 } | 714 } |
767 std::string service_instance_id = service->GetIdentifier(); | 715 std::string service_instance_id = service->GetIdentifier(); |
768 const std::string& device_address = device->GetAddress(); | 716 const std::string& device_address = device->GetAddress(); |
769 auto insert_result = service_id_to_device_address_.insert( | 717 auto insert_result = service_id_to_device_address_.insert( |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1030 characteristic_id_to_service_id_.clear(); | 978 characteristic_id_to_service_id_.clear(); |
1031 service_id_to_device_address_.clear(); | 979 service_id_to_device_address_.clear(); |
1032 connected_devices_.reset( | 980 connected_devices_.reset( |
1033 new FrameConnectedBluetoothDevices(render_frame_host_)); | 981 new FrameConnectedBluetoothDevices(render_frame_host_)); |
1034 allowed_devices_map_ = BluetoothAllowedDevicesMap(); | 982 allowed_devices_map_ = BluetoothAllowedDevicesMap(); |
1035 device_chooser_controller_.reset(); | 983 device_chooser_controller_.reset(); |
1036 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); | 984 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); |
1037 } | 985 } |
1038 | 986 |
1039 } // namespace content | 987 } // namespace content |
OLD | NEW |