summaryrefslogtreecommitdiffstats
path: root/chrome/browser/download
diff options
context:
space:
mode:
authormsimonides@opera.com <msimonides@opera.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-23 12:03:33 +0000
committermsimonides@opera.com <msimonides@opera.com@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-23 12:03:33 +0000
commit5206ae88cd5b226471a304c7f5b2740a6a7bfe79 (patch)
tree4d65e1b52b75c2a922afbeff38f02b40ada6bc9d /chrome/browser/download
parentcd579f088339420404891ea0cb116e95bbb1c2c1 (diff)
downloadchromium_src-5206ae88cd5b226471a304c7f5b2740a6a7bfe79.zip
chromium_src-5206ae88cd5b226471a304c7f5b2740a6a7bfe79.tar.gz
chromium_src-5206ae88cd5b226471a304c7f5b2740a6a7bfe79.tar.bz2
Create CrxInstaller directly in WebstoreInstaller
The WebstoreInstaller needs a way to keep track of extensions being downloaded and installed. The installation is handled by CrxInstaller but when it used to be created automatically by the ChromeDownloadManagerDelegate, the WebstoreInstaller had little control over it and needed the CrxInstaller to keep the original_download_url as sort of an identifier. With this change the WebstoreInstaller creates the CrxInstaller itself and keeps a pointer to it so there is no more need for CrxInstaller::original_download_url(). This is also more robust because URLs are not unique identifiers (there could be two installations run simultaneously for one download URL which would have led to a crash in the old code). BUG=360487 Review URL: https://codereview.chromium.org/226023003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@265615 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download')
-rw-r--r--chrome/browser/download/chrome_download_manager_delegate.cc4
-rw-r--r--chrome/browser/download/download_crx_util.cc29
-rw-r--r--chrome/browser/download/download_crx_util.h5
-rw-r--r--chrome/browser/download/download_crx_util_android.cc9
4 files changed, 33 insertions, 14 deletions
diff --git a/chrome/browser/download/chrome_download_manager_delegate.cc b/chrome/browser/download/chrome_download_manager_delegate.cc
index dd3b42a..64c93d3 100644
--- a/chrome/browser/download/chrome_download_manager_delegate.cc
+++ b/chrome/browser/download/chrome_download_manager_delegate.cc
@@ -35,6 +35,7 @@
#include "chrome/browser/download/save_package_file_picker.h"
#include "chrome/browser/extensions/api/downloads/downloads_api.h"
#include "chrome/browser/extensions/crx_installer.h"
+#include "chrome/browser/extensions/webstore_installer.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
@@ -369,7 +370,8 @@ bool ChromeDownloadManagerDelegate::ShouldCompleteDownload(
bool ChromeDownloadManagerDelegate::ShouldOpenDownload(
DownloadItem* item, const content::DownloadOpenDelayedCallback& callback) {
- if (download_crx_util::IsExtensionDownload(*item)) {
+ if (download_crx_util::IsExtensionDownload(*item) &&
+ !extensions::WebstoreInstaller::GetAssociatedApproval(*item)) {
scoped_refptr<extensions::CrxInstaller> crx_installer =
download_crx_util::OpenChromeExtension(profile_, *item);
diff --git a/chrome/browser/download/download_crx_util.cc b/chrome/browser/download/download_crx_util.cc
index bea0aaa..441c82b 100644
--- a/chrome/browser/download/download_crx_util.cc
+++ b/chrome/browser/download/download_crx_util.cc
@@ -69,11 +69,9 @@ void SetMockInstallPromptForTesting(
mock_install_prompt_for_testing = mock_prompt.release();
}
-scoped_refptr<extensions::CrxInstaller> OpenChromeExtension(
+scoped_refptr<extensions::CrxInstaller> CreateCrxInstaller(
Profile* profile,
- const DownloadItem& download_item) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-
+ const content::DownloadItem& download_item) {
ExtensionService* service = extensions::ExtensionSystem::Get(profile)->
extension_service();
CHECK(service);
@@ -87,6 +85,19 @@ scoped_refptr<extensions::CrxInstaller> OpenChromeExtension(
installer->set_error_on_unsupported_requirements(true);
installer->set_delete_source(true);
installer->set_install_cause(extension_misc::INSTALL_CAUSE_USER_DOWNLOAD);
+ installer->set_original_mime_type(download_item.GetOriginalMimeType());
+ installer->set_apps_require_extension_mime_type(true);
+
+ return installer;
+}
+
+scoped_refptr<extensions::CrxInstaller> OpenChromeExtension(
+ Profile* profile,
+ const DownloadItem& download_item) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ scoped_refptr<extensions::CrxInstaller> installer(
+ CreateCrxInstaller(profile, download_item));
if (OffStoreInstallAllowedByPrefs(profile, download_item)) {
installer->set_off_store_install_allow_reason(
@@ -98,15 +109,7 @@ scoped_refptr<extensions::CrxInstaller> OpenChromeExtension(
installer->InstallUserScript(download_item.GetFullPath(),
download_item.GetURL());
} else {
- bool is_gallery_download =
- WebstoreInstaller::GetAssociatedApproval(download_item) != NULL;
- installer->set_original_mime_type(download_item.GetOriginalMimeType());
- installer->set_apps_require_extension_mime_type(true);
- installer->set_download_url(download_item.GetURL());
- installer->set_is_gallery_install(is_gallery_download);
- if (is_gallery_download)
- installer->set_original_download_url(download_item.GetOriginalUrl());
- installer->set_allow_silent_install(is_gallery_download);
+ DCHECK(!WebstoreInstaller::GetAssociatedApproval(download_item));
installer->InstallCrx(download_item.GetFullPath());
}
diff --git a/chrome/browser/download/download_crx_util.h b/chrome/browser/download/download_crx_util.h
index 1807a59..cc99c19 100644
--- a/chrome/browser/download/download_crx_util.h
+++ b/chrome/browser/download/download_crx_util.h
@@ -30,6 +30,11 @@ namespace download_crx_util {
void SetMockInstallPromptForTesting(
scoped_ptr<ExtensionInstallPrompt> mock_prompt);
+// Create and pre-configure a CrxInstaller for a given |download_item|.
+scoped_refptr<extensions::CrxInstaller> CreateCrxInstaller(
+ Profile* profile,
+ const content::DownloadItem& download_item);
+
// Start installing a downloaded item item as a CRX (extension, theme, app,
// ...). The installer does work on the file thread, so the installation
// is not complete when this function returns. Returns the object managing
diff --git a/chrome/browser/download/download_crx_util_android.cc b/chrome/browser/download/download_crx_util_android.cc
index 4b068a8..76c9d81 100644
--- a/chrome/browser/download/download_crx_util_android.cc
+++ b/chrome/browser/download/download_crx_util_android.cc
@@ -14,6 +14,15 @@ using content::DownloadItem;
namespace download_crx_util {
+scoped_refptr<extensions::CrxInstaller> CreateCrxInstaller(
+ Profile* profile,
+ const content::DownloadItem& download_item) {
+ NOTIMPLEMENTED() << "CrxInstaller not implemented on Android";
+ scoped_refptr<extensions::CrxInstaller> installer(
+ extensions::CrxInstaller::CreateSilent(NULL));
+ return installer;
+}
+
void SetMockInstallPromptForTesting(ExtensionInstallPrompt* mock_prompt) {
NOTIMPLEMENTED();
}