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

Unified 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: added code to check session->chooser_permission_manager 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/bluetooth/bluetooth_dispatcher_host.cc
diff --git a/content/browser/bluetooth/bluetooth_dispatcher_host.cc b/content/browser/bluetooth/bluetooth_dispatcher_host.cc
index deb626df075cda1a08b08e8fc27ee6164cdd1dbf..4dac43c77569a6749f69dd09c420691f8403b5a0 100644
--- a/content/browser/bluetooth/bluetooth_dispatcher_host.cc
+++ b/content/browser/bluetooth/bluetooth_dispatcher_host.cc
@@ -24,6 +24,9 @@
#include "content/browser/bluetooth/first_device_bluetooth_chooser.h"
#include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/common/bluetooth/bluetooth_messages.h"
+#include "content/public/browser/browser_context.h"
+#include "content/public/browser/chooser_permission_manager.h"
+#include "content/public/browser/permission_type.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "device/bluetooth/bluetooth_adapter.h"
@@ -40,6 +43,14 @@ using device::BluetoothGattCharacteristic;
using device::BluetoothGattService;
using device::BluetoothUUID;
+namespace {
+
+const char kDeviceAddressKey[] = "device-address";
+const char kDeviceNameKey[] = "device-name";
+const char kDeviceUUIDsKey[] = "device-uuids";
+
+} // namespace
+
namespace content {
namespace {
@@ -340,12 +351,16 @@ struct BluetoothDispatcherHost::RequestDeviceSession {
public:
RequestDeviceSession(int thread_id,
int request_id,
+ ChooserPermissionManager* chooser_permission_manager,
url::Origin origin,
+ url::Origin embedding_origin,
const std::vector<BluetoothScanFilter>& filters,
const std::vector<BluetoothUUID>& optional_services)
: thread_id(thread_id),
request_id(request_id),
+ chooser_permission_manager(chooser_permission_manager),
origin(origin),
+ embedding_origin(embedding_origin),
filters(filters),
optional_services(optional_services) {}
@@ -371,7 +386,9 @@ struct BluetoothDispatcherHost::RequestDeviceSession {
const int thread_id;
const int request_id;
+ ChooserPermissionManager* chooser_permission_manager;
const url::Origin origin;
+ const url::Origin embedding_origin;
const std::vector<BluetoothScanFilter> filters;
const std::vector<BluetoothUUID> optional_services;
scoped_ptr<BluetoothChooser> chooser;
@@ -658,18 +675,30 @@ void BluetoothDispatcherHost::OnRequestDevice(
return;
}
+ WebContents* web_contents =
+ WebContents::FromRenderFrameHost(render_frame_host);
+
+ url::Origin embedding_origin;
+ ChooserPermissionManager* chooser_permission_manager = nullptr;
+
+ if (web_contents) {
+ embedding_origin = web_contents->GetMainFrame()->GetLastCommittedOrigin();
+ chooser_permission_manager =
+ web_contents->GetBrowserContext()->GetChooserPermissionManager();
+ }
+
// Create storage for the information that backs the chooser, and show the
// chooser.
RequestDeviceSession* const session = new RequestDeviceSession(
- thread_id, request_id, render_frame_host->GetLastCommittedOrigin(),
- filters, optional_services);
+ thread_id, request_id, chooser_permission_manager,
+ render_frame_host->GetLastCommittedOrigin(), embedding_origin, filters,
+ optional_services);
int chooser_id = request_device_sessions_.Add(session);
BluetoothChooser::EventHandler chooser_event_handler =
base::Bind(&BluetoothDispatcherHost::OnBluetoothChooserEvent,
weak_ptr_on_ui_thread_, chooser_id);
- if (WebContents* web_contents =
- WebContents::FromRenderFrameHost(render_frame_host)) {
+ if (web_contents) {
if (WebContentsDelegate* delegate = web_contents->GetDelegate()) {
session->chooser = delegate->RunBluetoothChooser(
web_contents, chooser_event_handler,
@@ -1193,6 +1222,30 @@ void BluetoothDispatcherHost::FinishClosingChooser(
for (BluetoothUUID uuid : device->GetUUIDs())
VLOG(1) << "\t" << uuid.canonical_value();
+ if (session->chooser_permission_manager) {
+ scoped_ptr<base::DictionaryValue> device_dict(new base::DictionaryValue());
+ device_dict->SetString(kDeviceAddressKey, device_id);
+ device_dict->SetString(kDeviceNameKey, device->GetName());
+
+ // Compute the union of session->optional_services and session->filters.
+ std::set<device::BluetoothUUID> services(session->optional_services.begin(),
+ session->optional_services.end());
+ for (const content::BluetoothScanFilter& filter : session->filters) {
+ services.insert(filter.services.begin(), filter.services.end());
+ }
+ scoped_ptr<base::ListValue> device_uuids_list(new base::ListValue());
+ device::BluetoothDevice::UUIDList uuid_list = device->GetUUIDs();
+ for (const auto& uuid : uuid_list) {
+ if (services.find(uuid) != services.end())
+ device_uuids_list->AppendString(uuid.value());
+ }
+ device_dict->Set(kDeviceUUIDsKey, std::move(device_uuids_list));
+
+ session->chooser_permission_manager->GrantPermission(
+ content::PermissionType::BLUETOOTH, session->origin,
+ session->embedding_origin, std::move(device_dict));
+ }
+
const std::string& device_id_for_origin = allowed_devices_map_.AddDevice(
session->origin, device->GetAddress(), session->filters,
session->optional_services);

Powered by Google App Engine
This is Rietveld 408576698