Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(514)

Side by Side Diff: content/browser/bluetooth/web_bluetooth_service_impl.cc

Issue 2654403002: Implement WebBluetooth descriptor.writeValue() (Closed)
Patch Set: #4 Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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: A service, characteristic, or descriptor ID not in the 5 // ID Not In Map Note: A service, characteristic, or descriptor ID not in the
6 // corresponding WebBluetoothServiceImpl map [service_id_to_device_address_, 6 // corresponding WebBluetoothServiceImpl map [service_id_to_device_address_,
7 // characteristic_id_to_service_id_, descriptor_id_to_characteristic_id_] 7 // characteristic_id_to_service_id_, descriptor_id_to_characteristic_id_]
8 // implies a hostile renderer because a renderer obtains the corresponding ID 8 // implies a hostile renderer because a renderer obtains the corresponding ID
9 // from this class and it will be added to the map at that time. 9 // from this class and it will be added to the map at that time.
10 10
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 return; 768 return;
769 } 769 }
770 770
771 query_result.descriptor->ReadRemoteDescriptor( 771 query_result.descriptor->ReadRemoteDescriptor(
772 base::Bind(&WebBluetoothServiceImpl::OnDescriptorReadValueSuccess, 772 base::Bind(&WebBluetoothServiceImpl::OnDescriptorReadValueSuccess,
773 weak_ptr_factory_.GetWeakPtr(), callback), 773 weak_ptr_factory_.GetWeakPtr(), callback),
774 base::Bind(&WebBluetoothServiceImpl::OnDescriptorReadValueFailed, 774 base::Bind(&WebBluetoothServiceImpl::OnDescriptorReadValueFailed,
775 weak_ptr_factory_.GetWeakPtr(), callback)); 775 weak_ptr_factory_.GetWeakPtr(), callback));
776 } 776 }
777 777
778 void WebBluetoothServiceImpl::RemoteDescriptorWriteValue(
779 const std::string& descriptor_instance_id,
780 const std::vector<uint8_t>& value,
781 const RemoteDescriptorWriteValueCallback& callback) {
782 DCHECK_CURRENTLY_ON(BrowserThread::UI);
783
784 // We perform the length check on the renderer side. So if we
785 // get a value with length > 512, we can assume it's a hostile
786 // renderer and kill it.
787 if (value.size() > 512) {
788 CrashRendererAndClosePipe(bad_message::BDH_INVALID_WRITE_VALUE_LENGTH);
789 return;
790 }
791
792 const CacheQueryResult query_result =
793 QueryCacheForDescriptor(descriptor_instance_id);
794
795 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) {
796 return;
797 }
798
799 if (query_result.outcome != CacheQueryOutcome::SUCCESS) {
800 callback.Run(query_result.GetWebResult());
801 return;
802 }
803
804 if (BluetoothBlocklist::Get().IsExcludedFromWrites(
805 query_result.descriptor->GetUUID())) {
806 callback.Run(blink::mojom::WebBluetoothResult::BLOCKLISTED_WRITE);
807 return;
808 }
809
810 query_result.descriptor->WriteRemoteDescriptor(
811 value, base::Bind(&WebBluetoothServiceImpl::OnDescriptorWriteValueSuccess,
812 weak_ptr_factory_.GetWeakPtr(), callback),
813 base::Bind(&WebBluetoothServiceImpl::OnDescriptorWriteValueFailed,
814 weak_ptr_factory_.GetWeakPtr(), callback));
815 }
816
778 void WebBluetoothServiceImpl::RequestDeviceImpl( 817 void WebBluetoothServiceImpl::RequestDeviceImpl(
779 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, 818 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options,
780 const RequestDeviceCallback& callback, 819 const RequestDeviceCallback& callback,
781 device::BluetoothAdapter* adapter) { 820 device::BluetoothAdapter* adapter) {
782 // requestDevice() can only be called when processing a user-gesture and any 821 // requestDevice() can only be called when processing a user-gesture and any
783 // user gesture outside of a chooser should close the chooser. This does 822 // user gesture outside of a chooser should close the chooser. This does
784 // not happen on all platforms so we don't DCHECK that the old one is closed. 823 // not happen on all platforms so we don't DCHECK that the old one is closed.
785 // We destroy the old chooser before constructing the new one to make sure 824 // We destroy the old chooser before constructing the new one to make sure
786 // they can't conflict. 825 // they can't conflict.
787 device_chooser_controller_.reset(); 826 device_chooser_controller_.reset();
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 1025
987 void WebBluetoothServiceImpl::OnDescriptorReadValueFailed( 1026 void WebBluetoothServiceImpl::OnDescriptorReadValueFailed(
988 const RemoteDescriptorReadValueCallback& callback, 1027 const RemoteDescriptorReadValueCallback& callback,
989 device::BluetoothRemoteGattService::GattErrorCode error_code) { 1028 device::BluetoothRemoteGattService::GattErrorCode error_code) {
990 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1029 DCHECK_CURRENTLY_ON(BrowserThread::UI);
991 callback.Run(TranslateGATTErrorAndRecord(error_code, 1030 callback.Run(TranslateGATTErrorAndRecord(error_code,
992 UMAGATTOperation::DESCRIPTOR_READ), 1031 UMAGATTOperation::DESCRIPTOR_READ),
993 base::nullopt /* value */); 1032 base::nullopt /* value */);
994 } 1033 }
995 1034
1035 void WebBluetoothServiceImpl::OnDescriptorWriteValueSuccess(
1036 const RemoteDescriptorWriteValueCallback& callback) {
1037 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1038 // TODO(667319): We are reporting failures to UMA but not reporting successes
1039 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS);
1040 }
1041
1042 void WebBluetoothServiceImpl::OnDescriptorWriteValueFailed(
1043 const RemoteDescriptorWriteValueCallback& callback,
1044 device::BluetoothRemoteGattService::GattErrorCode error_code) {
1045 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1046 // TODO(683477) reporting for .writeValue()
1047 callback.Run(TranslateGATTErrorAndRecord(error_code,
1048 UMAGATTOperation::DESCRIPTOR_WRITE));
1049 }
1050
996 CacheQueryResult WebBluetoothServiceImpl::QueryCacheForDevice( 1051 CacheQueryResult WebBluetoothServiceImpl::QueryCacheForDevice(
997 const WebBluetoothDeviceId& device_id) { 1052 const WebBluetoothDeviceId& device_id) {
998 const std::string& device_address = 1053 const std::string& device_address =
999 allowed_devices_map_.GetDeviceAddress(GetOrigin(), device_id); 1054 allowed_devices_map_.GetDeviceAddress(GetOrigin(), device_id);
1000 if (device_address.empty()) { 1055 if (device_address.empty()) {
1001 CrashRendererAndClosePipe(bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN); 1056 CrashRendererAndClosePipe(bad_message::BDH_DEVICE_NOT_ALLOWED_FOR_ORIGIN);
1002 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER); 1057 return CacheQueryResult(CacheQueryOutcome::BAD_RENDERER);
1003 } 1058 }
1004 1059
1005 CacheQueryResult result; 1060 CacheQueryResult result;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 characteristic_id_to_service_id_.clear(); 1183 characteristic_id_to_service_id_.clear();
1129 service_id_to_device_address_.clear(); 1184 service_id_to_device_address_.clear();
1130 connected_devices_.reset( 1185 connected_devices_.reset(
1131 new FrameConnectedBluetoothDevices(render_frame_host_)); 1186 new FrameConnectedBluetoothDevices(render_frame_host_));
1132 allowed_devices_map_ = BluetoothAllowedDevicesMap(); 1187 allowed_devices_map_ = BluetoothAllowedDevicesMap();
1133 device_chooser_controller_.reset(); 1188 device_chooser_controller_.reset();
1134 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); 1189 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this);
1135 } 1190 }
1136 1191
1137 } // namespace content 1192 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698