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

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

Issue 1560263002: Store Bluetooth permissions in website settings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: modified ChooserPermissionManager to take url::Origin as parameter Created 4 years, 11 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_metrics.h" 23 #include "content/browser/bluetooth/bluetooth_metrics.h"
24 #include "content/browser/bluetooth/first_device_bluetooth_chooser.h" 24 #include "content/browser/bluetooth/first_device_bluetooth_chooser.h"
25 #include "content/browser/frame_host/render_frame_host_impl.h" 25 #include "content/browser/frame_host/render_frame_host_impl.h"
26 #include "content/common/bluetooth/bluetooth_messages.h" 26 #include "content/common/bluetooth/bluetooth_messages.h"
27 #include "content/public/browser/browser_context.h"
28 #include "content/public/browser/chooser_permission_manager.h"
27 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
28 #include "content/public/browser/web_contents_delegate.h" 30 #include "content/public/browser/web_contents_delegate.h"
29 #include "device/bluetooth/bluetooth_adapter.h" 31 #include "device/bluetooth/bluetooth_adapter.h"
30 #include "device/bluetooth/bluetooth_adapter_factory.h" 32 #include "device/bluetooth/bluetooth_adapter_factory.h"
31 #include "device/bluetooth/bluetooth_device.h" 33 #include "device/bluetooth/bluetooth_device.h"
32 #include "device/bluetooth/bluetooth_discovery_session.h" 34 #include "device/bluetooth/bluetooth_discovery_session.h"
33 #include "device/bluetooth/bluetooth_gatt_characteristic.h" 35 #include "device/bluetooth/bluetooth_gatt_characteristic.h"
34 #include "device/bluetooth/bluetooth_gatt_service.h" 36 #include "device/bluetooth/bluetooth_gatt_service.h"
35 37
36 using blink::WebBluetoothError; 38 using blink::WebBluetoothError;
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 // Clear adapter, releasing observer references. 335 // Clear adapter, releasing observer references.
334 set_adapter(scoped_refptr<device::BluetoothAdapter>()); 336 set_adapter(scoped_refptr<device::BluetoothAdapter>());
335 } 337 }
336 338
337 // Stores information associated with an in-progress requestDevice call. This 339 // Stores information associated with an in-progress requestDevice call. This
338 // will include the state of the active chooser dialog in a future patch. 340 // will include the state of the active chooser dialog in a future patch.
339 struct BluetoothDispatcherHost::RequestDeviceSession { 341 struct BluetoothDispatcherHost::RequestDeviceSession {
340 public: 342 public:
341 RequestDeviceSession(int thread_id, 343 RequestDeviceSession(int thread_id,
342 int request_id, 344 int request_id,
345 ChooserPermissionManager* chooser_permission_manager,
343 url::Origin origin, 346 url::Origin origin,
347 url::Origin embedding_origin,
344 const std::vector<BluetoothScanFilter>& filters, 348 const std::vector<BluetoothScanFilter>& filters,
345 const std::vector<BluetoothUUID>& optional_services) 349 const std::vector<BluetoothUUID>& optional_services)
346 : thread_id(thread_id), 350 : thread_id(thread_id),
347 request_id(request_id), 351 request_id(request_id),
352 chooser_permission_manager(chooser_permission_manager),
348 origin(origin), 353 origin(origin),
354 embedding_origin(embedding_origin),
349 filters(filters), 355 filters(filters),
350 optional_services(optional_services) {} 356 optional_services(optional_services) {}
351 357
352 void AddFilteredDevice(const device::BluetoothDevice& device) { 358 void AddFilteredDevice(const device::BluetoothDevice& device) {
353 if (chooser && MatchesFilters(device, filters)) { 359 if (chooser && MatchesFilters(device, filters)) {
354 chooser->AddDevice(device.GetAddress(), device.GetName()); 360 chooser->AddDevice(device.GetAddress(), device.GetName());
355 } 361 }
356 } 362 }
357 363
358 scoped_ptr<device::BluetoothDiscoveryFilter> ComputeScanFilter() const { 364 scoped_ptr<device::BluetoothDiscoveryFilter> ComputeScanFilter() const {
359 std::set<BluetoothUUID> services; 365 std::set<BluetoothUUID> services;
360 for (const BluetoothScanFilter& filter : filters) { 366 for (const BluetoothScanFilter& filter : filters) {
361 services.insert(filter.services.begin(), filter.services.end()); 367 services.insert(filter.services.begin(), filter.services.end());
362 } 368 }
363 scoped_ptr<device::BluetoothDiscoveryFilter> discovery_filter( 369 scoped_ptr<device::BluetoothDiscoveryFilter> discovery_filter(
364 new device::BluetoothDiscoveryFilter( 370 new device::BluetoothDiscoveryFilter(
365 device::BluetoothDiscoveryFilter::TRANSPORT_DUAL)); 371 device::BluetoothDiscoveryFilter::TRANSPORT_DUAL));
366 for (const BluetoothUUID& service : services) { 372 for (const BluetoothUUID& service : services) {
367 discovery_filter->AddUUID(service); 373 discovery_filter->AddUUID(service);
368 } 374 }
369 return discovery_filter; 375 return discovery_filter;
370 } 376 }
371 377
372 const int thread_id; 378 const int thread_id;
373 const int request_id; 379 const int request_id;
380 ChooserPermissionManager* chooser_permission_manager;
374 const url::Origin origin; 381 const url::Origin origin;
382 const url::Origin embedding_origin;
375 const std::vector<BluetoothScanFilter> filters; 383 const std::vector<BluetoothScanFilter> filters;
376 const std::vector<BluetoothUUID> optional_services; 384 const std::vector<BluetoothUUID> optional_services;
377 scoped_ptr<BluetoothChooser> chooser; 385 scoped_ptr<BluetoothChooser> chooser;
378 scoped_ptr<device::BluetoothDiscoverySession> discovery_session; 386 scoped_ptr<device::BluetoothDiscoverySession> discovery_session;
379 }; 387 };
380 388
381 struct BluetoothDispatcherHost::CacheQueryResult { 389 struct BluetoothDispatcherHost::CacheQueryResult {
382 CacheQueryResult() 390 CacheQueryResult()
383 : device(nullptr), 391 : device(nullptr),
384 service(nullptr), 392 service(nullptr),
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 return; 659 return;
652 } 660 }
653 661
654 // The renderer should never send empty filters. 662 // The renderer should never send empty filters.
655 if (HasEmptyOrInvalidFilter(filters)) { 663 if (HasEmptyOrInvalidFilter(filters)) {
656 bad_message::ReceivedBadMessage(this, 664 bad_message::ReceivedBadMessage(this,
657 bad_message::BDH_EMPTY_OR_INVALID_FILTERS); 665 bad_message::BDH_EMPTY_OR_INVALID_FILTERS);
658 return; 666 return;
659 } 667 }
660 668
669 WebContents* web_contents =
670 WebContents::FromRenderFrameHost(render_frame_host);
671
672 url::Origin embedding_origin;
673 ChooserPermissionManager* chooser_permission_manager = nullptr;
674
675 if (web_contents) {
676 embedding_origin = web_contents->GetMainFrame()->GetLastCommittedOrigin();
677 chooser_permission_manager =
678 web_contents->GetBrowserContext()->GetChooserPermissionManager();
679 }
680
661 // Create storage for the information that backs the chooser, and show the 681 // Create storage for the information that backs the chooser, and show the
662 // chooser. 682 // chooser.
663 RequestDeviceSession* const session = new RequestDeviceSession( 683 RequestDeviceSession* const session = new RequestDeviceSession(
664 thread_id, request_id, render_frame_host->GetLastCommittedOrigin(), 684 thread_id, request_id, chooser_permission_manager,
665 filters, optional_services); 685 render_frame_host->GetLastCommittedOrigin(), embedding_origin, filters,
686 optional_services);
666 int chooser_id = request_device_sessions_.Add(session); 687 int chooser_id = request_device_sessions_.Add(session);
667 688
668 BluetoothChooser::EventHandler chooser_event_handler = 689 BluetoothChooser::EventHandler chooser_event_handler =
669 base::Bind(&BluetoothDispatcherHost::OnBluetoothChooserEvent, 690 base::Bind(&BluetoothDispatcherHost::OnBluetoothChooserEvent,
670 weak_ptr_on_ui_thread_, chooser_id); 691 weak_ptr_on_ui_thread_, chooser_id);
671 if (WebContents* web_contents = 692 if (web_contents) {
672 WebContents::FromRenderFrameHost(render_frame_host)) {
673 if (WebContentsDelegate* delegate = web_contents->GetDelegate()) { 693 if (WebContentsDelegate* delegate = web_contents->GetDelegate()) {
674 session->chooser = delegate->RunBluetoothChooser( 694 session->chooser = delegate->RunBluetoothChooser(
675 web_contents, chooser_event_handler, 695 web_contents, chooser_event_handler,
676 // TODO(ortuno): Replace with GetLastCommittedOrigin. 696 // TODO(ortuno): Replace with GetLastCommittedOrigin.
677 // http://crbug.com/577451 697 // http://crbug.com/577451
678 render_frame_host->GetLastCommittedURL().GetOrigin()); 698 render_frame_host->GetLastCommittedURL().GetOrigin());
679 } 699 }
680 } 700 }
681 if (!session->chooser) { 701 if (!session->chooser) {
682 LOG(WARNING) 702 LOG(WARNING)
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 WebBluetoothError::ChosenDeviceVanished)); 1206 WebBluetoothError::ChosenDeviceVanished));
1187 request_device_sessions_.Remove(chooser_id); 1207 request_device_sessions_.Remove(chooser_id);
1188 return; 1208 return;
1189 } 1209 }
1190 1210
1191 VLOG(1) << "Device: " << device->GetName(); 1211 VLOG(1) << "Device: " << device->GetName();
1192 VLOG(1) << "UUIDs: "; 1212 VLOG(1) << "UUIDs: ";
1193 for (BluetoothUUID uuid : device->GetUUIDs()) 1213 for (BluetoothUUID uuid : device->GetUUIDs())
1194 VLOG(1) << "\t" << uuid.canonical_value(); 1214 VLOG(1) << "\t" << uuid.canonical_value();
1195 1215
1216 session->chooser_permission_manager->GrantPermission(
1217 session->origin, session->embedding_origin, device_id);
1218
1196 const std::string& device_id_for_origin = allowed_devices_map_.AddDevice( 1219 const std::string& device_id_for_origin = allowed_devices_map_.AddDevice(
1197 session->origin, device->GetAddress(), session->filters, 1220 session->origin, device->GetAddress(), session->filters,
1198 session->optional_services); 1221 session->optional_services);
1199 1222
1200 content::BluetoothDevice device_ipc( 1223 content::BluetoothDevice device_ipc(
1201 device_id_for_origin, // id 1224 device_id_for_origin, // id
1202 device->GetName(), // name 1225 device->GetName(), // name
1203 content::BluetoothDevice::ValidatePower( 1226 content::BluetoothDevice::ValidatePower(
1204 device->GetInquiryTxPower()), // tx_power 1227 device->GetInquiryTxPower()), // tx_power
1205 content::BluetoothDevice::ValidatePower( 1228 content::BluetoothDevice::ValidatePower(
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1458 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1481 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1459 NOTIMPLEMENTED(); 1482 NOTIMPLEMENTED();
1460 } 1483 }
1461 1484
1462 void BluetoothDispatcherHost::ShowNeedLocationLink() { 1485 void BluetoothDispatcherHost::ShowNeedLocationLink() {
1463 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1486 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1464 NOTIMPLEMENTED(); 1487 NOTIMPLEMENTED();
1465 } 1488 }
1466 1489
1467 } // namespace content 1490 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698