OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/extensions/extension_management_test_util.h" | 5 #include "chrome/browser/extensions/extension_management_test_util.h" |
6 | 6 |
7 #include "components/crx_file/id_util.h" | 7 #include "components/crx_file/id_util.h" |
8 | 8 |
9 namespace extensions { | 9 namespace extensions { |
10 | 10 |
11 namespace schema = schema_constants; | 11 namespace schema = schema_constants; |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 const char kInstallSourcesPath[] = "*.install_sources"; | |
16 const char kAllowedTypesPath[] = "*.allowed_types"; | |
17 | |
15 std::string make_path(std::string a, std::string b) { | 18 std::string make_path(std::string a, std::string b) { |
16 return a + "." + b; | 19 return a + "." + b; |
17 } | 20 } |
18 | 21 |
19 const char kInstallSourcesPath[] = "*.install_sources"; | |
20 const char kAllowedTypesPath[] = "*.allowed_types"; | |
21 | |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 ExtensionManagementPrefUpdaterBase::ExtensionManagementPrefUpdaterBase() { | 24 ExtensionManagementPrefUpdaterBase::ExtensionManagementPrefUpdaterBase() { |
25 } | 25 } |
26 | 26 |
27 ExtensionManagementPrefUpdaterBase::~ExtensionManagementPrefUpdaterBase() { | 27 ExtensionManagementPrefUpdaterBase::~ExtensionManagementPrefUpdaterBase() { |
28 } | 28 } |
29 | 29 |
30 // Helper functions for per extension settings --------------------------------- | |
31 | |
30 void ExtensionManagementPrefUpdaterBase::UnsetPerExtensionSettings( | 32 void ExtensionManagementPrefUpdaterBase::UnsetPerExtensionSettings( |
31 const ExtensionId& id) { | 33 const ExtensionId& id) { |
32 DCHECK(crx_file::id_util::IdIsValid(id)); | 34 DCHECK(crx_file::id_util::IdIsValid(id)); |
33 pref_->RemoveWithoutPathExpansion(id, NULL); | 35 pref_->RemoveWithoutPathExpansion(id, NULL); |
34 } | 36 } |
35 | 37 |
36 void ExtensionManagementPrefUpdaterBase::ClearPerExtensionSettings( | 38 void ExtensionManagementPrefUpdaterBase::ClearPerExtensionSettings( |
37 const ExtensionId& id) { | 39 const ExtensionId& id) { |
38 DCHECK(crx_file::id_util::IdIsValid(id)); | 40 DCHECK(crx_file::id_util::IdIsValid(id)); |
39 pref_->SetWithoutPathExpansion(id, new base::DictionaryValue()); | 41 pref_->SetWithoutPathExpansion(id, new base::DictionaryValue()); |
40 } | 42 } |
41 | 43 |
44 // Helper functions for 'installation_mode' manipulation ----------------------- | |
45 | |
42 void ExtensionManagementPrefUpdaterBase::SetBlacklistedByDefault(bool value) { | 46 void ExtensionManagementPrefUpdaterBase::SetBlacklistedByDefault(bool value) { |
43 pref_->SetString(make_path(schema::kWildcard, schema::kInstallationMode), | 47 pref_->SetString(make_path(schema::kWildcard, schema::kInstallationMode), |
44 value ? schema::kBlocked : schema::kAllowed); | 48 value ? schema::kBlocked : schema::kAllowed); |
45 } | 49 } |
46 | 50 |
47 void ExtensionManagementPrefUpdaterBase:: | 51 void ExtensionManagementPrefUpdaterBase:: |
48 ClearInstallationModesForIndividualExtensions() { | 52 ClearInstallationModesForIndividualExtensions() { |
49 for (base::DictionaryValue::Iterator it(*pref_.get()); !it.IsAtEnd(); | 53 for (base::DictionaryValue::Iterator it(*pref_.get()); !it.IsAtEnd(); |
50 it.Advance()) { | 54 it.Advance()) { |
51 DCHECK(it.value().IsType(base::Value::TYPE_DICTIONARY)); | 55 DCHECK(it.value().IsType(base::Value::TYPE_DICTIONARY)); |
(...skipping 18 matching lines...) Expand all Loading... | |
70 void ExtensionManagementPrefUpdaterBase::SetIndividualExtensionAutoInstalled( | 74 void ExtensionManagementPrefUpdaterBase::SetIndividualExtensionAutoInstalled( |
71 const ExtensionId& id, | 75 const ExtensionId& id, |
72 const std::string& update_url, | 76 const std::string& update_url, |
73 bool forced) { | 77 bool forced) { |
74 DCHECK(crx_file::id_util::IdIsValid(id)); | 78 DCHECK(crx_file::id_util::IdIsValid(id)); |
75 pref_->SetString(make_path(id, schema::kInstallationMode), | 79 pref_->SetString(make_path(id, schema::kInstallationMode), |
76 forced ? schema::kForceInstalled : schema::kNormalInstalled); | 80 forced ? schema::kForceInstalled : schema::kNormalInstalled); |
77 pref_->SetString(make_path(id, schema::kUpdateUrl), update_url); | 81 pref_->SetString(make_path(id, schema::kUpdateUrl), update_url); |
78 } | 82 } |
79 | 83 |
84 // Helper functions for 'install_sources' manipulation ------------------------- | |
85 | |
80 void ExtensionManagementPrefUpdaterBase::UnsetInstallSources() { | 86 void ExtensionManagementPrefUpdaterBase::UnsetInstallSources() { |
81 pref_->Remove(kInstallSourcesPath, NULL); | 87 pref_->Remove(kInstallSourcesPath, NULL); |
82 } | 88 } |
83 | 89 |
84 void ExtensionManagementPrefUpdaterBase::ClearInstallSources() { | 90 void ExtensionManagementPrefUpdaterBase::ClearInstallSources() { |
85 ClearList(kInstallSourcesPath); | 91 ClearList(kInstallSourcesPath); |
86 } | 92 } |
87 | 93 |
88 void ExtensionManagementPrefUpdaterBase::AddInstallSource( | 94 void ExtensionManagementPrefUpdaterBase::AddInstallSource( |
89 const std::string& install_source) { | 95 const std::string& install_source) { |
90 AddStringToList(kInstallSourcesPath, install_source); | 96 AddStringToList(kInstallSourcesPath, install_source); |
91 } | 97 } |
92 | 98 |
93 void ExtensionManagementPrefUpdaterBase::RemoveInstallSource( | 99 void ExtensionManagementPrefUpdaterBase::RemoveInstallSource( |
94 const std::string& install_source) { | 100 const std::string& install_source) { |
95 RemoveStringFromList(kInstallSourcesPath, install_source); | 101 RemoveStringFromList(kInstallSourcesPath, install_source); |
96 } | 102 } |
97 | 103 |
104 // Helper functions for 'allowed_types' manipulation --------------------------- | |
105 | |
98 void ExtensionManagementPrefUpdaterBase::UnsetAllowedTypes() { | 106 void ExtensionManagementPrefUpdaterBase::UnsetAllowedTypes() { |
99 pref_->Remove(kAllowedTypesPath, NULL); | 107 pref_->Remove(kAllowedTypesPath, NULL); |
100 } | 108 } |
101 | 109 |
102 void ExtensionManagementPrefUpdaterBase::ClearAllowedTypes() { | 110 void ExtensionManagementPrefUpdaterBase::ClearAllowedTypes() { |
103 ClearList(kAllowedTypesPath); | 111 ClearList(kAllowedTypesPath); |
104 } | 112 } |
105 | 113 |
106 void ExtensionManagementPrefUpdaterBase::AddAllowedType( | 114 void ExtensionManagementPrefUpdaterBase::AddAllowedType( |
107 const std::string& allowed_type) { | 115 const std::string& allowed_type) { |
108 AddStringToList(kAllowedTypesPath, allowed_type); | 116 AddStringToList(kAllowedTypesPath, allowed_type); |
109 } | 117 } |
110 | 118 |
119 void ExtensionManagementPrefUpdaterBase::RemoveAllowedType( | |
120 const std::string& allowd_type) { | |
Joao da Silva
2014/10/15 14:39:25
allowed_type
binjin
2014/10/16 18:13:58
Done.
| |
121 RemoveStringFromList(kAllowedTypesPath, allowd_type); | |
122 } | |
123 | |
124 // Helper functions for 'blocked_permissions' manipulation --------------------- | |
125 | |
126 void ExtensionManagementPrefUpdaterBase::UnsetBlockedPermissions( | |
127 const std::string& prefix) { | |
128 DCHECK(prefix == schema::kWildcard || crx_file::id_util::IdIsValid(prefix)); | |
129 pref_->Remove(make_path(prefix, schema::kBlockedPermissions), NULL); | |
130 } | |
131 | |
132 void ExtensionManagementPrefUpdaterBase::ClearBlockedPermissions( | |
133 const std::string& prefix) { | |
134 DCHECK(prefix == schema::kWildcard || crx_file::id_util::IdIsValid(prefix)); | |
135 ClearList(make_path(prefix, schema::kBlockedPermissions)); | |
136 } | |
137 | |
138 void ExtensionManagementPrefUpdaterBase::AddBlockedPermission( | |
139 const std::string& prefix, | |
140 const std::string& permission) { | |
141 DCHECK(prefix == schema::kWildcard || crx_file::id_util::IdIsValid(prefix)); | |
142 AddStringToList(make_path(prefix, schema::kBlockedPermissions), permission); | |
143 } | |
144 | |
145 void ExtensionManagementPrefUpdaterBase::RemoveBlockedPermission( | |
146 const std::string& prefix, | |
147 const std::string& permission) { | |
148 DCHECK(prefix == schema::kWildcard || crx_file::id_util::IdIsValid(prefix)); | |
149 RemoveStringFromList(make_path(prefix, schema::kBlockedPermissions), | |
150 permission); | |
151 } | |
152 | |
153 // Helper functions for 'allowed_permissions' manipulation --------------------- | |
154 | |
155 void ExtensionManagementPrefUpdaterBase::UnsetAllowedPermissions( | |
156 const std::string& id) { | |
157 DCHECK(crx_file::id_util::IdIsValid(id)); | |
158 pref_->Remove(make_path(id, schema::kAllowedPermissions), NULL); | |
159 } | |
160 | |
161 void ExtensionManagementPrefUpdaterBase::ClearAllowedPermissions( | |
162 const std::string& id) { | |
163 DCHECK(crx_file::id_util::IdIsValid(id)); | |
164 ClearList(make_path(id, schema::kAllowedPermissions)); | |
165 } | |
166 | |
167 void ExtensionManagementPrefUpdaterBase::AddAllowedPermission( | |
168 const std::string& id, | |
169 const std::string& permission) { | |
170 DCHECK(crx_file::id_util::IdIsValid(id)); | |
171 AddStringToList(make_path(id, schema::kAllowedPermissions), permission); | |
172 } | |
173 | |
174 void ExtensionManagementPrefUpdaterBase::RemoveAllowedPermission( | |
175 const std::string& id, | |
176 const std::string& permission) { | |
177 DCHECK(crx_file::id_util::IdIsValid(id)); | |
178 RemoveStringFromList(make_path(id, schema::kAllowedPermissions), permission); | |
179 } | |
180 | |
181 // Expose a read-only preference to user --------------------------------------- | |
182 | |
111 const base::DictionaryValue* ExtensionManagementPrefUpdaterBase::GetPref() { | 183 const base::DictionaryValue* ExtensionManagementPrefUpdaterBase::GetPref() { |
112 return pref_.get(); | 184 return pref_.get(); |
113 } | 185 } |
114 | 186 |
187 // Private section functions --------------------------------------------------- | |
188 | |
115 void ExtensionManagementPrefUpdaterBase::SetPref(base::DictionaryValue* pref) { | 189 void ExtensionManagementPrefUpdaterBase::SetPref(base::DictionaryValue* pref) { |
116 pref_.reset(pref); | 190 pref_.reset(pref); |
117 } | 191 } |
118 | 192 |
119 scoped_ptr<base::DictionaryValue> | 193 scoped_ptr<base::DictionaryValue> |
120 ExtensionManagementPrefUpdaterBase::TakePref() { | 194 ExtensionManagementPrefUpdaterBase::TakePref() { |
121 return pref_.Pass(); | 195 return pref_.Pass(); |
122 } | 196 } |
123 | 197 |
124 void ExtensionManagementPrefUpdaterBase::RemoveAllowedType( | |
125 const std::string& allowd_type) { | |
126 RemoveStringFromList(kAllowedTypesPath, allowd_type); | |
127 } | |
128 | |
129 void ExtensionManagementPrefUpdaterBase::ClearList(const std::string& path) { | 198 void ExtensionManagementPrefUpdaterBase::ClearList(const std::string& path) { |
130 pref_->Set(path, new base::ListValue()); | 199 pref_->Set(path, new base::ListValue()); |
131 } | 200 } |
132 | 201 |
133 void ExtensionManagementPrefUpdaterBase::AddStringToList( | 202 void ExtensionManagementPrefUpdaterBase::AddStringToList( |
134 const std::string& path, | 203 const std::string& path, |
135 const std::string& str) { | 204 const std::string& str) { |
136 base::ListValue* list_value = NULL; | 205 base::ListValue* list_value = NULL; |
137 if (!pref_->GetList(path, &list_value)) { | 206 if (!pref_->GetList(path, &list_value)) { |
138 list_value = new base::ListValue(); | 207 list_value = new base::ListValue(); |
139 pref_->Set(path, list_value); | 208 pref_->Set(path, list_value); |
140 } | 209 } |
141 CHECK(list_value->AppendIfNotPresent(new base::StringValue(str))); | 210 CHECK(list_value->AppendIfNotPresent(new base::StringValue(str))); |
142 } | 211 } |
143 | 212 |
144 void ExtensionManagementPrefUpdaterBase::RemoveStringFromList( | 213 void ExtensionManagementPrefUpdaterBase::RemoveStringFromList( |
145 const std::string& path, | 214 const std::string& path, |
146 const std::string& str) { | 215 const std::string& str) { |
147 base::ListValue* list_value = NULL; | 216 base::ListValue* list_value = NULL; |
148 if (pref_->GetList(path, &list_value)) | 217 if (pref_->GetList(path, &list_value)) |
149 CHECK(list_value->Remove(base::StringValue(str), NULL)); | 218 CHECK(list_value->Remove(base::StringValue(str), NULL)); |
150 } | 219 } |
151 | 220 |
152 } // namespace extensions | 221 } // namespace extensions |
OLD | NEW |