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" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 } | 44 } |
45 | 45 |
46 } // namespace | 46 } // namespace |
47 | 47 |
48 // Tests can call this method to inject a mock ExtensionInstallUI | 48 // Tests can call this method to inject a mock ExtensionInstallUI |
49 // to be used to confirm permissions on a downloaded CRX. | 49 // to be used to confirm permissions on a downloaded CRX. |
50 void SetMockInstallUIForTesting(ExtensionInstallUI* mock_ui) { | 50 void SetMockInstallUIForTesting(ExtensionInstallUI* mock_ui) { |
51 mock_install_ui_for_testing = mock_ui; | 51 mock_install_ui_for_testing = mock_ui; |
52 } | 52 } |
53 | 53 |
| 54 bool ShouldOpenExtensionDownload(const DownloadItem& download_item) { |
| 55 if (extensions::switch_utils::IsOffStoreInstallEnabled() || |
| 56 WebstoreInstaller::GetAssociatedApproval(download_item)) { |
| 57 return true; |
| 58 } else { |
| 59 return false; |
| 60 } |
| 61 } |
| 62 |
54 scoped_refptr<CrxInstaller> OpenChromeExtension( | 63 scoped_refptr<CrxInstaller> OpenChromeExtension( |
55 Profile* profile, | 64 Profile* profile, |
56 const DownloadItem& download_item) { | 65 const DownloadItem& download_item) { |
57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
58 | 67 |
59 ExtensionService* service = profile->GetExtensionService(); | 68 ExtensionService* service = profile->GetExtensionService(); |
60 CHECK(service); | 69 CHECK(service); |
61 | 70 |
62 scoped_refptr<CrxInstaller> installer( | 71 scoped_refptr<CrxInstaller> installer( |
63 CrxInstaller::Create( | 72 CrxInstaller::Create( |
64 service, | 73 service, |
65 CreateExtensionInstallUI(profile), | 74 CreateExtensionInstallUI(profile), |
66 WebstoreInstaller::GetAssociatedApproval(download_item))); | 75 WebstoreInstaller::GetAssociatedApproval(download_item))); |
67 installer->set_delete_source(true); | 76 installer->set_delete_source(true); |
68 | 77 |
69 if (UserScript::IsURLUserScript(download_item.GetURL(), | 78 if (UserScript::IsURLUserScript(download_item.GetURL(), |
70 download_item.GetMimeType())) { | 79 download_item.GetMimeType())) { |
71 installer->InstallUserScript(download_item.GetFullPath(), | 80 installer->InstallUserScript(download_item.GetFullPath(), |
72 download_item.GetURL()); | 81 download_item.GetURL()); |
73 } else { | 82 } else { |
74 bool is_gallery_download = | 83 bool is_gallery_download = service->IsDownloadFromGallery( |
75 WebstoreInstaller::GetAssociatedApproval(download_item) != NULL; | 84 download_item.GetURL(), download_item.GetReferrerUrl()); |
76 installer->set_original_mime_type(download_item.GetOriginalMimeType()); | 85 installer->set_original_mime_type(download_item.GetOriginalMimeType()); |
77 installer->set_apps_require_extension_mime_type(true); | 86 installer->set_apps_require_extension_mime_type(true); |
78 installer->set_download_url(download_item.GetURL()); | 87 installer->set_download_url(download_item.GetURL()); |
79 installer->set_is_gallery_install(is_gallery_download); | 88 installer->set_is_gallery_install(is_gallery_download); |
80 if (is_gallery_download) | 89 if (is_gallery_download) |
81 installer->set_original_download_url(download_item.GetOriginalUrl()); | 90 installer->set_original_download_url(download_item.GetOriginalUrl()); |
82 installer->set_allow_silent_install(is_gallery_download); | 91 installer->set_allow_silent_install(is_gallery_download); |
83 installer->set_install_cause(extension_misc::INSTALL_CAUSE_USER_DOWNLOAD); | 92 installer->set_install_cause(extension_misc::INSTALL_CAUSE_USER_DOWNLOAD); |
84 installer->InstallCrx(download_item.GetFullPath()); | 93 installer->InstallCrx(download_item.GetFullPath()); |
85 } | 94 } |
86 | 95 |
87 return installer; | 96 return installer; |
88 } | 97 } |
89 | 98 |
90 } // namespace download_crx_util | 99 } // namespace download_crx_util |
OLD | NEW |