Chromium Code Reviews| 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.h" | 5 #include "chrome/browser/extensions/extension_management.h" |
| 6 | 6 |
| 7 #include <algorithm> | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 7 #include "base/bind.h" | 11 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 13 #include "base/logging.h" |
| 10 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
| 11 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/values.h" | |
| 12 #include "chrome/browser/extensions/extension_management_constants.h" | 17 #include "chrome/browser/extensions/extension_management_constants.h" |
| 18 #include "chrome/browser/extensions/extension_management_internal.h" | |
| 13 #include "chrome/browser/extensions/external_policy_loader.h" | 19 #include "chrome/browser/extensions/external_policy_loader.h" |
| 14 #include "chrome/browser/extensions/external_provider_impl.h" | 20 #include "chrome/browser/extensions/external_provider_impl.h" |
| 15 #include "chrome/browser/extensions/standard_management_policy_provider.h" | 21 #include "chrome/browser/extensions/standard_management_policy_provider.h" |
| 16 #include "chrome/browser/profiles/incognito_helpers.h" | 22 #include "chrome/browser/profiles/incognito_helpers.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 18 #include "components/crx_file/id_util.h" | 24 #include "components/crx_file/id_util.h" |
| 19 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 25 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 20 #include "components/pref_registry/pref_registry_syncable.h" | 26 #include "components/pref_registry/pref_registry_syncable.h" |
| 21 #include "extensions/browser/pref_names.h" | 27 #include "extensions/browser/pref_names.h" |
| 22 #include "extensions/common/url_pattern.h" | 28 #include "extensions/common/url_pattern.h" |
| 29 #include "extensions/common/url_pattern_set.h" | |
| 23 #include "url/gurl.h" | 30 #include "url/gurl.h" |
| 24 | 31 |
| 25 namespace extensions { | 32 namespace extensions { |
| 26 | 33 |
| 27 namespace { | 34 namespace { |
| 28 | |
| 29 const char kMalformedPreferenceWarning[] = | 35 const char kMalformedPreferenceWarning[] = |
| 30 "Malformed extension management preference."; | 36 "Malformed extension management preference."; |
| 37 } // namespace | |
| 31 | 38 |
| 32 enum Scope { | 39 namespace internal { |
| 33 // Parses the default settings. | |
| 34 SCOPE_DEFAULT = 0, | |
| 35 // Parses the settings for an extension with specified extension ID. | |
| 36 SCOPE_INDIVIDUAL, | |
| 37 }; | |
| 38 | 40 |
| 39 // Parse the individual settings for |settings|. |dict| is the a | 41 IndividualSettings::IndividualSettings() { |
|
Joao da Silva
2014/09/25 08:53:51
Move this to extension_management_internal.cc
(sa
binjin
2014/09/25 13:19:18
Done.
| |
| 40 // sub-dictionary in extension management preference and |scope| represents | 42 Reset(); |
| 41 // the applicable range of the settings, a single extension, a group of | 43 } |
| 42 // extensions or default settings. | 44 |
| 43 // Note that in case of parsing errors, |settings| will NOT be left untouched. | 45 IndividualSettings::~IndividualSettings() { |
| 44 bool ParseIndividualSettings( | 46 } |
| 45 const base::DictionaryValue* dict, | 47 |
| 46 Scope scope, | 48 bool IndividualSettings::Parse(const base::DictionaryValue* dict, Scope scope) { |
| 47 ExtensionManagement::IndividualSettings* settings) { | |
| 48 std::string installation_mode; | 49 std::string installation_mode; |
| 49 if (dict->GetStringWithoutPathExpansion(schema_constants::kInstallationMode, | 50 if (dict->GetStringWithoutPathExpansion(schema_constants::kInstallationMode, |
| 50 &installation_mode)) { | 51 &installation_mode)) { |
| 51 if (installation_mode == schema_constants::kAllowed) { | 52 if (installation_mode == schema_constants::kAllowed) { |
| 52 settings->installation_mode = ExtensionManagement::INSTALLATION_ALLOWED; | 53 this->installation_mode = ExtensionManagement::INSTALLATION_ALLOWED; |
| 53 } else if (installation_mode == schema_constants::kBlocked) { | 54 } else if (installation_mode == schema_constants::kBlocked) { |
| 54 settings->installation_mode = ExtensionManagement::INSTALLATION_BLOCKED; | 55 this->installation_mode = ExtensionManagement::INSTALLATION_BLOCKED; |
| 55 } else if (installation_mode == schema_constants::kForceInstalled) { | 56 } else if (installation_mode == schema_constants::kForceInstalled) { |
| 56 settings->installation_mode = ExtensionManagement::INSTALLATION_FORCED; | 57 this->installation_mode = ExtensionManagement::INSTALLATION_FORCED; |
| 57 } else if (installation_mode == schema_constants::kNormalInstalled) { | 58 } else if (installation_mode == schema_constants::kNormalInstalled) { |
| 58 settings->installation_mode = | 59 this->installation_mode = ExtensionManagement::INSTALLATION_RECOMMENDED; |
| 59 ExtensionManagement::INSTALLATION_RECOMMENDED; | |
| 60 } else { | 60 } else { |
| 61 // Invalid value for 'installation_mode'. | 61 // Invalid value for 'installation_mode'. |
| 62 LOG(WARNING) << kMalformedPreferenceWarning; | 62 LOG(WARNING) << kMalformedPreferenceWarning; |
| 63 return false; | 63 return false; |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 if (settings->installation_mode == ExtensionManagement::INSTALLATION_FORCED || | 67 if (this->installation_mode == ExtensionManagement::INSTALLATION_FORCED || |
| 68 settings->installation_mode == | 68 this->installation_mode == |
| 69 ExtensionManagement::INSTALLATION_RECOMMENDED) { | 69 ExtensionManagement::INSTALLATION_RECOMMENDED) { |
| 70 if (scope != SCOPE_INDIVIDUAL) { | 70 if (scope != SCOPE_INDIVIDUAL) { |
| 71 // Only individual extensions are allowed to be automatically installed. | 71 // Only individual extensions are allowed to be automatically installed. |
| 72 LOG(WARNING) << kMalformedPreferenceWarning; | 72 LOG(WARNING) << kMalformedPreferenceWarning; |
| 73 return false; | 73 return false; |
| 74 } | 74 } |
| 75 std::string update_url; | 75 std::string update_url; |
| 76 if (dict->GetStringWithoutPathExpansion(schema_constants::kUpdateUrl, | 76 if (dict->GetStringWithoutPathExpansion(schema_constants::kUpdateUrl, |
| 77 &update_url) && | 77 &update_url) && |
| 78 GURL(update_url).is_valid()) { | 78 GURL(update_url).is_valid()) { |
| 79 settings->update_url = update_url; | 79 this->update_url = update_url; |
| 80 } else { | 80 } else { |
| 81 // No valid update URL for extension. | 81 // No valid update URL for extension. |
| 82 LOG(WARNING) << kMalformedPreferenceWarning; | 82 LOG(WARNING) << kMalformedPreferenceWarning; |
| 83 return false; | 83 return false; |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 return true; | 87 return true; |
| 88 } | 88 } |
| 89 | 89 |
| 90 } // namespace | 90 void IndividualSettings::Reset() { |
| 91 | |
| 92 ExtensionManagement::IndividualSettings::IndividualSettings() { | |
| 93 Reset(); | |
| 94 } | |
| 95 | |
| 96 ExtensionManagement::IndividualSettings::~IndividualSettings() { | |
| 97 } | |
| 98 | |
| 99 void ExtensionManagement::IndividualSettings::Reset() { | |
| 100 installation_mode = ExtensionManagement::INSTALLATION_ALLOWED; | 91 installation_mode = ExtensionManagement::INSTALLATION_ALLOWED; |
| 101 update_url.clear(); | 92 update_url.clear(); |
| 102 } | 93 } |
| 103 | 94 |
| 104 ExtensionManagement::GlobalSettings::GlobalSettings() { | 95 GlobalSettings::GlobalSettings() { |
| 105 Reset(); | 96 Reset(); |
| 106 } | 97 } |
| 107 | 98 |
| 108 ExtensionManagement::GlobalSettings::~GlobalSettings() { | 99 GlobalSettings::~GlobalSettings() { |
| 109 } | 100 } |
| 110 | 101 |
| 111 void ExtensionManagement::GlobalSettings::Reset() { | 102 void GlobalSettings::Reset() { |
| 112 has_restricted_install_sources = false; | 103 has_restricted_install_sources = false; |
| 113 install_sources.ClearPatterns(); | 104 install_sources.ClearPatterns(); |
| 114 has_restricted_allowed_types = false; | 105 has_restricted_allowed_types = false; |
| 115 allowed_types.clear(); | 106 allowed_types.clear(); |
| 116 } | 107 } |
| 117 | 108 |
| 109 } // namespace internal | |
| 110 | |
| 118 ExtensionManagement::ExtensionManagement(PrefService* pref_service) | 111 ExtensionManagement::ExtensionManagement(PrefService* pref_service) |
| 119 : pref_service_(pref_service) { | 112 : pref_service_(pref_service) { |
| 120 pref_change_registrar_.Init(pref_service_); | 113 pref_change_registrar_.Init(pref_service_); |
| 121 base::Closure pref_change_callback = base::Bind( | 114 base::Closure pref_change_callback = base::Bind( |
| 122 &ExtensionManagement::OnExtensionPrefChanged, base::Unretained(this)); | 115 &ExtensionManagement::OnExtensionPrefChanged, base::Unretained(this)); |
| 123 pref_change_registrar_.Add(pref_names::kInstallAllowList, | 116 pref_change_registrar_.Add(pref_names::kInstallAllowList, |
| 124 pref_change_callback); | 117 pref_change_callback); |
| 125 pref_change_registrar_.Add(pref_names::kInstallDenyList, | 118 pref_change_registrar_.Add(pref_names::kInstallDenyList, |
| 126 pref_change_callback); | 119 pref_change_callback); |
| 127 pref_change_registrar_.Add(pref_names::kInstallForceList, | 120 pref_change_registrar_.Add(pref_names::kInstallForceList, |
| 128 pref_change_callback); | 121 pref_change_callback); |
| 129 pref_change_registrar_.Add(pref_names::kAllowedInstallSites, | 122 pref_change_registrar_.Add(pref_names::kAllowedInstallSites, |
| 130 pref_change_callback); | 123 pref_change_callback); |
| 131 pref_change_registrar_.Add(pref_names::kAllowedTypes, pref_change_callback); | 124 pref_change_registrar_.Add(pref_names::kAllowedTypes, pref_change_callback); |
| 132 pref_change_registrar_.Add(pref_names::kExtensionManagement, | 125 pref_change_registrar_.Add(pref_names::kExtensionManagement, |
| 133 pref_change_callback); | 126 pref_change_callback); |
| 127 // Note that both |global_settings_| and |default_settings_| will be null | |
| 128 // before first call to Refresh(), so in order to resolve this, Refresh() must | |
| 129 // be called in the initialization of ExtensionManagement. | |
| 134 Refresh(); | 130 Refresh(); |
| 135 provider_.reset(new StandardManagementPolicyProvider(this)); | 131 provider_.reset(new StandardManagementPolicyProvider(this)); |
| 136 } | 132 } |
| 137 | 133 |
| 138 ExtensionManagement::~ExtensionManagement() { | 134 ExtensionManagement::~ExtensionManagement() { |
| 139 } | 135 } |
| 140 | 136 |
| 141 void ExtensionManagement::AddObserver(Observer* observer) { | 137 void ExtensionManagement::AddObserver(Observer* observer) { |
| 142 observer_list_.AddObserver(observer); | 138 observer_list_.AddObserver(observer); |
| 143 } | 139 } |
| 144 | 140 |
| 145 void ExtensionManagement::RemoveObserver(Observer* observer) { | 141 void ExtensionManagement::RemoveObserver(Observer* observer) { |
| 146 observer_list_.RemoveObserver(observer); | 142 observer_list_.RemoveObserver(observer); |
| 147 } | 143 } |
| 148 | 144 |
| 149 ManagementPolicy::Provider* ExtensionManagement::GetProvider() { | 145 ManagementPolicy::Provider* ExtensionManagement::GetProvider() const { |
| 150 return provider_.get(); | 146 return provider_.get(); |
| 151 } | 147 } |
| 152 | 148 |
| 153 bool ExtensionManagement::BlacklistedByDefault() { | 149 bool ExtensionManagement::BlacklistedByDefault() const { |
| 154 return default_settings_.installation_mode == INSTALLATION_BLOCKED; | 150 return default_settings_->installation_mode == INSTALLATION_BLOCKED; |
| 151 } | |
| 152 | |
| 153 ExtensionManagement::InstallationMode ExtensionManagement::GetInstallationMode( | |
| 154 const ExtensionId& id) const { | |
| 155 return ReadById(id)->installation_mode; | |
| 155 } | 156 } |
| 156 | 157 |
| 157 scoped_ptr<base::DictionaryValue> ExtensionManagement::GetForceInstallList() | 158 scoped_ptr<base::DictionaryValue> ExtensionManagement::GetForceInstallList() |
| 158 const { | 159 const { |
| 159 scoped_ptr<base::DictionaryValue> forcelist(new base::DictionaryValue()); | 160 scoped_ptr<base::DictionaryValue> forcelist(new base::DictionaryValue()); |
| 160 for (SettingsIdMap::const_iterator it = settings_by_id_.begin(); | 161 for (SettingsIdMap::const_iterator it = settings_by_id_.begin(); |
| 161 it != settings_by_id_.end(); | 162 it != settings_by_id_.end(); |
| 162 ++it) { | 163 ++it) { |
| 163 if (it->second.installation_mode == INSTALLATION_FORCED) { | 164 if (it->second->installation_mode == INSTALLATION_FORCED) { |
| 164 ExternalPolicyLoader::AddExtension( | 165 ExternalPolicyLoader::AddExtension( |
| 165 forcelist.get(), it->first, it->second.update_url); | 166 forcelist.get(), it->first, it->second->update_url); |
| 166 } | 167 } |
| 167 } | 168 } |
| 168 return forcelist.Pass(); | 169 return forcelist.Pass(); |
| 169 } | 170 } |
| 170 | 171 |
| 171 bool ExtensionManagement::IsInstallationAllowed(const ExtensionId& id) const { | 172 bool ExtensionManagement::IsInstallationAllowed(const ExtensionId& id) const { |
| 172 return ReadById(id).installation_mode != INSTALLATION_BLOCKED; | 173 return ReadById(id)->installation_mode != INSTALLATION_BLOCKED; |
| 173 } | 174 } |
| 174 | 175 |
| 175 bool ExtensionManagement::IsOffstoreInstallAllowed(const GURL& url, | 176 bool ExtensionManagement::IsOffstoreInstallAllowed( |
| 176 const GURL& referrer_url) { | 177 const GURL& url, |
| 178 const GURL& referrer_url) const { | |
| 177 // No allowed install sites specified, disallow by default. | 179 // No allowed install sites specified, disallow by default. |
| 178 if (!global_settings_.has_restricted_install_sources) | 180 if (!global_settings_->has_restricted_install_sources) |
| 179 return false; | 181 return false; |
| 180 | 182 |
| 181 const extensions::URLPatternSet& url_patterns = | 183 const extensions::URLPatternSet& url_patterns = |
| 182 global_settings_.install_sources; | 184 global_settings_->install_sources; |
| 183 | 185 |
| 184 if (!url_patterns.MatchesURL(url)) | 186 if (!url_patterns.MatchesURL(url)) |
| 185 return false; | 187 return false; |
| 186 | 188 |
| 187 // The referrer URL must also be whitelisted, unless the URL has the file | 189 // The referrer URL must also be whitelisted, unless the URL has the file |
| 188 // scheme (there's no referrer for those URLs). | 190 // scheme (there's no referrer for those URLs). |
| 189 return url.SchemeIsFile() || url_patterns.MatchesURL(referrer_url); | 191 return url.SchemeIsFile() || url_patterns.MatchesURL(referrer_url); |
| 190 } | 192 } |
| 191 | 193 |
| 192 const ExtensionManagement::IndividualSettings& ExtensionManagement::ReadById( | 194 bool ExtensionManagement::IsAllowedManifestType( |
| 193 const ExtensionId& id) const { | 195 Manifest::Type manifest_type) const { |
| 194 DCHECK(crx_file::id_util::IdIsValid(id)) << "Invalid ID: " << id; | 196 if (!global_settings_->has_restricted_allowed_types) |
| 195 SettingsIdMap::const_iterator it = settings_by_id_.find(id); | 197 return true; |
| 196 if (it != settings_by_id_.end()) | |
| 197 return it->second; | |
| 198 return default_settings_; | |
| 199 } | |
| 200 | 198 |
| 201 const ExtensionManagement::GlobalSettings& | 199 const std::vector<Manifest::Type>& allowed_types = |
| 202 ExtensionManagement::ReadGlobalSettings() const { | 200 global_settings_->allowed_types; |
| 203 return global_settings_; | 201 if (std::find(allowed_types.begin(), allowed_types.end(), manifest_type) == |
| 202 allowed_types.end()) | |
| 203 return false; | |
| 204 | |
| 205 return true; | |
|
Joao da Silva
2014/09/25 08:53:50
return std::find(...) != allowed_types.end();
binjin
2014/09/25 13:19:18
Done.
| |
| 204 } | 206 } |
| 205 | 207 |
| 206 void ExtensionManagement::Refresh() { | 208 void ExtensionManagement::Refresh() { |
| 207 // Load all extension management settings preferences. | 209 // Load all extension management settings preferences. |
| 208 const base::ListValue* allowed_list_pref = | 210 const base::ListValue* allowed_list_pref = |
| 209 static_cast<const base::ListValue*>(LoadPreference( | 211 static_cast<const base::ListValue*>(LoadPreference( |
| 210 pref_names::kInstallAllowList, true, base::Value::TYPE_LIST)); | 212 pref_names::kInstallAllowList, true, base::Value::TYPE_LIST)); |
| 211 // Allow user to use preference to block certain extensions. Note that policy | 213 // Allow user to use preference to block certain extensions. Note that policy |
| 212 // managed forcelist or whitelist will always override this. | 214 // managed forcelist or whitelist will always override this. |
| 213 const base::ListValue* denied_list_pref = | 215 const base::ListValue* denied_list_pref = |
| 214 static_cast<const base::ListValue*>(LoadPreference( | 216 static_cast<const base::ListValue*>(LoadPreference( |
| 215 pref_names::kInstallDenyList, false, base::Value::TYPE_LIST)); | 217 pref_names::kInstallDenyList, false, base::Value::TYPE_LIST)); |
| 216 const base::DictionaryValue* forced_list_pref = | 218 const base::DictionaryValue* forced_list_pref = |
| 217 static_cast<const base::DictionaryValue*>(LoadPreference( | 219 static_cast<const base::DictionaryValue*>(LoadPreference( |
| 218 pref_names::kInstallForceList, true, base::Value::TYPE_DICTIONARY)); | 220 pref_names::kInstallForceList, true, base::Value::TYPE_DICTIONARY)); |
| 219 const base::ListValue* install_sources_pref = | 221 const base::ListValue* install_sources_pref = |
| 220 static_cast<const base::ListValue*>(LoadPreference( | 222 static_cast<const base::ListValue*>(LoadPreference( |
| 221 pref_names::kAllowedInstallSites, true, base::Value::TYPE_LIST)); | 223 pref_names::kAllowedInstallSites, true, base::Value::TYPE_LIST)); |
| 222 const base::ListValue* allowed_types_pref = | 224 const base::ListValue* allowed_types_pref = |
| 223 static_cast<const base::ListValue*>(LoadPreference( | 225 static_cast<const base::ListValue*>(LoadPreference( |
| 224 pref_names::kAllowedTypes, true, base::Value::TYPE_LIST)); | 226 pref_names::kAllowedTypes, true, base::Value::TYPE_LIST)); |
| 225 const base::DictionaryValue* dict_pref = | 227 const base::DictionaryValue* dict_pref = |
| 226 static_cast<const base::DictionaryValue*>( | 228 static_cast<const base::DictionaryValue*>( |
| 227 LoadPreference(pref_names::kExtensionManagement, | 229 LoadPreference(pref_names::kExtensionManagement, |
| 228 true, | 230 true, |
| 229 base::Value::TYPE_DICTIONARY)); | 231 base::Value::TYPE_DICTIONARY)); |
| 230 | 232 |
| 231 // Reset all settings. | 233 // Reset all settings. |
| 232 global_settings_.Reset(); | 234 global_settings_.reset(new internal::GlobalSettings()); |
| 233 settings_by_id_.clear(); | 235 settings_by_id_.clear(); |
| 234 default_settings_.Reset(); | 236 default_settings_.reset(new internal::IndividualSettings()); |
| 235 | 237 |
| 236 // Parse default settings. | 238 // Parse default settings. |
| 237 const base::StringValue wildcard("*"); | 239 const base::StringValue wildcard("*"); |
| 238 if (denied_list_pref && | 240 if (denied_list_pref && |
| 239 denied_list_pref->Find(wildcard) != denied_list_pref->end()) { | 241 denied_list_pref->Find(wildcard) != denied_list_pref->end()) { |
| 240 default_settings_.installation_mode = INSTALLATION_BLOCKED; | 242 default_settings_->installation_mode = INSTALLATION_BLOCKED; |
| 241 } | 243 } |
| 242 | 244 |
| 243 const base::DictionaryValue* subdict = NULL; | 245 const base::DictionaryValue* subdict = NULL; |
| 244 if (dict_pref && | 246 if (dict_pref && |
| 245 dict_pref->GetDictionary(schema_constants::kWildcard, &subdict)) { | 247 dict_pref->GetDictionary(schema_constants::kWildcard, &subdict)) { |
| 246 if (!ParseIndividualSettings(subdict, SCOPE_DEFAULT, &default_settings_)) { | 248 if (!default_settings_->Parse(subdict, internal::SCOPE_DEFAULT)) { |
| 247 LOG(WARNING) << "Default extension management settings parsing error."; | 249 LOG(WARNING) << "Default extension management settings parsing error."; |
| 248 default_settings_.Reset(); | 250 default_settings_->Reset(); |
| 249 } | 251 } |
| 250 | 252 |
| 251 // Settings from new preference have higher priority over legacy ones. | 253 // Settings from new preference have higher priority over legacy ones. |
| 252 const base::ListValue* list_value = NULL; | 254 const base::ListValue* list_value = NULL; |
| 253 if (subdict->GetList(schema_constants::kInstallSources, &list_value)) | 255 if (subdict->GetList(schema_constants::kInstallSources, &list_value)) |
| 254 install_sources_pref = list_value; | 256 install_sources_pref = list_value; |
| 255 if (subdict->GetList(schema_constants::kAllowedTypes, &list_value)) | 257 if (subdict->GetList(schema_constants::kAllowedTypes, &list_value)) |
| 256 allowed_types_pref = list_value; | 258 allowed_types_pref = list_value; |
| 257 } | 259 } |
| 258 | 260 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 278 if (forced_list_pref) { | 280 if (forced_list_pref) { |
| 279 std::string update_url; | 281 std::string update_url; |
| 280 for (base::DictionaryValue::Iterator it(*forced_list_pref); !it.IsAtEnd(); | 282 for (base::DictionaryValue::Iterator it(*forced_list_pref); !it.IsAtEnd(); |
| 281 it.Advance()) { | 283 it.Advance()) { |
| 282 if (!crx_file::id_util::IdIsValid(it.key())) | 284 if (!crx_file::id_util::IdIsValid(it.key())) |
| 283 continue; | 285 continue; |
| 284 const base::DictionaryValue* dict_value = NULL; | 286 const base::DictionaryValue* dict_value = NULL; |
| 285 if (it.value().GetAsDictionary(&dict_value) && | 287 if (it.value().GetAsDictionary(&dict_value) && |
| 286 dict_value->GetStringWithoutPathExpansion( | 288 dict_value->GetStringWithoutPathExpansion( |
| 287 ExternalProviderImpl::kExternalUpdateUrl, &update_url)) { | 289 ExternalProviderImpl::kExternalUpdateUrl, &update_url)) { |
| 288 IndividualSettings* by_id = AccessById(it.key()); | 290 linked_ptr<internal::IndividualSettings> by_id = AccessById(it.key()); |
| 289 by_id->installation_mode = INSTALLATION_FORCED; | 291 by_id->installation_mode = INSTALLATION_FORCED; |
| 290 by_id->update_url = update_url; | 292 by_id->update_url = update_url; |
| 291 } | 293 } |
| 292 } | 294 } |
| 293 } | 295 } |
| 294 | 296 |
| 295 if (install_sources_pref) { | 297 if (install_sources_pref) { |
| 296 global_settings_.has_restricted_install_sources = true; | 298 global_settings_->has_restricted_install_sources = true; |
| 297 for (base::ListValue::const_iterator it = install_sources_pref->begin(); | 299 for (base::ListValue::const_iterator it = install_sources_pref->begin(); |
| 298 it != install_sources_pref->end(); ++it) { | 300 it != install_sources_pref->end(); ++it) { |
| 299 std::string url_pattern; | 301 std::string url_pattern; |
| 300 if ((*it)->GetAsString(&url_pattern)) { | 302 if ((*it)->GetAsString(&url_pattern)) { |
| 301 URLPattern entry(URLPattern::SCHEME_ALL); | 303 URLPattern entry(URLPattern::SCHEME_ALL); |
| 302 if (entry.Parse(url_pattern) == URLPattern::PARSE_SUCCESS) { | 304 if (entry.Parse(url_pattern) == URLPattern::PARSE_SUCCESS) { |
| 303 global_settings_.install_sources.AddPattern(entry); | 305 global_settings_->install_sources.AddPattern(entry); |
| 304 } else { | 306 } else { |
| 305 LOG(WARNING) << "Invalid URL pattern in for preference " | 307 LOG(WARNING) << "Invalid URL pattern in for preference " |
| 306 << pref_names::kAllowedInstallSites << ": " | 308 << pref_names::kAllowedInstallSites << ": " |
| 307 << url_pattern << "."; | 309 << url_pattern << "."; |
| 308 } | 310 } |
| 309 } | 311 } |
| 310 } | 312 } |
| 311 } | 313 } |
| 312 | 314 |
| 313 if (allowed_types_pref) { | 315 if (allowed_types_pref) { |
| 314 global_settings_.has_restricted_allowed_types = true; | 316 global_settings_->has_restricted_allowed_types = true; |
| 315 for (base::ListValue::const_iterator it = allowed_types_pref->begin(); | 317 for (base::ListValue::const_iterator it = allowed_types_pref->begin(); |
| 316 it != allowed_types_pref->end(); ++it) { | 318 it != allowed_types_pref->end(); ++it) { |
| 317 int int_value; | 319 int int_value; |
| 318 std::string string_value; | 320 std::string string_value; |
| 319 if ((*it)->GetAsInteger(&int_value) && int_value >= 0 && | 321 if ((*it)->GetAsInteger(&int_value) && int_value >= 0 && |
| 320 int_value < Manifest::Type::NUM_LOAD_TYPES) { | 322 int_value < Manifest::Type::NUM_LOAD_TYPES) { |
| 321 global_settings_.allowed_types.push_back( | 323 global_settings_->allowed_types.push_back( |
| 322 static_cast<Manifest::Type>(int_value)); | 324 static_cast<Manifest::Type>(int_value)); |
| 323 } else if ((*it)->GetAsString(&string_value)) { | 325 } else if ((*it)->GetAsString(&string_value)) { |
| 324 Manifest::Type manifest_type = | 326 Manifest::Type manifest_type = |
| 325 schema_constants::GetManifestType(string_value); | 327 schema_constants::GetManifestType(string_value); |
| 326 if (manifest_type != Manifest::TYPE_UNKNOWN) | 328 if (manifest_type != Manifest::TYPE_UNKNOWN) |
| 327 global_settings_.allowed_types.push_back(manifest_type); | 329 global_settings_->allowed_types.push_back(manifest_type); |
| 328 } | 330 } |
| 329 } | 331 } |
| 330 } | 332 } |
| 331 | 333 |
| 332 if (dict_pref) { | 334 if (dict_pref) { |
| 333 // Parse new extension management preference. | 335 // Parse new extension management preference. |
| 334 for (base::DictionaryValue::Iterator iter(*dict_pref); !iter.IsAtEnd(); | 336 for (base::DictionaryValue::Iterator iter(*dict_pref); !iter.IsAtEnd(); |
| 335 iter.Advance()) { | 337 iter.Advance()) { |
| 336 if (iter.key() == schema_constants::kWildcard) | 338 if (iter.key() == schema_constants::kWildcard) |
| 337 continue; | 339 continue; |
| 338 if (!iter.value().GetAsDictionary(&subdict)) { | 340 if (!iter.value().GetAsDictionary(&subdict)) { |
| 339 LOG(WARNING) << kMalformedPreferenceWarning; | 341 LOG(WARNING) << kMalformedPreferenceWarning; |
| 340 continue; | 342 continue; |
| 341 } | 343 } |
| 342 if (StartsWithASCII(iter.key(), schema_constants::kUpdateUrlPrefix, true)) | 344 if (StartsWithASCII(iter.key(), schema_constants::kUpdateUrlPrefix, true)) |
| 343 continue; | 345 continue; |
| 344 const std::string& extension_id = iter.key(); | 346 const std::string& extension_id = iter.key(); |
| 345 if (!crx_file::id_util::IdIsValid(extension_id)) { | 347 if (!crx_file::id_util::IdIsValid(extension_id)) { |
| 346 LOG(WARNING) << kMalformedPreferenceWarning; | 348 LOG(WARNING) << kMalformedPreferenceWarning; |
| 347 continue; | 349 continue; |
| 348 } | 350 } |
| 349 IndividualSettings* by_id = AccessById(extension_id); | 351 linked_ptr<internal::IndividualSettings> by_id = AccessById(extension_id); |
| 350 if (!ParseIndividualSettings(subdict, SCOPE_INDIVIDUAL, by_id)) { | 352 if (!by_id->Parse(subdict, internal::SCOPE_INDIVIDUAL)) { |
| 351 settings_by_id_.erase(settings_by_id_.find(extension_id)); | 353 settings_by_id_.erase(settings_by_id_.find(extension_id)); |
| 352 LOG(WARNING) << "Malformed Extension Management settings for " | 354 LOG(WARNING) << "Malformed Extension Management settings for " |
| 353 << extension_id << "."; | 355 << extension_id << "."; |
| 354 } | 356 } |
| 355 } | 357 } |
| 356 } | 358 } |
| 357 } | 359 } |
| 358 | 360 |
| 359 const base::Value* ExtensionManagement::LoadPreference( | 361 const base::Value* ExtensionManagement::LoadPreference( |
| 360 const char* pref_name, | 362 const char* pref_name, |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 374 void ExtensionManagement::OnExtensionPrefChanged() { | 376 void ExtensionManagement::OnExtensionPrefChanged() { |
| 375 Refresh(); | 377 Refresh(); |
| 376 NotifyExtensionManagementPrefChanged(); | 378 NotifyExtensionManagementPrefChanged(); |
| 377 } | 379 } |
| 378 | 380 |
| 379 void ExtensionManagement::NotifyExtensionManagementPrefChanged() { | 381 void ExtensionManagement::NotifyExtensionManagementPrefChanged() { |
| 380 FOR_EACH_OBSERVER( | 382 FOR_EACH_OBSERVER( |
| 381 Observer, observer_list_, OnExtensionManagementSettingsChanged()); | 383 Observer, observer_list_, OnExtensionManagementSettingsChanged()); |
| 382 } | 384 } |
| 383 | 385 |
| 384 ExtensionManagement::IndividualSettings* ExtensionManagement::AccessById( | 386 linked_ptr<const internal::IndividualSettings> ExtensionManagement::ReadById( |
| 387 const ExtensionId& id) const { | |
| 388 DCHECK(crx_file::id_util::IdIsValid(id)) << "Invalid ID: " << id; | |
| 389 SettingsIdMap::const_iterator it = settings_by_id_.find(id); | |
| 390 if (it != settings_by_id_.end()) | |
| 391 return it->second; | |
| 392 return default_settings_; | |
| 393 } | |
| 394 | |
| 395 linked_ptr<const internal::GlobalSettings> | |
| 396 ExtensionManagement::ReadGlobalSettings() const { | |
| 397 return global_settings_; | |
| 398 } | |
| 399 | |
| 400 linked_ptr<internal::IndividualSettings> ExtensionManagement::AccessById( | |
| 385 const ExtensionId& id) { | 401 const ExtensionId& id) { |
| 386 DCHECK(crx_file::id_util::IdIsValid(id)) << "Invalid ID: " << id; | 402 DCHECK(crx_file::id_util::IdIsValid(id)) << "Invalid ID: " << id; |
| 387 SettingsIdMap::iterator it = settings_by_id_.find(id); | 403 SettingsIdMap::iterator it = settings_by_id_.find(id); |
| 388 if (it == settings_by_id_.end()) | 404 if (it == settings_by_id_.end()) { |
| 389 it = settings_by_id_.insert(std::make_pair(id, default_settings_)).first; | 405 linked_ptr<internal::IndividualSettings> settings( |
| 390 return &it->second; | 406 new internal::IndividualSettings(*default_settings_)); |
| 407 it = settings_by_id_.insert(std::make_pair(id, settings)).first; | |
| 408 } | |
| 409 return it->second; | |
| 391 } | 410 } |
| 392 | 411 |
| 393 ExtensionManagement* ExtensionManagementFactory::GetForBrowserContext( | 412 ExtensionManagement* ExtensionManagementFactory::GetForBrowserContext( |
| 394 content::BrowserContext* context) { | 413 content::BrowserContext* context) { |
| 395 return static_cast<ExtensionManagement*>( | 414 return static_cast<ExtensionManagement*>( |
| 396 GetInstance()->GetServiceForBrowserContext(context, true)); | 415 GetInstance()->GetServiceForBrowserContext(context, true)); |
| 397 } | 416 } |
| 398 | 417 |
| 399 ExtensionManagementFactory* ExtensionManagementFactory::GetInstance() { | 418 ExtensionManagementFactory* ExtensionManagementFactory::GetInstance() { |
| 400 return Singleton<ExtensionManagementFactory>::get(); | 419 return Singleton<ExtensionManagementFactory>::get(); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 421 } | 440 } |
| 422 | 441 |
| 423 void ExtensionManagementFactory::RegisterProfilePrefs( | 442 void ExtensionManagementFactory::RegisterProfilePrefs( |
| 424 user_prefs::PrefRegistrySyncable* user_prefs) { | 443 user_prefs::PrefRegistrySyncable* user_prefs) { |
| 425 user_prefs->RegisterDictionaryPref( | 444 user_prefs->RegisterDictionaryPref( |
| 426 pref_names::kExtensionManagement, | 445 pref_names::kExtensionManagement, |
| 427 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 446 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 428 } | 447 } |
| 429 | 448 |
| 430 } // namespace extensions | 449 } // namespace extensions |
| OLD | NEW |