Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: content/browser/bluetooth/bluetooth_dispatcher_host.cc

Issue 1706503002: Add enterprise policy to turn off Bluetooth. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Fix nits Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/content_browser_client.h"
28 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
29 #include "content/public/browser/web_contents_delegate.h" 30 #include "content/public/browser/web_contents_delegate.h"
30 #include "device/bluetooth/bluetooth_adapter.h" 31 #include "device/bluetooth/bluetooth_adapter.h"
31 #include "device/bluetooth/bluetooth_adapter_factory.h" 32 #include "device/bluetooth/bluetooth_adapter_factory.h"
32 #include "device/bluetooth/bluetooth_device.h" 33 #include "device/bluetooth/bluetooth_device.h"
33 #include "device/bluetooth/bluetooth_discovery_session.h" 34 #include "device/bluetooth/bluetooth_discovery_session.h"
34 #include "device/bluetooth/bluetooth_gatt_characteristic.h" 35 #include "device/bluetooth/bluetooth_gatt_characteristic.h"
35 #include "device/bluetooth/bluetooth_gatt_service.h" 36 #include "device/bluetooth/bluetooth_gatt_service.h"
36 37
37 using blink::WebBluetoothError; 38 using blink::WebBluetoothError;
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 WebBluetoothError::RequestDeviceWithBlacklistedUUID)); 1059 WebBluetoothError::RequestDeviceWithBlacklistedUUID));
1059 return; 1060 return;
1060 } 1061 }
1061 std::vector<BluetoothUUID> optional_services_blacklist_filtered( 1062 std::vector<BluetoothUUID> optional_services_blacklist_filtered(
1062 optional_services); 1063 optional_services);
1063 BluetoothBlacklist::Get().RemoveExcludedUuids( 1064 BluetoothBlacklist::Get().RemoveExcludedUuids(
1064 &optional_services_blacklist_filtered); 1065 &optional_services_blacklist_filtered);
1065 1066
1066 RenderFrameHostImpl* render_frame_host = 1067 RenderFrameHostImpl* render_frame_host =
1067 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id); 1068 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id);
1069 WebContents* web_contents =
1070 WebContents::FromRenderFrameHost(render_frame_host);
1068 1071
1069 if (!render_frame_host) { 1072 if (!render_frame_host || !web_contents) {
1070 DLOG(WARNING) 1073 DLOG(WARNING) << "Got a requestDevice IPC without a matching "
1071 << "Got a requestDevice IPC without a matching RenderFrameHost: " 1074 << "RenderFrameHost or WebContents: " << render_process_id_
1072 << render_process_id_ << ", " << frame_routing_id; 1075 << ", " << frame_routing_id;
1073 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_RENDER_FRAME); 1076 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_RENDER_FRAME);
1074 Send(new BluetoothMsg_RequestDeviceError( 1077 Send(new BluetoothMsg_RequestDeviceError(
1075 thread_id, request_id, WebBluetoothError::RequestDeviceWithoutFrame)); 1078 thread_id, request_id, WebBluetoothError::RequestDeviceWithoutFrame));
1076 return; 1079 return;
1077 } 1080 }
1078 1081
1079 if (render_frame_host->GetLastCommittedOrigin().unique()) { 1082 const url::Origin requesting_origin =
1083 render_frame_host->GetLastCommittedOrigin();
1084 const url::Origin embedding_origin =
1085 web_contents->GetMainFrame()->GetLastCommittedOrigin();
1086
1087 if (requesting_origin.unique()) {
1080 VLOG(1) << "Request device with unique origin."; 1088 VLOG(1) << "Request device with unique origin.";
1081 Send(new BluetoothMsg_RequestDeviceError( 1089 Send(new BluetoothMsg_RequestDeviceError(
1082 thread_id, request_id, 1090 thread_id, request_id,
1083 WebBluetoothError::RequestDeviceWithUniqueOrigin)); 1091 WebBluetoothError::RequestDeviceWithUniqueOrigin));
1084 return; 1092 return;
1085 } 1093 }
1086 1094
1087 DCHECK(adapter_.get()); 1095 DCHECK(adapter_.get());
1088 1096
1089 if (!adapter_->IsPresent()) { 1097 if (!adapter_->IsPresent()) {
1090 VLOG(1) << "Bluetooth Adapter not present. Can't serve requestDevice."; 1098 VLOG(1) << "Bluetooth Adapter not present. Can't serve requestDevice.";
1091 RecordRequestDeviceOutcome( 1099 RecordRequestDeviceOutcome(
1092 UMARequestDeviceOutcome::BLUETOOTH_ADAPTER_NOT_PRESENT); 1100 UMARequestDeviceOutcome::BLUETOOTH_ADAPTER_NOT_PRESENT);
1093 Send(new BluetoothMsg_RequestDeviceError( 1101 Send(new BluetoothMsg_RequestDeviceError(
1094 thread_id, request_id, WebBluetoothError::NoBluetoothAdapter)); 1102 thread_id, request_id, WebBluetoothError::NoBluetoothAdapter));
1095 return; 1103 return;
1096 } 1104 }
1097 1105
1098 // The renderer should never send empty filters. 1106 // The renderer should never send empty filters.
1099 if (HasEmptyOrInvalidFilter(filters)) { 1107 if (HasEmptyOrInvalidFilter(filters)) {
1100 bad_message::ReceivedBadMessage(this, 1108 bad_message::ReceivedBadMessage(this,
1101 bad_message::BDH_EMPTY_OR_INVALID_FILTERS); 1109 bad_message::BDH_EMPTY_OR_INVALID_FILTERS);
1102 return; 1110 return;
1103 } 1111 }
1104 1112
1113 if (!GetContentClient()->browser()->AllowWebBluetooth(
1114 web_contents->GetBrowserContext(), requesting_origin,
1115 embedding_origin)) {
1116 RecordRequestDeviceOutcome(
1117 UMARequestDeviceOutcome::BLUETOOTH_CHOOSER_GLOBALLY_DISABLED);
1118 Send(new BluetoothMsg_RequestDeviceError(
1119 thread_id, request_id, WebBluetoothError::ChooserDisabled));
1120 return;
1121 }
1122
1105 // Create storage for the information that backs the chooser, and show the 1123 // Create storage for the information that backs the chooser, and show the
1106 // chooser. 1124 // chooser.
1107 RequestDeviceSession* const session = 1125 RequestDeviceSession* const session = new RequestDeviceSession(
1108 new RequestDeviceSession(thread_id, request_id, frame_routing_id, 1126 thread_id, request_id, frame_routing_id, requesting_origin, filters,
1109 render_frame_host->GetLastCommittedOrigin(), 1127 optional_services_blacklist_filtered);
1110 filters, optional_services_blacklist_filtered);
1111 int chooser_id = request_device_sessions_.Add(session); 1128 int chooser_id = request_device_sessions_.Add(session);
1112 1129
1113 BluetoothChooser::EventHandler chooser_event_handler = 1130 BluetoothChooser::EventHandler chooser_event_handler =
1114 base::Bind(&BluetoothDispatcherHost::OnBluetoothChooserEvent, 1131 base::Bind(&BluetoothDispatcherHost::OnBluetoothChooserEvent,
1115 weak_ptr_on_ui_thread_, chooser_id); 1132 weak_ptr_on_ui_thread_, chooser_id);
1116 if (WebContents* web_contents = 1133 if (WebContentsDelegate* delegate = web_contents->GetDelegate()) {
1117 WebContents::FromRenderFrameHost(render_frame_host)) { 1134 session->chooser =
1118 if (WebContentsDelegate* delegate = web_contents->GetDelegate()) { 1135 delegate->RunBluetoothChooser(render_frame_host, chooser_event_handler);
1119 session->chooser = delegate->RunBluetoothChooser(render_frame_host,
1120 chooser_event_handler);
1121 }
1122 } 1136 }
1123 if (!session->chooser) { 1137 if (!session->chooser) {
1124 LOG(WARNING) 1138 LOG(WARNING)
1125 << "No Bluetooth chooser implementation; falling back to first device."; 1139 << "No Bluetooth chooser implementation; falling back to first device.";
1126 session->chooser.reset( 1140 session->chooser.reset(
1127 new FirstDeviceBluetoothChooser(chooser_event_handler)); 1141 new FirstDeviceBluetoothChooser(chooser_event_handler));
1128 } 1142 }
1129 1143
1130 if (!session->chooser->CanAskForScanningPermission()) { 1144 if (!session->chooser->CanAskForScanningPermission()) {
1131 VLOG(1) << "Closing immediately because Chooser cannot obtain permission."; 1145 VLOG(1) << "Closing immediately because Chooser cannot obtain permission.";
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
1541 1555
1542 bool BluetoothDispatcherHost::CanFrameAccessCharacteristicInstance( 1556 bool BluetoothDispatcherHost::CanFrameAccessCharacteristicInstance(
1543 int frame_routing_id, 1557 int frame_routing_id,
1544 const std::string& characteristic_instance_id) { 1558 const std::string& characteristic_instance_id) {
1545 return QueryCacheForCharacteristic(GetOrigin(frame_routing_id), 1559 return QueryCacheForCharacteristic(GetOrigin(frame_routing_id),
1546 characteristic_instance_id) 1560 characteristic_instance_id)
1547 .outcome != CacheQueryOutcome::BAD_RENDERER; 1561 .outcome != CacheQueryOutcome::BAD_RENDERER;
1548 } 1562 }
1549 1563
1550 } // namespace content 1564 } // namespace content
OLDNEW
« no previous file with comments | « components/policy/resources/policy_templates.json ('k') | content/browser/bluetooth/bluetooth_metrics.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698