| 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. |
| 11 | 11 |
| 12 #include "content/browser/bluetooth/web_bluetooth_service_impl.h" | 12 #include "content/browser/bluetooth/web_bluetooth_service_impl.h" |
| 13 | 13 |
| 14 #include <algorithm> | 14 #include <algorithm> |
| 15 | 15 |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 18 #include "content/browser/bluetooth/bluetooth_blacklist.h" | 18 #include "content/browser/bluetooth/bluetooth_blacklist.h" |
| 19 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h" | 19 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h" |
| 20 #include "content/browser/bluetooth/bluetooth_metrics.h" | 20 #include "content/browser/bluetooth/bluetooth_metrics.h" |
| 21 #include "content/browser/bluetooth/frame_connected_bluetooth_devices.h" | 21 #include "content/browser/bluetooth/frame_connected_bluetooth_devices.h" |
| 22 #include "content/browser/renderer_host/render_process_host_impl.h" | 22 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 23 #include "content/common/bluetooth/web_bluetooth_device_id.h" | |
| 24 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/navigation_handle.h" | 24 #include "content/public/browser/navigation_handle.h" |
| 26 #include "content/public/browser/render_frame_host.h" | 25 #include "content/public/browser/render_frame_host.h" |
| 27 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 28 #include "device/bluetooth/bluetooth_adapter_factory_wrapper.h" | 27 #include "device/bluetooth/bluetooth_adapter_factory_wrapper.h" |
| 29 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" | 28 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
| 30 | 29 |
| 31 using device::BluetoothAdapterFactoryWrapper; | 30 using device::BluetoothAdapterFactoryWrapper; |
| 32 using device::BluetoothUUID; | 31 using device::BluetoothUUID; |
| 33 | 32 |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 VLOG(1) << "Adding device to device chooser controller: " | 230 VLOG(1) << "Adding device to device chooser controller: " |
| 232 << device->GetAddress(); | 231 << device->GetAddress(); |
| 233 device_chooser_controller_->AddFilteredDevice(*device); | 232 device_chooser_controller_->AddFilteredDevice(*device); |
| 234 } | 233 } |
| 235 } | 234 } |
| 236 | 235 |
| 237 void WebBluetoothServiceImpl::DeviceChanged(device::BluetoothAdapter* adapter, | 236 void WebBluetoothServiceImpl::DeviceChanged(device::BluetoothAdapter* adapter, |
| 238 device::BluetoothDevice* device) { | 237 device::BluetoothDevice* device) { |
| 239 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 238 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 240 if (!device->IsGattConnected()) { | 239 if (!device->IsGattConnected()) { |
| 241 base::Optional<WebBluetoothDeviceId> device_id = | 240 std::string device_id = |
| 242 connected_devices_->CloseConnectionToDeviceWithAddress( | 241 connected_devices_->CloseConnectionToDeviceWithAddress( |
| 243 device->GetAddress()); | 242 device->GetAddress()); |
| 244 if (device_id && client_) { | 243 if (!device_id.empty()) { |
| 245 client_->GattServerDisconnected(device_id.value()); | 244 if (client_) { |
| 245 client_->GattServerDisconnected(device_id); |
| 246 } |
| 246 } | 247 } |
| 247 } | 248 } |
| 248 } | 249 } |
| 249 | 250 |
| 250 void WebBluetoothServiceImpl::GattServicesDiscovered( | 251 void WebBluetoothServiceImpl::GattServicesDiscovered( |
| 251 device::BluetoothAdapter* adapter, | 252 device::BluetoothAdapter* adapter, |
| 252 device::BluetoothDevice* device) { | 253 device::BluetoothDevice* device) { |
| 253 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 254 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 254 const std::string& device_address = device->GetAddress(); | 255 const std::string& device_address = device->GetAddress(); |
| 255 VLOG(1) << "Services discovered for device: " << device_address; | 256 VLOG(1) << "Services discovered for device: " << device_address; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 } | 324 } |
| 324 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_BLUETOOTH_ADAPTER); | 325 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_BLUETOOTH_ADAPTER); |
| 325 callback.Run(blink::mojom::WebBluetoothError::NO_BLUETOOTH_ADAPTER, | 326 callback.Run(blink::mojom::WebBluetoothError::NO_BLUETOOTH_ADAPTER, |
| 326 nullptr /* device */); | 327 nullptr /* device */); |
| 327 return; | 328 return; |
| 328 } | 329 } |
| 329 RequestDeviceImpl(std::move(options), callback, GetAdapter()); | 330 RequestDeviceImpl(std::move(options), callback, GetAdapter()); |
| 330 } | 331 } |
| 331 | 332 |
| 332 void WebBluetoothServiceImpl::RemoteServerConnect( | 333 void WebBluetoothServiceImpl::RemoteServerConnect( |
| 333 const WebBluetoothDeviceId& device_id, | 334 const mojo::String& device_id, |
| 334 const RemoteServerConnectCallback& callback) { | 335 const RemoteServerConnectCallback& callback) { |
| 335 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 336 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 336 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::CONNECT_GATT); | 337 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::CONNECT_GATT); |
| 337 | 338 |
| 338 const CacheQueryResult query_result = QueryCacheForDevice(device_id); | 339 const CacheQueryResult query_result = QueryCacheForDevice(device_id); |
| 339 | 340 |
| 340 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 341 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 341 RecordConnectGATTOutcome(query_result.outcome); | 342 RecordConnectGATTOutcome(query_result.outcome); |
| 342 callback.Run(query_result.GetWebError()); | 343 callback.Run(query_result.GetWebError()); |
| 343 return; | 344 return; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 357 // abstraction doesn't currently support checking for pending connections. | 358 // abstraction doesn't currently support checking for pending connections. |
| 358 // TODO(ortuno): CHECK that this never happens once the platform | 359 // TODO(ortuno): CHECK that this never happens once the platform |
| 359 // abstraction allows to check for pending connections. | 360 // abstraction allows to check for pending connections. |
| 360 // http://crbug.com/583544 | 361 // http://crbug.com/583544 |
| 361 const base::TimeTicks start_time = base::TimeTicks::Now(); | 362 const base::TimeTicks start_time = base::TimeTicks::Now(); |
| 362 query_result.device->CreateGattConnection( | 363 query_result.device->CreateGattConnection( |
| 363 base::Bind(&WebBluetoothServiceImpl::OnCreateGATTConnectionSuccess, | 364 base::Bind(&WebBluetoothServiceImpl::OnCreateGATTConnectionSuccess, |
| 364 weak_ptr_factory_.GetWeakPtr(), device_id, start_time, | 365 weak_ptr_factory_.GetWeakPtr(), device_id, start_time, |
| 365 callback), | 366 callback), |
| 366 base::Bind(&WebBluetoothServiceImpl::OnCreateGATTConnectionFailed, | 367 base::Bind(&WebBluetoothServiceImpl::OnCreateGATTConnectionFailed, |
| 367 weak_ptr_factory_.GetWeakPtr(), start_time, callback)); | 368 weak_ptr_factory_.GetWeakPtr(), device_id, start_time, |
| 369 callback)); |
| 368 } | 370 } |
| 369 | 371 |
| 370 void WebBluetoothServiceImpl::RemoteServerDisconnect( | 372 void WebBluetoothServiceImpl::RemoteServerDisconnect( |
| 371 const WebBluetoothDeviceId& device_id) { | 373 const mojo::String& device_id) { |
| 372 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 374 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 373 RecordWebBluetoothFunctionCall( | 375 RecordWebBluetoothFunctionCall( |
| 374 UMAWebBluetoothFunction::REMOTE_GATT_SERVER_DISCONNECT); | 376 UMAWebBluetoothFunction::REMOTE_GATT_SERVER_DISCONNECT); |
| 375 | 377 |
| 376 if (connected_devices_->IsConnectedToDeviceWithId(device_id)) { | 378 if (connected_devices_->IsConnectedToDeviceWithId(device_id)) { |
| 377 VLOG(1) << "Disconnecting device: " << device_id.str(); | 379 VLOG(1) << "Disconnecting device: " << device_id; |
| 378 connected_devices_->CloseConnectionToDeviceWithId(device_id); | 380 connected_devices_->CloseConnectionToDeviceWithId(device_id); |
| 379 } | 381 } |
| 380 } | 382 } |
| 381 | 383 |
| 382 void WebBluetoothServiceImpl::RemoteServerGetPrimaryServices( | 384 void WebBluetoothServiceImpl::RemoteServerGetPrimaryServices( |
| 383 const WebBluetoothDeviceId& device_id, | 385 const mojo::String& device_id, |
| 384 blink::mojom::WebBluetoothGATTQueryQuantity quantity, | 386 blink::mojom::WebBluetoothGATTQueryQuantity quantity, |
| 385 const base::Optional<BluetoothUUID>& services_uuid, | 387 const base::Optional<BluetoothUUID>& services_uuid, |
| 386 const RemoteServerGetPrimaryServicesCallback& callback) { | 388 const RemoteServerGetPrimaryServicesCallback& callback) { |
| 387 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 389 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 388 RecordWebBluetoothFunctionCall( | 390 RecordWebBluetoothFunctionCall( |
| 389 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE | 391 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE |
| 390 ? UMAWebBluetoothFunction::GET_PRIMARY_SERVICE | 392 ? UMAWebBluetoothFunction::GET_PRIMARY_SERVICE |
| 391 : UMAWebBluetoothFunction::GET_PRIMARY_SERVICES); | 393 : UMAWebBluetoothFunction::GET_PRIMARY_SERVICES); |
| 392 RecordGetPrimaryServicesServices(quantity, services_uuid); | 394 RecordGetPrimaryServicesServices(quantity, services_uuid); |
| 393 | 395 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 | 684 |
| 683 device_chooser_controller_->GetDevice( | 685 device_chooser_controller_->GetDevice( |
| 684 std::move(options), | 686 std::move(options), |
| 685 base::Bind(&WebBluetoothServiceImpl::OnGetDeviceSuccess, | 687 base::Bind(&WebBluetoothServiceImpl::OnGetDeviceSuccess, |
| 686 weak_ptr_factory_.GetWeakPtr(), callback), | 688 weak_ptr_factory_.GetWeakPtr(), callback), |
| 687 base::Bind(&WebBluetoothServiceImpl::OnGetDeviceFailed, | 689 base::Bind(&WebBluetoothServiceImpl::OnGetDeviceFailed, |
| 688 weak_ptr_factory_.GetWeakPtr(), callback)); | 690 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 689 } | 691 } |
| 690 | 692 |
| 691 void WebBluetoothServiceImpl::RemoteServerGetPrimaryServicesImpl( | 693 void WebBluetoothServiceImpl::RemoteServerGetPrimaryServicesImpl( |
| 692 const WebBluetoothDeviceId& device_id, | 694 const mojo::String& device_id, |
| 693 blink::mojom::WebBluetoothGATTQueryQuantity quantity, | 695 blink::mojom::WebBluetoothGATTQueryQuantity quantity, |
| 694 const base::Optional<BluetoothUUID>& services_uuid, | 696 const base::Optional<BluetoothUUID>& services_uuid, |
| 695 const RemoteServerGetPrimaryServicesCallback& callback, | 697 const RemoteServerGetPrimaryServicesCallback& callback, |
| 696 device::BluetoothDevice* device) { | 698 device::BluetoothDevice* device) { |
| 697 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 699 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 698 DCHECK(device->IsGattServicesDiscoveryComplete()); | 700 DCHECK(device->IsGattServicesDiscoveryComplete()); |
| 699 | 701 |
| 700 std::vector<device::BluetoothRemoteGattService*> services = | 702 std::vector<device::BluetoothRemoteGattService*> services = |
| 701 services_uuid ? GetPrimaryServicesByUUID(device, services_uuid.value()) | 703 services_uuid ? GetPrimaryServicesByUUID(device, services_uuid.value()) |
| 702 : GetPrimaryServices(device); | 704 : GetPrimaryServices(device); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 const device::BluetoothDevice* const device = | 756 const device::BluetoothDevice* const device = |
| 755 GetAdapter()->GetDevice(device_address); | 757 GetAdapter()->GetDevice(device_address); |
| 756 if (device == nullptr) { | 758 if (device == nullptr) { |
| 757 VLOG(1) << "Device " << device_address << " no longer in adapter"; | 759 VLOG(1) << "Device " << device_address << " no longer in adapter"; |
| 758 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::CHOSEN_DEVICE_VANISHED); | 760 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::CHOSEN_DEVICE_VANISHED); |
| 759 callback.Run(blink::mojom::WebBluetoothError::CHOSEN_DEVICE_VANISHED, | 761 callback.Run(blink::mojom::WebBluetoothError::CHOSEN_DEVICE_VANISHED, |
| 760 nullptr /* device */); | 762 nullptr /* device */); |
| 761 return; | 763 return; |
| 762 } | 764 } |
| 763 | 765 |
| 764 const WebBluetoothDeviceId device_id_for_origin = | 766 const std::string device_id_for_origin = |
| 765 allowed_devices_map_.AddDevice(GetOrigin(), device_address, options); | 767 allowed_devices_map_.AddDevice(GetOrigin(), device_address, options); |
| 766 | 768 |
| 767 VLOG(1) << "Device: " << device->GetNameForDisplay(); | 769 VLOG(1) << "Device: " << device->GetNameForDisplay(); |
| 768 VLOG(1) << "UUIDs: "; | 770 VLOG(1) << "UUIDs: "; |
| 769 | 771 |
| 770 mojo::Array<mojo::String> filtered_uuids; | 772 mojo::Array<mojo::String> filtered_uuids; |
| 771 for (const BluetoothUUID& uuid : device->GetUUIDs()) { | 773 for (const BluetoothUUID& uuid : device->GetUUIDs()) { |
| 772 if (allowed_devices_map_.IsOriginAllowedToAccessService( | 774 if (allowed_devices_map_.IsOriginAllowedToAccessService( |
| 773 GetOrigin(), device_id_for_origin, uuid)) { | 775 GetOrigin(), device_id_for_origin, uuid)) { |
| 774 VLOG(1) << "\t Allowed: " << uuid.canonical_value(); | 776 VLOG(1) << "\t Allowed: " << uuid.canonical_value(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 791 | 793 |
| 792 void WebBluetoothServiceImpl::OnGetDeviceFailed( | 794 void WebBluetoothServiceImpl::OnGetDeviceFailed( |
| 793 const RequestDeviceCallback& callback, | 795 const RequestDeviceCallback& callback, |
| 794 blink::mojom::WebBluetoothError error) { | 796 blink::mojom::WebBluetoothError error) { |
| 795 // Errors are recorded by the *device_chooser_controller_. | 797 // Errors are recorded by the *device_chooser_controller_. |
| 796 callback.Run(error, nullptr /* device */); | 798 callback.Run(error, nullptr /* device */); |
| 797 device_chooser_controller_.reset(); | 799 device_chooser_controller_.reset(); |
| 798 } | 800 } |
| 799 | 801 |
| 800 void WebBluetoothServiceImpl::OnCreateGATTConnectionSuccess( | 802 void WebBluetoothServiceImpl::OnCreateGATTConnectionSuccess( |
| 801 const WebBluetoothDeviceId& device_id, | 803 const std::string& device_id, |
| 802 base::TimeTicks start_time, | 804 base::TimeTicks start_time, |
| 803 const RemoteServerConnectCallback& callback, | 805 const RemoteServerConnectCallback& callback, |
| 804 std::unique_ptr<device::BluetoothGattConnection> connection) { | 806 std::unique_ptr<device::BluetoothGattConnection> connection) { |
| 805 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 807 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 806 RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - start_time); | 808 RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - start_time); |
| 807 RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS); | 809 RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS); |
| 808 | 810 |
| 809 connected_devices_->Insert(device_id, std::move(connection)); | 811 connected_devices_->Insert(device_id, std::move(connection)); |
| 810 callback.Run(blink::mojom::WebBluetoothError::SUCCESS); | 812 callback.Run(blink::mojom::WebBluetoothError::SUCCESS); |
| 811 } | 813 } |
| 812 | 814 |
| 813 void WebBluetoothServiceImpl::OnCreateGATTConnectionFailed( | 815 void WebBluetoothServiceImpl::OnCreateGATTConnectionFailed( |
| 816 const std::string& device_id, |
| 814 base::TimeTicks start_time, | 817 base::TimeTicks start_time, |
| 815 const RemoteServerConnectCallback& callback, | 818 const RemoteServerConnectCallback& callback, |
| 816 device::BluetoothDevice::ConnectErrorCode error_code) { | 819 device::BluetoothDevice::ConnectErrorCode error_code) { |
| 817 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 820 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 818 RecordConnectGATTTimeFailed(base::TimeTicks::Now() - start_time); | 821 RecordConnectGATTTimeFailed(base::TimeTicks::Now() - start_time); |
| 819 callback.Run(TranslateConnectErrorAndRecord(error_code)); | 822 callback.Run(TranslateConnectErrorAndRecord(error_code)); |
| 820 } | 823 } |
| 821 | 824 |
| 822 void WebBluetoothServiceImpl::OnReadValueSuccess( | 825 void WebBluetoothServiceImpl::OnReadValueSuccess( |
| 823 const RemoteCharacteristicReadValueCallback& callback, | 826 const RemoteCharacteristicReadValueCallback& callback, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 } | 878 } |
| 876 | 879 |
| 877 void WebBluetoothServiceImpl::OnStopNotifySessionComplete( | 880 void WebBluetoothServiceImpl::OnStopNotifySessionComplete( |
| 878 const std::string& characteristic_instance_id, | 881 const std::string& characteristic_instance_id, |
| 879 const RemoteCharacteristicStopNotificationsCallback& callback) { | 882 const RemoteCharacteristicStopNotificationsCallback& callback) { |
| 880 characteristic_id_to_notify_session_.erase(characteristic_instance_id); | 883 characteristic_id_to_notify_session_.erase(characteristic_instance_id); |
| 881 callback.Run(); | 884 callback.Run(); |
| 882 } | 885 } |
| 883 | 886 |
| 884 CacheQueryResult WebBluetoothServiceImpl::QueryCacheForDevice( | 887 CacheQueryResult WebBluetoothServiceImpl::QueryCacheForDevice( |
| 885 const WebBluetoothDeviceId& device_id) { | 888 const std::string& device_id) { |
| 886 const std::string& device_address = | 889 const std::string& device_address = |
| 887 allowed_devices_map_.GetDeviceAddress(GetOrigin(), device_id); | 890 allowed_devices_map_.GetDeviceAddress(GetOrigin(), device_id); |
| 888 if (device_address.empty()) { | 891 if (device_address.empty()) { |
| 889 CrashRendererAndClosePipe(bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN); | 892 CrashRendererAndClosePipe(bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN); |
| 890 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER); | 893 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER); |
| 891 } | 894 } |
| 892 | 895 |
| 893 CacheQueryResult result; | 896 CacheQueryResult result; |
| 894 result.device = GetAdapter()->GetDevice(device_address); | 897 result.device = GetAdapter()->GetDevice(device_address); |
| 895 | 898 |
| 896 // When a device can't be found in the BluetoothAdapter, that generally | 899 // When a device can't be found in the BluetoothAdapter, that generally |
| 897 // indicates that it's gone out of range. We reject with a NetworkError in | 900 // indicates that it's gone out of range. We reject with a NetworkError in |
| 898 // that case. | 901 // that case. |
| 899 if (result.device == nullptr) { | 902 if (result.device == nullptr) { |
| 900 result.outcome = CacheQueryOutcome::NO_DEVICE; | 903 result.outcome = CacheQueryOutcome::NO_DEVICE; |
| 901 } | 904 } |
| 902 return result; | 905 return result; |
| 903 } | 906 } |
| 904 | 907 |
| 905 CacheQueryResult WebBluetoothServiceImpl::QueryCacheForService( | 908 CacheQueryResult WebBluetoothServiceImpl::QueryCacheForService( |
| 906 const std::string& service_instance_id) { | 909 const std::string& service_instance_id) { |
| 907 auto device_iter = service_id_to_device_address_.find(service_instance_id); | 910 auto device_iter = service_id_to_device_address_.find(service_instance_id); |
| 908 | 911 |
| 909 // Kill the render, see "ID Not in Map Note" above. | 912 // Kill the render, see "ID Not in Map Note" above. |
| 910 if (device_iter == service_id_to_device_address_.end()) { | 913 if (device_iter == service_id_to_device_address_.end()) { |
| 911 CrashRendererAndClosePipe(bad_message::BDH_INVALID_SERVICE_ID); | 914 CrashRendererAndClosePipe(bad_message::BDH_INVALID_SERVICE_ID); |
| 912 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER); | 915 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER); |
| 913 } | 916 } |
| 914 | 917 |
| 915 const WebBluetoothDeviceId* device_id = | 918 const std::string& device_id = |
| 916 allowed_devices_map_.GetDeviceId(GetOrigin(), device_iter->second); | 919 allowed_devices_map_.GetDeviceId(GetOrigin(), device_iter->second); |
| 917 // Kill the renderer if origin is not allowed to access the device. | 920 // Kill the renderer if origin is not allowed to access the device. |
| 918 if (device_id == nullptr) { | 921 if (device_id.empty()) { |
| 919 CrashRendererAndClosePipe(bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN); | 922 CrashRendererAndClosePipe(bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN); |
| 920 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER); | 923 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER); |
| 921 } | 924 } |
| 922 | 925 |
| 923 CacheQueryResult result = QueryCacheForDevice(*device_id); | 926 CacheQueryResult result = QueryCacheForDevice(device_id); |
| 924 if (result.outcome != CacheQueryOutcome::SUCCESS) { | 927 if (result.outcome != CacheQueryOutcome::SUCCESS) { |
| 925 return result; | 928 return result; |
| 926 } | 929 } |
| 927 | 930 |
| 928 result.service = result.device->GetGattService(service_instance_id); | 931 result.service = result.device->GetGattService(service_instance_id); |
| 929 if (result.service == nullptr) { | 932 if (result.service == nullptr) { |
| 930 result.outcome = CacheQueryOutcome::NO_SERVICE; | 933 result.outcome = CacheQueryOutcome::NO_SERVICE; |
| 931 } else if (!allowed_devices_map_.IsOriginAllowedToAccessService( | 934 } else if (!allowed_devices_map_.IsOriginAllowedToAccessService( |
| 932 GetOrigin(), *device_id, result.service->GetUUID())) { | 935 GetOrigin(), device_id, result.service->GetUUID())) { |
| 933 CrashRendererAndClosePipe(bad_message::BDH_SERVICE_NOT_ALLOWED_FOR_ORIGIN); | 936 CrashRendererAndClosePipe(bad_message::BDH_SERVICE_NOT_ALLOWED_FOR_ORIGIN); |
| 934 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER); | 937 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER); |
| 935 } | 938 } |
| 936 return result; | 939 return result; |
| 937 } | 940 } |
| 938 | 941 |
| 939 CacheQueryResult WebBluetoothServiceImpl::QueryCacheForCharacteristic( | 942 CacheQueryResult WebBluetoothServiceImpl::QueryCacheForCharacteristic( |
| 940 const std::string& characteristic_instance_id) { | 943 const std::string& characteristic_instance_id) { |
| 941 auto characteristic_iter = | 944 auto characteristic_iter = |
| 942 characteristic_id_to_service_id_.find(characteristic_instance_id); | 945 characteristic_id_to_service_id_.find(characteristic_instance_id); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 characteristic_id_to_service_id_.clear(); | 990 characteristic_id_to_service_id_.clear(); |
| 988 service_id_to_device_address_.clear(); | 991 service_id_to_device_address_.clear(); |
| 989 connected_devices_.reset( | 992 connected_devices_.reset( |
| 990 new FrameConnectedBluetoothDevices(render_frame_host_)); | 993 new FrameConnectedBluetoothDevices(render_frame_host_)); |
| 991 allowed_devices_map_ = BluetoothAllowedDevicesMap(); | 994 allowed_devices_map_ = BluetoothAllowedDevicesMap(); |
| 992 device_chooser_controller_.reset(); | 995 device_chooser_controller_.reset(); |
| 993 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); | 996 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); |
| 994 } | 997 } |
| 995 | 998 |
| 996 } // namespace content | 999 } // namespace content |
| OLD | NEW |