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