| 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_blocklist.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" | 23 #include "content/common/bluetooth/web_bluetooth_device_id.h" |
| 24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/navigation_handle.h" | 25 #include "content/public/browser/navigation_handle.h" |
| 26 #include "content/public/browser/render_frame_host.h" | 26 #include "content/public/browser/render_frame_host.h" |
| 27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 28 #include "device/bluetooth/bluetooth_adapter_factory_wrapper.h" | 28 #include "device/bluetooth/bluetooth_adapter_factory_wrapper.h" |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 const RemoteServiceGetCharacteristicsCallback& callback) { | 451 const RemoteServiceGetCharacteristicsCallback& callback) { |
| 452 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 452 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 453 | 453 |
| 454 RecordWebBluetoothFunctionCall( | 454 RecordWebBluetoothFunctionCall( |
| 455 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE | 455 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE |
| 456 ? UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTIC | 456 ? UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTIC |
| 457 : UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTICS); | 457 : UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTICS); |
| 458 RecordGetCharacteristicsCharacteristic(quantity, characteristics_uuid); | 458 RecordGetCharacteristicsCharacteristic(quantity, characteristics_uuid); |
| 459 | 459 |
| 460 if (characteristics_uuid && | 460 if (characteristics_uuid && |
| 461 BluetoothBlacklist::Get().IsExcluded(characteristics_uuid.value())) { | 461 BluetoothBlocklist::Get().IsExcluded(characteristics_uuid.value())) { |
| 462 RecordGetCharacteristicsOutcome(quantity, | 462 RecordGetCharacteristicsOutcome(quantity, |
| 463 UMAGetCharacteristicOutcome::BLACKLISTED); | 463 UMAGetCharacteristicOutcome::BLOCKLISTED); |
| 464 callback.Run( | 464 callback.Run( |
| 465 blink::mojom::WebBluetoothResult::BLACKLISTED_CHARACTERISTIC_UUID, | 465 blink::mojom::WebBluetoothResult::BLOCKLISTED_CHARACTERISTIC_UUID, |
| 466 nullptr /* characteristics */); | 466 nullptr /* characteristics */); |
| 467 return; | 467 return; |
| 468 } | 468 } |
| 469 | 469 |
| 470 const CacheQueryResult query_result = | 470 const CacheQueryResult query_result = |
| 471 QueryCacheForService(service_instance_id); | 471 QueryCacheForService(service_instance_id); |
| 472 | 472 |
| 473 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | 473 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
| 474 return; | 474 return; |
| 475 } | 475 } |
| 476 | 476 |
| 477 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 477 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 478 RecordGetCharacteristicsOutcome(quantity, query_result.outcome); | 478 RecordGetCharacteristicsOutcome(quantity, query_result.outcome); |
| 479 callback.Run(query_result.GetWebResult(), nullptr /* characteristics */); | 479 callback.Run(query_result.GetWebResult(), nullptr /* characteristics */); |
| 480 return; | 480 return; |
| 481 } | 481 } |
| 482 | 482 |
| 483 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics = | 483 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics = |
| 484 characteristics_uuid | 484 characteristics_uuid |
| 485 ? GetCharacteristicsByUUID(query_result.service, | 485 ? GetCharacteristicsByUUID(query_result.service, |
| 486 characteristics_uuid.value()) | 486 characteristics_uuid.value()) |
| 487 : query_result.service->GetCharacteristics(); | 487 : query_result.service->GetCharacteristics(); |
| 488 | 488 |
| 489 mojo::Array<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr> | 489 mojo::Array<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr> |
| 490 response_characteristics; | 490 response_characteristics; |
| 491 for (device::BluetoothRemoteGattCharacteristic* characteristic : | 491 for (device::BluetoothRemoteGattCharacteristic* characteristic : |
| 492 characteristics) { | 492 characteristics) { |
| 493 if (BluetoothBlacklist::Get().IsExcluded(characteristic->GetUUID())) { | 493 if (BluetoothBlocklist::Get().IsExcluded(characteristic->GetUUID())) { |
| 494 continue; | 494 continue; |
| 495 } | 495 } |
| 496 std::string characteristic_instance_id = characteristic->GetIdentifier(); | 496 std::string characteristic_instance_id = characteristic->GetIdentifier(); |
| 497 auto insert_result = characteristic_id_to_service_id_.insert( | 497 auto insert_result = characteristic_id_to_service_id_.insert( |
| 498 std::make_pair(characteristic_instance_id, service_instance_id)); | 498 std::make_pair(characteristic_instance_id, service_instance_id)); |
| 499 // If value is already in map, DCHECK it's valid. | 499 // If value is already in map, DCHECK it's valid. |
| 500 if (!insert_result.second) | 500 if (!insert_result.second) |
| 501 DCHECK(insert_result.first->second == service_instance_id); | 501 DCHECK(insert_result.first->second == service_instance_id); |
| 502 | 502 |
| 503 blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr characteristic_ptr = | 503 blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr characteristic_ptr = |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | 544 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
| 545 return; | 545 return; |
| 546 } | 546 } |
| 547 | 547 |
| 548 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 548 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 549 RecordCharacteristicReadValueOutcome(query_result.outcome); | 549 RecordCharacteristicReadValueOutcome(query_result.outcome); |
| 550 callback.Run(query_result.GetWebResult(), nullptr /* value */); | 550 callback.Run(query_result.GetWebResult(), nullptr /* value */); |
| 551 return; | 551 return; |
| 552 } | 552 } |
| 553 | 553 |
| 554 if (BluetoothBlacklist::Get().IsExcludedFromReads( | 554 if (BluetoothBlocklist::Get().IsExcludedFromReads( |
| 555 query_result.characteristic->GetUUID())) { | 555 query_result.characteristic->GetUUID())) { |
| 556 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::BLACKLISTED); | 556 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::BLOCKLISTED); |
| 557 callback.Run(blink::mojom::WebBluetoothResult::BLACKLISTED_READ, | 557 callback.Run(blink::mojom::WebBluetoothResult::BLOCKLISTED_READ, |
| 558 nullptr /* value */); | 558 nullptr /* value */); |
| 559 return; | 559 return; |
| 560 } | 560 } |
| 561 | 561 |
| 562 query_result.characteristic->ReadRemoteCharacteristic( | 562 query_result.characteristic->ReadRemoteCharacteristic( |
| 563 base::Bind(&WebBluetoothServiceImpl::OnReadValueSuccess, | 563 base::Bind(&WebBluetoothServiceImpl::OnReadValueSuccess, |
| 564 weak_ptr_factory_.GetWeakPtr(), callback), | 564 weak_ptr_factory_.GetWeakPtr(), callback), |
| 565 base::Bind(&WebBluetoothServiceImpl::OnReadValueFailed, | 565 base::Bind(&WebBluetoothServiceImpl::OnReadValueFailed, |
| 566 weak_ptr_factory_.GetWeakPtr(), callback)); | 566 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 567 } | 567 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 588 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | 588 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
| 589 return; | 589 return; |
| 590 } | 590 } |
| 591 | 591 |
| 592 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 592 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 593 RecordCharacteristicWriteValueOutcome(query_result.outcome); | 593 RecordCharacteristicWriteValueOutcome(query_result.outcome); |
| 594 callback.Run(query_result.GetWebResult()); | 594 callback.Run(query_result.GetWebResult()); |
| 595 return; | 595 return; |
| 596 } | 596 } |
| 597 | 597 |
| 598 if (BluetoothBlacklist::Get().IsExcludedFromWrites( | 598 if (BluetoothBlocklist::Get().IsExcludedFromWrites( |
| 599 query_result.characteristic->GetUUID())) { | 599 query_result.characteristic->GetUUID())) { |
| 600 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::BLACKLISTED); | 600 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::BLOCKLISTED); |
| 601 callback.Run(blink::mojom::WebBluetoothResult::BLACKLISTED_WRITE); | 601 callback.Run(blink::mojom::WebBluetoothResult::BLOCKLISTED_WRITE); |
| 602 return; | 602 return; |
| 603 } | 603 } |
| 604 | 604 |
| 605 query_result.characteristic->WriteRemoteCharacteristic( | 605 query_result.characteristic->WriteRemoteCharacteristic( |
| 606 value.To<std::vector<uint8_t>>(), | 606 value.To<std::vector<uint8_t>>(), |
| 607 base::Bind(&WebBluetoothServiceImpl::OnWriteValueSuccess, | 607 base::Bind(&WebBluetoothServiceImpl::OnWriteValueSuccess, |
| 608 weak_ptr_factory_.GetWeakPtr(), callback), | 608 weak_ptr_factory_.GetWeakPtr(), callback), |
| 609 base::Bind(&WebBluetoothServiceImpl::OnWriteValueFailed, | 609 base::Bind(&WebBluetoothServiceImpl::OnWriteValueFailed, |
| 610 weak_ptr_factory_.GetWeakPtr(), callback)); | 610 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 611 } | 611 } |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 characteristic_id_to_service_id_.clear(); | 992 characteristic_id_to_service_id_.clear(); |
| 993 service_id_to_device_address_.clear(); | 993 service_id_to_device_address_.clear(); |
| 994 connected_devices_.reset( | 994 connected_devices_.reset( |
| 995 new FrameConnectedBluetoothDevices(render_frame_host_)); | 995 new FrameConnectedBluetoothDevices(render_frame_host_)); |
| 996 allowed_devices_map_ = BluetoothAllowedDevicesMap(); | 996 allowed_devices_map_ = BluetoothAllowedDevicesMap(); |
| 997 device_chooser_controller_.reset(); | 997 device_chooser_controller_.reset(); |
| 998 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); | 998 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); |
| 999 } | 999 } |
| 1000 | 1000 |
| 1001 } // namespace content | 1001 } // namespace content |
| OLD | NEW |