| 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: 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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 279 |
| 280 void WebBluetoothServiceImpl::SetClient( | 280 void WebBluetoothServiceImpl::SetClient( |
| 281 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo client) { | 281 blink::mojom::WebBluetoothServiceClientAssociatedPtrInfo client) { |
| 282 DCHECK(!client_.get()); | 282 DCHECK(!client_.get()); |
| 283 client_.Bind(std::move(client)); | 283 client_.Bind(std::move(client)); |
| 284 } | 284 } |
| 285 | 285 |
| 286 void WebBluetoothServiceImpl::RequestDevice( | 286 void WebBluetoothServiceImpl::RequestDevice( |
| 287 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, | 287 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, |
| 288 const RequestDeviceCallback& callback) { | 288 const RequestDeviceCallback& callback) { |
| 289 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE); | |
| 290 RecordRequestDeviceOptions(options); | 289 RecordRequestDeviceOptions(options); |
| 291 | 290 |
| 292 if (!GetAdapter()) { | 291 if (!GetAdapter()) { |
| 293 if (BluetoothAdapterFactoryWrapper::Get().IsLowEnergyAvailable()) { | 292 if (BluetoothAdapterFactoryWrapper::Get().IsLowEnergyAvailable()) { |
| 294 BluetoothAdapterFactoryWrapper::Get().AcquireAdapter( | 293 BluetoothAdapterFactoryWrapper::Get().AcquireAdapter( |
| 295 this, base::Bind(&WebBluetoothServiceImpl::RequestDeviceImpl, | 294 this, base::Bind(&WebBluetoothServiceImpl::RequestDeviceImpl, |
| 296 weak_ptr_factory_.GetWeakPtr(), | 295 weak_ptr_factory_.GetWeakPtr(), |
| 297 base::Passed(std::move(options)), callback)); | 296 base::Passed(std::move(options)), callback)); |
| 298 return; | 297 return; |
| 299 } | 298 } |
| 300 RecordRequestDeviceOutcome( | 299 RecordRequestDeviceOutcome( |
| 301 UMARequestDeviceOutcome::BLUETOOTH_LOW_ENERGY_NOT_AVAILABLE); | 300 UMARequestDeviceOutcome::BLUETOOTH_LOW_ENERGY_NOT_AVAILABLE); |
| 302 callback.Run( | 301 callback.Run( |
| 303 blink::mojom::WebBluetoothResult::BLUETOOTH_LOW_ENERGY_NOT_AVAILABLE, | 302 blink::mojom::WebBluetoothResult::BLUETOOTH_LOW_ENERGY_NOT_AVAILABLE, |
| 304 nullptr /* device */); | 303 nullptr /* device */); |
| 305 return; | 304 return; |
| 306 } | 305 } |
| 307 RequestDeviceImpl(std::move(options), callback, GetAdapter()); | 306 RequestDeviceImpl(std::move(options), callback, GetAdapter()); |
| 308 } | 307 } |
| 309 | 308 |
| 310 void WebBluetoothServiceImpl::RemoteServerConnect( | 309 void WebBluetoothServiceImpl::RemoteServerConnect( |
| 311 const WebBluetoothDeviceId& device_id, | 310 const WebBluetoothDeviceId& device_id, |
| 312 const RemoteServerConnectCallback& callback) { | 311 const RemoteServerConnectCallback& callback) { |
| 313 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 312 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 314 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::CONNECT_GATT); | |
| 315 | 313 |
| 316 const CacheQueryResult query_result = QueryCacheForDevice(device_id); | 314 const CacheQueryResult query_result = QueryCacheForDevice(device_id); |
| 317 | 315 |
| 318 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 316 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 319 RecordConnectGATTOutcome(query_result.outcome); | 317 RecordConnectGATTOutcome(query_result.outcome); |
| 320 callback.Run(query_result.GetWebResult()); | 318 callback.Run(query_result.GetWebResult()); |
| 321 return; | 319 return; |
| 322 } | 320 } |
| 323 | 321 |
| 324 if (connected_devices_->IsConnectedToDeviceWithId(device_id)) { | 322 if (connected_devices_->IsConnectedToDeviceWithId(device_id)) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 341 base::Bind(&WebBluetoothServiceImpl::OnCreateGATTConnectionSuccess, | 339 base::Bind(&WebBluetoothServiceImpl::OnCreateGATTConnectionSuccess, |
| 342 weak_ptr_factory_.GetWeakPtr(), device_id, start_time, | 340 weak_ptr_factory_.GetWeakPtr(), device_id, start_time, |
| 343 callback), | 341 callback), |
| 344 base::Bind(&WebBluetoothServiceImpl::OnCreateGATTConnectionFailed, | 342 base::Bind(&WebBluetoothServiceImpl::OnCreateGATTConnectionFailed, |
| 345 weak_ptr_factory_.GetWeakPtr(), start_time, callback)); | 343 weak_ptr_factory_.GetWeakPtr(), start_time, callback)); |
| 346 } | 344 } |
| 347 | 345 |
| 348 void WebBluetoothServiceImpl::RemoteServerDisconnect( | 346 void WebBluetoothServiceImpl::RemoteServerDisconnect( |
| 349 const WebBluetoothDeviceId& device_id) { | 347 const WebBluetoothDeviceId& device_id) { |
| 350 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 348 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 351 RecordWebBluetoothFunctionCall( | |
| 352 UMAWebBluetoothFunction::REMOTE_GATT_SERVER_DISCONNECT); | |
| 353 | 349 |
| 354 if (connected_devices_->IsConnectedToDeviceWithId(device_id)) { | 350 if (connected_devices_->IsConnectedToDeviceWithId(device_id)) { |
| 355 DVLOG(1) << "Disconnecting device: " << device_id.str(); | 351 DVLOG(1) << "Disconnecting device: " << device_id.str(); |
| 356 connected_devices_->CloseConnectionToDeviceWithId(device_id); | 352 connected_devices_->CloseConnectionToDeviceWithId(device_id); |
| 357 } | 353 } |
| 358 } | 354 } |
| 359 | 355 |
| 360 void WebBluetoothServiceImpl::RemoteServerGetPrimaryServices( | 356 void WebBluetoothServiceImpl::RemoteServerGetPrimaryServices( |
| 361 const WebBluetoothDeviceId& device_id, | 357 const WebBluetoothDeviceId& device_id, |
| 362 blink::mojom::WebBluetoothGATTQueryQuantity quantity, | 358 blink::mojom::WebBluetoothGATTQueryQuantity quantity, |
| 363 const base::Optional<BluetoothUUID>& services_uuid, | 359 const base::Optional<BluetoothUUID>& services_uuid, |
| 364 const RemoteServerGetPrimaryServicesCallback& callback) { | 360 const RemoteServerGetPrimaryServicesCallback& callback) { |
| 365 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 361 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 366 RecordWebBluetoothFunctionCall( | |
| 367 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE | |
| 368 ? UMAWebBluetoothFunction::GET_PRIMARY_SERVICE | |
| 369 : UMAWebBluetoothFunction::GET_PRIMARY_SERVICES); | |
| 370 RecordGetPrimaryServicesServices(quantity, services_uuid); | 362 RecordGetPrimaryServicesServices(quantity, services_uuid); |
| 371 | 363 |
| 372 if (!allowed_devices().IsAllowedToAccessAtLeastOneService(device_id)) { | 364 if (!allowed_devices().IsAllowedToAccessAtLeastOneService(device_id)) { |
| 373 callback.Run( | 365 callback.Run( |
| 374 blink::mojom::WebBluetoothResult::NOT_ALLOWED_TO_ACCESS_ANY_SERVICE, | 366 blink::mojom::WebBluetoothResult::NOT_ALLOWED_TO_ACCESS_ANY_SERVICE, |
| 375 base::nullopt /* service */); | 367 base::nullopt /* service */); |
| 376 return; | 368 return; |
| 377 } | 369 } |
| 378 | 370 |
| 379 if (services_uuid && | 371 if (services_uuid && |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 base::Unretained(this), device_id, quantity, services_uuid, callback)); | 405 base::Unretained(this), device_id, quantity, services_uuid, callback)); |
| 414 } | 406 } |
| 415 | 407 |
| 416 void WebBluetoothServiceImpl::RemoteServiceGetCharacteristics( | 408 void WebBluetoothServiceImpl::RemoteServiceGetCharacteristics( |
| 417 const std::string& service_instance_id, | 409 const std::string& service_instance_id, |
| 418 blink::mojom::WebBluetoothGATTQueryQuantity quantity, | 410 blink::mojom::WebBluetoothGATTQueryQuantity quantity, |
| 419 const base::Optional<BluetoothUUID>& characteristics_uuid, | 411 const base::Optional<BluetoothUUID>& characteristics_uuid, |
| 420 const RemoteServiceGetCharacteristicsCallback& callback) { | 412 const RemoteServiceGetCharacteristicsCallback& callback) { |
| 421 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 413 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 422 | 414 |
| 423 RecordWebBluetoothFunctionCall( | |
| 424 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE | |
| 425 ? UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTIC | |
| 426 : UMAWebBluetoothFunction::SERVICE_GET_CHARACTERISTICS); | |
| 427 RecordGetCharacteristicsCharacteristic(quantity, characteristics_uuid); | 415 RecordGetCharacteristicsCharacteristic(quantity, characteristics_uuid); |
| 428 | 416 |
| 429 if (characteristics_uuid && | 417 if (characteristics_uuid && |
| 430 BluetoothBlocklist::Get().IsExcluded(characteristics_uuid.value())) { | 418 BluetoothBlocklist::Get().IsExcluded(characteristics_uuid.value())) { |
| 431 RecordGetCharacteristicsOutcome(quantity, | 419 RecordGetCharacteristicsOutcome(quantity, |
| 432 UMAGetCharacteristicOutcome::BLOCKLISTED); | 420 UMAGetCharacteristicOutcome::BLOCKLISTED); |
| 433 callback.Run( | 421 callback.Run( |
| 434 blink::mojom::WebBluetoothResult::BLOCKLISTED_CHARACTERISTIC_UUID, | 422 blink::mojom::WebBluetoothResult::BLOCKLISTED_CHARACTERISTIC_UUID, |
| 435 base::nullopt /* characteristics */); | 423 base::nullopt /* characteristics */); |
| 436 return; | 424 return; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 base::nullopt /* characteristics */); | 489 base::nullopt /* characteristics */); |
| 502 } | 490 } |
| 503 | 491 |
| 504 void WebBluetoothServiceImpl::RemoteCharacteristicGetDescriptors( | 492 void WebBluetoothServiceImpl::RemoteCharacteristicGetDescriptors( |
| 505 const std::string& characteristic_instance_id, | 493 const std::string& characteristic_instance_id, |
| 506 blink::mojom::WebBluetoothGATTQueryQuantity quantity, | 494 blink::mojom::WebBluetoothGATTQueryQuantity quantity, |
| 507 const base::Optional<BluetoothUUID>& descriptors_uuid, | 495 const base::Optional<BluetoothUUID>& descriptors_uuid, |
| 508 const RemoteCharacteristicGetDescriptorsCallback& callback) { | 496 const RemoteCharacteristicGetDescriptorsCallback& callback) { |
| 509 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 497 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 510 | 498 |
| 511 RecordWebBluetoothFunctionCall( | |
| 512 quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE | |
| 513 ? UMAWebBluetoothFunction::CHARACTERISTIC_GET_DESCRIPTOR | |
| 514 : UMAWebBluetoothFunction::CHARACTERISTIC_GET_DESCRIPTORS); | |
| 515 RecordGetDescriptorsDescriptor(quantity, descriptors_uuid); | 499 RecordGetDescriptorsDescriptor(quantity, descriptors_uuid); |
| 516 | 500 |
| 517 if (descriptors_uuid && | 501 if (descriptors_uuid && |
| 518 BluetoothBlocklist::Get().IsExcluded(descriptors_uuid.value())) { | 502 BluetoothBlocklist::Get().IsExcluded(descriptors_uuid.value())) { |
| 519 RecordGetDescriptorsOutcome(quantity, UMAGetDescriptorOutcome::BLOCKLISTED); | 503 RecordGetDescriptorsOutcome(quantity, UMAGetDescriptorOutcome::BLOCKLISTED); |
| 520 callback.Run(blink::mojom::WebBluetoothResult::BLOCKLISTED_DESCRIPTOR_UUID, | 504 callback.Run(blink::mojom::WebBluetoothResult::BLOCKLISTED_DESCRIPTOR_UUID, |
| 521 base::nullopt /* descriptor */); | 505 base::nullopt /* descriptor */); |
| 522 return; | 506 return; |
| 523 } | 507 } |
| 524 | 508 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 callback.Run(descriptors_uuid | 560 callback.Run(descriptors_uuid |
| 577 ? blink::mojom::WebBluetoothResult::DESCRIPTOR_NOT_FOUND | 561 ? blink::mojom::WebBluetoothResult::DESCRIPTOR_NOT_FOUND |
| 578 : blink::mojom::WebBluetoothResult::NO_DESCRIPTORS_FOUND, | 562 : blink::mojom::WebBluetoothResult::NO_DESCRIPTORS_FOUND, |
| 579 base::nullopt /* descriptors */); | 563 base::nullopt /* descriptors */); |
| 580 } | 564 } |
| 581 | 565 |
| 582 void WebBluetoothServiceImpl::RemoteCharacteristicReadValue( | 566 void WebBluetoothServiceImpl::RemoteCharacteristicReadValue( |
| 583 const std::string& characteristic_instance_id, | 567 const std::string& characteristic_instance_id, |
| 584 const RemoteCharacteristicReadValueCallback& callback) { | 568 const RemoteCharacteristicReadValueCallback& callback) { |
| 585 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 569 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 586 RecordWebBluetoothFunctionCall( | |
| 587 UMAWebBluetoothFunction::CHARACTERISTIC_READ_VALUE); | |
| 588 | 570 |
| 589 const CacheQueryResult query_result = | 571 const CacheQueryResult query_result = |
| 590 QueryCacheForCharacteristic(characteristic_instance_id); | 572 QueryCacheForCharacteristic(characteristic_instance_id); |
| 591 | 573 |
| 592 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | 574 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
| 593 return; | 575 return; |
| 594 } | 576 } |
| 595 | 577 |
| 596 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 578 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 597 RecordCharacteristicReadValueOutcome(query_result.outcome); | 579 RecordCharacteristicReadValueOutcome(query_result.outcome); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 612 weak_ptr_factory_.GetWeakPtr(), callback), | 594 weak_ptr_factory_.GetWeakPtr(), callback), |
| 613 base::Bind(&WebBluetoothServiceImpl::OnCharacteristicReadValueFailed, | 595 base::Bind(&WebBluetoothServiceImpl::OnCharacteristicReadValueFailed, |
| 614 weak_ptr_factory_.GetWeakPtr(), callback)); | 596 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 615 } | 597 } |
| 616 | 598 |
| 617 void WebBluetoothServiceImpl::RemoteCharacteristicWriteValue( | 599 void WebBluetoothServiceImpl::RemoteCharacteristicWriteValue( |
| 618 const std::string& characteristic_instance_id, | 600 const std::string& characteristic_instance_id, |
| 619 const std::vector<uint8_t>& value, | 601 const std::vector<uint8_t>& value, |
| 620 const RemoteCharacteristicWriteValueCallback& callback) { | 602 const RemoteCharacteristicWriteValueCallback& callback) { |
| 621 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 603 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 622 RecordWebBluetoothFunctionCall( | |
| 623 UMAWebBluetoothFunction::CHARACTERISTIC_WRITE_VALUE); | |
| 624 | 604 |
| 625 // We perform the length check on the renderer side. So if we | 605 // We perform the length check on the renderer side. So if we |
| 626 // get a value with length > 512, we can assume it's a hostile | 606 // get a value with length > 512, we can assume it's a hostile |
| 627 // renderer and kill it. | 607 // renderer and kill it. |
| 628 if (value.size() > 512) { | 608 if (value.size() > 512) { |
| 629 CrashRendererAndClosePipe(bad_message::BDH_INVALID_WRITE_VALUE_LENGTH); | 609 CrashRendererAndClosePipe(bad_message::BDH_INVALID_WRITE_VALUE_LENGTH); |
| 630 return; | 610 return; |
| 631 } | 611 } |
| 632 | 612 |
| 633 const CacheQueryResult query_result = | 613 const CacheQueryResult query_result = |
| (...skipping 21 matching lines...) Expand all Loading... |
| 655 base::Bind(&WebBluetoothServiceImpl::OnCharacteristicWriteValueSuccess, | 635 base::Bind(&WebBluetoothServiceImpl::OnCharacteristicWriteValueSuccess, |
| 656 weak_ptr_factory_.GetWeakPtr(), callback), | 636 weak_ptr_factory_.GetWeakPtr(), callback), |
| 657 base::Bind(&WebBluetoothServiceImpl::OnCharacteristicWriteValueFailed, | 637 base::Bind(&WebBluetoothServiceImpl::OnCharacteristicWriteValueFailed, |
| 658 weak_ptr_factory_.GetWeakPtr(), callback)); | 638 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 659 } | 639 } |
| 660 | 640 |
| 661 void WebBluetoothServiceImpl::RemoteCharacteristicStartNotifications( | 641 void WebBluetoothServiceImpl::RemoteCharacteristicStartNotifications( |
| 662 const std::string& characteristic_instance_id, | 642 const std::string& characteristic_instance_id, |
| 663 const RemoteCharacteristicStartNotificationsCallback& callback) { | 643 const RemoteCharacteristicStartNotificationsCallback& callback) { |
| 664 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 644 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 665 RecordWebBluetoothFunctionCall( | |
| 666 UMAWebBluetoothFunction::CHARACTERISTIC_START_NOTIFICATIONS); | |
| 667 | 645 |
| 668 auto iter = | 646 auto iter = |
| 669 characteristic_id_to_notify_session_.find(characteristic_instance_id); | 647 characteristic_id_to_notify_session_.find(characteristic_instance_id); |
| 670 if (iter != characteristic_id_to_notify_session_.end() && | 648 if (iter != characteristic_id_to_notify_session_.end() && |
| 671 iter->second->IsActive()) { | 649 iter->second->IsActive()) { |
| 672 // If the frame has already started notifications and the notifications | 650 // If the frame has already started notifications and the notifications |
| 673 // are active we return SUCCESS. | 651 // are active we return SUCCESS. |
| 674 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS); | 652 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS); |
| 675 return; | 653 return; |
| 676 } | 654 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 701 base::Bind(&WebBluetoothServiceImpl::OnStartNotifySessionSuccess, | 679 base::Bind(&WebBluetoothServiceImpl::OnStartNotifySessionSuccess, |
| 702 weak_ptr_factory_.GetWeakPtr(), callback), | 680 weak_ptr_factory_.GetWeakPtr(), callback), |
| 703 base::Bind(&WebBluetoothServiceImpl::OnStartNotifySessionFailed, | 681 base::Bind(&WebBluetoothServiceImpl::OnStartNotifySessionFailed, |
| 704 weak_ptr_factory_.GetWeakPtr(), callback)); | 682 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 705 } | 683 } |
| 706 | 684 |
| 707 void WebBluetoothServiceImpl::RemoteCharacteristicStopNotifications( | 685 void WebBluetoothServiceImpl::RemoteCharacteristicStopNotifications( |
| 708 const std::string& characteristic_instance_id, | 686 const std::string& characteristic_instance_id, |
| 709 const RemoteCharacteristicStopNotificationsCallback& callback) { | 687 const RemoteCharacteristicStopNotificationsCallback& callback) { |
| 710 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 688 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 711 RecordWebBluetoothFunctionCall( | |
| 712 UMAWebBluetoothFunction::CHARACTERISTIC_STOP_NOTIFICATIONS); | |
| 713 | 689 |
| 714 const CacheQueryResult query_result = | 690 const CacheQueryResult query_result = |
| 715 QueryCacheForCharacteristic(characteristic_instance_id); | 691 QueryCacheForCharacteristic(characteristic_instance_id); |
| 716 | 692 |
| 717 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | 693 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
| 718 return; | 694 return; |
| 719 } | 695 } |
| 720 | 696 |
| 721 auto notify_session_iter = | 697 auto notify_session_iter = |
| 722 characteristic_id_to_notify_session_.find(characteristic_instance_id); | 698 characteristic_id_to_notify_session_.find(characteristic_instance_id); |
| 723 if (notify_session_iter == characteristic_id_to_notify_session_.end()) { | 699 if (notify_session_iter == characteristic_id_to_notify_session_.end()) { |
| 724 // If the frame hasn't subscribed to notifications before we just | 700 // If the frame hasn't subscribed to notifications before we just |
| 725 // run the callback. | 701 // run the callback. |
| 726 callback.Run(); | 702 callback.Run(); |
| 727 return; | 703 return; |
| 728 } | 704 } |
| 729 notify_session_iter->second->Stop(base::Bind( | 705 notify_session_iter->second->Stop(base::Bind( |
| 730 &WebBluetoothServiceImpl::OnStopNotifySessionComplete, | 706 &WebBluetoothServiceImpl::OnStopNotifySessionComplete, |
| 731 weak_ptr_factory_.GetWeakPtr(), characteristic_instance_id, callback)); | 707 weak_ptr_factory_.GetWeakPtr(), characteristic_instance_id, callback)); |
| 732 } | 708 } |
| 733 | 709 |
| 734 void WebBluetoothServiceImpl::RemoteDescriptorReadValue( | 710 void WebBluetoothServiceImpl::RemoteDescriptorReadValue( |
| 735 const std::string& descriptor_instance_id, | 711 const std::string& descriptor_instance_id, |
| 736 const RemoteDescriptorReadValueCallback& callback) { | 712 const RemoteDescriptorReadValueCallback& callback) { |
| 737 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 713 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 738 RecordWebBluetoothFunctionCall( | |
| 739 UMAWebBluetoothFunction::DESCRIPTOR_READ_VALUE); | |
| 740 | 714 |
| 741 const CacheQueryResult query_result = | 715 const CacheQueryResult query_result = |
| 742 QueryCacheForDescriptor(descriptor_instance_id); | 716 QueryCacheForDescriptor(descriptor_instance_id); |
| 743 | 717 |
| 744 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { | 718 if (query_result.outcome == CacheQueryOutcome::BAD_RENDERER) { |
| 745 return; | 719 return; |
| 746 } | 720 } |
| 747 | 721 |
| 748 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 722 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
| 749 RecordDescriptorReadValueOutcome(query_result.outcome); | 723 RecordDescriptorReadValueOutcome(query_result.outcome); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 764 weak_ptr_factory_.GetWeakPtr(), callback), | 738 weak_ptr_factory_.GetWeakPtr(), callback), |
| 765 base::Bind(&WebBluetoothServiceImpl::OnDescriptorReadValueFailed, | 739 base::Bind(&WebBluetoothServiceImpl::OnDescriptorReadValueFailed, |
| 766 weak_ptr_factory_.GetWeakPtr(), callback)); | 740 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 767 } | 741 } |
| 768 | 742 |
| 769 void WebBluetoothServiceImpl::RemoteDescriptorWriteValue( | 743 void WebBluetoothServiceImpl::RemoteDescriptorWriteValue( |
| 770 const std::string& descriptor_instance_id, | 744 const std::string& descriptor_instance_id, |
| 771 const std::vector<uint8_t>& value, | 745 const std::vector<uint8_t>& value, |
| 772 const RemoteDescriptorWriteValueCallback& callback) { | 746 const RemoteDescriptorWriteValueCallback& callback) { |
| 773 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 747 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 774 RecordWebBluetoothFunctionCall( | |
| 775 UMAWebBluetoothFunction::DESCRIPTOR_WRITE_VALUE); | |
| 776 | 748 |
| 777 // We perform the length check on the renderer side. So if we | 749 // We perform the length check on the renderer side. So if we |
| 778 // get a value with length > 512, we can assume it's a hostile | 750 // get a value with length > 512, we can assume it's a hostile |
| 779 // renderer and kill it. | 751 // renderer and kill it. |
| 780 if (value.size() > 512) { | 752 if (value.size() > 512) { |
| 781 CrashRendererAndClosePipe(bad_message::BDH_INVALID_WRITE_VALUE_LENGTH); | 753 CrashRendererAndClosePipe(bad_message::BDH_INVALID_WRITE_VALUE_LENGTH); |
| 782 return; | 754 return; |
| 783 } | 755 } |
| 784 | 756 |
| 785 const CacheQueryResult query_result = | 757 const CacheQueryResult query_result = |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1186 descriptor_id_to_characteristic_id_.clear(); | 1158 descriptor_id_to_characteristic_id_.clear(); |
| 1187 characteristic_id_to_service_id_.clear(); | 1159 characteristic_id_to_service_id_.clear(); |
| 1188 service_id_to_device_address_.clear(); | 1160 service_id_to_device_address_.clear(); |
| 1189 connected_devices_.reset( | 1161 connected_devices_.reset( |
| 1190 new FrameConnectedBluetoothDevices(render_frame_host_)); | 1162 new FrameConnectedBluetoothDevices(render_frame_host_)); |
| 1191 device_chooser_controller_.reset(); | 1163 device_chooser_controller_.reset(); |
| 1192 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); | 1164 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); |
| 1193 } | 1165 } |
| 1194 | 1166 |
| 1195 } // namespace content | 1167 } // namespace content |
| OLD | NEW |