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_util.h" | 7 #include "chrome/browser/download/download_util.h" |
8 #include "chrome/browser/extensions/crx_installer.h" | 8 #include "chrome/browser/extensions/crx_installer.h" |
9 #include "chrome/browser/extensions/extension_install_ui.h" | 9 #include "chrome/browser/extensions/extension_install_ui.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/extensions/extension_system.h" |
11 #include "chrome/browser/extensions/webstore_installer.h" | 12 #include "chrome/browser/extensions/webstore_installer.h" |
12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
14 #include "chrome/common/extensions/extension_switch_utils.h" | 15 #include "chrome/common/extensions/extension_switch_utils.h" |
15 #include "content/public/browser/download_item.h" | 16 #include "content/public/browser/download_item.h" |
16 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
17 | 18 |
18 using content::BrowserThread; | 19 using content::BrowserThread; |
19 using content::DownloadItem; | 20 using content::DownloadItem; |
20 | 21 |
(...skipping 15 matching lines...) Expand all Loading... |
36 if (mock_install_ui_for_testing) { | 37 if (mock_install_ui_for_testing) { |
37 result = mock_install_ui_for_testing; | 38 result = mock_install_ui_for_testing; |
38 mock_install_ui_for_testing = NULL; | 39 mock_install_ui_for_testing = NULL; |
39 } else { | 40 } else { |
40 result = new ExtensionInstallUI(profile); | 41 result = new ExtensionInstallUI(profile); |
41 } | 42 } |
42 | 43 |
43 return result; | 44 return result; |
44 } | 45 } |
45 | 46 |
| 47 bool OffStoreInstallAllowedByPrefs(Profile* profile, const DownloadItem& item) { |
| 48 ExtensionPrefs* prefs = |
| 49 ExtensionSystem::Get(profile)->extension_service()->extension_prefs(); |
| 50 CHECK(prefs); |
| 51 |
| 52 URLPatternSet url_patterns = prefs->GetAllowedInstallSites(); |
| 53 |
| 54 // TODO(aa): RefererURL is cleared in some cases, for example when going |
| 55 // between secure and non-secure URLs. It would be better if DownloadItem |
| 56 // tracked the initiating page explicitly. |
| 57 return url_patterns.MatchesURL(item.GetURL()) && |
| 58 url_patterns.MatchesURL(item.GetReferrerUrl()); |
| 59 } |
| 60 |
46 } // namespace | 61 } // namespace |
47 | 62 |
48 // Tests can call this method to inject a mock ExtensionInstallUI | 63 // Tests can call this method to inject a mock ExtensionInstallUI |
49 // to be used to confirm permissions on a downloaded CRX. | 64 // to be used to confirm permissions on a downloaded CRX. |
50 void SetMockInstallUIForTesting(ExtensionInstallUI* mock_ui) { | 65 void SetMockInstallUIForTesting(ExtensionInstallUI* mock_ui) { |
51 mock_install_ui_for_testing = mock_ui; | 66 mock_install_ui_for_testing = mock_ui; |
52 } | 67 } |
53 | 68 |
54 scoped_refptr<CrxInstaller> OpenChromeExtension( | 69 scoped_refptr<CrxInstaller> OpenChromeExtension( |
55 Profile* profile, | 70 Profile* profile, |
56 const DownloadItem& download_item) { | 71 const DownloadItem& download_item) { |
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
58 | 73 |
59 ExtensionService* service = profile->GetExtensionService(); | 74 ExtensionService* service = profile->GetExtensionService(); |
60 CHECK(service); | 75 CHECK(service); |
61 | 76 |
62 scoped_refptr<CrxInstaller> installer( | 77 scoped_refptr<CrxInstaller> installer( |
63 CrxInstaller::Create( | 78 CrxInstaller::Create( |
64 service, | 79 service, |
65 CreateExtensionInstallUI(profile), | 80 CreateExtensionInstallUI(profile), |
66 WebstoreInstaller::GetAssociatedApproval(download_item))); | 81 WebstoreInstaller::GetAssociatedApproval(download_item))); |
67 | 82 |
68 installer->set_delete_source(true); | 83 installer->set_delete_source(true); |
69 installer->set_install_cause(extension_misc::INSTALL_CAUSE_USER_DOWNLOAD); | 84 installer->set_install_cause(extension_misc::INSTALL_CAUSE_USER_DOWNLOAD); |
70 | 85 |
| 86 if (OffStoreInstallAllowedByPrefs(profile, download_item)) { |
| 87 installer->set_off_store_install_allow_reason( |
| 88 CrxInstaller::OffStoreInstallAllowedBecausePref); |
| 89 } |
| 90 |
71 if (UserScript::IsURLUserScript(download_item.GetURL(), | 91 if (UserScript::IsURLUserScript(download_item.GetURL(), |
72 download_item.GetMimeType())) { | 92 download_item.GetMimeType())) { |
73 installer->InstallUserScript(download_item.GetFullPath(), | 93 installer->InstallUserScript(download_item.GetFullPath(), |
74 download_item.GetURL()); | 94 download_item.GetURL()); |
75 } else { | 95 } else { |
76 bool is_gallery_download = | 96 bool is_gallery_download = |
77 WebstoreInstaller::GetAssociatedApproval(download_item) != NULL; | 97 WebstoreInstaller::GetAssociatedApproval(download_item) != NULL; |
78 installer->set_original_mime_type(download_item.GetOriginalMimeType()); | 98 installer->set_original_mime_type(download_item.GetOriginalMimeType()); |
79 installer->set_apps_require_extension_mime_type(true); | 99 installer->set_apps_require_extension_mime_type(true); |
80 installer->set_download_url(download_item.GetURL()); | 100 installer->set_download_url(download_item.GetURL()); |
(...skipping 15 matching lines...) Expand all Loading... |
96 if (download_item.GetMimeType() == extensions::Extension::kMimeType || | 116 if (download_item.GetMimeType() == extensions::Extension::kMimeType || |
97 UserScript::IsURLUserScript(download_item.GetURL(), | 117 UserScript::IsURLUserScript(download_item.GetURL(), |
98 download_item.GetMimeType())) { | 118 download_item.GetMimeType())) { |
99 return true; | 119 return true; |
100 } else { | 120 } else { |
101 return false; | 121 return false; |
102 } | 122 } |
103 } | 123 } |
104 | 124 |
105 } // namespace download_crx_util | 125 } // namespace download_crx_util |
OLD | NEW |