OLD | NEW |
(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 } |
OLD | NEW |