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

Side by Side Diff: chrome/browser/extensions/policy_handlers.cc

Issue 2539363004: Make base::Value::TYPE a scoped enum. (Closed)
Patch Set: Rebase Created 4 years 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/policy_handlers.h" 5 #include "chrome/browser/extensions/policy_handlers.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 10 matching lines...) Expand all
21 #include "extensions/common/extension.h" 21 #include "extensions/common/extension.h"
22 #include "url/gurl.h" 22 #include "url/gurl.h"
23 23
24 namespace extensions { 24 namespace extensions {
25 25
26 // ExtensionListPolicyHandler implementation ----------------------------------- 26 // ExtensionListPolicyHandler implementation -----------------------------------
27 27
28 ExtensionListPolicyHandler::ExtensionListPolicyHandler(const char* policy_name, 28 ExtensionListPolicyHandler::ExtensionListPolicyHandler(const char* policy_name,
29 const char* pref_path, 29 const char* pref_path,
30 bool allow_wildcards) 30 bool allow_wildcards)
31 : policy::TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST), 31 : policy::TypeCheckingPolicyHandler(policy_name, base::Value::Type::LIST),
32 pref_path_(pref_path), 32 pref_path_(pref_path),
33 allow_wildcards_(allow_wildcards) {} 33 allow_wildcards_(allow_wildcards) {}
34 34
35 ExtensionListPolicyHandler::~ExtensionListPolicyHandler() {} 35 ExtensionListPolicyHandler::~ExtensionListPolicyHandler() {}
36 36
37 bool ExtensionListPolicyHandler::CheckPolicySettings( 37 bool ExtensionListPolicyHandler::CheckPolicySettings(
38 const policy::PolicyMap& policies, 38 const policy::PolicyMap& policies,
39 policy::PolicyErrorMap* errors) { 39 policy::PolicyErrorMap* errors) {
40 return CheckAndGetList(policies, errors, NULL); 40 return CheckAndGetList(policies, errors, NULL);
41 } 41 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 74 }
75 75
76 // Filter the list, rejecting any invalid extension IDs. 76 // Filter the list, rejecting any invalid extension IDs.
77 std::unique_ptr<base::ListValue> filtered_list(new base::ListValue()); 77 std::unique_ptr<base::ListValue> filtered_list(new base::ListValue());
78 for (base::ListValue::const_iterator entry(list_value->begin()); 78 for (base::ListValue::const_iterator entry(list_value->begin());
79 entry != list_value->end(); ++entry) { 79 entry != list_value->end(); ++entry) {
80 std::string id; 80 std::string id;
81 if (!(*entry)->GetAsString(&id)) { 81 if (!(*entry)->GetAsString(&id)) {
82 errors->AddError(policy_name(), entry - list_value->begin(), 82 errors->AddError(policy_name(), entry - list_value->begin(),
83 IDS_POLICY_TYPE_ERROR, 83 IDS_POLICY_TYPE_ERROR,
84 base::Value::GetTypeName(base::Value::TYPE_STRING)); 84 base::Value::GetTypeName(base::Value::Type::STRING));
85 continue; 85 continue;
86 } 86 }
87 if (!(allow_wildcards_ && id == "*") && !crx_file::id_util::IdIsValid(id)) { 87 if (!(allow_wildcards_ && id == "*") && !crx_file::id_util::IdIsValid(id)) {
88 errors->AddError(policy_name(), 88 errors->AddError(policy_name(),
89 entry - list_value->begin(), 89 entry - list_value->begin(),
90 IDS_POLICY_VALUE_FORMAT_ERROR); 90 IDS_POLICY_VALUE_FORMAT_ERROR);
91 continue; 91 continue;
92 } 92 }
93 filtered_list->AppendString(id); 93 filtered_list->AppendString(id);
94 } 94 }
95 95
96 if (extension_ids) 96 if (extension_ids)
97 *extension_ids = std::move(filtered_list); 97 *extension_ids = std::move(filtered_list);
98 98
99 return true; 99 return true;
100 } 100 }
101 101
102 // ExtensionInstallForcelistPolicyHandler implementation ----------------------- 102 // ExtensionInstallForcelistPolicyHandler implementation -----------------------
103 103
104 ExtensionInstallForcelistPolicyHandler::ExtensionInstallForcelistPolicyHandler() 104 ExtensionInstallForcelistPolicyHandler::ExtensionInstallForcelistPolicyHandler()
105 : policy::TypeCheckingPolicyHandler(policy::key::kExtensionInstallForcelist, 105 : policy::TypeCheckingPolicyHandler(policy::key::kExtensionInstallForcelist,
106 base::Value::TYPE_LIST) {} 106 base::Value::Type::LIST) {}
107 107
108 ExtensionInstallForcelistPolicyHandler:: 108 ExtensionInstallForcelistPolicyHandler::
109 ~ExtensionInstallForcelistPolicyHandler() {} 109 ~ExtensionInstallForcelistPolicyHandler() {}
110 110
111 bool ExtensionInstallForcelistPolicyHandler::CheckPolicySettings( 111 bool ExtensionInstallForcelistPolicyHandler::CheckPolicySettings(
112 const policy::PolicyMap& policies, 112 const policy::PolicyMap& policies,
113 policy::PolicyErrorMap* errors) { 113 policy::PolicyErrorMap* errors) {
114 const base::Value* value; 114 const base::Value* value;
115 return CheckAndGetValue(policies, errors, &value) && 115 return CheckAndGetValue(policies, errors, &value) &&
116 ParseList(value, NULL, errors); 116 ParseList(value, NULL, errors);
(...skipping 25 matching lines...) Expand all
142 return false; 142 return false;
143 } 143 }
144 144
145 for (base::ListValue::const_iterator entry(policy_list_value->begin()); 145 for (base::ListValue::const_iterator entry(policy_list_value->begin());
146 entry != policy_list_value->end(); ++entry) { 146 entry != policy_list_value->end(); ++entry) {
147 std::string entry_string; 147 std::string entry_string;
148 if (!(*entry)->GetAsString(&entry_string)) { 148 if (!(*entry)->GetAsString(&entry_string)) {
149 if (errors) { 149 if (errors) {
150 errors->AddError(policy_name(), entry - policy_list_value->begin(), 150 errors->AddError(policy_name(), entry - policy_list_value->begin(),
151 IDS_POLICY_TYPE_ERROR, 151 IDS_POLICY_TYPE_ERROR,
152 base::Value::GetTypeName(base::Value::TYPE_STRING)); 152 base::Value::GetTypeName(base::Value::Type::STRING));
153 } 153 }
154 continue; 154 continue;
155 } 155 }
156 156
157 // Each string item of the list has the following form: 157 // Each string item of the list has the following form:
158 // <extension_id>;<update_url> 158 // <extension_id>;<update_url>
159 // Note: The update URL might also contain semicolons. 159 // Note: The update URL might also contain semicolons.
160 size_t pos = entry_string.find(';'); 160 size_t pos = entry_string.find(';');
161 if (pos == std::string::npos) { 161 if (pos == std::string::npos) {
162 if (errors) { 162 if (errors) {
(...skipping 23 matching lines...) Expand all
186 } 186 }
187 187
188 return true; 188 return true;
189 } 189 }
190 190
191 // ExtensionURLPatternListPolicyHandler implementation ------------------------- 191 // ExtensionURLPatternListPolicyHandler implementation -------------------------
192 192
193 ExtensionURLPatternListPolicyHandler::ExtensionURLPatternListPolicyHandler( 193 ExtensionURLPatternListPolicyHandler::ExtensionURLPatternListPolicyHandler(
194 const char* policy_name, 194 const char* policy_name,
195 const char* pref_path) 195 const char* pref_path)
196 : policy::TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST), 196 : policy::TypeCheckingPolicyHandler(policy_name, base::Value::Type::LIST),
197 pref_path_(pref_path) {} 197 pref_path_(pref_path) {}
198 198
199 ExtensionURLPatternListPolicyHandler::~ExtensionURLPatternListPolicyHandler() {} 199 ExtensionURLPatternListPolicyHandler::~ExtensionURLPatternListPolicyHandler() {}
200 200
201 bool ExtensionURLPatternListPolicyHandler::CheckPolicySettings( 201 bool ExtensionURLPatternListPolicyHandler::CheckPolicySettings(
202 const policy::PolicyMap& policies, 202 const policy::PolicyMap& policies,
203 policy::PolicyErrorMap* errors) { 203 policy::PolicyErrorMap* errors) {
204 const base::Value* value = NULL; 204 const base::Value* value = NULL;
205 if (!CheckAndGetValue(policies, errors, &value)) 205 if (!CheckAndGetValue(policies, errors, &value))
206 return false; 206 return false;
207 207
208 if (!value) 208 if (!value)
209 return true; 209 return true;
210 210
211 const base::ListValue* list_value = NULL; 211 const base::ListValue* list_value = NULL;
212 if (!value->GetAsList(&list_value)) { 212 if (!value->GetAsList(&list_value)) {
213 NOTREACHED(); 213 NOTREACHED();
214 return false; 214 return false;
215 } 215 }
216 216
217 // Check that the list contains valid URLPattern strings only. 217 // Check that the list contains valid URLPattern strings only.
218 for (base::ListValue::const_iterator entry(list_value->begin()); 218 for (base::ListValue::const_iterator entry(list_value->begin());
219 entry != list_value->end(); ++entry) { 219 entry != list_value->end(); ++entry) {
220 std::string url_pattern_string; 220 std::string url_pattern_string;
221 if (!(*entry)->GetAsString(&url_pattern_string)) { 221 if (!(*entry)->GetAsString(&url_pattern_string)) {
222 errors->AddError(policy_name(), entry - list_value->begin(), 222 errors->AddError(policy_name(), entry - list_value->begin(),
223 IDS_POLICY_TYPE_ERROR, 223 IDS_POLICY_TYPE_ERROR,
224 base::Value::GetTypeName(base::Value::TYPE_STRING)); 224 base::Value::GetTypeName(base::Value::Type::STRING));
225 return false; 225 return false;
226 } 226 }
227 227
228 URLPattern pattern(URLPattern::SCHEME_ALL); 228 URLPattern pattern(URLPattern::SCHEME_ALL);
229 if (pattern.Parse(url_pattern_string) != URLPattern::PARSE_SUCCESS) { 229 if (pattern.Parse(url_pattern_string) != URLPattern::PARSE_SUCCESS) {
230 errors->AddError(policy_name(), 230 errors->AddError(policy_name(),
231 entry - list_value->begin(), 231 entry - list_value->begin(),
232 IDS_POLICY_VALUE_FORMAT_ERROR); 232 IDS_POLICY_VALUE_FORMAT_ERROR);
233 return false; 233 return false;
234 } 234 }
(...skipping 30 matching lines...) Expand all
265 policy::PolicyErrorMap* errors) { 265 policy::PolicyErrorMap* errors) {
266 std::unique_ptr<base::Value> policy_value; 266 std::unique_ptr<base::Value> policy_value;
267 if (!CheckAndGetValue(policies, errors, &policy_value)) 267 if (!CheckAndGetValue(policies, errors, &policy_value))
268 return false; 268 return false;
269 if (!policy_value) 269 if (!policy_value)
270 return true; 270 return true;
271 271
272 // |policy_value| is expected to conform to the defined schema. But it's 272 // |policy_value| is expected to conform to the defined schema. But it's
273 // not strictly valid since there are additional restrictions. 273 // not strictly valid since there are additional restrictions.
274 const base::DictionaryValue* dict_value = NULL; 274 const base::DictionaryValue* dict_value = NULL;
275 DCHECK(policy_value->IsType(base::Value::TYPE_DICTIONARY)); 275 DCHECK(policy_value->IsType(base::Value::Type::DICTIONARY));
276 policy_value->GetAsDictionary(&dict_value); 276 policy_value->GetAsDictionary(&dict_value);
277 277
278 for (base::DictionaryValue::Iterator it(*dict_value); !it.IsAtEnd(); 278 for (base::DictionaryValue::Iterator it(*dict_value); !it.IsAtEnd();
279 it.Advance()) { 279 it.Advance()) {
280 DCHECK(it.key() == schema_constants::kWildcard || 280 DCHECK(it.key() == schema_constants::kWildcard ||
281 crx_file::id_util::IdIsValid(it.key())); 281 crx_file::id_util::IdIsValid(it.key()));
282 DCHECK(it.value().IsType(base::Value::TYPE_DICTIONARY)); 282 DCHECK(it.value().IsType(base::Value::Type::DICTIONARY));
283 283
284 // Extracts sub dictionary. 284 // Extracts sub dictionary.
285 const base::DictionaryValue* sub_dict = NULL; 285 const base::DictionaryValue* sub_dict = NULL;
286 it.value().GetAsDictionary(&sub_dict); 286 it.value().GetAsDictionary(&sub_dict);
287 287
288 std::string installation_mode; 288 std::string installation_mode;
289 if (sub_dict->GetString(schema_constants::kInstallationMode, 289 if (sub_dict->GetString(schema_constants::kInstallationMode,
290 &installation_mode)) { 290 &installation_mode)) {
291 if (installation_mode == schema_constants::kForceInstalled || 291 if (installation_mode == schema_constants::kForceInstalled ||
292 installation_mode == schema_constants::kNormalInstalled) { 292 installation_mode == schema_constants::kNormalInstalled) {
(...skipping 24 matching lines...) Expand all
317 void ExtensionSettingsPolicyHandler::ApplyPolicySettings( 317 void ExtensionSettingsPolicyHandler::ApplyPolicySettings(
318 const policy::PolicyMap& policies, 318 const policy::PolicyMap& policies,
319 PrefValueMap* prefs) { 319 PrefValueMap* prefs) {
320 std::unique_ptr<base::Value> policy_value; 320 std::unique_ptr<base::Value> policy_value;
321 if (!CheckAndGetValue(policies, NULL, &policy_value) || !policy_value) 321 if (!CheckAndGetValue(policies, NULL, &policy_value) || !policy_value)
322 return; 322 return;
323 prefs->SetValue(pref_names::kExtensionManagement, std::move(policy_value)); 323 prefs->SetValue(pref_names::kExtensionManagement, std::move(policy_value));
324 } 324 }
325 325
326 } // namespace extensions 326 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/external_provider_impl.cc ('k') | chrome/browser/extensions/webstore_data_fetcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698