OLD | NEW |
---|---|
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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 // ExtensionInstallListPolicyHandler implementation ---------------------------- |
103 | 103 |
104 ExtensionInstallForcelistPolicyHandler::ExtensionInstallForcelistPolicyHandler() | 104 ExtensionInstallListPolicyHandler::ExtensionInstallListPolicyHandler( |
105 : policy::TypeCheckingPolicyHandler(policy::key::kExtensionInstallForcelist, | 105 const char* policy_name, |
106 base::Value::TYPE_LIST) {} | 106 const char* pref_name) |
107 : policy::TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST), | |
108 pref_name_(pref_name) {} | |
107 | 109 |
108 ExtensionInstallForcelistPolicyHandler:: | 110 ExtensionInstallListPolicyHandler::~ExtensionInstallListPolicyHandler() {} |
109 ~ExtensionInstallForcelistPolicyHandler() {} | |
110 | 111 |
111 bool ExtensionInstallForcelistPolicyHandler::CheckPolicySettings( | 112 bool ExtensionInstallListPolicyHandler::CheckPolicySettings( |
112 const policy::PolicyMap& policies, | 113 const policy::PolicyMap& policies, |
113 policy::PolicyErrorMap* errors) { | 114 policy::PolicyErrorMap* errors) { |
114 const base::Value* value; | 115 const base::Value* value; |
115 return CheckAndGetValue(policies, errors, &value) && | 116 return CheckAndGetValue(policies, errors, &value) && |
116 ParseList(value, NULL, errors); | 117 ParseList(value, nullptr, errors); |
117 } | 118 } |
118 | 119 |
119 void ExtensionInstallForcelistPolicyHandler::ApplyPolicySettings( | 120 void ExtensionInstallListPolicyHandler::ApplyPolicySettings( |
120 const policy::PolicyMap& policies, | 121 const policy::PolicyMap& policies, |
121 PrefValueMap* prefs) { | 122 PrefValueMap* prefs) { |
122 const base::Value* value = NULL; | 123 const base::Value* value = nullptr; |
123 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 124 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
124 if (CheckAndGetValue(policies, NULL, &value) && | 125 if (CheckAndGetValue(policies, nullptr, &value) && value && |
125 value && | 126 ParseList(value, dict.get(), nullptr)) { |
126 ParseList(value, dict.get(), NULL)) { | 127 prefs->SetValue(pref_name(), std::move(dict)); |
127 prefs->SetValue(pref_names::kInstallForceList, std::move(dict)); | |
128 } | 128 } |
129 } | 129 } |
130 | 130 |
131 bool ExtensionInstallForcelistPolicyHandler::ParseList( | 131 bool ExtensionInstallListPolicyHandler::ParseList( |
132 const base::Value* policy_value, | 132 const base::Value* policy_value, |
133 base::DictionaryValue* extension_dict, | 133 base::DictionaryValue* extension_dict, |
134 policy::PolicyErrorMap* errors) { | 134 policy::PolicyErrorMap* errors) { |
135 if (!policy_value) | 135 if (!policy_value) |
136 return true; | 136 return true; |
137 | 137 |
138 const base::ListValue* policy_list_value = NULL; | 138 const base::ListValue* policy_list_value = nullptr; |
139 if (!policy_value->GetAsList(&policy_list_value)) { | 139 if (!policy_value->GetAsList(&policy_list_value)) { |
140 // This should have been caught in CheckPolicySettings. | 140 // This should have been caught in CheckPolicySettings. |
141 NOTREACHED(); | 141 NOTREACHED(); |
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)) { |
(...skipping 11 matching lines...) Expand all Loading... | |
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) { |
163 errors->AddError(policy_name(), | 163 errors->AddError(policy_name(), |
164 entry - policy_list_value->begin(), | 164 entry - policy_list_value->begin(), |
165 IDS_POLICY_VALUE_FORMAT_ERROR); | 165 IDS_POLICY_VALUE_FORMAT_ERROR); |
166 } | 166 } |
167 continue; | 167 continue; |
168 } | 168 } |
169 | 169 |
170 std::string extension_id = entry_string.substr(0, pos); | 170 const std::string extension_id = entry_string.substr(0, pos); |
171 std::string update_url = entry_string.substr(pos+1); | 171 const std::string update_url = entry_string.substr(pos + 1); |
172 if (!crx_file::id_util::IdIsValid(extension_id) || | 172 if (!crx_file::id_util::IdIsValid(extension_id) || |
173 !GURL(update_url).is_valid()) { | 173 !GURL(update_url).is_valid()) { |
174 if (errors) { | 174 if (errors) { |
175 errors->AddError(policy_name(), | 175 errors->AddError(policy_name(), |
176 entry - policy_list_value->begin(), | 176 entry - policy_list_value->begin(), |
177 IDS_POLICY_VALUE_FORMAT_ERROR); | 177 IDS_POLICY_VALUE_FORMAT_ERROR); |
178 } | 178 } |
179 continue; | 179 continue; |
180 } | 180 } |
181 | 181 |
182 if (extension_dict) { | 182 if (extension_dict) { |
183 extensions::ExternalPolicyLoader::AddExtension( | 183 ExternalPolicyLoader::AddExtension(extension_dict, extension_id, |
184 extension_dict, extension_id, update_url); | 184 update_url); |
185 VLOG(1) << "ParseList ext=" << extension_id << ", url=" << update_url; | |
asargent_no_longer_on_chrome
2016/11/14 21:30:25
nit: does this logging meet the criteria for getti
achuithb
2016/11/14 21:59:00
We can probably get rid of this
Denis Kuznetsov (DE-MUC)
2016/11/17 18:13:01
Done.
| |
185 } | 186 } |
186 } | 187 } |
187 | 188 |
188 return true; | 189 return true; |
189 } | 190 } |
190 | 191 |
192 // ExtensionInstallForcelistPolicyHandler implementation ----------------------- | |
193 | |
194 ExtensionInstallForcelistPolicyHandler::ExtensionInstallForcelistPolicyHandler() | |
195 : ExtensionInstallListPolicyHandler(policy::key::kExtensionInstallForcelist, | |
196 pref_names::kInstallForceList) {} | |
197 | |
198 ExtensionInstallForcelistPolicyHandler:: | |
199 ~ExtensionInstallForcelistPolicyHandler() {} | |
200 | |
201 // ExtensionInstallSigninlistPolicyHandler implementation | |
202 // ----------------------- | |
203 | |
204 ExtensionInstallSigninListPolicyHandler:: | |
205 ExtensionInstallSigninListPolicyHandler() | |
206 : ExtensionInstallListPolicyHandler(policy::key::kLoginApps, | |
207 pref_names::kInstallSigninList) {} | |
208 | |
209 ExtensionInstallSigninListPolicyHandler:: | |
210 ~ExtensionInstallSigninListPolicyHandler() {} | |
211 | |
191 // ExtensionURLPatternListPolicyHandler implementation ------------------------- | 212 // ExtensionURLPatternListPolicyHandler implementation ------------------------- |
192 | 213 |
193 ExtensionURLPatternListPolicyHandler::ExtensionURLPatternListPolicyHandler( | 214 ExtensionURLPatternListPolicyHandler::ExtensionURLPatternListPolicyHandler( |
194 const char* policy_name, | 215 const char* policy_name, |
195 const char* pref_path) | 216 const char* pref_path) |
196 : policy::TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST), | 217 : policy::TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST), |
197 pref_path_(pref_path) {} | 218 pref_path_(pref_path) {} |
198 | 219 |
199 ExtensionURLPatternListPolicyHandler::~ExtensionURLPatternListPolicyHandler() {} | 220 ExtensionURLPatternListPolicyHandler::~ExtensionURLPatternListPolicyHandler() {} |
200 | 221 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 void ExtensionSettingsPolicyHandler::ApplyPolicySettings( | 338 void ExtensionSettingsPolicyHandler::ApplyPolicySettings( |
318 const policy::PolicyMap& policies, | 339 const policy::PolicyMap& policies, |
319 PrefValueMap* prefs) { | 340 PrefValueMap* prefs) { |
320 std::unique_ptr<base::Value> policy_value; | 341 std::unique_ptr<base::Value> policy_value; |
321 if (!CheckAndGetValue(policies, NULL, &policy_value) || !policy_value) | 342 if (!CheckAndGetValue(policies, NULL, &policy_value) || !policy_value) |
322 return; | 343 return; |
323 prefs->SetValue(pref_names::kExtensionManagement, std::move(policy_value)); | 344 prefs->SetValue(pref_names::kExtensionManagement, std::move(policy_value)); |
324 } | 345 } |
325 | 346 |
326 } // namespace extensions | 347 } // namespace extensions |
OLD | NEW |