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; |
| 31 |
30 namespace content { | 32 namespace content { |
31 | 33 |
32 namespace { | 34 namespace { |
33 | 35 |
34 blink::mojom::WebBluetoothError TranslateConnectErrorAndRecord( | 36 blink::mojom::WebBluetoothError TranslateConnectErrorAndRecord( |
35 device::BluetoothDevice::ConnectErrorCode error_code) { | 37 device::BluetoothDevice::ConnectErrorCode error_code) { |
36 switch (error_code) { | 38 switch (error_code) { |
37 case device::BluetoothDevice::ERROR_UNKNOWN: | 39 case device::BluetoothDevice::ERROR_UNKNOWN: |
38 RecordConnectGATTOutcome(UMAConnectGATTOutcome::UNKNOWN); | 40 RecordConnectGATTOutcome(UMAConnectGATTOutcome::UNKNOWN); |
39 return blink::mojom::WebBluetoothError::CONNECT_UNKNOWN_ERROR; | 41 return blink::mojom::WebBluetoothError::CONNECT_UNKNOWN_ERROR; |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 client_.Bind(std::move(client)); | 291 client_.Bind(std::move(client)); |
290 } | 292 } |
291 | 293 |
292 void WebBluetoothServiceImpl::RequestDevice( | 294 void WebBluetoothServiceImpl::RequestDevice( |
293 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, | 295 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, |
294 const RequestDeviceCallback& callback) { | 296 const RequestDeviceCallback& callback) { |
295 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE); | 297 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE); |
296 RecordRequestDeviceOptions(options); | 298 RecordRequestDeviceOptions(options); |
297 | 299 |
298 if (!GetAdapter()) { | 300 if (!GetAdapter()) { |
299 if (GetBluetoothAdapterFactoryWrapper()->IsBluetoothAdapterAvailable()) { | 301 if (BluetoothAdapterFactoryWrapper::Get().IsBluetoothAdapterAvailable()) { |
300 GetBluetoothAdapterFactoryWrapper()->AcquireAdapter( | 302 BluetoothAdapterFactoryWrapper::Get().AcquireAdapter( |
301 this, base::Bind(&WebBluetoothServiceImpl::RequestDeviceImpl, | 303 this, base::Bind(&WebBluetoothServiceImpl::RequestDeviceImpl, |
302 weak_ptr_factory_.GetWeakPtr(), | 304 weak_ptr_factory_.GetWeakPtr(), |
303 base::Passed(std::move(options)), callback)); | 305 base::Passed(std::move(options)), callback)); |
304 return; | 306 return; |
305 } | 307 } |
306 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_BLUETOOTH_ADAPTER); | 308 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_BLUETOOTH_ADAPTER); |
307 callback.Run(blink::mojom::WebBluetoothError::NO_BLUETOOTH_ADAPTER, | 309 callback.Run(blink::mojom::WebBluetoothError::NO_BLUETOOTH_ADAPTER, |
308 nullptr /* device */); | 310 nullptr /* device */); |
309 return; | 311 return; |
310 } | 312 } |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 | 650 |
649 void WebBluetoothServiceImpl::RequestDeviceImpl( | 651 void WebBluetoothServiceImpl::RequestDeviceImpl( |
650 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, | 652 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, |
651 const RequestDeviceCallback& callback, | 653 const RequestDeviceCallback& callback, |
652 device::BluetoothAdapter* adapter) { | 654 device::BluetoothAdapter* adapter) { |
653 // requestDevice() can only be called when processing a user-gesture and | 655 // requestDevice() can only be called when processing a user-gesture and |
654 // any user gesture outside of a chooser should close the chooser so we should | 656 // any user gesture outside of a chooser should close the chooser so we should |
655 // never get a request with an open chooser. | 657 // never get a request with an open chooser. |
656 CHECK(!device_chooser_controller_.get()); | 658 CHECK(!device_chooser_controller_.get()); |
657 | 659 |
658 device_chooser_controller_.reset(new BluetoothDeviceChooserController( | 660 device_chooser_controller_.reset( |
659 this, render_frame_host_, adapter, | 661 new BluetoothDeviceChooserController(this, render_frame_host_, adapter)); |
660 GetBluetoothAdapterFactoryWrapper()->GetScanDuration())); | |
661 | 662 |
662 device_chooser_controller_->GetDevice( | 663 device_chooser_controller_->GetDevice( |
663 std::move(options), | 664 std::move(options), |
664 base::Bind(&WebBluetoothServiceImpl::OnGetDeviceSuccess, | 665 base::Bind(&WebBluetoothServiceImpl::OnGetDeviceSuccess, |
665 weak_ptr_factory_.GetWeakPtr(), callback), | 666 weak_ptr_factory_.GetWeakPtr(), callback), |
666 base::Bind(&WebBluetoothServiceImpl::OnGetDeviceFailed, | 667 base::Bind(&WebBluetoothServiceImpl::OnGetDeviceFailed, |
667 weak_ptr_factory_.GetWeakPtr(), callback)); | 668 weak_ptr_factory_.GetWeakPtr(), callback)); |
668 } | 669 } |
669 | 670 |
670 void WebBluetoothServiceImpl::RemoteServerGetPrimaryServiceImpl( | 671 void WebBluetoothServiceImpl::RemoteServerGetPrimaryServiceImpl( |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
919 result.outcome = CacheQueryOutcome::NO_CHARACTERISTIC; | 920 result.outcome = CacheQueryOutcome::NO_CHARACTERISTIC; |
920 } | 921 } |
921 | 922 |
922 return result; | 923 return result; |
923 } | 924 } |
924 | 925 |
925 RenderProcessHost* WebBluetoothServiceImpl::GetRenderProcessHost() { | 926 RenderProcessHost* WebBluetoothServiceImpl::GetRenderProcessHost() { |
926 return render_frame_host_->GetProcess(); | 927 return render_frame_host_->GetProcess(); |
927 } | 928 } |
928 | 929 |
929 BluetoothAdapterFactoryWrapper* | |
930 WebBluetoothServiceImpl::GetBluetoothAdapterFactoryWrapper() { | |
931 RenderProcessHostImpl* render_process_host_impl = | |
932 static_cast<RenderProcessHostImpl*>(GetRenderProcessHost()); | |
933 return render_process_host_impl->GetBluetoothAdapterFactoryWrapper(); | |
934 } | |
935 | |
936 device::BluetoothAdapter* WebBluetoothServiceImpl::GetAdapter() { | 930 device::BluetoothAdapter* WebBluetoothServiceImpl::GetAdapter() { |
937 return GetBluetoothAdapterFactoryWrapper()->GetAdapter(this); | 931 return BluetoothAdapterFactoryWrapper::Get().GetAdapter(this); |
938 } | 932 } |
939 | 933 |
940 void WebBluetoothServiceImpl::CrashRendererAndClosePipe( | 934 void WebBluetoothServiceImpl::CrashRendererAndClosePipe( |
941 bad_message::BadMessageReason reason) { | 935 bad_message::BadMessageReason reason) { |
942 bad_message::ReceivedBadMessage(GetRenderProcessHost(), reason); | 936 bad_message::ReceivedBadMessage(GetRenderProcessHost(), reason); |
943 binding_.Close(); | 937 binding_.Close(); |
944 } | 938 } |
945 | 939 |
946 url::Origin WebBluetoothServiceImpl::GetOrigin() { | 940 url::Origin WebBluetoothServiceImpl::GetOrigin() { |
947 return render_frame_host_->GetLastCommittedOrigin(); | 941 return render_frame_host_->GetLastCommittedOrigin(); |
948 } | 942 } |
949 | 943 |
950 void WebBluetoothServiceImpl::ClearState() { | 944 void WebBluetoothServiceImpl::ClearState() { |
951 characteristic_id_to_notify_session_.clear(); | 945 characteristic_id_to_notify_session_.clear(); |
952 pending_primary_services_requests_.clear(); | 946 pending_primary_services_requests_.clear(); |
953 characteristic_id_to_service_id_.clear(); | 947 characteristic_id_to_service_id_.clear(); |
954 service_id_to_device_address_.clear(); | 948 service_id_to_device_address_.clear(); |
955 connected_devices_.reset( | 949 connected_devices_.reset( |
956 new FrameConnectedBluetoothDevices(render_frame_host_)); | 950 new FrameConnectedBluetoothDevices(render_frame_host_)); |
957 allowed_devices_map_ = BluetoothAllowedDevicesMap(); | 951 allowed_devices_map_ = BluetoothAllowedDevicesMap(); |
958 device_chooser_controller_.reset(); | 952 device_chooser_controller_.reset(); |
959 GetBluetoothAdapterFactoryWrapper()->ReleaseAdapter(this); | 953 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); |
960 } | 954 } |
961 | 955 |
962 } // namespace content | 956 } // namespace content |
OLD | NEW |