| 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_adapter_factory_wrapper.h" | |
| 19 #include "content/browser/bluetooth/bluetooth_blacklist.h" | 18 #include "content/browser/bluetooth/bluetooth_blacklist.h" |
| 20 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h" | 19 #include "content/browser/bluetooth/bluetooth_device_chooser_controller.h" |
| 21 #include "content/browser/bluetooth/bluetooth_metrics.h" | 20 #include "content/browser/bluetooth/bluetooth_metrics.h" |
| 22 #include "content/browser/bluetooth/frame_connected_bluetooth_devices.h" | 21 #include "content/browser/bluetooth/frame_connected_bluetooth_devices.h" |
| 23 #include "content/browser/renderer_host/render_process_host_impl.h" | 22 #include "content/browser/renderer_host/render_process_host_impl.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" |
| 27 #include "device/bluetooth/bluetooth_adapter_factory_wrapper.h" |
| 28 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" | 28 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" |
| 29 | 29 |
| 30 using device::BluetoothAdapterFactoryWrapper; |
| 30 using device::BluetoothUUID; | 31 using device::BluetoothUUID; |
| 31 | 32 |
| 32 namespace content { | 33 namespace content { |
| 33 | 34 |
| 34 namespace { | 35 namespace { |
| 35 | 36 |
| 36 blink::mojom::WebBluetoothError TranslateConnectErrorAndRecord( | 37 blink::mojom::WebBluetoothError TranslateConnectErrorAndRecord( |
| 37 device::BluetoothDevice::ConnectErrorCode error_code) { | 38 device::BluetoothDevice::ConnectErrorCode error_code) { |
| 38 switch (error_code) { | 39 switch (error_code) { |
| 39 case device::BluetoothDevice::ERROR_UNKNOWN: | 40 case device::BluetoothDevice::ERROR_UNKNOWN: |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 client_.Bind(std::move(client)); | 308 client_.Bind(std::move(client)); |
| 308 } | 309 } |
| 309 | 310 |
| 310 void WebBluetoothServiceImpl::RequestDevice( | 311 void WebBluetoothServiceImpl::RequestDevice( |
| 311 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, | 312 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, |
| 312 const RequestDeviceCallback& callback) { | 313 const RequestDeviceCallback& callback) { |
| 313 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE); | 314 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE); |
| 314 RecordRequestDeviceOptions(options); | 315 RecordRequestDeviceOptions(options); |
| 315 | 316 |
| 316 if (!GetAdapter()) { | 317 if (!GetAdapter()) { |
| 317 if (GetBluetoothAdapterFactoryWrapper()->IsBluetoothAdapterAvailable()) { | 318 if (BluetoothAdapterFactoryWrapper::Get().IsBluetoothAdapterAvailable()) { |
| 318 GetBluetoothAdapterFactoryWrapper()->AcquireAdapter( | 319 BluetoothAdapterFactoryWrapper::Get().AcquireAdapter( |
| 319 this, base::Bind(&WebBluetoothServiceImpl::RequestDeviceImpl, | 320 this, base::Bind(&WebBluetoothServiceImpl::RequestDeviceImpl, |
| 320 weak_ptr_factory_.GetWeakPtr(), | 321 weak_ptr_factory_.GetWeakPtr(), |
| 321 base::Passed(std::move(options)), callback)); | 322 base::Passed(std::move(options)), callback)); |
| 322 return; | 323 return; |
| 323 } | 324 } |
| 324 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_BLUETOOTH_ADAPTER); | 325 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_BLUETOOTH_ADAPTER); |
| 325 callback.Run(blink::mojom::WebBluetoothError::NO_BLUETOOTH_ADAPTER, | 326 callback.Run(blink::mojom::WebBluetoothError::NO_BLUETOOTH_ADAPTER, |
| 326 nullptr /* device */); | 327 nullptr /* device */); |
| 327 return; | 328 return; |
| 328 } | 329 } |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, | 672 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, |
| 672 const RequestDeviceCallback& callback, | 673 const RequestDeviceCallback& callback, |
| 673 device::BluetoothAdapter* adapter) { | 674 device::BluetoothAdapter* adapter) { |
| 674 // requestDevice() can only be called when processing a user-gesture and any | 675 // requestDevice() can only be called when processing a user-gesture and any |
| 675 // user gesture outside of a chooser should close the chooser. This does | 676 // user gesture outside of a chooser should close the chooser. This does |
| 676 // not happen on all platforms so we don't DCHECK that the old one is closed. | 677 // not happen on all platforms so we don't DCHECK that the old one is closed. |
| 677 // We destroy the old chooser before constructing the new one to make sure | 678 // We destroy the old chooser before constructing the new one to make sure |
| 678 // they can't conflict. | 679 // they can't conflict. |
| 679 device_chooser_controller_.reset(); | 680 device_chooser_controller_.reset(); |
| 680 | 681 |
| 681 device_chooser_controller_.reset(new BluetoothDeviceChooserController( | 682 device_chooser_controller_.reset( |
| 682 this, render_frame_host_, adapter, | 683 new BluetoothDeviceChooserController(this, render_frame_host_, adapter)); |
| 683 GetBluetoothAdapterFactoryWrapper()->GetScanDuration())); | |
| 684 | 684 |
| 685 device_chooser_controller_->GetDevice( | 685 device_chooser_controller_->GetDevice( |
| 686 std::move(options), | 686 std::move(options), |
| 687 base::Bind(&WebBluetoothServiceImpl::OnGetDeviceSuccess, | 687 base::Bind(&WebBluetoothServiceImpl::OnGetDeviceSuccess, |
| 688 weak_ptr_factory_.GetWeakPtr(), callback), | 688 weak_ptr_factory_.GetWeakPtr(), callback), |
| 689 base::Bind(&WebBluetoothServiceImpl::OnGetDeviceFailed, | 689 base::Bind(&WebBluetoothServiceImpl::OnGetDeviceFailed, |
| 690 weak_ptr_factory_.GetWeakPtr(), callback)); | 690 weak_ptr_factory_.GetWeakPtr(), callback)); |
| 691 } | 691 } |
| 692 | 692 |
| 693 void WebBluetoothServiceImpl::RemoteServerGetPrimaryServicesImpl( | 693 void WebBluetoothServiceImpl::RemoteServerGetPrimaryServicesImpl( |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 result.outcome = CacheQueryOutcome::NO_CHARACTERISTIC; | 963 result.outcome = CacheQueryOutcome::NO_CHARACTERISTIC; |
| 964 } | 964 } |
| 965 | 965 |
| 966 return result; | 966 return result; |
| 967 } | 967 } |
| 968 | 968 |
| 969 RenderProcessHost* WebBluetoothServiceImpl::GetRenderProcessHost() { | 969 RenderProcessHost* WebBluetoothServiceImpl::GetRenderProcessHost() { |
| 970 return render_frame_host_->GetProcess(); | 970 return render_frame_host_->GetProcess(); |
| 971 } | 971 } |
| 972 | 972 |
| 973 BluetoothAdapterFactoryWrapper* | |
| 974 WebBluetoothServiceImpl::GetBluetoothAdapterFactoryWrapper() { | |
| 975 RenderProcessHostImpl* render_process_host_impl = | |
| 976 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost()); | |
| 977 return render_process_host_impl->GetBluetoothAdapterFactoryWrapper(); | |
| 978 } | |
| 979 | |
| 980 device::BluetoothAdapter* WebBluetoothServiceImpl::GetAdapter() { | 973 device::BluetoothAdapter* WebBluetoothServiceImpl::GetAdapter() { |
| 981 return GetBluetoothAdapterFactoryWrapper()->GetAdapter(this); | 974 return BluetoothAdapterFactoryWrapper::Get().GetAdapter(this); |
| 982 } | 975 } |
| 983 | 976 |
| 984 void WebBluetoothServiceImpl::CrashRendererAndClosePipe( | 977 void WebBluetoothServiceImpl::CrashRendererAndClosePipe( |
| 985 bad_message::BadMessageReason reason) { | 978 bad_message::BadMessageReason reason) { |
| 986 bad_message::ReceivedBadMessage(GetRenderProcessHost(), reason); | 979 bad_message::ReceivedBadMessage(GetRenderProcessHost(), reason); |
| 987 binding_.Close(); | 980 binding_.Close(); |
| 988 } | 981 } |
| 989 | 982 |
| 990 url::Origin WebBluetoothServiceImpl::GetOrigin() { | 983 url::Origin WebBluetoothServiceImpl::GetOrigin() { |
| 991 return render_frame_host_->GetLastCommittedOrigin(); | 984 return render_frame_host_->GetLastCommittedOrigin(); |
| 992 } | 985 } |
| 993 | 986 |
| 994 void WebBluetoothServiceImpl::ClearState() { | 987 void WebBluetoothServiceImpl::ClearState() { |
| 995 characteristic_id_to_notify_session_.clear(); | 988 characteristic_id_to_notify_session_.clear(); |
| 996 pending_primary_services_requests_.clear(); | 989 pending_primary_services_requests_.clear(); |
| 997 characteristic_id_to_service_id_.clear(); | 990 characteristic_id_to_service_id_.clear(); |
| 998 service_id_to_device_address_.clear(); | 991 service_id_to_device_address_.clear(); |
| 999 connected_devices_.reset( | 992 connected_devices_.reset( |
| 1000 new FrameConnectedBluetoothDevices(render_frame_host_)); | 993 new FrameConnectedBluetoothDevices(render_frame_host_)); |
| 1001 allowed_devices_map_ = BluetoothAllowedDevicesMap(); | 994 allowed_devices_map_ = BluetoothAllowedDevicesMap(); |
| 1002 device_chooser_controller_.reset(); | 995 device_chooser_controller_.reset(); |
| 1003 GetBluetoothAdapterFactoryWrapper()->ReleaseAdapter(this); | 996 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); |
| 1004 } | 997 } |
| 1005 | 998 |
| 1006 } // namespace content | 999 } // namespace content |
| OLD | NEW |