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

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: cleaned up changes at bluetooth_dispatcher_host.cc 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 content::WebContents* web_contents,
343 url::Origin origin, 346 url::Origin origin,
344 const std::vector<BluetoothScanFilter>& filters, 347 const std::vector<BluetoothScanFilter>& filters,
345 const std::vector<BluetoothUUID>& optional_services) 348 const std::vector<BluetoothUUID>& optional_services)
346 : thread_id(thread_id), 349 : thread_id(thread_id),
347 request_id(request_id), 350 request_id(request_id),
351 web_contents(web_contents),
348 origin(origin), 352 origin(origin),
349 filters(filters), 353 filters(filters),
350 optional_services(optional_services) {} 354 optional_services(optional_services) {}
351 355
352 void AddFilteredDevice(const device::BluetoothDevice& device) { 356 void AddFilteredDevice(const device::BluetoothDevice& device) {
353 if (chooser && MatchesFilters(device, filters)) { 357 if (chooser && MatchesFilters(device, filters)) {
354 chooser->AddDevice(device.GetAddress(), device.GetName()); 358 chooser->AddDevice(device.GetAddress(), device.GetName());
355 } 359 }
356 } 360 }
357 361
358 scoped_ptr<device::BluetoothDiscoveryFilter> ComputeScanFilter() const { 362 scoped_ptr<device::BluetoothDiscoveryFilter> ComputeScanFilter() const {
359 std::set<BluetoothUUID> services; 363 std::set<BluetoothUUID> services;
360 for (const BluetoothScanFilter& filter : filters) { 364 for (const BluetoothScanFilter& filter : filters) {
361 services.insert(filter.services.begin(), filter.services.end()); 365 services.insert(filter.services.begin(), filter.services.end());
362 } 366 }
363 scoped_ptr<device::BluetoothDiscoveryFilter> discovery_filter( 367 scoped_ptr<device::BluetoothDiscoveryFilter> discovery_filter(
364 new device::BluetoothDiscoveryFilter( 368 new device::BluetoothDiscoveryFilter(
365 device::BluetoothDiscoveryFilter::TRANSPORT_DUAL)); 369 device::BluetoothDiscoveryFilter::TRANSPORT_DUAL));
366 for (const BluetoothUUID& service : services) { 370 for (const BluetoothUUID& service : services) {
367 discovery_filter->AddUUID(service); 371 discovery_filter->AddUUID(service);
368 } 372 }
369 return discovery_filter; 373 return discovery_filter;
370 } 374 }
371 375
372 const int thread_id; 376 const int thread_id;
373 const int request_id; 377 const int request_id;
378 content::WebContents* web_contents;
374 const url::Origin origin; 379 const url::Origin origin;
375 const std::vector<BluetoothScanFilter> filters; 380 const std::vector<BluetoothScanFilter> filters;
376 const std::vector<BluetoothUUID> optional_services; 381 const std::vector<BluetoothUUID> optional_services;
377 scoped_ptr<BluetoothChooser> chooser; 382 scoped_ptr<BluetoothChooser> chooser;
378 scoped_ptr<device::BluetoothDiscoverySession> discovery_session; 383 scoped_ptr<device::BluetoothDiscoverySession> discovery_session;
379 }; 384 };
380 385
381 struct BluetoothDispatcherHost::CacheQueryResult { 386 struct BluetoothDispatcherHost::CacheQueryResult {
382 CacheQueryResult() 387 CacheQueryResult()
383 : device(nullptr), 388 : device(nullptr),
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 return; 656 return;
652 } 657 }
653 658
654 // The renderer should never send empty filters. 659 // The renderer should never send empty filters.
655 if (HasEmptyOrInvalidFilter(filters)) { 660 if (HasEmptyOrInvalidFilter(filters)) {
656 bad_message::ReceivedBadMessage(this, 661 bad_message::ReceivedBadMessage(this,
657 bad_message::BDH_EMPTY_OR_INVALID_FILTERS); 662 bad_message::BDH_EMPTY_OR_INVALID_FILTERS);
658 return; 663 return;
659 } 664 }
660 665
666 WebContents* web_contents =
667 WebContents::FromRenderFrameHost(render_frame_host);
668
661 // Create storage for the information that backs the chooser, and show the 669 // Create storage for the information that backs the chooser, and show the
662 // chooser. 670 // chooser.
663 RequestDeviceSession* const session = new RequestDeviceSession( 671 RequestDeviceSession* const session = new RequestDeviceSession(
664 thread_id, request_id, render_frame_host->GetLastCommittedOrigin(), 672 thread_id, request_id, web_contents,
665 filters, optional_services); 673 render_frame_host->GetLastCommittedOrigin(), filters, optional_services);
666 int chooser_id = request_device_sessions_.Add(session); 674 int chooser_id = request_device_sessions_.Add(session);
667 675
668 BluetoothChooser::EventHandler chooser_event_handler = 676 BluetoothChooser::EventHandler chooser_event_handler =
669 base::Bind(&BluetoothDispatcherHost::OnBluetoothChooserEvent, 677 base::Bind(&BluetoothDispatcherHost::OnBluetoothChooserEvent,
670 weak_ptr_on_ui_thread_, chooser_id); 678 weak_ptr_on_ui_thread_, chooser_id);
671 if (WebContents* web_contents = 679 if (web_contents) {
672 WebContents::FromRenderFrameHost(render_frame_host)) {
673 if (WebContentsDelegate* delegate = web_contents->GetDelegate()) { 680 if (WebContentsDelegate* delegate = web_contents->GetDelegate()) {
674 session->chooser = delegate->RunBluetoothChooser( 681 session->chooser = delegate->RunBluetoothChooser(
675 web_contents, chooser_event_handler, 682 web_contents, chooser_event_handler,
676 // TODO(ortuno): Replace with GetLastCommittedOrigin. 683 // TODO(ortuno): Replace with GetLastCommittedOrigin.
677 // http://crbug.com/577451 684 // http://crbug.com/577451
678 render_frame_host->GetLastCommittedURL().GetOrigin()); 685 render_frame_host->GetLastCommittedURL().GetOrigin());
679 } 686 }
680 } 687 }
681 if (!session->chooser) { 688 if (!session->chooser) {
682 LOG(WARNING) 689 LOG(WARNING)
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 WebBluetoothError::ChosenDeviceVanished)); 1193 WebBluetoothError::ChosenDeviceVanished));
1187 request_device_sessions_.Remove(chooser_id); 1194 request_device_sessions_.Remove(chooser_id);
1188 return; 1195 return;
1189 } 1196 }
1190 1197
1191 VLOG(1) << "Device: " << device->GetName(); 1198 VLOG(1) << "Device: " << device->GetName();
1192 VLOG(1) << "UUIDs: "; 1199 VLOG(1) << "UUIDs: ";
1193 for (BluetoothUUID uuid : device->GetUUIDs()) 1200 for (BluetoothUUID uuid : device->GetUUIDs())
1194 VLOG(1) << "\t" << uuid.canonical_value(); 1201 VLOG(1) << "\t" << uuid.canonical_value();
1195 1202
1203 GURL embedding_origin =
ortuno 2016/01/19 21:09:31 Can you add a TODO that points to an issue to chan
juncai 2016/01/19 22:21:37 Modified ChooserPermissionManager to take url::Ori
1204 session->web_contents->GetMainFrame()->GetLastCommittedURL().GetOrigin();
ortuno 2016/01/19 21:09:31 Could the WebContents object be deleted before Fin
juncai 2016/01/19 22:21:37 store chooser_permission_manager pointer instead o
1205 BrowserContext* browser_context = session->web_contents->GetBrowserContext();
1206 ChooserPermissionManager* chooser_permission_manager =
1207 browser_context->GetChooserPermissionManager();
1208 chooser_permission_manager->GrantPermission(GURL(session->origin.Serialize()),
1209 embedding_origin, device_id);
1210
1196 const std::string& device_id_for_origin = allowed_devices_map_.AddDevice( 1211 const std::string& device_id_for_origin = allowed_devices_map_.AddDevice(
1197 session->origin, device->GetAddress(), session->filters, 1212 session->origin, device->GetAddress(), session->filters,
1198 session->optional_services); 1213 session->optional_services);
1199 1214
1200 content::BluetoothDevice device_ipc( 1215 content::BluetoothDevice device_ipc(
1201 device_id_for_origin, // id 1216 device_id_for_origin, // id
1202 device->GetName(), // name 1217 device->GetName(), // name
1203 content::BluetoothDevice::ValidatePower( 1218 content::BluetoothDevice::ValidatePower(
1204 device->GetInquiryTxPower()), // tx_power 1219 device->GetInquiryTxPower()), // tx_power
1205 content::BluetoothDevice::ValidatePower( 1220 content::BluetoothDevice::ValidatePower(
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1458 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1473 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1459 NOTIMPLEMENTED(); 1474 NOTIMPLEMENTED();
1460 } 1475 }
1461 1476
1462 void BluetoothDispatcherHost::ShowNeedLocationLink() { 1477 void BluetoothDispatcherHost::ShowNeedLocationLink() {
1463 DCHECK_CURRENTLY_ON(BrowserThread::UI); 1478 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1464 NOTIMPLEMENTED(); 1479 NOTIMPLEMENTED();
1465 } 1480 }
1466 1481
1467 } // namespace content 1482 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698