| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 } | 93 } |
| 94 filtered_list->AppendString(id); | 94 filtered_list->AppendString(id); |
| 95 } | 95 } |
| 96 | 96 |
| 97 if (extension_ids) | 97 if (extension_ids) |
| 98 *extension_ids = std::move(filtered_list); | 98 *extension_ids = std::move(filtered_list); |
| 99 | 99 |
| 100 return true; | 100 return true; |
| 101 } | 101 } |
| 102 | 102 |
| 103 // ExtensionInstallForcelistPolicyHandler implementation ----------------------- | 103 // ExtensionInstallListPolicyHandler implementation ---------------------------- |
| 104 | 104 |
| 105 ExtensionInstallForcelistPolicyHandler::ExtensionInstallForcelistPolicyHandler() | 105 ExtensionInstallListPolicyHandler::ExtensionInstallListPolicyHandler( |
| 106 : policy::TypeCheckingPolicyHandler(policy::key::kExtensionInstallForcelist, | 106 const char* policy_name, |
| 107 base::Value::TYPE_LIST) {} | 107 const char* pref_name) |
| 108 : policy::TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST), |
| 109 pref_name_(pref_name) {} |
| 108 | 110 |
| 109 ExtensionInstallForcelistPolicyHandler:: | 111 ExtensionInstallListPolicyHandler::~ExtensionInstallListPolicyHandler() {} |
| 110 ~ExtensionInstallForcelistPolicyHandler() {} | |
| 111 | 112 |
| 112 bool ExtensionInstallForcelistPolicyHandler::CheckPolicySettings( | 113 bool ExtensionInstallListPolicyHandler::CheckPolicySettings( |
| 113 const policy::PolicyMap& policies, | 114 const policy::PolicyMap& policies, |
| 114 policy::PolicyErrorMap* errors) { | 115 policy::PolicyErrorMap* errors) { |
| 115 const base::Value* value; | 116 const base::Value* value; |
| 116 return CheckAndGetValue(policies, errors, &value) && | 117 return CheckAndGetValue(policies, errors, &value) && |
| 117 ParseList(value, NULL, errors); | 118 ParseList(value, nullptr, errors); |
| 118 } | 119 } |
| 119 | 120 |
| 120 void ExtensionInstallForcelistPolicyHandler::ApplyPolicySettings( | 121 void ExtensionInstallListPolicyHandler::ApplyPolicySettings( |
| 121 const policy::PolicyMap& policies, | 122 const policy::PolicyMap& policies, |
| 122 PrefValueMap* prefs) { | 123 PrefValueMap* prefs) { |
| 123 const base::Value* value = NULL; | 124 const base::Value* value = nullptr; |
| 124 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 125 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 125 if (CheckAndGetValue(policies, NULL, &value) && | 126 if (CheckAndGetValue(policies, nullptr, &value) && value && |
| 126 value && | 127 ParseList(value, dict.get(), nullptr)) { |
| 127 ParseList(value, dict.get(), NULL)) { | 128 prefs->SetValue(pref_name(), std::move(dict)); |
| 128 prefs->SetValue(pref_names::kInstallForceList, std::move(dict)); | |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 | 131 |
| 132 bool ExtensionInstallForcelistPolicyHandler::ParseList( | 132 bool ExtensionInstallListPolicyHandler::ParseList( |
| 133 const base::Value* policy_value, | 133 const base::Value* policy_value, |
| 134 base::DictionaryValue* extension_dict, | 134 base::DictionaryValue* extension_dict, |
| 135 policy::PolicyErrorMap* errors) { | 135 policy::PolicyErrorMap* errors) { |
| 136 if (!policy_value) | 136 if (!policy_value) |
| 137 return true; | 137 return true; |
| 138 | 138 |
| 139 const base::ListValue* policy_list_value = NULL; | 139 const base::ListValue* policy_list_value = nullptr; |
| 140 if (!policy_value->GetAsList(&policy_list_value)) { | 140 if (!policy_value->GetAsList(&policy_list_value)) { |
| 141 // This should have been caught in CheckPolicySettings. | 141 // This should have been caught in CheckPolicySettings. |
| 142 NOTREACHED(); | 142 NOTREACHED(); |
| 143 return false; | 143 return false; |
| 144 } | 144 } |
| 145 | 145 |
| 146 for (base::ListValue::const_iterator entry(policy_list_value->begin()); | 146 for (base::ListValue::const_iterator entry(policy_list_value->begin()); |
| 147 entry != policy_list_value->end(); ++entry) { | 147 entry != policy_list_value->end(); ++entry) { |
| 148 std::string entry_string; | 148 std::string entry_string; |
| 149 if (!(*entry)->GetAsString(&entry_string)) { | 149 if (!(*entry)->GetAsString(&entry_string)) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 162 size_t pos = entry_string.find(';'); | 162 size_t pos = entry_string.find(';'); |
| 163 if (pos == std::string::npos) { | 163 if (pos == std::string::npos) { |
| 164 if (errors) { | 164 if (errors) { |
| 165 errors->AddError(policy_name(), | 165 errors->AddError(policy_name(), |
| 166 entry - policy_list_value->begin(), | 166 entry - policy_list_value->begin(), |
| 167 IDS_POLICY_VALUE_FORMAT_ERROR); | 167 IDS_POLICY_VALUE_FORMAT_ERROR); |
| 168 } | 168 } |
| 169 continue; | 169 continue; |
| 170 } | 170 } |
| 171 | 171 |
| 172 std::string extension_id = entry_string.substr(0, pos); | 172 const std::string extension_id = entry_string.substr(0, pos); |
| 173 std::string update_url = entry_string.substr(pos+1); | 173 const std::string update_url = entry_string.substr(pos + 1); |
| 174 if (!crx_file::id_util::IdIsValid(extension_id) || | 174 if (!crx_file::id_util::IdIsValid(extension_id) || |
| 175 !GURL(update_url).is_valid()) { | 175 !GURL(update_url).is_valid()) { |
| 176 if (errors) { | 176 if (errors) { |
| 177 errors->AddError(policy_name(), | 177 errors->AddError(policy_name(), |
| 178 entry - policy_list_value->begin(), | 178 entry - policy_list_value->begin(), |
| 179 IDS_POLICY_VALUE_FORMAT_ERROR); | 179 IDS_POLICY_VALUE_FORMAT_ERROR); |
| 180 } | 180 } |
| 181 continue; | 181 continue; |
| 182 } | 182 } |
| 183 | 183 |
| 184 if (extension_dict) { | 184 if (extension_dict) { |
| 185 extensions::ExternalPolicyLoader::AddExtension( | 185 ExternalPolicyLoader::AddExtension(extension_dict, extension_id, |
| 186 extension_dict, extension_id, update_url); | 186 update_url); |
| 187 VLOG(1) << "ParseList ext=" << extension_id << ", url=" << update_url; |
| 187 } | 188 } |
| 188 } | 189 } |
| 189 | 190 |
| 190 return true; | 191 return true; |
| 191 } | 192 } |
| 192 | 193 |
| 194 // ExtensionInstallForcelistPolicyHandler implementation ----------------------- |
| 195 |
| 196 ExtensionInstallForcelistPolicyHandler::ExtensionInstallForcelistPolicyHandler() |
| 197 : ExtensionInstallListPolicyHandler(policy::key::kExtensionInstallForcelist, |
| 198 pref_names::kInstallForceList) {} |
| 199 |
| 200 ExtensionInstallForcelistPolicyHandler:: |
| 201 ~ExtensionInstallForcelistPolicyHandler() {} |
| 202 |
| 203 // ExtensionInstallLoginlistPolicyHandler implementation ----------------------- |
| 204 |
| 205 ExtensionInstallLoginlistPolicyHandler::ExtensionInstallLoginlistPolicyHandler() |
| 206 : ExtensionInstallListPolicyHandler(policy::key::kLoginApps, |
| 207 pref_names::kInstallLoginList) {} |
| 208 |
| 209 ExtensionInstallLoginlistPolicyHandler:: |
| 210 ~ExtensionInstallLoginlistPolicyHandler() {} |
| 211 |
| 193 // ExtensionURLPatternListPolicyHandler implementation ------------------------- | 212 // ExtensionURLPatternListPolicyHandler implementation ------------------------- |
| 194 | 213 |
| 195 ExtensionURLPatternListPolicyHandler::ExtensionURLPatternListPolicyHandler( | 214 ExtensionURLPatternListPolicyHandler::ExtensionURLPatternListPolicyHandler( |
| 196 const char* policy_name, | 215 const char* policy_name, |
| 197 const char* pref_path) | 216 const char* pref_path) |
| 198 : policy::TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST), | 217 : policy::TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST), |
| 199 pref_path_(pref_path) {} | 218 pref_path_(pref_path) {} |
| 200 | 219 |
| 201 ExtensionURLPatternListPolicyHandler::~ExtensionURLPatternListPolicyHandler() {} | 220 ExtensionURLPatternListPolicyHandler::~ExtensionURLPatternListPolicyHandler() {} |
| 202 | 221 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 void ExtensionSettingsPolicyHandler::ApplyPolicySettings( | 339 void ExtensionSettingsPolicyHandler::ApplyPolicySettings( |
| 321 const policy::PolicyMap& policies, | 340 const policy::PolicyMap& policies, |
| 322 PrefValueMap* prefs) { | 341 PrefValueMap* prefs) { |
| 323 std::unique_ptr<base::Value> policy_value; | 342 std::unique_ptr<base::Value> policy_value; |
| 324 if (!CheckAndGetValue(policies, NULL, &policy_value) || !policy_value) | 343 if (!CheckAndGetValue(policies, NULL, &policy_value) || !policy_value) |
| 325 return; | 344 return; |
| 326 prefs->SetValue(pref_names::kExtensionManagement, std::move(policy_value)); | 345 prefs->SetValue(pref_names::kExtensionManagement, std::move(policy_value)); |
| 327 } | 346 } |
| 328 | 347 |
| 329 } // namespace extensions | 348 } // namespace extensions |
| OLD | NEW |