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 } | |
Finnur
2014/09/12 13:55:34
no braces (single line if).
binjin
2014/09/12 13:57:26
Done.
| |
104 | |
105 const extensions::URLPatternSet& url_patterns = | |
106 global_settings_.install_sources; | |
107 | |
108 if (!url_patterns.MatchesURL(url)) | |
109 return false; | |
110 | |
111 // The referrer URL must also be whitelisted, unless the URL has the file | |
112 // scheme (there's no referrer for those URLs). | |
113 return url.SchemeIsFile() || url_patterns.MatchesURL(referrer_url); | |
114 } | |
115 | |
97 const ExtensionManagement::IndividualSettings& ExtensionManagement::ReadById( | 116 const ExtensionManagement::IndividualSettings& ExtensionManagement::ReadById( |
98 const ExtensionId& id) const { | 117 const ExtensionId& id) const { |
99 DCHECK(crx_file::id_util::IdIsValid(id)) << "Invalid ID: " << id; | 118 DCHECK(crx_file::id_util::IdIsValid(id)) << "Invalid ID: " << id; |
100 SettingsIdMap::const_iterator it = settings_by_id_.find(id); | 119 SettingsIdMap::const_iterator it = settings_by_id_.find(id); |
101 if (it != settings_by_id_.end()) | 120 if (it != settings_by_id_.end()) |
102 return it->second; | 121 return it->second; |
103 return default_settings_; | 122 return default_settings_; |
104 } | 123 } |
105 | 124 |
106 const ExtensionManagement::GlobalSettings& | 125 const ExtensionManagement::GlobalSettings& |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 return new ExtensionManagement( | 288 return new ExtensionManagement( |
270 Profile::FromBrowserContext(context)->GetPrefs()); | 289 Profile::FromBrowserContext(context)->GetPrefs()); |
271 } | 290 } |
272 | 291 |
273 content::BrowserContext* ExtensionManagementFactory::GetBrowserContextToUse( | 292 content::BrowserContext* ExtensionManagementFactory::GetBrowserContextToUse( |
274 content::BrowserContext* context) const { | 293 content::BrowserContext* context) const { |
275 return chrome::GetBrowserContextRedirectedInIncognito(context); | 294 return chrome::GetBrowserContextRedirectedInIncognito(context); |
276 } | 295 } |
277 | 296 |
278 } // namespace extensions | 297 } // namespace extensions |
OLD | NEW |