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

Unified Diff: chrome/browser/ui/bluetooth/bluetooth_chooser_context.cc

Issue 1560263002: Store Bluetooth permissions in website settings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: moved bluetooth chooser context related code to non ios source in .gypi file 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: chrome/browser/ui/bluetooth/bluetooth_chooser_context.cc
diff --git a/chrome/browser/ui/bluetooth/bluetooth_chooser_context.cc b/chrome/browser/ui/bluetooth/bluetooth_chooser_context.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8ef0894c6ebd00572d2e931688dcc05bceda4855
--- /dev/null
+++ b/chrome/browser/ui/bluetooth/bluetooth_chooser_context.cc
@@ -0,0 +1,81 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/bluetooth/bluetooth_chooser_context.h"
+
+#include <utility>
+
+#include "base/values.h"
+#include "chrome/browser/profiles/profile.h"
+
+namespace {
+
+const char kDeviceIdKey[] = "device-id";
+const char kDeviceNameKey[] = "device-name";
+
+const base::DictionaryValue* FindForDevice(
+ const std::vector<scoped_ptr<base::DictionaryValue>>& device_list,
+ const base::string16& device_name,
+ const std::string& device_id) {
+ for (const scoped_ptr<base::DictionaryValue>& device_dict : device_list) {
+ base::string16 tmp_device_name;
+ std::string tmp_device_id;
+ if (device_dict->GetString(kDeviceNameKey, &tmp_device_name) &&
+ tmp_device_name == device_name &&
+ device_dict->GetString(kDeviceIdKey, &tmp_device_id) &&
+ tmp_device_id == device_id) {
+ return device_dict.get();
+ }
+ }
+ return nullptr;
+}
+
+} // namespace
+
+BluetoothChooserContext::BluetoothChooserContext(Profile* profile)
+ : ChooserContextBase(profile,
+ CONTENT_SETTINGS_TYPE_BLUETOOTH_CHOOSER_DATA) {}
+
+BluetoothChooserContext::~BluetoothChooserContext() {}
+
+void BluetoothChooserContext::GrantDevicePermission(
+ const GURL& requesting_origin,
+ const GURL& embedding_origin,
+ const base::string16& device_name,
+ const std::string& device_id) {
+ scoped_ptr<base::DictionaryValue> device_dict(new base::DictionaryValue());
+ device_dict->SetString(kDeviceNameKey, device_name);
Reilly Grant (use Gerrit) 2016/01/06 18:44:13 No, don't remove this one! We want to store the de
juncai 2016/01/11 21:55:16 Done.
+ device_dict->SetString(kDeviceIdKey, device_id);
+ GrantObjectPermission(requesting_origin, embedding_origin,
+ std::move(device_dict));
+}
+
+void BluetoothChooserContext::RevokeDevicePermission(
+ const GURL& requesting_origin,
+ const GURL& embedding_origin,
+ const base::string16& device_name,
+ const std::string& device_id) {
+ std::vector<scoped_ptr<base::DictionaryValue>> device_list =
+ GetGrantedObjects(requesting_origin, embedding_origin);
+ const base::DictionaryValue* entry =
+ FindForDevice(device_list, device_name, device_id);
+ if (entry)
+ RevokeObjectPermission(requesting_origin, embedding_origin, *entry);
+}
+
+bool BluetoothChooserContext::HasDevicePermission(
+ const GURL& requesting_origin,
+ const GURL& embedding_origin,
+ const base::string16& device_name,
+ const std::string& device_id) {
+ std::vector<scoped_ptr<base::DictionaryValue>> device_list =
+ GetGrantedObjects(requesting_origin, embedding_origin);
+ return FindForDevice(device_list, device_name, device_id) != nullptr;
+}
+
+bool BluetoothChooserContext::IsValidObject(
+ const base::DictionaryValue& object) {
+ return object.size() == 2 && object.HasKey(kDeviceNameKey) &&
+ object.HasKey(kDeviceIdKey);
+}

Powered by Google App Engine
This is Rietveld 408576698