OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Download code which handles CRX files (extensions, themes, apps, ...). | 5 // Download code which handles CRX files (extensions, themes, apps, ...). |
6 | 6 |
7 #include "chrome/browser/download/download_crx_util.h" | 7 #include "chrome/browser/download/download_crx_util.h" |
8 | 8 |
9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
10 #include "chrome/browser/extensions/crx_installer.h" | 10 #include "chrome/browser/extensions/crx_installer.h" |
11 #include "chrome/browser/extensions/extension_install_prompt.h" | 11 #include "chrome/browser/extensions/extension_install_prompt.h" |
12 #include "chrome/browser/extensions/extension_management.h" | |
12 #include "chrome/browser/extensions/webstore_installer.h" | 13 #include "chrome/browser/extensions/webstore_installer.h" |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/browser_finder.h" | 15 #include "chrome/browser/ui/browser_finder.h" |
15 #include "chrome/browser/ui/host_desktop.h" | 16 #include "chrome/browser/ui/host_desktop.h" |
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 17 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
17 #include "content/public/browser/download_item.h" | 18 #include "content/public/browser/download_item.h" |
18 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
19 #include "extensions/browser/extension_prefs.h" | |
20 #include "extensions/browser/extension_system.h" | 20 #include "extensions/browser/extension_system.h" |
21 #include "extensions/common/user_script.h" | 21 #include "extensions/common/user_script.h" |
22 | 22 |
23 using content::BrowserThread; | 23 using content::BrowserThread; |
24 using content::DownloadItem; | 24 using content::DownloadItem; |
25 using extensions::WebstoreInstaller; | 25 using extensions::WebstoreInstaller; |
26 | 26 |
27 namespace download_crx_util { | 27 namespace download_crx_util { |
28 | 28 |
29 namespace { | 29 namespace { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 if (download_item.GetMimeType() == extensions::Extension::kMimeType || | 124 if (download_item.GetMimeType() == extensions::Extension::kMimeType || |
125 extensions::UserScript::IsURLUserScript(download_item.GetURL(), | 125 extensions::UserScript::IsURLUserScript(download_item.GetURL(), |
126 download_item.GetMimeType())) { | 126 download_item.GetMimeType())) { |
127 return true; | 127 return true; |
128 } else { | 128 } else { |
129 return false; | 129 return false; |
130 } | 130 } |
131 } | 131 } |
132 | 132 |
133 bool OffStoreInstallAllowedByPrefs(Profile* profile, const DownloadItem& item) { | 133 bool OffStoreInstallAllowedByPrefs(Profile* profile, const DownloadItem& item) { |
134 extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile); | 134 extensions::ExtensionManagement* extension_management = |
135 CHECK(prefs); | 135 extensions::ExtensionManagementFactory::GetForBrowserContext(profile); |
136 | 136 |
137 extensions::URLPatternSet url_patterns = prefs->GetAllowedInstallSites(); | 137 // No allowed install sites specified, disallow by default. |
binjin
2014/09/09 23:57:51
It turns out that it's how ExtensionInstallSources
Joao da Silva
2014/09/10 10:05:54
I think this is fine. This preference was never me
| |
138 if (!extension_management->ReadGlobalSettings() | |
139 .has_restricted_install_sources) { | |
140 return false; | |
141 } | |
142 | |
143 const extensions::URLPatternSet& url_patterns = | |
144 extension_management->ReadGlobalSettings().install_sources; | |
138 | 145 |
139 if (!url_patterns.MatchesURL(item.GetURL())) | 146 if (!url_patterns.MatchesURL(item.GetURL())) |
140 return false; | 147 return false; |
141 | 148 |
142 // The referrer URL must also be whitelisted, unless the URL has the file | 149 // The referrer URL must also be whitelisted, unless the URL has the file |
143 // scheme (there's no referrer for those URLs). | 150 // scheme (there's no referrer for those URLs). |
144 // TODO(aa): RefererURL is cleared in some cases, for example when going | 151 // TODO(aa): RefererURL is cleared in some cases, for example when going |
145 // between secure and non-secure URLs. It would be better if DownloadItem | 152 // between secure and non-secure URLs. It would be better if DownloadItem |
146 // tracked the initiating page explicitly. | 153 // tracked the initiating page explicitly. |
147 return url_patterns.MatchesURL(item.GetReferrerUrl()) || | 154 return url_patterns.MatchesURL(item.GetReferrerUrl()) || |
148 item.GetURL().SchemeIsFile(); | 155 item.GetURL().SchemeIsFile(); |
Joao da Silva
2014/09/10 10:05:54
What do you think of moving all this logic to Exte
asanka
2014/09/10 16:14:02
+1. The only use of this function is in DownloadTa
binjin
2014/09/12 11:46:14
Done.
| |
149 } | 156 } |
150 | 157 |
151 } // namespace download_crx_util | 158 } // namespace download_crx_util |
OLD | NEW |