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

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: address reillyg@'s comments 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..ba60a709b59cda2607fb2affa85e5a2cecab28a6
--- /dev/null
+++ b/chrome/browser/ui/bluetooth/bluetooth_chooser_context.cc
@@ -0,0 +1,70 @@
+// 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"
Jeffrey Yasskin 2016/01/06 19:10:55 I don't think you're using this #include.
juncai 2016/01/11 21:55:16 Done.
+
+namespace {
+
+const char kDeviceIdKey[] = "device-id";
+
+const base::DictionaryValue* FindForDevice(
+ const std::vector<scoped_ptr<base::DictionaryValue>>& device_list,
+ const std::string& device_id) {
+ for (const scoped_ptr<base::DictionaryValue>& device_dict : device_list) {
+ std::string tmp_device_id;
+ if (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 std::string& device_id) {
+ scoped_ptr<base::DictionaryValue> device_dict(new base::DictionaryValue());
+ 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 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_id);
+ if (entry)
+ RevokeObjectPermission(requesting_origin, embedding_origin, *entry);
+}
+
+bool BluetoothChooserContext::HasDevicePermission(
+ const GURL& requesting_origin,
+ const GURL& embedding_origin,
+ const std::string& device_id) {
+ std::vector<scoped_ptr<base::DictionaryValue>> device_list =
+ GetGrantedObjects(requesting_origin, embedding_origin);
+ return FindForDevice(device_list, device_id) != nullptr;
+}
+
+bool BluetoothChooserContext::IsValidObject(
+ const base::DictionaryValue& object) {
+ return object.size() == 1 && object.HasKey(kDeviceIdKey);
Jeffrey Yasskin 2016/01/06 19:10:55 Also check that the device ID is a string?
juncai 2016/01/11 21:55:16 Done.
+}

Powered by Google App Engine
This is Rietveld 408576698