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: A service, characteristic, or descriptor ID not in the |
6 // A service, characteristic, or descriptor ID not in the corresponding | 6 // corresponding WebBluetoothServiceImpl map [service_id_to_device_address_, |
7 // WebBluetoothServiceImpl map [service_id_to_device_address_, | 7 // characteristic_id_to_service_id_, descriptor_id_to_characteristic_id_] |
8 // characteristic_id_to_service_id_, descriptor_to_characteristic_] implies a | 8 // implies a hostile renderer because a renderer obtains the corresponding ID |
9 // hostile renderer because a renderer obtains the corresponding ID from this | 9 // from this 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 | 10 |
12 #include "content/browser/bluetooth/web_bluetooth_service_impl.h" | 11 #include "content/browser/bluetooth/web_bluetooth_service_impl.h" |
13 | 12 |
14 #include <algorithm> | 13 #include <algorithm> |
15 | 14 |
16 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
18 #include "content/browser/bluetooth/bluetooth_blocklist.h" | 17 #include "content/browser/bluetooth/bluetooth_blocklist.h" |
19 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h" | 18 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h" |
20 #include "content/browser/bluetooth/bluetooth_metrics.h" | 19 #include "content/browser/bluetooth/bluetooth_metrics.h" |
21 #include "content/browser/bluetooth/frame_connected_bluetooth_devices.h" | 20 #include "content/browser/bluetooth/frame_connected_bluetooth_devices.h" |
22 #include "content/browser/renderer_host/render_process_host_impl.h" | 21 #include "content/browser/renderer_host/render_process_host_impl.h" |
23 #include "content/common/bluetooth/web_bluetooth_device_id.h" | 22 #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" |
| 29 #include "device/bluetooth/bluetooth_remote_gatt_descriptor.h" |
30 | 30 |
31 using device::BluetoothAdapterFactoryWrapper; | 31 using device::BluetoothAdapterFactoryWrapper; |
32 using device::BluetoothUUID; | 32 using device::BluetoothUUID; |
33 | 33 |
34 namespace content { | 34 namespace content { |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 blink::mojom::WebBluetoothResult TranslateConnectErrorAndRecord( | 38 blink::mojom::WebBluetoothResult TranslateConnectErrorAndRecord( |
39 device::BluetoothDevice::ConnectErrorCode error_code) { | 39 device::BluetoothDevice::ConnectErrorCode error_code) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 UMAGATTOperationOutcome::NOT_PAIRED); | 122 UMAGATTOperationOutcome::NOT_PAIRED); |
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 std::vector<device::BluetoothRemoteGattDescriptor*> GetDescriptorsByUUID( |
| 133 device::BluetoothRemoteGattCharacteristic* characteristic, |
| 134 const BluetoothUUID& descriptor_uuid) { |
| 135 std::vector<device::BluetoothRemoteGattDescriptor*> descriptors; |
| 136 VLOG(1) << "Looking for descriptor: " << descriptor_uuid.canonical_value(); |
| 137 for (device::BluetoothRemoteGattDescriptor* descriptor : |
| 138 characteristic->GetDescriptors()) { |
| 139 VLOG(1) << "Descriptor in cache: " |
| 140 << descriptor->GetUUID().canonical_value(); |
| 141 if (descriptor->GetUUID() == descriptor_uuid) { |
| 142 descriptors.push_back(descriptor); |
| 143 } |
| 144 } |
| 145 return descriptors; |
| 146 } |
132 | 147 |
133 // TODO(ortuno): This should really be a BluetoothDevice method. | 148 // TODO(ortuno): This should really be a BluetoothDevice method. |
134 // Replace when implemented. http://crbug.com/552022 | 149 // Replace when implemented. http://crbug.com/552022 |
135 std::vector<device::BluetoothRemoteGattCharacteristic*> | 150 std::vector<device::BluetoothRemoteGattCharacteristic*> |
136 GetCharacteristicsByUUID(device::BluetoothRemoteGattService* service, | 151 GetCharacteristicsByUUID(device::BluetoothRemoteGattService* service, |
137 const BluetoothUUID& characteristic_uuid) { | 152 const BluetoothUUID& characteristic_uuid) { |
138 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics; | 153 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics; |
139 VLOG(1) << "Looking for characteristic: " | 154 VLOG(1) << "Looking for characteristic: " |
140 << characteristic_uuid.canonical_value(); | 155 << characteristic_uuid.canonical_value(); |
141 for (device::BluetoothRemoteGattCharacteristic* characteristic : | 156 for (device::BluetoothRemoteGattCharacteristic* characteristic : |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 RecordGetCharacteristicsOutcome( | 548 RecordGetCharacteristicsOutcome( |
534 quantity, characteristics_uuid | 549 quantity, characteristics_uuid |
535 ? UMAGetCharacteristicOutcome::NOT_FOUND | 550 ? UMAGetCharacteristicOutcome::NOT_FOUND |
536 : UMAGetCharacteristicOutcome::NO_CHARACTERISTICS); | 551 : UMAGetCharacteristicOutcome::NO_CHARACTERISTICS); |
537 callback.Run(characteristics_uuid | 552 callback.Run(characteristics_uuid |
538 ? blink::mojom::WebBluetoothResult::CHARACTERISTIC_NOT_FOUND | 553 ? blink::mojom::WebBluetoothResult::CHARACTERISTIC_NOT_FOUND |
539 : blink::mojom::WebBluetoothResult::NO_CHARACTERISTICS_FOUND, | 554 : blink::mojom::WebBluetoothResult::NO_CHARACTERISTICS_FOUND, |
540 base::nullopt /* characteristics */); | 555 base::nullopt /* characteristics */); |
541 } | 556 } |
542 | 557 |
| 558 void WebBluetoothServiceImpl::RemoteCharacteristicGetDescriptors( |
| 559 const std::string& characteristic_instance_id, |
| 560 blink::mojom::WebBluetoothGATTQueryQuantity quantity, |
| 561 const base::Optional<BluetoothUUID>& descriptors_uuid, |
| 562 const RemoteCharacteristicGetDescriptorsCallback& callback) { |
| 563 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 564 |
| 565 if (descriptors_uuid && |
| 566 BluetoothBlocklist::Get().IsExcluded(descriptors_uuid.value())) { |
| 567 callback.Run(blink::mojom::WebBluetoothResult::BLOCKLISTED_DESCRIPTOR_UUID, |
| 568 base::nullopt /* descriptor */); |
| 569 return; |
| 570 } |
| 571 |
| 572 const CacheQueryResult query_result = |
| 573 QueryCacheForCharacteristic(characteristic_instance_id); |
| 574 |
| 575 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
| 576 return; |
| 577 } |
| 578 |
| 579 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 580 callback.Run(query_result.GetWebResult(), base::nullopt /* descriptor */); |
| 581 return; |
| 582 } |
| 583 |
| 584 std::vector<device::BluetoothRemoteGattDescriptor*> descriptors = |
| 585 descriptors_uuid ? GetDescriptorsByUUID(query_result.characteristic, |
| 586 descriptors_uuid.value()) |
| 587 : query_result.characteristic->GetDescriptors(); |
| 588 |
| 589 std::vector<blink::mojom::WebBluetoothRemoteGATTDescriptorPtr> |
| 590 response_descriptors; |
| 591 for (device::BluetoothRemoteGattDescriptor* descriptor : descriptors) { |
| 592 if (BluetoothBlocklist::Get().IsExcluded(descriptor->GetUUID())) { |
| 593 continue; |
| 594 } |
| 595 std::string descriptor_instance_id = descriptor->GetIdentifier(); |
| 596 |
| 597 auto insert_result = descriptor_id_to_characteristic_id_.insert( |
| 598 {descriptor_instance_id, characteristic_instance_id}); |
| 599 // If value is already in map, DCHECK it's valid. |
| 600 if (!insert_result.second) |
| 601 DCHECK(insert_result.first->second == characteristic_instance_id); |
| 602 |
| 603 blink::mojom::WebBluetoothRemoteGATTDescriptorPtr descriptor_ptr = |
| 604 blink::mojom::WebBluetoothRemoteGATTDescriptor::New(); |
| 605 |
| 606 descriptor_ptr->instance_id = descriptor_instance_id; |
| 607 descriptor_ptr->uuid = descriptor->GetUUID().canonical_value(); |
| 608 response_descriptors.push_back(std::move(descriptor_ptr)); |
| 609 |
| 610 if (quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE) { |
| 611 break; |
| 612 } |
| 613 } |
| 614 |
| 615 if (!response_descriptors.empty()) { |
| 616 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, |
| 617 std::move(response_descriptors)); |
| 618 return; |
| 619 } |
| 620 |
| 621 callback.Run(descriptors_uuid |
| 622 ? blink::mojom::WebBluetoothResult::DESCRIPTOR_NOT_FOUND |
| 623 : blink::mojom::WebBluetoothResult::NO_DESCRIPTORS_FOUND, |
| 624 base::nullopt /* descriptors */); |
| 625 } |
| 626 |
| 627 void WebBluetoothServiceImpl::RemoteDescriptorReadValue( |
| 628 const std::string& descriptor_instance_id, |
| 629 const RemoteDescriptorReadValueCallback& callback) { |
| 630 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 631 |
| 632 const CacheQueryResult query_result = |
| 633 QueryCacheForDescriptor(descriptor_instance_id); |
| 634 |
| 635 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
| 636 return; |
| 637 } |
| 638 |
| 639 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 640 callback.Run(query_result.GetWebResult(), base::nullopt /* value */); |
| 641 return; |
| 642 } |
| 643 |
| 644 if (BluetoothBlocklist::Get().IsExcludedFromReads( |
| 645 query_result.descriptor->GetUUID())) { |
| 646 callback.Run(blink::mojom::WebBluetoothResult::BLOCKLISTED_READ, |
| 647 base::nullopt /* value */); |
| 648 return; |
| 649 } |
| 650 |
| 651 query_result.descriptor->ReadRemoteDescriptor( |
| 652 base::Bind(&WebBluetoothServiceImpl::OnDescriptorReadValueSuccess, |
| 653 weak_ptr_factory_.GetWeakPtr(), callback), |
| 654 base::Bind(&WebBluetoothServiceImpl::OnDescriptorReadValueFailed, |
| 655 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 656 } |
| 657 |
| 658 void WebBluetoothServiceImpl::RemoteDescriptorWriteValue( |
| 659 const std::string& descriptor_instance_id, |
| 660 const std::vector<uint8_t>& value, |
| 661 const RemoteDescriptorWriteValueCallback& callback) { |
| 662 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 663 |
| 664 // We perform the length check on the renderer side. So if we |
| 665 // get a value with length > 512, we can assume it's a hostile |
| 666 // renderer and kill it. |
| 667 if (value.size() > 512) { |
| 668 CrashRendererAndClosePipe(bad_message::BDH_INVALID_WRITE_VALUE_LENGTH); |
| 669 return; |
| 670 } |
| 671 |
| 672 const CacheQueryResult query_result = |
| 673 QueryCacheForDescriptor(descriptor_instance_id); |
| 674 |
| 675 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
| 676 return; |
| 677 } |
| 678 |
| 679 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 680 callback.Run(query_result.GetWebResult()); |
| 681 return; |
| 682 } |
| 683 |
| 684 if (BluetoothBlocklist::Get().IsExcludedFromWrites( |
| 685 query_result.descriptor->GetUUID())) { |
| 686 callback.Run(blink::mojom::WebBluetoothResult::BLOCKLISTED_WRITE); |
| 687 return; |
| 688 } |
| 689 |
| 690 query_result.descriptor->WriteRemoteDescriptor( |
| 691 value, base::Bind(&WebBluetoothServiceImpl::OnDescriptorWriteValueSuccess, |
| 692 weak_ptr_factory_.GetWeakPtr(), callback), |
| 693 base::Bind(&WebBluetoothServiceImpl::OnDescriptorWriteValueFailed, |
| 694 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 695 } |
| 696 |
543 void WebBluetoothServiceImpl::RemoteCharacteristicReadValue( | 697 void WebBluetoothServiceImpl::RemoteCharacteristicReadValue( |
544 const std::string& characteristic_instance_id, | 698 const std::string& characteristic_instance_id, |
545 const RemoteCharacteristicReadValueCallback& callback) { | 699 const RemoteCharacteristicReadValueCallback& callback) { |
546 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 700 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
547 RecordWebBluetoothFunctionCall( | 701 RecordWebBluetoothFunctionCall( |
548 UMAWebBluetoothFunction::CHARACTERISTIC_READ_VALUE); | 702 UMAWebBluetoothFunction::CHARACTERISTIC_READ_VALUE); |
549 | 703 |
550 const CacheQueryResult query_result = | 704 const CacheQueryResult query_result = |
551 QueryCacheForCharacteristic(characteristic_instance_id); | 705 QueryCacheForCharacteristic(characteristic_instance_id); |
552 | 706 |
553 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | 707 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
554 return; | 708 return; |
555 } | 709 } |
556 | 710 |
557 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 711 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
558 RecordCharacteristicReadValueOutcome(query_result.outcome); | 712 RecordCharacteristicReadValueOutcome(query_result.outcome); |
559 callback.Run(query_result.GetWebResult(), base::nullopt /* value */); | 713 callback.Run(query_result.GetWebResult(), base::nullopt /* value */); |
560 return; | 714 return; |
561 } | 715 } |
562 | 716 |
563 if (BluetoothBlocklist::Get().IsExcludedFromReads( | 717 if (BluetoothBlocklist::Get().IsExcludedFromReads( |
564 query_result.characteristic->GetUUID())) { | 718 query_result.characteristic->GetUUID())) { |
565 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::BLOCKLISTED); | 719 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::BLOCKLISTED); |
566 callback.Run(blink::mojom::WebBluetoothResult::BLOCKLISTED_READ, | 720 callback.Run(blink::mojom::WebBluetoothResult::BLOCKLISTED_READ, |
567 base::nullopt /* value */); | 721 base::nullopt /* value */); |
568 return; | 722 return; |
569 } | 723 } |
570 | 724 |
571 query_result.characteristic->ReadRemoteCharacteristic( | 725 query_result.characteristic->ReadRemoteCharacteristic( |
572 base::Bind(&WebBluetoothServiceImpl::OnReadValueSuccess, | 726 base::Bind(&WebBluetoothServiceImpl::OnCharacteristicReadValueSuccess, |
573 weak_ptr_factory_.GetWeakPtr(), callback), | 727 weak_ptr_factory_.GetWeakPtr(), callback), |
574 base::Bind(&WebBluetoothServiceImpl::OnReadValueFailed, | 728 base::Bind(&WebBluetoothServiceImpl::OnCharacteristicReadValueFailed, |
575 weak_ptr_factory_.GetWeakPtr(), callback)); | 729 weak_ptr_factory_.GetWeakPtr(), callback)); |
576 } | 730 } |
577 | 731 |
578 void WebBluetoothServiceImpl::RemoteCharacteristicWriteValue( | 732 void WebBluetoothServiceImpl::RemoteCharacteristicWriteValue( |
579 const std::string& characteristic_instance_id, | 733 const std::string& characteristic_instance_id, |
580 const std::vector<uint8_t>& value, | 734 const std::vector<uint8_t>& value, |
581 const RemoteCharacteristicWriteValueCallback& callback) { | 735 const RemoteCharacteristicWriteValueCallback& callback) { |
582 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 736 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
583 RecordWebBluetoothFunctionCall( | 737 RecordWebBluetoothFunctionCall( |
584 UMAWebBluetoothFunction::CHARACTERISTIC_WRITE_VALUE); | 738 UMAWebBluetoothFunction::CHARACTERISTIC_WRITE_VALUE); |
(...skipping 20 matching lines...) Expand all Loading... |
605 } | 759 } |
606 | 760 |
607 if (BluetoothBlocklist::Get().IsExcludedFromWrites( | 761 if (BluetoothBlocklist::Get().IsExcludedFromWrites( |
608 query_result.characteristic->GetUUID())) { | 762 query_result.characteristic->GetUUID())) { |
609 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::BLOCKLISTED); | 763 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::BLOCKLISTED); |
610 callback.Run(blink::mojom::WebBluetoothResult::BLOCKLISTED_WRITE); | 764 callback.Run(blink::mojom::WebBluetoothResult::BLOCKLISTED_WRITE); |
611 return; | 765 return; |
612 } | 766 } |
613 | 767 |
614 query_result.characteristic->WriteRemoteCharacteristic( | 768 query_result.characteristic->WriteRemoteCharacteristic( |
615 value, base::Bind(&WebBluetoothServiceImpl::OnWriteValueSuccess, | 769 value, |
616 weak_ptr_factory_.GetWeakPtr(), callback), | 770 base::Bind(&WebBluetoothServiceImpl::OnCharacteristicWriteValueSuccess, |
617 base::Bind(&WebBluetoothServiceImpl::OnWriteValueFailed, | 771 weak_ptr_factory_.GetWeakPtr(), callback), |
| 772 base::Bind(&WebBluetoothServiceImpl::OnCharacteristicWriteValueFailed, |
618 weak_ptr_factory_.GetWeakPtr(), callback)); | 773 weak_ptr_factory_.GetWeakPtr(), callback)); |
619 } | 774 } |
620 | 775 |
621 void WebBluetoothServiceImpl::RemoteCharacteristicStartNotifications( | 776 void WebBluetoothServiceImpl::RemoteCharacteristicStartNotifications( |
622 const std::string& characteristic_instance_id, | 777 const std::string& characteristic_instance_id, |
623 const RemoteCharacteristicStartNotificationsCallback& callback) { | 778 const RemoteCharacteristicStartNotificationsCallback& callback) { |
624 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 779 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
625 RecordWebBluetoothFunctionCall( | 780 RecordWebBluetoothFunctionCall( |
626 UMAWebBluetoothFunction::CHARACTERISTIC_START_NOTIFICATIONS); | 781 UMAWebBluetoothFunction::CHARACTERISTIC_START_NOTIFICATIONS); |
627 | 782 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 | 979 |
825 void WebBluetoothServiceImpl::OnCreateGATTConnectionFailed( | 980 void WebBluetoothServiceImpl::OnCreateGATTConnectionFailed( |
826 base::TimeTicks start_time, | 981 base::TimeTicks start_time, |
827 const RemoteServerConnectCallback& callback, | 982 const RemoteServerConnectCallback& callback, |
828 device::BluetoothDevice::ConnectErrorCode error_code) { | 983 device::BluetoothDevice::ConnectErrorCode error_code) { |
829 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 984 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
830 RecordConnectGATTTimeFailed(base::TimeTicks::Now() - start_time); | 985 RecordConnectGATTTimeFailed(base::TimeTicks::Now() - start_time); |
831 callback.Run(TranslateConnectErrorAndRecord(error_code)); | 986 callback.Run(TranslateConnectErrorAndRecord(error_code)); |
832 } | 987 } |
833 | 988 |
834 void WebBluetoothServiceImpl::OnReadValueSuccess( | 989 void WebBluetoothServiceImpl::OnDescriptorReadValueSuccess( |
| 990 const RemoteDescriptorReadValueCallback& callback, |
| 991 const std::vector<uint8_t>& value) { |
| 992 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 993 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, value); |
| 994 } |
| 995 |
| 996 void WebBluetoothServiceImpl::OnDescriptorReadValueFailed( |
| 997 const RemoteDescriptorReadValueCallback& callback, |
| 998 device::BluetoothRemoteGattService::GattErrorCode error_code) { |
| 999 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1000 callback.Run(TranslateGATTErrorAndRecord(error_code, |
| 1001 UMAGATTOperation::DESCRIPTOR_READ), |
| 1002 base::nullopt /* value */); |
| 1003 } |
| 1004 |
| 1005 void WebBluetoothServiceImpl::OnDescriptorWriteValueSuccess( |
| 1006 const RemoteDescriptorWriteValueCallback& callback) { |
| 1007 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1008 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS); |
| 1009 } |
| 1010 |
| 1011 void WebBluetoothServiceImpl::OnDescriptorWriteValueFailed( |
| 1012 const RemoteDescriptorWriteValueCallback& callback, |
| 1013 device::BluetoothRemoteGattService::GattErrorCode error_code) { |
| 1014 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1015 callback.Run(TranslateGATTErrorAndRecord(error_code, |
| 1016 UMAGATTOperation::DESCRIPTOR_WRITE)); |
| 1017 } |
| 1018 |
| 1019 void WebBluetoothServiceImpl::OnCharacteristicReadValueSuccess( |
835 const RemoteCharacteristicReadValueCallback& callback, | 1020 const RemoteCharacteristicReadValueCallback& callback, |
836 const std::vector<uint8_t>& value) { | 1021 const std::vector<uint8_t>& value) { |
837 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1022 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
838 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::SUCCESS); | 1023 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::SUCCESS); |
839 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, value); | 1024 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, value); |
840 } | 1025 } |
841 | 1026 |
842 void WebBluetoothServiceImpl::OnReadValueFailed( | 1027 void WebBluetoothServiceImpl::OnCharacteristicReadValueFailed( |
843 const RemoteCharacteristicReadValueCallback& callback, | 1028 const RemoteCharacteristicReadValueCallback& callback, |
844 device::BluetoothRemoteGattService::GattErrorCode error_code) { | 1029 device::BluetoothRemoteGattService::GattErrorCode error_code) { |
845 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1030 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
846 callback.Run(TranslateGATTErrorAndRecord( | 1031 callback.Run(TranslateGATTErrorAndRecord( |
847 error_code, UMAGATTOperation::CHARACTERISTIC_READ), | 1032 error_code, UMAGATTOperation::CHARACTERISTIC_READ), |
848 base::nullopt /* value */); | 1033 base::nullopt /* value */); |
849 } | 1034 } |
850 | 1035 |
851 void WebBluetoothServiceImpl::OnWriteValueSuccess( | 1036 void WebBluetoothServiceImpl::OnCharacteristicWriteValueSuccess( |
852 const RemoteCharacteristicWriteValueCallback& callback) { | 1037 const RemoteCharacteristicWriteValueCallback& callback) { |
853 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1038 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
854 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::SUCCESS); | 1039 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::SUCCESS); |
855 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS); | 1040 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS); |
856 } | 1041 } |
857 | 1042 |
858 void WebBluetoothServiceImpl::OnWriteValueFailed( | 1043 void WebBluetoothServiceImpl::OnCharacteristicWriteValueFailed( |
859 const RemoteCharacteristicWriteValueCallback& callback, | 1044 const RemoteCharacteristicWriteValueCallback& callback, |
860 device::BluetoothRemoteGattService::GattErrorCode error_code) { | 1045 device::BluetoothRemoteGattService::GattErrorCode error_code) { |
861 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1046 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
862 callback.Run(TranslateGATTErrorAndRecord( | 1047 callback.Run(TranslateGATTErrorAndRecord( |
863 error_code, UMAGATTOperation::CHARACTERISTIC_WRITE)); | 1048 error_code, UMAGATTOperation::CHARACTERISTIC_WRITE)); |
864 } | 1049 } |
865 | 1050 |
866 void WebBluetoothServiceImpl::OnStartNotifySessionSuccess( | 1051 void WebBluetoothServiceImpl::OnStartNotifySessionSuccess( |
867 const RemoteCharacteristicStartNotificationsCallback& callback, | 1052 const RemoteCharacteristicStartNotificationsCallback& callback, |
868 std::unique_ptr<device::BluetoothGattNotifySession> notify_session) { | 1053 std::unique_ptr<device::BluetoothGattNotifySession> notify_session) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
967 result.characteristic = | 1152 result.characteristic = |
968 result.service->GetCharacteristic(characteristic_instance_id); | 1153 result.service->GetCharacteristic(characteristic_instance_id); |
969 | 1154 |
970 if (result.characteristic == nullptr) { | 1155 if (result.characteristic == nullptr) { |
971 result.outcome = CacheQueryOutcome::NO_CHARACTERISTIC; | 1156 result.outcome = CacheQueryOutcome::NO_CHARACTERISTIC; |
972 } | 1157 } |
973 | 1158 |
974 return result; | 1159 return result; |
975 } | 1160 } |
976 | 1161 |
| 1162 CacheQueryResult WebBluetoothServiceImpl::QueryCacheForDescriptor( |
| 1163 const std::string& descriptor_instance_id) { |
| 1164 auto descriptor_iter = |
| 1165 descriptor_id_to_characteristic_id_.find(descriptor_instance_id); |
| 1166 |
| 1167 // Kill the render, see "ID Not in Map Note" above. |
| 1168 if (descriptor_iter == descriptor_id_to_characteristic_id_.end()) { |
| 1169 CrashRendererAndClosePipe(bad_message::BDH_INVALID_DESCRIPTOR_ID); |
| 1170 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER); |
| 1171 } |
| 1172 |
| 1173 CacheQueryResult result = |
| 1174 QueryCacheForCharacteristic(descriptor_iter->second); |
| 1175 if (result.outcome != CacheQueryOutcome::SUCCESS) { |
| 1176 return result; |
| 1177 } |
| 1178 |
| 1179 result.descriptor = |
| 1180 result.characteristic->GetDescriptor(descriptor_instance_id); |
| 1181 |
| 1182 if (result.descriptor == nullptr) { |
| 1183 result.outcome = CacheQueryOutcome::NO_DESCRIPTOR; |
| 1184 } |
| 1185 |
| 1186 return result; |
| 1187 } |
| 1188 |
977 RenderProcessHost* WebBluetoothServiceImpl::GetRenderProcessHost() { | 1189 RenderProcessHost* WebBluetoothServiceImpl::GetRenderProcessHost() { |
978 return render_frame_host_->GetProcess(); | 1190 return render_frame_host_->GetProcess(); |
979 } | 1191 } |
980 | 1192 |
981 device::BluetoothAdapter* WebBluetoothServiceImpl::GetAdapter() { | 1193 device::BluetoothAdapter* WebBluetoothServiceImpl::GetAdapter() { |
982 return BluetoothAdapterFactoryWrapper::Get().GetAdapter(this); | 1194 return BluetoothAdapterFactoryWrapper::Get().GetAdapter(this); |
983 } | 1195 } |
984 | 1196 |
985 void WebBluetoothServiceImpl::CrashRendererAndClosePipe( | 1197 void WebBluetoothServiceImpl::CrashRendererAndClosePipe( |
986 bad_message::BadMessageReason reason) { | 1198 bad_message::BadMessageReason reason) { |
987 bad_message::ReceivedBadMessage(GetRenderProcessHost(), reason); | 1199 bad_message::ReceivedBadMessage(GetRenderProcessHost(), reason); |
988 binding_.Close(); | 1200 binding_.Close(); |
989 } | 1201 } |
990 | 1202 |
991 url::Origin WebBluetoothServiceImpl::GetOrigin() { | 1203 url::Origin WebBluetoothServiceImpl::GetOrigin() { |
992 return render_frame_host_->GetLastCommittedOrigin(); | 1204 return render_frame_host_->GetLastCommittedOrigin(); |
993 } | 1205 } |
994 | 1206 |
995 void WebBluetoothServiceImpl::ClearState() { | 1207 void WebBluetoothServiceImpl::ClearState() { |
996 characteristic_id_to_notify_session_.clear(); | 1208 characteristic_id_to_notify_session_.clear(); |
997 pending_primary_services_requests_.clear(); | 1209 pending_primary_services_requests_.clear(); |
| 1210 descriptor_id_to_characteristic_id_.clear(); |
998 characteristic_id_to_service_id_.clear(); | 1211 characteristic_id_to_service_id_.clear(); |
999 service_id_to_device_address_.clear(); | 1212 service_id_to_device_address_.clear(); |
1000 connected_devices_.reset( | 1213 connected_devices_.reset( |
1001 new FrameConnectedBluetoothDevices(render_frame_host_)); | 1214 new FrameConnectedBluetoothDevices(render_frame_host_)); |
1002 allowed_devices_map_ = BluetoothAllowedDevicesMap(); | 1215 allowed_devices_map_ = BluetoothAllowedDevicesMap(); |
1003 device_chooser_controller_.reset(); | 1216 device_chooser_controller_.reset(); |
1004 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); | 1217 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); |
1005 } | 1218 } |
1006 | 1219 |
1007 } // namespace content | 1220 } // namespace content |
OLD | NEW |