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