| 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 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 const RemoteServiceGetCharacteristicsCallback& callback) { | 459 const RemoteServiceGetCharacteristicsCallback& callback) { |
| 460 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 460 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 461 | 461 |
| 462 RecordWebBluetoothFunctionCall( | 462 RecordWebBluetoothFunctionCall( |
| 463 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE | 463 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE |
| 464 ? UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTIC | 464 ? UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTIC |
| 465 : UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTICS); | 465 : UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTICS); |
| 466 RecordGetCharacteristicsCharacteristic(quantity, characteristics_uuid); | 466 RecordGetCharacteristicsCharacteristic(quantity, characteristics_uuid); |
| 467 | 467 |
| 468 if (characteristics_uuid && | 468 if (characteristics_uuid && |
| 469 BluetoothBlacklist::Get().IsExcluded(characteristics_uuid.value())) { | 469 BluetoothBlocklist::Get().IsExcluded(characteristics_uuid.value())) { |
| 470 RecordGetCharacteristicsOutcome(quantity, | 470 RecordGetCharacteristicsOutcome(quantity, |
| 471 UMAGetCharacteristicOutcome::BLACKLISTED); | 471 UMAGetCharacteristicOutcome::BLOCKLISTED); |
| 472 callback.Run( | 472 callback.Run( |
| 473 blink::mojom::WebBluetoothResult::BLACKLISTED_CHARACTERISTIC_UUID, | 473 blink::mojom::WebBluetoothResult::BLOCKLISTED_CHARACTERISTIC_UUID, |
| 474 nullptr /* characteristics */); | 474 nullptr /* characteristics */); |
| 475 return; | 475 return; |
| 476 } | 476 } |
| 477 | 477 |
| 478 const CacheQueryResult query_result = | 478 const CacheQueryResult query_result = |
| 479 QueryCacheForService(service_instance_id); | 479 QueryCacheForService(service_instance_id); |
| 480 | 480 |
| 481 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | 481 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
| 482 return; | 482 return; |
| 483 } | 483 } |
| 484 | 484 |
| 485 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 485 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 486 RecordGetCharacteristicsOutcome(quantity, query_result.outcome); | 486 RecordGetCharacteristicsOutcome(quantity, query_result.outcome); |
| 487 callback.Run(query_result.GetWebResult(), nullptr /* characteristics */); | 487 callback.Run(query_result.GetWebResult(), nullptr /* characteristics */); |
| 488 return; | 488 return; |
| 489 } | 489 } |
| 490 | 490 |
| 491 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics = | 491 std::vector<device::BluetoothRemoteGattCharacteristic*> characteristics = |
| 492 characteristics_uuid | 492 characteristics_uuid |
| 493 ? GetCharacteristicsByUUID(query_result.service, | 493 ? GetCharacteristicsByUUID(query_result.service, |
| 494 characteristics_uuid.value()) | 494 characteristics_uuid.value()) |
| 495 : query_result.service->GetCharacteristics(); | 495 : query_result.service->GetCharacteristics(); |
| 496 | 496 |
| 497 mojo::Array<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr> | 497 mojo::Array<blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr> |
| 498 response_characteristics; | 498 response_characteristics; |
| 499 for (device::BluetoothRemoteGattCharacteristic* characteristic : | 499 for (device::BluetoothRemoteGattCharacteristic* characteristic : |
| 500 characteristics) { | 500 characteristics) { |
| 501 if (BluetoothBlacklist::Get().IsExcluded(characteristic->GetUUID())) { | 501 if (BluetoothBlocklist::Get().IsExcluded(characteristic->GetUUID())) { |
| 502 continue; | 502 continue; |
| 503 } | 503 } |
| 504 std::string characteristic_instance_id = characteristic->GetIdentifier(); | 504 std::string characteristic_instance_id = characteristic->GetIdentifier(); |
| 505 auto insert_result = characteristic_id_to_service_id_.insert( | 505 auto insert_result = characteristic_id_to_service_id_.insert( |
| 506 std::make_pair(characteristic_instance_id, service_instance_id)); | 506 std::make_pair(characteristic_instance_id, service_instance_id)); |
| 507 // If value is already in map, DCHECK it's valid. | 507 // If value is already in map, DCHECK it's valid. |
| 508 if (!insert_result.second) | 508 if (!insert_result.second) |
| 509 DCHECK(insert_result.first->second == service_instance_id); | 509 DCHECK(insert_result.first->second == service_instance_id); |
| 510 | 510 |
| 511 blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr characteristic_ptr = | 511 blink::mojom::WebBluetoothRemoteGATTCharacteristicPtr characteristic_ptr = |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | 552 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
| 553 return; | 553 return; |
| 554 } | 554 } |
| 555 | 555 |
| 556 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 556 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 557 RecordCharacteristicReadValueOutcome(query_result.outcome); | 557 RecordCharacteristicReadValueOutcome(query_result.outcome); |
| 558 callback.Run(query_result.GetWebResult(), nullptr /* value */); | 558 callback.Run(query_result.GetWebResult(), nullptr /* value */); |
| 559 return; | 559 return; |
| 560 } | 560 } |
| 561 | 561 |
| 562 if (BluetoothBlacklist::Get().IsExcludedFromReads( | 562 if (BluetoothBlocklist::Get().IsExcludedFromReads( |
| 563 query_result.characteristic->GetUUID())) { | 563 query_result.characteristic->GetUUID())) { |
| 564 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::BLACKLISTED); | 564 RecordCharacteristicReadValueOutcome(UMAGATTOperationOutcome::BLOCKLISTED); |
| 565 callback.Run(blink::mojom::WebBluetoothResult::BLACKLISTED_READ, | 565 callback.Run(blink::mojom::WebBluetoothResult::BLOCKLISTED_READ, |
| 566 nullptr /* value */); | 566 nullptr /* value */); |
| 567 return; | 567 return; |
| 568 } | 568 } |
| 569 | 569 |
| 570 query_result.characteristic->ReadRemoteCharacteristic( | 570 query_result.characteristic->ReadRemoteCharacteristic( |
| 571 base::Bind(&WebBluetoothServiceImpl::OnReadValueSuccess, | 571 base::Bind(&WebBluetoothServiceImpl::OnReadValueSuccess, |
| 572 weak_ptr_factory_.GetWeakPtr(), callback), | 572 weak_ptr_factory_.GetWeakPtr(), callback), |
| 573 base::Bind(&WebBluetoothServiceImpl::OnReadValueFailed, | 573 base::Bind(&WebBluetoothServiceImpl::OnReadValueFailed, |
| 574 weak_ptr_factory_.GetWeakPtr(), callback)); | 574 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 575 } | 575 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 596 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | 596 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
| 597 return; | 597 return; |
| 598 } | 598 } |
| 599 | 599 |
| 600 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 600 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 601 RecordCharacteristicWriteValueOutcome(query_result.outcome); | 601 RecordCharacteristicWriteValueOutcome(query_result.outcome); |
| 602 callback.Run(query_result.GetWebResult()); | 602 callback.Run(query_result.GetWebResult()); |
| 603 return; | 603 return; |
| 604 } | 604 } |
| 605 | 605 |
| 606 if (BluetoothBlacklist::Get().IsExcludedFromWrites( | 606 if (BluetoothBlocklist::Get().IsExcludedFromWrites( |
| 607 query_result.characteristic->GetUUID())) { | 607 query_result.characteristic->GetUUID())) { |
| 608 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::BLACKLISTED); | 608 RecordCharacteristicWriteValueOutcome(UMAGATTOperationOutcome::BLOCKLISTED); |
| 609 callback.Run(blink::mojom::WebBluetoothResult::BLACKLISTED_WRITE); | 609 callback.Run(blink::mojom::WebBluetoothResult::BLOCKLISTED_WRITE); |
| 610 return; | 610 return; |
| 611 } | 611 } |
| 612 | 612 |
| 613 query_result.characteristic->WriteRemoteCharacteristic( | 613 query_result.characteristic->WriteRemoteCharacteristic( |
| 614 value.To<std::vector<uint8_t>>(), | 614 value.To<std::vector<uint8_t>>(), |
| 615 base::Bind(&WebBluetoothServiceImpl::OnWriteValueSuccess, | 615 base::Bind(&WebBluetoothServiceImpl::OnWriteValueSuccess, |
| 616 weak_ptr_factory_.GetWeakPtr(), callback), | 616 weak_ptr_factory_.GetWeakPtr(), callback), |
| 617 base::Bind(&WebBluetoothServiceImpl::OnWriteValueFailed, | 617 base::Bind(&WebBluetoothServiceImpl::OnWriteValueFailed, |
| 618 weak_ptr_factory_.GetWeakPtr(), callback)); | 618 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 619 } | 619 } |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1000 characteristic_id_to_service_id_.clear(); | 1000 characteristic_id_to_service_id_.clear(); |
| 1001 service_id_to_device_address_.clear(); | 1001 service_id_to_device_address_.clear(); |
| 1002 connected_devices_.reset( | 1002 connected_devices_.reset( |
| 1003 new FrameConnectedBluetoothDevices(render_frame_host_)); | 1003 new FrameConnectedBluetoothDevices(render_frame_host_)); |
| 1004 allowed_devices_map_ = BluetoothAllowedDevicesMap(); | 1004 allowed_devices_map_ = BluetoothAllowedDevicesMap(); |
| 1005 device_chooser_controller_.reset(); | 1005 device_chooser_controller_.reset(); |
| 1006 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); | 1006 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); |
| 1007 } | 1007 } |
| 1008 | 1008 |
| 1009 } // namespace content | 1009 } // namespace content |
| OLD | NEW |