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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "chrome/browser/extensions/external_policy_loader.h" |
11 #include "chrome/browser/extensions/external_provider_impl.h" | 12 #include "chrome/browser/extensions/external_provider_impl.h" |
12 #include "chrome/browser/extensions/standard_management_policy_provider.h" | 13 #include "chrome/browser/extensions/standard_management_policy_provider.h" |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
14 #include "components/crx_file/id_util.h" | 15 #include "components/crx_file/id_util.h" |
15 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 16 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
16 #include "extensions/browser/pref_names.h" | 17 #include "extensions/browser/pref_names.h" |
17 #include "extensions/common/url_pattern.h" | 18 #include "extensions/common/url_pattern.h" |
18 | 19 |
19 namespace extensions { | 20 namespace extensions { |
20 | 21 |
(...skipping 10 matching lines...) Expand all Loading... |
31 } | 32 } |
32 | 33 |
33 void ExtensionManagement::GlobalSettings::Reset() { | 34 void ExtensionManagement::GlobalSettings::Reset() { |
34 has_restricted_install_sources = false; | 35 has_restricted_install_sources = false; |
35 install_sources.ClearPatterns(); | 36 install_sources.ClearPatterns(); |
36 has_restricted_allowed_types = false; | 37 has_restricted_allowed_types = false; |
37 allowed_types.clear(); | 38 allowed_types.clear(); |
38 } | 39 } |
39 | 40 |
40 ExtensionManagement::ExtensionManagement(PrefService* pref_service) | 41 ExtensionManagement::ExtensionManagement(PrefService* pref_service) |
41 : pref_service_(pref_service) { | 42 : allow_user_preference_(false), pref_service_(pref_service) { |
42 pref_change_registrar_.Init(pref_service_); | 43 pref_change_registrar_.Init(pref_service_); |
43 base::Closure pref_change_callback = base::Bind( | 44 base::Closure pref_change_callback = base::Bind( |
44 &ExtensionManagement::OnExtensionPrefChanged, base::Unretained(this)); | 45 &ExtensionManagement::OnExtensionPrefChanged, base::Unretained(this)); |
45 pref_change_registrar_.Add(pref_names::kInstallAllowList, | 46 pref_change_registrar_.Add(pref_names::kInstallAllowList, |
46 pref_change_callback); | 47 pref_change_callback); |
47 pref_change_registrar_.Add(pref_names::kInstallDenyList, | 48 pref_change_registrar_.Add(pref_names::kInstallDenyList, |
48 pref_change_callback); | 49 pref_change_callback); |
49 pref_change_registrar_.Add(pref_names::kInstallForceList, | 50 pref_change_registrar_.Add(pref_names::kInstallForceList, |
50 pref_change_callback); | 51 pref_change_callback); |
51 pref_change_registrar_.Add(pref_names::kAllowedInstallSites, | 52 pref_change_registrar_.Add(pref_names::kAllowedInstallSites, |
(...skipping 15 matching lines...) Expand all Loading... |
67 } | 68 } |
68 | 69 |
69 ManagementPolicy::Provider* ExtensionManagement::GetProvider() { | 70 ManagementPolicy::Provider* ExtensionManagement::GetProvider() { |
70 return provider_.get(); | 71 return provider_.get(); |
71 } | 72 } |
72 | 73 |
73 bool ExtensionManagement::BlacklistedByDefault() { | 74 bool ExtensionManagement::BlacklistedByDefault() { |
74 return default_settings_.installation_mode == INSTALLATION_BLOCKED; | 75 return default_settings_.installation_mode == INSTALLATION_BLOCKED; |
75 } | 76 } |
76 | 77 |
| 78 scoped_ptr<base::DictionaryValue> ExtensionManagement::GetForceInstallList() |
| 79 const { |
| 80 scoped_ptr<base::DictionaryValue> forcelist(new base::DictionaryValue()); |
| 81 for (SettingsIdMap::const_iterator it = settings_by_id_.begin(); |
| 82 it != settings_by_id_.end(); |
| 83 ++it) { |
| 84 if (it->second.installation_mode == INSTALLATION_FORCED) { |
| 85 ExternalPolicyLoader::AddExtension( |
| 86 forcelist.get(), it->first, it->second.update_url); |
| 87 } |
| 88 } |
| 89 return forcelist.Pass(); |
| 90 } |
| 91 |
| 92 bool ExtensionManagement::IsInstallationAllowed(const ExtensionId& id) const { |
| 93 return ReadById(id).installation_mode != INSTALLATION_BLOCKED; |
| 94 } |
| 95 |
77 const ExtensionManagement::IndividualSettings& ExtensionManagement::ReadById( | 96 const ExtensionManagement::IndividualSettings& ExtensionManagement::ReadById( |
78 const ExtensionId& id) const { | 97 const ExtensionId& id) const { |
79 DCHECK(crx_file::id_util::IdIsValid(id)) << "Invalid ID: " << id; | 98 DCHECK(crx_file::id_util::IdIsValid(id)) << "Invalid ID: " << id; |
80 SettingsIdMap::const_iterator it = settings_by_id_.find(id); | 99 SettingsIdMap::const_iterator it = settings_by_id_.find(id); |
81 if (it != settings_by_id_.end()) | 100 if (it != settings_by_id_.end()) |
82 return it->second; | 101 return it->second; |
83 return default_settings_; | 102 return default_settings_; |
84 } | 103 } |
85 | 104 |
86 const ExtensionManagement::GlobalSettings& | 105 const ExtensionManagement::GlobalSettings& |
87 ExtensionManagement::ReadGlobalSettings() const { | 106 ExtensionManagement::ReadGlobalSettings() const { |
88 return global_settings_; | 107 return global_settings_; |
89 } | 108 } |
90 | 109 |
| 110 void ExtensionManagement::AllowUserPreferenceForTesting() const { |
| 111 allow_user_preference_ = true; |
| 112 } |
| 113 |
91 void ExtensionManagement::Refresh() { | 114 void ExtensionManagement::Refresh() { |
92 // Load all extension management settings preferences. | 115 // Load all extension management settings preferences. |
93 const base::ListValue* allowed_list_pref = | 116 const base::ListValue* allowed_list_pref = |
94 static_cast<const base::ListValue*>(LoadPreference( | 117 static_cast<const base::ListValue*>(LoadPreference( |
95 pref_names::kInstallAllowList, true, base::Value::TYPE_LIST)); | 118 pref_names::kInstallAllowList, true, base::Value::TYPE_LIST)); |
96 // Allow user to use preference to block certain extensions. Note that policy | 119 // Allow user to use preference to block certain extensions. Note that policy |
97 // managed forcelist or whitelist will always override this. | 120 // managed forcelist or whitelist will always override this. |
98 const base::ListValue* denied_list_pref = | 121 const base::ListValue* denied_list_pref = |
99 static_cast<const base::ListValue*>(LoadPreference( | 122 static_cast<const base::ListValue*>(LoadPreference( |
100 pref_names::kInstallDenyList, false, base::Value::TYPE_LIST)); | 123 pref_names::kInstallDenyList, false, base::Value::TYPE_LIST)); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 // new ExtensionManagement policy is added. | 214 // new ExtensionManagement policy is added. |
192 } | 215 } |
193 | 216 |
194 const base::Value* ExtensionManagement::LoadPreference( | 217 const base::Value* ExtensionManagement::LoadPreference( |
195 const char* pref_name, | 218 const char* pref_name, |
196 bool force_managed, | 219 bool force_managed, |
197 base::Value::Type expected_type) { | 220 base::Value::Type expected_type) { |
198 const PrefService::Preference* pref = | 221 const PrefService::Preference* pref = |
199 pref_service_->FindPreference(pref_name); | 222 pref_service_->FindPreference(pref_name); |
200 if (pref && !pref->IsDefaultValue() && | 223 if (pref && !pref->IsDefaultValue() && |
201 (!force_managed || pref->IsManaged())) { | 224 (!force_managed || allow_user_preference_ || pref->IsManaged())) { |
202 const base::Value* value = pref->GetValue(); | 225 const base::Value* value = pref->GetValue(); |
203 if (value && value->IsType(expected_type)) | 226 if (value && value->IsType(expected_type)) |
204 return value; | 227 return value; |
205 } | 228 } |
206 return NULL; | 229 return NULL; |
207 } | 230 } |
208 | 231 |
209 void ExtensionManagement::OnExtensionPrefChanged() { | 232 void ExtensionManagement::OnExtensionPrefChanged() { |
210 Refresh(); | 233 Refresh(); |
211 NotifyExtensionManagementPrefChanged(); | 234 NotifyExtensionManagementPrefChanged(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 ExtensionManagementFactory::~ExtensionManagementFactory() { | 267 ExtensionManagementFactory::~ExtensionManagementFactory() { |
245 } | 268 } |
246 | 269 |
247 KeyedService* ExtensionManagementFactory::BuildServiceInstanceFor( | 270 KeyedService* ExtensionManagementFactory::BuildServiceInstanceFor( |
248 content::BrowserContext* context) const { | 271 content::BrowserContext* context) const { |
249 return new ExtensionManagement( | 272 return new ExtensionManagement( |
250 Profile::FromBrowserContext(context)->GetPrefs()); | 273 Profile::FromBrowserContext(context)->GetPrefs()); |
251 } | 274 } |
252 | 275 |
253 } // namespace extensions | 276 } // namespace extensions |
OLD | NEW |