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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/bluetooth/bluetooth_chooser_context.h"
6
7 #include <utility>
8
9 #include "base/values.h"
10 #include "chrome/browser/profiles/profile.h"
11
12 namespace {
13
14 const char kDeviceIdKey[] = "device-id";
15 const char kDeviceNameKey[] = "device-name";
16
17 const base::DictionaryValue* FindForDevice(
18 const std::vector<scoped_ptr<base::DictionaryValue>>& device_list,
19 const base::string16& device_name,
20 const std::string& device_id) {
21 for (const scoped_ptr<base::DictionaryValue>& device_dict : device_list) {
22 base::string16 tmp_device_name;
23 std::string tmp_device_id;
24 if (device_dict->GetString(kDeviceNameKey, &tmp_device_name) &&
25 tmp_device_name == device_name &&
26 device_dict->GetString(kDeviceIdKey, &tmp_device_id) &&
27 tmp_device_id == device_id) {
28 return device_dict.get();
29 }
30 }
31 return nullptr;
32 }
33
34 } // namespace
35
36 BluetoothChooserContext::BluetoothChooserContext(Profile* profile)
37 : ChooserContextBase(profile,
38 CONTENT_SETTINGS_TYPE_BLUETOOTH_CHOOSER_DATA) {}
39
40 BluetoothChooserContext::~BluetoothChooserContext() {}
41
42 void BluetoothChooserContext::GrantDevicePermission(
43 const GURL& requesting_origin,
44 const GURL& embedding_origin,
45 const base::string16& device_name,
46 const std::string& device_id) {
47 scoped_ptr<base::DictionaryValue> device_dict(new base::DictionaryValue());
48 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.
49 device_dict->SetString(kDeviceIdKey, device_id);
50 GrantObjectPermission(requesting_origin, embedding_origin,
51 std::move(device_dict));
52 }
53
54 void BluetoothChooserContext::RevokeDevicePermission(
55 const GURL& requesting_origin,
56 const GURL& embedding_origin,
57 const base::string16& device_name,
58 const std::string& device_id) {
59 std::vector<scoped_ptr<base::DictionaryValue>> device_list =
60 GetGrantedObjects(requesting_origin, embedding_origin);
61 const base::DictionaryValue* entry =
62 FindForDevice(device_list, device_name, device_id);
63 if (entry)
64 RevokeObjectPermission(requesting_origin, embedding_origin, *entry);
65 }
66
67 bool BluetoothChooserContext::HasDevicePermission(
68 const GURL& requesting_origin,
69 const GURL& embedding_origin,
70 const base::string16& device_name,
71 const std::string& device_id) {
72 std::vector<scoped_ptr<base::DictionaryValue>> device_list =
73 GetGrantedObjects(requesting_origin, embedding_origin);
74 return FindForDevice(device_list, device_name, device_id) != nullptr;
75 }
76
77 bool BluetoothChooserContext::IsValidObject(
78 const base::DictionaryValue& object) {
79 return object.size() == 2 && object.HasKey(kDeviceNameKey) &&
80 object.HasKey(kDeviceIdKey);
81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698