OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // BluetoothDispatcherHost map [service_to_device_, characteristic_to_service_, | 7 // BluetoothDispatcherHost map [service_to_device_, characteristic_to_service_, |
8 // descriptor_to_characteristic_] implies a hostile renderer because a renderer | 8 // descriptor_to_characteristic_] implies a hostile renderer because a renderer |
9 // obtains the corresponding ID from this class and it will be added to the map | 9 // obtains the corresponding ID from this class and it will be added to the map |
10 // at that time. | 10 // at that time. |
11 | 11 |
12 #include "content/browser/bluetooth/bluetooth_dispatcher_host.h" | 12 #include "content/browser/bluetooth/bluetooth_dispatcher_host.h" |
13 | 13 |
14 #include <stddef.h> | 14 #include <stddef.h> |
15 | 15 |
16 #include <utility> | 16 #include <utility> |
17 | 17 |
18 #include "base/bind.h" | 18 #include "base/bind.h" |
19 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
21 #include "base/thread_task_runner_handle.h" | 21 #include "base/thread_task_runner_handle.h" |
22 #include "content/browser/bad_message.h" | 22 #include "content/browser/bad_message.h" |
23 #include "content/browser/bluetooth/bluetooth_blacklist.h" | 23 #include "content/browser/bluetooth/bluetooth_blacklist.h" |
24 #include "content/browser/bluetooth/bluetooth_metrics.h" | 24 #include "content/browser/bluetooth/bluetooth_metrics.h" |
25 #include "content/browser/bluetooth/first_device_bluetooth_chooser.h" | 25 #include "content/browser/bluetooth/first_device_bluetooth_chooser.h" |
26 #include "content/browser/frame_host/render_frame_host_impl.h" | 26 #include "content/browser/frame_host/render_frame_host_impl.h" |
27 #include "content/common/bluetooth/bluetooth_messages.h" | 27 #include "content/common/bluetooth/bluetooth_messages.h" |
| 28 #include "content/public/browser/browser_context.h" |
| 29 #include "content/public/browser/permission_manager.h" |
| 30 #include "content/public/browser/permission_type.h" |
28 #include "content/public/browser/web_contents.h" | 31 #include "content/public/browser/web_contents.h" |
29 #include "content/public/browser/web_contents_delegate.h" | 32 #include "content/public/browser/web_contents_delegate.h" |
30 #include "device/bluetooth/bluetooth_adapter.h" | 33 #include "device/bluetooth/bluetooth_adapter.h" |
31 #include "device/bluetooth/bluetooth_adapter_factory.h" | 34 #include "device/bluetooth/bluetooth_adapter_factory.h" |
32 #include "device/bluetooth/bluetooth_device.h" | 35 #include "device/bluetooth/bluetooth_device.h" |
33 #include "device/bluetooth/bluetooth_discovery_session.h" | 36 #include "device/bluetooth/bluetooth_discovery_session.h" |
34 #include "device/bluetooth/bluetooth_gatt_characteristic.h" | 37 #include "device/bluetooth/bluetooth_gatt_characteristic.h" |
35 #include "device/bluetooth/bluetooth_gatt_service.h" | 38 #include "device/bluetooth/bluetooth_gatt_service.h" |
36 | 39 |
37 using blink::WebBluetoothError; | 40 using blink::WebBluetoothError; |
(...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 WebBluetoothError::RequestDeviceWithBlacklistedUUID)); | 1020 WebBluetoothError::RequestDeviceWithBlacklistedUUID)); |
1018 return; | 1021 return; |
1019 } | 1022 } |
1020 std::vector<BluetoothUUID> optional_services_blacklist_filtered( | 1023 std::vector<BluetoothUUID> optional_services_blacklist_filtered( |
1021 optional_services); | 1024 optional_services); |
1022 BluetoothBlacklist::Get().RemoveExcludedUuids( | 1025 BluetoothBlacklist::Get().RemoveExcludedUuids( |
1023 &optional_services_blacklist_filtered); | 1026 &optional_services_blacklist_filtered); |
1024 | 1027 |
1025 RenderFrameHostImpl* render_frame_host = | 1028 RenderFrameHostImpl* render_frame_host = |
1026 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id); | 1029 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id); |
| 1030 WebContents* web_contents = |
| 1031 WebContents::FromRenderFrameHost(render_frame_host); |
1027 | 1032 |
1028 if (!render_frame_host) { | 1033 if (!render_frame_host || !web_contents) { |
1029 DLOG(WARNING) | 1034 DLOG(WARNING) << "Got a requestDevice IPC without a matching " |
1030 << "Got a requestDevice IPC without a matching RenderFrameHost: " | 1035 << "RenderFrameHost or WebContents: " << render_process_id_ |
1031 << render_process_id_ << ", " << frame_routing_id; | 1036 << ", " << frame_routing_id; |
1032 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_RENDER_FRAME); | 1037 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_RENDER_FRAME); |
1033 Send(new BluetoothMsg_RequestDeviceError( | 1038 Send(new BluetoothMsg_RequestDeviceError( |
1034 thread_id, request_id, WebBluetoothError::RequestDeviceWithoutFrame)); | 1039 thread_id, request_id, WebBluetoothError::RequestDeviceWithoutFrame)); |
1035 return; | 1040 return; |
1036 } | 1041 } |
1037 | 1042 |
1038 if (render_frame_host->GetLastCommittedOrigin().unique()) { | 1043 const url::Origin requesting_origin = |
| 1044 render_frame_host->GetLastCommittedOrigin(); |
| 1045 const url::Origin embedding_origin = |
| 1046 web_contents->GetMainFrame()->GetLastCommittedOrigin(); |
| 1047 |
| 1048 if (requesting_origin.unique()) { |
1039 VLOG(1) << "Request device with unique origin."; | 1049 VLOG(1) << "Request device with unique origin."; |
1040 Send(new BluetoothMsg_RequestDeviceError( | 1050 Send(new BluetoothMsg_RequestDeviceError( |
1041 thread_id, request_id, | 1051 thread_id, request_id, |
1042 WebBluetoothError::RequestDeviceWithUniqueOrigin)); | 1052 WebBluetoothError::RequestDeviceWithUniqueOrigin)); |
1043 return; | 1053 return; |
1044 } | 1054 } |
1045 | 1055 |
1046 DCHECK(adapter_.get()); | 1056 DCHECK(adapter_.get()); |
1047 | 1057 |
1048 if (!adapter_->IsPresent()) { | 1058 if (!adapter_->IsPresent()) { |
1049 VLOG(1) << "Bluetooth Adapter not present. Can't serve requestDevice."; | 1059 VLOG(1) << "Bluetooth Adapter not present. Can't serve requestDevice."; |
1050 RecordRequestDeviceOutcome( | 1060 RecordRequestDeviceOutcome( |
1051 UMARequestDeviceOutcome::BLUETOOTH_ADAPTER_NOT_PRESENT); | 1061 UMARequestDeviceOutcome::BLUETOOTH_ADAPTER_NOT_PRESENT); |
1052 Send(new BluetoothMsg_RequestDeviceError( | 1062 Send(new BluetoothMsg_RequestDeviceError( |
1053 thread_id, request_id, WebBluetoothError::NoBluetoothAdapter)); | 1063 thread_id, request_id, WebBluetoothError::NoBluetoothAdapter)); |
1054 return; | 1064 return; |
1055 } | 1065 } |
1056 | 1066 |
1057 // The renderer should never send empty filters. | 1067 // The renderer should never send empty filters. |
1058 if (HasEmptyOrInvalidFilter(filters)) { | 1068 if (HasEmptyOrInvalidFilter(filters)) { |
1059 bad_message::ReceivedBadMessage(this, | 1069 bad_message::ReceivedBadMessage(this, |
1060 bad_message::BDH_EMPTY_OR_INVALID_FILTERS); | 1070 bad_message::BDH_EMPTY_OR_INVALID_FILTERS); |
1061 return; | 1071 return; |
1062 } | 1072 } |
1063 | 1073 |
| 1074 if (web_contents->GetBrowserContext() |
| 1075 ->GetPermissionManager() |
| 1076 ->GetPermissionStatus(PermissionType::BLUETOOTH_GUARD, |
| 1077 GURL(requesting_origin.Serialize()), |
| 1078 GURL(embedding_origin.Serialize())) != |
| 1079 PermissionStatus::ASK) { |
| 1080 RecordRequestDeviceOutcome( |
| 1081 UMARequestDeviceOutcome::BLUETOOTH_CHOOSER_GLOBALLY_DISABLED); |
| 1082 Send(new BluetoothMsg_RequestDeviceError( |
| 1083 thread_id, request_id, WebBluetoothError::ChooserDisabled)); |
| 1084 return; |
| 1085 } |
| 1086 |
1064 // Create storage for the information that backs the chooser, and show the | 1087 // Create storage for the information that backs the chooser, and show the |
1065 // chooser. | 1088 // chooser. |
1066 RequestDeviceSession* const session = new RequestDeviceSession( | 1089 RequestDeviceSession* const session = |
1067 thread_id, request_id, render_frame_host->GetLastCommittedOrigin(), | 1090 new RequestDeviceSession(thread_id, request_id, requesting_origin, |
1068 filters, optional_services_blacklist_filtered); | 1091 filters, optional_services_blacklist_filtered); |
1069 int chooser_id = request_device_sessions_.Add(session); | 1092 int chooser_id = request_device_sessions_.Add(session); |
1070 | 1093 |
1071 BluetoothChooser::EventHandler chooser_event_handler = | 1094 BluetoothChooser::EventHandler chooser_event_handler = |
1072 base::Bind(&BluetoothDispatcherHost::OnBluetoothChooserEvent, | 1095 base::Bind(&BluetoothDispatcherHost::OnBluetoothChooserEvent, |
1073 weak_ptr_on_ui_thread_, chooser_id); | 1096 weak_ptr_on_ui_thread_, chooser_id); |
1074 if (WebContents* web_contents = | 1097 if (WebContentsDelegate* delegate = web_contents->GetDelegate()) { |
1075 WebContents::FromRenderFrameHost(render_frame_host)) { | 1098 session->chooser = |
1076 if (WebContentsDelegate* delegate = web_contents->GetDelegate()) { | 1099 delegate->RunBluetoothChooser(render_frame_host, chooser_event_handler); |
1077 session->chooser = delegate->RunBluetoothChooser(render_frame_host, | |
1078 chooser_event_handler); | |
1079 } | |
1080 } | 1100 } |
1081 if (!session->chooser) { | 1101 if (!session->chooser) { |
1082 LOG(WARNING) | 1102 LOG(WARNING) |
1083 << "No Bluetooth chooser implementation; falling back to first device."; | 1103 << "No Bluetooth chooser implementation; falling back to first device."; |
1084 session->chooser.reset( | 1104 session->chooser.reset( |
1085 new FirstDeviceBluetoothChooser(chooser_event_handler)); | 1105 new FirstDeviceBluetoothChooser(chooser_event_handler)); |
1086 } | 1106 } |
1087 | 1107 |
1088 if (!session->chooser->CanAskForScanningPermission()) { | 1108 if (!session->chooser->CanAskForScanningPermission()) { |
1089 VLOG(1) << "Closing immediately because Chooser cannot obtain permission."; | 1109 VLOG(1) << "Closing immediately because Chooser cannot obtain permission."; |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1514 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1534 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1515 NOTIMPLEMENTED(); | 1535 NOTIMPLEMENTED(); |
1516 } | 1536 } |
1517 | 1537 |
1518 void BluetoothDispatcherHost::ShowNeedLocationLink() { | 1538 void BluetoothDispatcherHost::ShowNeedLocationLink() { |
1519 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1539 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
1520 NOTIMPLEMENTED(); | 1540 NOTIMPLEMENTED(); |
1521 } | 1541 } |
1522 | 1542 |
1523 } // namespace content | 1543 } // namespace content |
OLD | NEW |