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

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: store Bluetooth permissions in website settings 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
16 const base::DictionaryValue* FindForDevice(
17 const std::vector<scoped_ptr<base::DictionaryValue>>& device_list,
18 const std::string& device_id) {
19 for (const scoped_ptr<base::DictionaryValue>& device_dict : device_list) {
20 std::string tmp_device_id;
21 if (device_dict->GetString(kDeviceIdKey, &tmp_device_id) &&
22 tmp_device_id == device_id) {
23 return device_dict.get();
24 }
25 }
26 return nullptr;
27 }
28
29 } // namespace
30
31 BluetoothChooserContext::BluetoothChooserContext(Profile* profile)
32 : ChooserContextBase(profile,
33 CONTENT_SETTINGS_TYPE_BLUETOOTH_CHOOSER_DATA) {}
34
35 BluetoothChooserContext::~BluetoothChooserContext() {}
36
37 void BluetoothChooserContext::GrantDevicePermission(
38 const GURL& requesting_origin,
39 const GURL& embedding_origin,
40 const std::string& device_id) {
41 scoped_ptr<base::DictionaryValue> device_dict(new base::DictionaryValue());
42 device_dict->SetString(kDeviceIdKey, device_id);
43 GrantObjectPermission(requesting_origin, embedding_origin,
44 std::move(device_dict));
45 }
46
47 void BluetoothChooserContext::RevokeDevicePermission(
48 const GURL& requesting_origin,
49 const GURL& embedding_origin,
50 const std::string& device_id) {
51 std::vector<scoped_ptr<base::DictionaryValue>> device_list =
52 GetGrantedObjects(requesting_origin, embedding_origin);
53 const base::DictionaryValue* entry = FindForDevice(device_list, device_id);
54 if (entry)
55 RevokeObjectPermission(requesting_origin, embedding_origin, *entry);
56 }
57
58 bool BluetoothChooserContext::HasDevicePermission(
59 const GURL& requesting_origin,
60 const GURL& embedding_origin,
61 const std::string& device_id) {
62 std::vector<scoped_ptr<base::DictionaryValue>> device_list =
63 GetGrantedObjects(requesting_origin, embedding_origin);
64 return FindForDevice(device_list, device_id) != nullptr;
65 }
66
67 bool BluetoothChooserContext::IsValidObject(
68 const base::DictionaryValue& object) {
69 return object.size() == 1 && object.HasKey(kDeviceIdKey);
70 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698