| 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 WebBluetoothServiceImpl::WebBluetoothServiceImpl( | 135 WebBluetoothServiceImpl::WebBluetoothServiceImpl( |
| 188 RenderFrameHost* render_frame_host, | 136 RenderFrameHost* render_frame_host, |
| 189 blink::mojom::WebBluetoothServiceRequest request) | 137 blink::mojom::WebBluetoothServiceRequest request) |
| 190 : WebContentsObserver(WebContents::FromRenderFrameHost(render_frame_host)), | 138 : WebContentsObserver(WebContents::FromRenderFrameHost(render_frame_host)), |
| 191 connected_devices_(new FrameConnectedBluetoothDevices(render_frame_host)), | 139 connected_devices_(new FrameConnectedBluetoothDevices(render_frame_host)), |
| 192 render_frame_host_(render_frame_host), | 140 render_frame_host_(render_frame_host), |
| 193 binding_(this, std::move(request)), | 141 binding_(this, std::move(request)), |
| 194 weak_ptr_factory_(this) { | 142 weak_ptr_factory_(this) { |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 | 432 |
| 485 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 433 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 486 RecordGetCharacteristicsOutcome(quantity, query_result.outcome); | 434 RecordGetCharacteristicsOutcome(quantity, query_result.outcome); |
| 487 callback.Run(query_result.GetWebResult(), | 435 callback.Run(query_result.GetWebResult(), |
| 488 base::nullopt /* characteristics */); | 436 base::nullopt /* characteristics */); |
| 489 return; | 437 return; |
| 490 } | 438 } |
| 491 | 439 |
| 492 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics = | 440 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics = |
| 493 characteristics_uuid | 441 characteristics_uuid |
| 494 ? GetCharacteristicsByUUID(query_result.service, | 442 ? query_result.device->GetCharacteristicsByUUID( |
| 495 characteristics_uuid.value()) | 443 service_instance_id, characteristics_uuid.value()) |
| 496 : query_result.service->GetCharacteristics(); | 444 : query_result.service->GetCharacteristics(); |
| 497 | 445 |
| 498 std::vector<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr> | 446 std::vector<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr> |
| 499 response_characteristics; | 447 response_characteristics; |
| 500 for (device::BluetoothRemoteGattCharacteristic* characteristic : | 448 for (device::BluetoothRemoteGattCharacteristic* characteristic : |
| 501 characteristics) { | 449 characteristics) { |
| 502 if (BluetoothBlocklist::Get().IsExcluded(characteristic->GetUUID())) { | 450 if (BluetoothBlocklist::Get().IsExcluded(characteristic->GetUUID())) { |
| 503 continue; | 451 continue; |
| 504 } | 452 } |
| 505 std::string characteristic_instance_id = characteristic->GetIdentifier(); | 453 std::string characteristic_instance_id = characteristic->GetIdentifier(); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 void WebBluetoothServiceImpl::RemoteServerGetPrimaryServicesImpl( | 664 void WebBluetoothServiceImpl::RemoteServerGetPrimaryServicesImpl( |
| 717 const WebBluetoothDeviceId& device_id, | 665 const WebBluetoothDeviceId& device_id, |
| 718 blink::mojom::WebBluetoothGATTQueryQuantity quantity, | 666 blink::mojom::WebBluetoothGATTQueryQuantity quantity, |
| 719 const base::Optional<BluetoothUUID>& services_uuid, | 667 const base::Optional<BluetoothUUID>& services_uuid, |
| 720 const RemoteServerGetPrimaryServicesCallback& callback, | 668 const RemoteServerGetPrimaryServicesCallback& callback, |
| 721 device::BluetoothDevice* device) { | 669 device::BluetoothDevice* device) { |
| 722 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 670 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 723 DCHECK(device->IsGattServicesDiscoveryComplete()); | 671 DCHECK(device->IsGattServicesDiscoveryComplete()); |
| 724 | 672 |
| 725 std::vector<device::BluetoothRemoteGattService*> services = | 673 std::vector<device::BluetoothRemoteGattService*> services = |
| 726 services_uuid ? GetPrimaryServicesByUUID(device, services_uuid.value()) | 674 services_uuid ? device->GetPrimaryServicesByUUID(services_uuid.value()) |
| 727 : GetPrimaryServices(device); | 675 : device->GetPrimaryServices(); |
| 728 | 676 |
| 729 std::vector<blink::mojom::WebBluetoothRemoteGATTServicePtr> response_services; | 677 std::vector<blink::mojom::WebBluetoothRemoteGATTServicePtr> response_services; |
| 730 for (device::BluetoothRemoteGattService* service : services) { | 678 for (device::BluetoothRemoteGattService* service : services) { |
| 731 if (!allowed_devices_map_.IsOriginAllowedToAccessService( | 679 if (!allowed_devices_map_.IsOriginAllowedToAccessService( |
| 732 GetOrigin(), device_id, service->GetUUID())) { | 680 GetOrigin(), device_id, service->GetUUID())) { |
| 733 continue; | 681 continue; |
| 734 } | 682 } |
| 735 std::string service_instance_id = service->GetIdentifier(); | 683 std::string service_instance_id = service->GetIdentifier(); |
| 736 const std::string& device_address = device->GetAddress(); | 684 const std::string& device_address = device->GetAddress(); |
| 737 auto insert_result = service_id_to_device_address_.insert( | 685 auto insert_result = service_id_to_device_address_.insert( |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 998 characteristic_id_to_service_id_.clear(); | 946 characteristic_id_to_service_id_.clear(); |
| 999 service_id_to_device_address_.clear(); | 947 service_id_to_device_address_.clear(); |
| 1000 connected_devices_.reset( | 948 connected_devices_.reset( |
| 1001 new FrameConnectedBluetoothDevices(render_frame_host_)); | 949 new FrameConnectedBluetoothDevices(render_frame_host_)); |
| 1002 allowed_devices_map_ = BluetoothAllowedDevicesMap(); | 950 allowed_devices_map_ = BluetoothAllowedDevicesMap(); |
| 1003 device_chooser_controller_.reset(); | 951 device_chooser_controller_.reset(); |
| 1004 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); | 952 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); |
| 1005 } | 953 } |
| 1006 | 954 |
| 1007 } // namespace content | 955 } // namespace content |
| OLD | NEW |