| 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_policy_loader.h" |
| 12 #include "chrome/browser/extensions/external_provider_impl.h" | 12 #include "chrome/browser/extensions/external_provider_impl.h" |
| 13 #include "chrome/browser/extensions/standard_management_policy_provider.h" | 13 #include "chrome/browser/extensions/standard_management_policy_provider.h" |
| 14 #include "chrome/browser/profiles/incognito_helpers.h" | 14 #include "chrome/browser/profiles/incognito_helpers.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "components/crx_file/id_util.h" | 16 #include "components/crx_file/id_util.h" |
| 17 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 17 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 18 #include "extensions/browser/pref_names.h" | 18 #include "extensions/browser/pref_names.h" |
| 19 #include "extensions/common/url_pattern.h" | 19 #include "extensions/common/url_pattern.h" |
| 20 #include "url/gurl.h" |
| 20 | 21 |
| 21 namespace extensions { | 22 namespace extensions { |
| 22 | 23 |
| 23 void ExtensionManagement::IndividualSettings::Reset() { | 24 void ExtensionManagement::IndividualSettings::Reset() { |
| 24 installation_mode = ExtensionManagement::INSTALLATION_ALLOWED; | 25 installation_mode = ExtensionManagement::INSTALLATION_ALLOWED; |
| 25 update_url.clear(); | 26 update_url.clear(); |
| 26 } | 27 } |
| 27 | 28 |
| 28 ExtensionManagement::GlobalSettings::GlobalSettings() { | 29 ExtensionManagement::GlobalSettings::GlobalSettings() { |
| 29 Reset(); | 30 Reset(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 forcelist.get(), it->first, it->second.update_url); | 88 forcelist.get(), it->first, it->second.update_url); |
| 88 } | 89 } |
| 89 } | 90 } |
| 90 return forcelist.Pass(); | 91 return forcelist.Pass(); |
| 91 } | 92 } |
| 92 | 93 |
| 93 bool ExtensionManagement::IsInstallationAllowed(const ExtensionId& id) const { | 94 bool ExtensionManagement::IsInstallationAllowed(const ExtensionId& id) const { |
| 94 return ReadById(id).installation_mode != INSTALLATION_BLOCKED; | 95 return ReadById(id).installation_mode != INSTALLATION_BLOCKED; |
| 95 } | 96 } |
| 96 | 97 |
| 98 bool ExtensionManagement::IsOffstoreInstallAllowed(const GURL& url, |
| 99 const GURL& referrer_url) { |
| 100 // No allowed install sites specified, disallow by default. |
| 101 if (!global_settings_.has_restricted_install_sources) |
| 102 return false; |
| 103 |
| 104 const extensions::URLPatternSet& url_patterns = |
| 105 global_settings_.install_sources; |
| 106 |
| 107 if (!url_patterns.MatchesURL(url)) |
| 108 return false; |
| 109 |
| 110 // The referrer URL must also be whitelisted, unless the URL has the file |
| 111 // scheme (there's no referrer for those URLs). |
| 112 return url.SchemeIsFile() || url_patterns.MatchesURL(referrer_url); |
| 113 } |
| 114 |
| 97 const ExtensionManagement::IndividualSettings& ExtensionManagement::ReadById( | 115 const ExtensionManagement::IndividualSettings& ExtensionManagement::ReadById( |
| 98 const ExtensionId& id) const { | 116 const ExtensionId& id) const { |
| 99 DCHECK(crx_file::id_util::IdIsValid(id)) << "Invalid ID: " << id; | 117 DCHECK(crx_file::id_util::IdIsValid(id)) << "Invalid ID: " << id; |
| 100 SettingsIdMap::const_iterator it = settings_by_id_.find(id); | 118 SettingsIdMap::const_iterator it = settings_by_id_.find(id); |
| 101 if (it != settings_by_id_.end()) | 119 if (it != settings_by_id_.end()) |
| 102 return it->second; | 120 return it->second; |
| 103 return default_settings_; | 121 return default_settings_; |
| 104 } | 122 } |
| 105 | 123 |
| 106 const ExtensionManagement::GlobalSettings& | 124 const ExtensionManagement::GlobalSettings& |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 return new ExtensionManagement( | 287 return new ExtensionManagement( |
| 270 Profile::FromBrowserContext(context)->GetPrefs()); | 288 Profile::FromBrowserContext(context)->GetPrefs()); |
| 271 } | 289 } |
| 272 | 290 |
| 273 content::BrowserContext* ExtensionManagementFactory::GetBrowserContextToUse( | 291 content::BrowserContext* ExtensionManagementFactory::GetBrowserContextToUse( |
| 274 content::BrowserContext* context) const { | 292 content::BrowserContext* context) const { |
| 275 return chrome::GetBrowserContextRedirectedInIncognito(context); | 293 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 276 } | 294 } |
| 277 | 295 |
| 278 } // namespace extensions | 296 } // namespace extensions |
| OLD | NEW |