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

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

Issue 1666003002: bluetooth: Add Web Bluetooth blacklist checks to requestDevice. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bt-blacklist-
Patch Set: address ortuno 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
« no previous file with comments | « no previous file | content/browser/bluetooth/bluetooth_metrics.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_metrics.h" 24 #include "content/browser/bluetooth/bluetooth_metrics.h"
24 #include "content/browser/bluetooth/first_device_bluetooth_chooser.h" 25 #include "content/browser/bluetooth/first_device_bluetooth_chooser.h"
25 #include "content/browser/frame_host/render_frame_host_impl.h" 26 #include "content/browser/frame_host/render_frame_host_impl.h"
26 #include "content/common/bluetooth/bluetooth_messages.h" 27 #include "content/common/bluetooth/bluetooth_messages.h"
27 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
28 #include "content/public/browser/web_contents_delegate.h" 29 #include "content/public/browser/web_contents_delegate.h"
29 #include "device/bluetooth/bluetooth_adapter.h" 30 #include "device/bluetooth/bluetooth_adapter.h"
30 #include "device/bluetooth/bluetooth_adapter_factory.h" 31 #include "device/bluetooth/bluetooth_adapter_factory.h"
31 #include "device/bluetooth/bluetooth_device.h" 32 #include "device/bluetooth/bluetooth_device.h"
32 #include "device/bluetooth/bluetooth_discovery_session.h" 33 #include "device/bluetooth/bluetooth_discovery_session.h"
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 986 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
986 set_adapter(adapter); 987 set_adapter(adapter);
987 continuation.Run(); 988 continuation.Run();
988 } 989 }
989 990
990 void BluetoothDispatcherHost::OnRequestDeviceImpl( 991 void BluetoothDispatcherHost::OnRequestDeviceImpl(
991 int thread_id, 992 int thread_id,
992 int request_id, 993 int request_id,
993 int frame_routing_id, 994 int frame_routing_id,
994 const std::vector<BluetoothScanFilter>& filters, 995 const std::vector<BluetoothScanFilter>& filters,
995 const std::vector<BluetoothUUID>& optional_services) { 996 const std::vector<BluetoothUUID>&
997 optional_services_before_being_filtered_by_blacklist) {
ortuno 2016/02/12 18:34:59 I'm not sure how to handle the naming here. Should
scheib 2016/02/12 21:00:52 After in person discussion decided to keep name 'o
996 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 998 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
997 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE); 999 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE);
998 RecordRequestDeviceArguments(filters, optional_services); 1000 RecordRequestDeviceArguments(
1001 filters, optional_services_before_being_filtered_by_blacklist);
999 1002
1000 VLOG(1) << "requestDevice called with the following filters: "; 1003 VLOG(1) << "requestDevice called with the following filters: ";
1001 for (const BluetoothScanFilter& filter : filters) { 1004 for (const BluetoothScanFilter& filter : filters) {
1002 VLOG(1) << "Name: " << filter.name; 1005 VLOG(1) << "Name: " << filter.name;
1003 VLOG(1) << "Name Prefix: " << filter.namePrefix; 1006 VLOG(1) << "Name Prefix: " << filter.namePrefix;
1004 VLOG(1) << "Services:"; 1007 VLOG(1) << "Services:";
1005 VLOG(1) << "\t["; 1008 VLOG(1) << "\t[";
1006 for (const BluetoothUUID& service : filter.services) 1009 for (const BluetoothUUID& service : filter.services)
1007 VLOG(1) << "\t\t" << service.value(); 1010 VLOG(1) << "\t\t" << service.value();
1008 VLOG(1) << "\t]"; 1011 VLOG(1) << "\t]";
1009 } 1012 }
1010 1013
1011 VLOG(1) << "requestDevice called with the following optional services: "; 1014 VLOG(1) << "requestDevice called with the following optional services: ";
1012 for (const BluetoothUUID& service : optional_services) 1015 for (const BluetoothUUID& service :
1016 optional_services_before_being_filtered_by_blacklist)
1013 VLOG(1) << "\t" << service.value(); 1017 VLOG(1) << "\t" << service.value();
1014 1018
1019 // Check blacklist to reject invalid filters and adjust optional_services.
1020 if (BluetoothBlacklist::Get().IsExcluded(filters)) {
1021 RecordRequestDeviceOutcome(
1022 UMARequestDeviceOutcome::BLACKLISTED_SERVICE_IN_FILTER);
1023 Send(new BluetoothMsg_RequestDeviceError(
1024 thread_id, request_id,
1025 WebBluetoothError::RequestDeviceWithBlacklistedUUID));
1026 return;
1027 }
1028 std::vector<BluetoothUUID> optional_services_blacklist_filtered(
1029 optional_services_before_being_filtered_by_blacklist);
1030 BluetoothBlacklist::Get().RemoveExcludedUuids(
1031 &optional_services_blacklist_filtered);
1032
1015 RenderFrameHostImpl* render_frame_host = 1033 RenderFrameHostImpl* render_frame_host =
1016 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id); 1034 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id);
1017 1035
1018 if (!render_frame_host) { 1036 if (!render_frame_host) {
1019 DLOG(WARNING) 1037 DLOG(WARNING)
1020 << "Got a requestDevice IPC without a matching RenderFrameHost: " 1038 << "Got a requestDevice IPC without a matching RenderFrameHost: "
1021 << render_process_id_ << ", " << frame_routing_id; 1039 << render_process_id_ << ", " << frame_routing_id;
1022 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_RENDER_FRAME); 1040 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_RENDER_FRAME);
1023 Send(new BluetoothMsg_RequestDeviceError( 1041 Send(new BluetoothMsg_RequestDeviceError(
1024 thread_id, request_id, WebBluetoothError::RequestDeviceWithoutFrame)); 1042 thread_id, request_id, WebBluetoothError::RequestDeviceWithoutFrame));
(...skipping 23 matching lines...) Expand all
1048 if (HasEmptyOrInvalidFilter(filters)) { 1066 if (HasEmptyOrInvalidFilter(filters)) {
1049 bad_message::ReceivedBadMessage(this, 1067 bad_message::ReceivedBadMessage(this,
1050 bad_message::BDH_EMPTY_OR_INVALID_FILTERS); 1068 bad_message::BDH_EMPTY_OR_INVALID_FILTERS);
1051 return; 1069 return;
1052 } 1070 }
1053 1071
1054 // Create storage for the information that backs the chooser, and show the 1072 // Create storage for the information that backs the chooser, and show the
1055 // chooser. 1073 // chooser.
1056 RequestDeviceSession* const session = new RequestDeviceSession( 1074 RequestDeviceSession* const session = new RequestDeviceSession(
1057 thread_id, request_id, render_frame_host->GetLastCommittedOrigin(), 1075 thread_id, request_id, render_frame_host->GetLastCommittedOrigin(),
1058 filters, optional_services); 1076 filters, optional_services_blacklist_filtered);
1059 int chooser_id = request_device_sessions_.Add(session); 1077 int chooser_id = request_device_sessions_.Add(session);
1060 1078
1061 BluetoothChooser::EventHandler chooser_event_handler = 1079 BluetoothChooser::EventHandler chooser_event_handler =
1062 base::Bind(&BluetoothDispatcherHost::OnBluetoothChooserEvent, 1080 base::Bind(&BluetoothDispatcherHost::OnBluetoothChooserEvent,
1063 weak_ptr_on_ui_thread_, chooser_id); 1081 weak_ptr_on_ui_thread_, chooser_id);
1064 if (WebContents* web_contents = 1082 if (WebContents* web_contents =
1065 WebContents::FromRenderFrameHost(render_frame_host)) { 1083 WebContents::FromRenderFrameHost(render_frame_host)) {
1066 if (WebContentsDelegate* delegate = web_contents->GetDelegate()) { 1084 if (WebContentsDelegate* delegate = web_contents->GetDelegate()) {
1067 session->chooser = delegate->RunBluetoothChooser( 1085 session->chooser = delegate->RunBluetoothChooser(
1068 web_contents, chooser_event_handler, 1086 web_contents, chooser_event_handler,
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
1505 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1523 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1506 NOTIMPLEMENTED(); 1524 NOTIMPLEMENTED();
1507 } 1525 }
1508 1526
1509 void BluetoothDispatcherHost::ShowNeedLocationLink() { 1527 void BluetoothDispatcherHost::ShowNeedLocationLink() {
1510 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1528 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1511 NOTIMPLEMENTED(); 1529 NOTIMPLEMENTED();
1512 } 1530 }
1513 1531
1514 } // namespace content 1532 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/bluetooth/bluetooth_metrics.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698