OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/permissions/chooser_context_base.h" | 5 #include "chrome/browser/permissions/chooser_context_base.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
8 #include "components/content_settings/core/browser/host_content_settings_map.h" | 10 #include "components/content_settings/core/browser/host_content_settings_map.h" |
9 | 11 |
10 const char kObjectListKey[] = "chosen-objects"; | 12 const char kObjectListKey[] = "chosen-objects"; |
11 | 13 |
12 ChooserContextBase::ChooserContextBase( | 14 ChooserContextBase::ChooserContextBase( |
13 Profile* profile, | 15 Profile* profile, |
14 const ContentSettingsType data_content_settings_type) | 16 const ContentSettingsType data_content_settings_type) |
15 : host_content_settings_map_( | 17 : host_content_settings_map_( |
16 HostContentSettingsMapFactory::GetForProfile(profile)), | 18 HostContentSettingsMapFactory::GetForProfile(profile)), |
(...skipping 21 matching lines...) Expand all Loading... |
38 ChooserContextBase::GetGrantedObjects(const GURL& requesting_origin, | 40 ChooserContextBase::GetGrantedObjects(const GURL& requesting_origin, |
39 const GURL& embedding_origin) { | 41 const GURL& embedding_origin) { |
40 std::vector<scoped_ptr<base::DictionaryValue>> results; | 42 std::vector<scoped_ptr<base::DictionaryValue>> results; |
41 scoped_ptr<base::DictionaryValue> setting = | 43 scoped_ptr<base::DictionaryValue> setting = |
42 GetWebsiteSetting(requesting_origin, embedding_origin); | 44 GetWebsiteSetting(requesting_origin, embedding_origin); |
43 scoped_ptr<base::Value> objects; | 45 scoped_ptr<base::Value> objects; |
44 if (!setting->Remove(kObjectListKey, &objects)) | 46 if (!setting->Remove(kObjectListKey, &objects)) |
45 return results; | 47 return results; |
46 | 48 |
47 scoped_ptr<base::ListValue> object_list = | 49 scoped_ptr<base::ListValue> object_list = |
48 base::ListValue::From(objects.Pass()); | 50 base::ListValue::From(std::move(objects)); |
49 if (!object_list) | 51 if (!object_list) |
50 return results; | 52 return results; |
51 | 53 |
52 for (base::ListValue::iterator it = object_list->begin(); | 54 for (base::ListValue::iterator it = object_list->begin(); |
53 it != object_list->end(); ++it) { | 55 it != object_list->end(); ++it) { |
54 // Steal ownership of |object| from |object_list|. | 56 // Steal ownership of |object| from |object_list|. |
55 scoped_ptr<base::Value> object(*it); | 57 scoped_ptr<base::Value> object(*it); |
56 *it = nullptr; | 58 *it = nullptr; |
57 | 59 |
58 scoped_ptr<base::DictionaryValue> object_dict = | 60 scoped_ptr<base::DictionaryValue> object_dict = |
59 base::DictionaryValue::From(object.Pass()); | 61 base::DictionaryValue::From(std::move(object)); |
60 if (object_dict && IsValidObject(*object_dict)) | 62 if (object_dict && IsValidObject(*object_dict)) |
61 results.push_back(object_dict.Pass()); | 63 results.push_back(std::move(object_dict)); |
62 } | 64 } |
63 return results; | 65 return results; |
64 } | 66 } |
65 | 67 |
66 std::vector<scoped_ptr<ChooserContextBase::Object>> | 68 std::vector<scoped_ptr<ChooserContextBase::Object>> |
67 ChooserContextBase::GetAllGrantedObjects() { | 69 ChooserContextBase::GetAllGrantedObjects() { |
68 ContentSettingsForOneType content_settings; | 70 ContentSettingsForOneType content_settings; |
69 host_content_settings_map_->GetSettingsForOneType( | 71 host_content_settings_map_->GetSettingsForOneType( |
70 data_content_settings_type_, std::string(), &content_settings); | 72 data_content_settings_type_, std::string(), &content_settings); |
71 | 73 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 DCHECK(object); | 107 DCHECK(object); |
106 DCHECK(IsValidObject(*object)); | 108 DCHECK(IsValidObject(*object)); |
107 scoped_ptr<base::DictionaryValue> setting = | 109 scoped_ptr<base::DictionaryValue> setting = |
108 GetWebsiteSetting(requesting_origin, embedding_origin); | 110 GetWebsiteSetting(requesting_origin, embedding_origin); |
109 base::ListValue* object_list; | 111 base::ListValue* object_list; |
110 if (!setting->GetList(kObjectListKey, &object_list)) { | 112 if (!setting->GetList(kObjectListKey, &object_list)) { |
111 object_list = new base::ListValue(); | 113 object_list = new base::ListValue(); |
112 setting->Set(kObjectListKey, object_list); | 114 setting->Set(kObjectListKey, object_list); |
113 } | 115 } |
114 object_list->AppendIfNotPresent(object.release()); | 116 object_list->AppendIfNotPresent(object.release()); |
115 SetWebsiteSetting(requesting_origin, embedding_origin, setting.Pass()); | 117 SetWebsiteSetting(requesting_origin, embedding_origin, std::move(setting)); |
116 } | 118 } |
117 | 119 |
118 void ChooserContextBase::RevokeObjectPermission( | 120 void ChooserContextBase::RevokeObjectPermission( |
119 const GURL& requesting_origin, | 121 const GURL& requesting_origin, |
120 const GURL& embedding_origin, | 122 const GURL& embedding_origin, |
121 const base::DictionaryValue& object) { | 123 const base::DictionaryValue& object) { |
122 DCHECK(IsValidObject(object)); | 124 DCHECK(IsValidObject(object)); |
123 scoped_ptr<base::DictionaryValue> setting = | 125 scoped_ptr<base::DictionaryValue> setting = |
124 GetWebsiteSetting(requesting_origin, embedding_origin); | 126 GetWebsiteSetting(requesting_origin, embedding_origin); |
125 base::ListValue* object_list; | 127 base::ListValue* object_list; |
126 if (!setting->GetList(kObjectListKey, &object_list)) | 128 if (!setting->GetList(kObjectListKey, &object_list)) |
127 return; | 129 return; |
128 object_list->Remove(object, nullptr); | 130 object_list->Remove(object, nullptr); |
129 SetWebsiteSetting(requesting_origin, embedding_origin, setting.Pass()); | 131 SetWebsiteSetting(requesting_origin, embedding_origin, std::move(setting)); |
130 } | 132 } |
131 | 133 |
132 scoped_ptr<base::DictionaryValue> ChooserContextBase::GetWebsiteSetting( | 134 scoped_ptr<base::DictionaryValue> ChooserContextBase::GetWebsiteSetting( |
133 const GURL& requesting_origin, | 135 const GURL& requesting_origin, |
134 const GURL& embedding_origin) { | 136 const GURL& embedding_origin) { |
135 scoped_ptr<base::DictionaryValue> value = | 137 scoped_ptr<base::DictionaryValue> value = |
136 base::DictionaryValue::From(host_content_settings_map_->GetWebsiteSetting( | 138 base::DictionaryValue::From(host_content_settings_map_->GetWebsiteSetting( |
137 requesting_origin, embedding_origin, data_content_settings_type_, | 139 requesting_origin, embedding_origin, data_content_settings_type_, |
138 std::string(), nullptr)); | 140 std::string(), nullptr)); |
139 if (!value) | 141 if (!value) |
140 value.reset(new base::DictionaryValue()); | 142 value.reset(new base::DictionaryValue()); |
141 | 143 |
142 return value.Pass(); | 144 return value; |
143 } | 145 } |
144 | 146 |
145 void ChooserContextBase::SetWebsiteSetting(const GURL& requesting_origin, | 147 void ChooserContextBase::SetWebsiteSetting(const GURL& requesting_origin, |
146 const GURL& embedding_origin, | 148 const GURL& embedding_origin, |
147 scoped_ptr<base::Value> value) { | 149 scoped_ptr<base::Value> value) { |
148 host_content_settings_map_->SetWebsiteSettingDefaultScope( | 150 host_content_settings_map_->SetWebsiteSettingDefaultScope( |
149 requesting_origin, embedding_origin, data_content_settings_type_, | 151 requesting_origin, embedding_origin, data_content_settings_type_, |
150 std::string(), value.release()); | 152 std::string(), value.release()); |
151 } | 153 } |
OLD | NEW |