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 <string> | 7 #include <string> |
8 | 8 |
9 #include "components/crx_file/id_util.h" | 9 #include "components/crx_file/id_util.h" |
10 #include "components/policy/core/common/configuration_policy_provider.h" | 10 #include "components/policy/core/common/configuration_policy_provider.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 } | 34 } |
35 | 35 |
36 ExtensionManagementPrefUpdaterBase::~ExtensionManagementPrefUpdaterBase() { | 36 ExtensionManagementPrefUpdaterBase::~ExtensionManagementPrefUpdaterBase() { |
37 } | 37 } |
38 | 38 |
39 // Helper functions for per extension settings --------------------------------- | 39 // Helper functions for per extension settings --------------------------------- |
40 | 40 |
41 void ExtensionManagementPrefUpdaterBase::UnsetPerExtensionSettings( | 41 void ExtensionManagementPrefUpdaterBase::UnsetPerExtensionSettings( |
42 const ExtensionId& id) { | 42 const ExtensionId& id) { |
43 DCHECK(crx_file::id_util::IdIsValid(id)); | 43 DCHECK(crx_file::id_util::IdIsValid(id)); |
44 pref_->RemoveWithoutPathExpansion(id, NULL); | 44 pref_->RemoveWithoutPathExpansion(id, nullptr); |
45 } | 45 } |
46 | 46 |
47 void ExtensionManagementPrefUpdaterBase::ClearPerExtensionSettings( | 47 void ExtensionManagementPrefUpdaterBase::ClearPerExtensionSettings( |
48 const ExtensionId& id) { | 48 const ExtensionId& id) { |
49 DCHECK(crx_file::id_util::IdIsValid(id)); | 49 DCHECK(crx_file::id_util::IdIsValid(id)); |
50 pref_->SetWithoutPathExpansion(id, new base::DictionaryValue()); | 50 pref_->SetWithoutPathExpansion(id, new base::DictionaryValue()); |
51 } | 51 } |
52 | 52 |
53 // Helper functions for 'installation_mode' manipulation ----------------------- | 53 // Helper functions for 'installation_mode' manipulation ----------------------- |
54 | 54 |
55 void ExtensionManagementPrefUpdaterBase::SetBlacklistedByDefault(bool value) { | 55 void ExtensionManagementPrefUpdaterBase::SetBlacklistedByDefault(bool value) { |
56 pref_->SetString(make_path(schema::kWildcard, schema::kInstallationMode), | 56 pref_->SetString(make_path(schema::kWildcard, schema::kInstallationMode), |
57 value ? schema::kBlocked : schema::kAllowed); | 57 value ? schema::kBlocked : schema::kAllowed); |
58 } | 58 } |
59 | 59 |
60 void ExtensionManagementPrefUpdaterBase:: | 60 void ExtensionManagementPrefUpdaterBase:: |
61 ClearInstallationModesForIndividualExtensions() { | 61 ClearInstallationModesForIndividualExtensions() { |
62 for (base::DictionaryValue::Iterator it(*pref_.get()); !it.IsAtEnd(); | 62 for (base::DictionaryValue::Iterator it(*pref_.get()); !it.IsAtEnd(); |
63 it.Advance()) { | 63 it.Advance()) { |
64 DCHECK(it.value().IsType(base::Value::TYPE_DICTIONARY)); | 64 DCHECK(it.value().IsType(base::Value::TYPE_DICTIONARY)); |
65 if (it.key() != schema::kWildcard) { | 65 if (it.key() != schema::kWildcard) { |
66 DCHECK(crx_file::id_util::IdIsValid(it.key())); | 66 DCHECK(crx_file::id_util::IdIsValid(it.key())); |
67 pref_->Remove(make_path(it.key(), schema::kInstallationMode), NULL); | 67 pref_->Remove(make_path(it.key(), schema::kInstallationMode), nullptr); |
68 pref_->Remove(make_path(it.key(), schema::kUpdateUrl), NULL); | 68 pref_->Remove(make_path(it.key(), schema::kUpdateUrl), nullptr); |
69 } | 69 } |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 void | 73 void |
74 ExtensionManagementPrefUpdaterBase::SetIndividualExtensionInstallationAllowed( | 74 ExtensionManagementPrefUpdaterBase::SetIndividualExtensionInstallationAllowed( |
75 const ExtensionId& id, | 75 const ExtensionId& id, |
76 bool allowed) { | 76 bool allowed) { |
77 DCHECK(crx_file::id_util::IdIsValid(id)); | 77 DCHECK(crx_file::id_util::IdIsValid(id)); |
78 pref_->SetString(make_path(id, schema::kInstallationMode), | 78 pref_->SetString(make_path(id, schema::kInstallationMode), |
79 allowed ? schema::kAllowed : schema::kBlocked); | 79 allowed ? schema::kAllowed : schema::kBlocked); |
80 pref_->Remove(make_path(id, schema::kUpdateUrl), NULL); | 80 pref_->Remove(make_path(id, schema::kUpdateUrl), nullptr); |
81 } | 81 } |
82 | 82 |
83 void ExtensionManagementPrefUpdaterBase::SetIndividualExtensionAutoInstalled( | 83 void ExtensionManagementPrefUpdaterBase::SetIndividualExtensionAutoInstalled( |
84 const ExtensionId& id, | 84 const ExtensionId& id, |
85 const std::string& update_url, | 85 const std::string& update_url, |
86 bool forced) { | 86 bool forced) { |
87 DCHECK(crx_file::id_util::IdIsValid(id)); | 87 DCHECK(crx_file::id_util::IdIsValid(id)); |
88 pref_->SetString(make_path(id, schema::kInstallationMode), | 88 pref_->SetString(make_path(id, schema::kInstallationMode), |
89 forced ? schema::kForceInstalled : schema::kNormalInstalled); | 89 forced ? schema::kForceInstalled : schema::kNormalInstalled); |
90 pref_->SetString(make_path(id, schema::kUpdateUrl), update_url); | 90 pref_->SetString(make_path(id, schema::kUpdateUrl), update_url); |
91 } | 91 } |
92 | 92 |
93 // Helper functions for 'install_sources' manipulation ------------------------- | 93 // Helper functions for 'install_sources' manipulation ------------------------- |
94 | 94 |
95 void ExtensionManagementPrefUpdaterBase::UnsetInstallSources() { | 95 void ExtensionManagementPrefUpdaterBase::UnsetInstallSources() { |
96 pref_->Remove(kInstallSourcesPath, NULL); | 96 pref_->Remove(kInstallSourcesPath, nullptr); |
97 } | 97 } |
98 | 98 |
99 void ExtensionManagementPrefUpdaterBase::ClearInstallSources() { | 99 void ExtensionManagementPrefUpdaterBase::ClearInstallSources() { |
100 ClearList(kInstallSourcesPath); | 100 ClearList(kInstallSourcesPath); |
101 } | 101 } |
102 | 102 |
103 void ExtensionManagementPrefUpdaterBase::AddInstallSource( | 103 void ExtensionManagementPrefUpdaterBase::AddInstallSource( |
104 const std::string& install_source) { | 104 const std::string& install_source) { |
105 AddStringToList(kInstallSourcesPath, install_source); | 105 AddStringToList(kInstallSourcesPath, install_source); |
106 } | 106 } |
107 | 107 |
108 void ExtensionManagementPrefUpdaterBase::RemoveInstallSource( | 108 void ExtensionManagementPrefUpdaterBase::RemoveInstallSource( |
109 const std::string& install_source) { | 109 const std::string& install_source) { |
110 RemoveStringFromList(kInstallSourcesPath, install_source); | 110 RemoveStringFromList(kInstallSourcesPath, install_source); |
111 } | 111 } |
112 | 112 |
113 // Helper functions for 'allowed_types' manipulation --------------------------- | 113 // Helper functions for 'allowed_types' manipulation --------------------------- |
114 | 114 |
115 void ExtensionManagementPrefUpdaterBase::UnsetAllowedTypes() { | 115 void ExtensionManagementPrefUpdaterBase::UnsetAllowedTypes() { |
116 pref_->Remove(kAllowedTypesPath, NULL); | 116 pref_->Remove(kAllowedTypesPath, nullptr); |
117 } | 117 } |
118 | 118 |
119 void ExtensionManagementPrefUpdaterBase::ClearAllowedTypes() { | 119 void ExtensionManagementPrefUpdaterBase::ClearAllowedTypes() { |
120 ClearList(kAllowedTypesPath); | 120 ClearList(kAllowedTypesPath); |
121 } | 121 } |
122 | 122 |
123 void ExtensionManagementPrefUpdaterBase::AddAllowedType( | 123 void ExtensionManagementPrefUpdaterBase::AddAllowedType( |
124 const std::string& allowed_type) { | 124 const std::string& allowed_type) { |
125 AddStringToList(kAllowedTypesPath, allowed_type); | 125 AddStringToList(kAllowedTypesPath, allowed_type); |
126 } | 126 } |
127 | 127 |
128 void ExtensionManagementPrefUpdaterBase::RemoveAllowedType( | 128 void ExtensionManagementPrefUpdaterBase::RemoveAllowedType( |
129 const std::string& allowed_type) { | 129 const std::string& allowed_type) { |
130 RemoveStringFromList(kAllowedTypesPath, allowed_type); | 130 RemoveStringFromList(kAllowedTypesPath, allowed_type); |
131 } | 131 } |
132 | 132 |
133 // Helper functions for 'blocked_permissions' manipulation --------------------- | 133 // Helper functions for 'blocked_permissions' manipulation --------------------- |
134 | 134 |
135 void ExtensionManagementPrefUpdaterBase::UnsetBlockedPermissions( | 135 void ExtensionManagementPrefUpdaterBase::UnsetBlockedPermissions( |
136 const std::string& prefix) { | 136 const std::string& prefix) { |
137 DCHECK(prefix == schema::kWildcard || crx_file::id_util::IdIsValid(prefix)); | 137 DCHECK(prefix == schema::kWildcard || crx_file::id_util::IdIsValid(prefix)); |
138 pref_->Remove(make_path(prefix, schema::kBlockedPermissions), NULL); | 138 pref_->Remove(make_path(prefix, schema::kBlockedPermissions), nullptr); |
139 } | 139 } |
140 | 140 |
141 void ExtensionManagementPrefUpdaterBase::ClearBlockedPermissions( | 141 void ExtensionManagementPrefUpdaterBase::ClearBlockedPermissions( |
142 const std::string& prefix) { | 142 const std::string& prefix) { |
143 DCHECK(prefix == schema::kWildcard || crx_file::id_util::IdIsValid(prefix)); | 143 DCHECK(prefix == schema::kWildcard || crx_file::id_util::IdIsValid(prefix)); |
144 ClearList(make_path(prefix, schema::kBlockedPermissions)); | 144 ClearList(make_path(prefix, schema::kBlockedPermissions)); |
145 } | 145 } |
146 | 146 |
147 void ExtensionManagementPrefUpdaterBase::AddBlockedPermission( | 147 void ExtensionManagementPrefUpdaterBase::AddBlockedPermission( |
148 const std::string& prefix, | 148 const std::string& prefix, |
149 const std::string& permission) { | 149 const std::string& permission) { |
150 DCHECK(prefix == schema::kWildcard || crx_file::id_util::IdIsValid(prefix)); | 150 DCHECK(prefix == schema::kWildcard || crx_file::id_util::IdIsValid(prefix)); |
151 AddStringToList(make_path(prefix, schema::kBlockedPermissions), permission); | 151 AddStringToList(make_path(prefix, schema::kBlockedPermissions), permission); |
152 } | 152 } |
153 | 153 |
154 void ExtensionManagementPrefUpdaterBase::RemoveBlockedPermission( | 154 void ExtensionManagementPrefUpdaterBase::RemoveBlockedPermission( |
155 const std::string& prefix, | 155 const std::string& prefix, |
156 const std::string& permission) { | 156 const std::string& permission) { |
157 DCHECK(prefix == schema::kWildcard || crx_file::id_util::IdIsValid(prefix)); | 157 DCHECK(prefix == schema::kWildcard || crx_file::id_util::IdIsValid(prefix)); |
158 RemoveStringFromList(make_path(prefix, schema::kBlockedPermissions), | 158 RemoveStringFromList(make_path(prefix, schema::kBlockedPermissions), |
159 permission); | 159 permission); |
160 } | 160 } |
161 | 161 |
162 // Helper functions for 'allowed_permissions' manipulation --------------------- | 162 // Helper functions for 'allowed_permissions' manipulation --------------------- |
163 | 163 |
164 void ExtensionManagementPrefUpdaterBase::UnsetAllowedPermissions( | 164 void ExtensionManagementPrefUpdaterBase::UnsetAllowedPermissions( |
165 const std::string& id) { | 165 const std::string& id) { |
166 DCHECK(crx_file::id_util::IdIsValid(id)); | 166 DCHECK(crx_file::id_util::IdIsValid(id)); |
167 pref_->Remove(make_path(id, schema::kAllowedPermissions), NULL); | 167 pref_->Remove(make_path(id, schema::kAllowedPermissions), nullptr); |
168 } | 168 } |
169 | 169 |
170 void ExtensionManagementPrefUpdaterBase::ClearAllowedPermissions( | 170 void ExtensionManagementPrefUpdaterBase::ClearAllowedPermissions( |
171 const std::string& id) { | 171 const std::string& id) { |
172 DCHECK(crx_file::id_util::IdIsValid(id)); | 172 DCHECK(crx_file::id_util::IdIsValid(id)); |
173 ClearList(make_path(id, schema::kAllowedPermissions)); | 173 ClearList(make_path(id, schema::kAllowedPermissions)); |
174 } | 174 } |
175 | 175 |
176 void ExtensionManagementPrefUpdaterBase::AddAllowedPermission( | 176 void ExtensionManagementPrefUpdaterBase::AddAllowedPermission( |
177 const std::string& id, | 177 const std::string& id, |
178 const std::string& permission) { | 178 const std::string& permission) { |
179 DCHECK(crx_file::id_util::IdIsValid(id)); | 179 DCHECK(crx_file::id_util::IdIsValid(id)); |
180 AddStringToList(make_path(id, schema::kAllowedPermissions), permission); | 180 AddStringToList(make_path(id, schema::kAllowedPermissions), permission); |
181 } | 181 } |
182 | 182 |
183 void ExtensionManagementPrefUpdaterBase::RemoveAllowedPermission( | 183 void ExtensionManagementPrefUpdaterBase::RemoveAllowedPermission( |
184 const std::string& id, | 184 const std::string& id, |
185 const std::string& permission) { | 185 const std::string& permission) { |
186 DCHECK(crx_file::id_util::IdIsValid(id)); | 186 DCHECK(crx_file::id_util::IdIsValid(id)); |
187 RemoveStringFromList(make_path(id, schema::kAllowedPermissions), permission); | 187 RemoveStringFromList(make_path(id, schema::kAllowedPermissions), permission); |
188 } | 188 } |
189 | 189 |
| 190 // Helper functions for 'minimum_version' manipulation ------------------------- |
| 191 |
| 192 void ExtensionManagementPrefUpdaterBase::SetMinimumVersion( |
| 193 const std::string& id, |
| 194 const std::string& version) { |
| 195 DCHECK(crx_file::id_util::IdIsValid(id)); |
| 196 pref_->SetString(make_path(id, schema::kMinimumVersion), version); |
| 197 } |
| 198 |
| 199 void ExtensionManagementPrefUpdaterBase::UnsetMinimumVersion( |
| 200 const std::string& id) { |
| 201 DCHECK(crx_file::id_util::IdIsValid(id)); |
| 202 pref_->Remove(make_path(id, schema::kMinimumVersion), nullptr); |
| 203 } |
| 204 |
190 // Expose a read-only preference to user --------------------------------------- | 205 // Expose a read-only preference to user --------------------------------------- |
191 | 206 |
192 const base::DictionaryValue* ExtensionManagementPrefUpdaterBase::GetPref() { | 207 const base::DictionaryValue* ExtensionManagementPrefUpdaterBase::GetPref() { |
193 return pref_.get(); | 208 return pref_.get(); |
194 } | 209 } |
195 | 210 |
196 // Private section functions --------------------------------------------------- | 211 // Private section functions --------------------------------------------------- |
197 | 212 |
198 void ExtensionManagementPrefUpdaterBase::SetPref(base::DictionaryValue* pref) { | 213 void ExtensionManagementPrefUpdaterBase::SetPref(base::DictionaryValue* pref) { |
199 pref_.reset(pref); | 214 pref_.reset(pref); |
200 } | 215 } |
201 | 216 |
202 scoped_ptr<base::DictionaryValue> | 217 scoped_ptr<base::DictionaryValue> |
203 ExtensionManagementPrefUpdaterBase::TakePref() { | 218 ExtensionManagementPrefUpdaterBase::TakePref() { |
204 return pref_.Pass(); | 219 return pref_.Pass(); |
205 } | 220 } |
206 | 221 |
207 void ExtensionManagementPrefUpdaterBase::ClearList(const std::string& path) { | 222 void ExtensionManagementPrefUpdaterBase::ClearList(const std::string& path) { |
208 pref_->Set(path, new base::ListValue()); | 223 pref_->Set(path, new base::ListValue()); |
209 } | 224 } |
210 | 225 |
211 void ExtensionManagementPrefUpdaterBase::AddStringToList( | 226 void ExtensionManagementPrefUpdaterBase::AddStringToList( |
212 const std::string& path, | 227 const std::string& path, |
213 const std::string& str) { | 228 const std::string& str) { |
214 base::ListValue* list_value = NULL; | 229 base::ListValue* list_value = nullptr; |
215 if (!pref_->GetList(path, &list_value)) { | 230 if (!pref_->GetList(path, &list_value)) { |
216 list_value = new base::ListValue(); | 231 list_value = new base::ListValue(); |
217 pref_->Set(path, list_value); | 232 pref_->Set(path, list_value); |
218 } | 233 } |
219 CHECK(list_value->AppendIfNotPresent(new base::StringValue(str))); | 234 CHECK(list_value->AppendIfNotPresent(new base::StringValue(str))); |
220 } | 235 } |
221 | 236 |
222 void ExtensionManagementPrefUpdaterBase::RemoveStringFromList( | 237 void ExtensionManagementPrefUpdaterBase::RemoveStringFromList( |
223 const std::string& path, | 238 const std::string& path, |
224 const std::string& str) { | 239 const std::string& str) { |
225 base::ListValue* list_value = NULL; | 240 base::ListValue* list_value = nullptr; |
226 if (pref_->GetList(path, &list_value)) | 241 if (pref_->GetList(path, &list_value)) |
227 CHECK(list_value->Remove(base::StringValue(str), NULL)); | 242 CHECK(list_value->Remove(base::StringValue(str), nullptr)); |
228 } | 243 } |
229 | 244 |
230 // ExtensionManagementPolicyUpdater -------------------------------------------- | 245 // ExtensionManagementPolicyUpdater -------------------------------------------- |
231 | 246 |
232 ExtensionManagementPolicyUpdater::ExtensionManagementPolicyUpdater( | 247 ExtensionManagementPolicyUpdater::ExtensionManagementPolicyUpdater( |
233 policy::MockConfigurationPolicyProvider* policy_provider) | 248 policy::MockConfigurationPolicyProvider* policy_provider) |
234 : provider_(policy_provider), policies_(new policy::PolicyBundle) { | 249 : provider_(policy_provider), policies_(new policy::PolicyBundle) { |
235 policies_->CopyFrom(provider_->policies()); | 250 policies_->CopyFrom(provider_->policies()); |
236 const base::Value* policy_value = | 251 const base::Value* policy_value = |
237 policies_->Get(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, | 252 policies_->Get(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, |
238 std::string())) | 253 std::string())) |
239 .GetValue(policy::key::kExtensionSettings); | 254 .GetValue(policy::key::kExtensionSettings); |
240 const base::DictionaryValue* dict_value = nullptr; | 255 const base::DictionaryValue* dict_value = nullptr; |
241 if (policy_value && policy_value->GetAsDictionary(&dict_value)) | 256 if (policy_value && policy_value->GetAsDictionary(&dict_value)) |
242 SetPref(dict_value->DeepCopy()); | 257 SetPref(dict_value->DeepCopy()); |
243 else | 258 else |
244 SetPref(new base::DictionaryValue); | 259 SetPref(new base::DictionaryValue); |
245 } | 260 } |
246 | 261 |
247 ExtensionManagementPolicyUpdater::~ExtensionManagementPolicyUpdater() { | 262 ExtensionManagementPolicyUpdater::~ExtensionManagementPolicyUpdater() { |
248 policies_->Get(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, | 263 policies_->Get(policy::PolicyNamespace(policy::POLICY_DOMAIN_CHROME, |
249 std::string())) | 264 std::string())) |
250 .Set(policy::key::kExtensionSettings, policy::POLICY_LEVEL_MANDATORY, | 265 .Set(policy::key::kExtensionSettings, policy::POLICY_LEVEL_MANDATORY, |
251 policy::POLICY_SCOPE_USER, TakePref().release(), nullptr); | 266 policy::POLICY_SCOPE_USER, TakePref().release(), nullptr); |
252 provider_->UpdatePolicy(policies_.Pass()); | 267 provider_->UpdatePolicy(policies_.Pass()); |
253 } | 268 } |
254 | 269 |
255 } // namespace extensions | 270 } // namespace extensions |
OLD | NEW |