| Index: chrome/browser/download/chrome_download_manager_delegate.cc
|
| diff --git a/chrome/browser/download/chrome_download_manager_delegate.cc b/chrome/browser/download/chrome_download_manager_delegate.cc
|
| index 05b1382de50000d073ca0975672446e90ddfb55d..05b55dd8bb99a1fa37a96cc20ed7859ba818f5f9 100644
|
| --- a/chrome/browser/download/chrome_download_manager_delegate.cc
|
| +++ b/chrome/browser/download/chrome_download_manager_delegate.cc
|
| @@ -14,6 +14,7 @@
|
| #include "base/rand_util.h"
|
| #include "base/stringprintf.h"
|
| #include "base/time.h"
|
| +#include "base/utf_string_conversions.h"
|
| #include "chrome/browser/browser_process.h"
|
| #include "chrome/browser/download/download_crx_util.h"
|
| #include "chrome/browser/download/download_extensions.h"
|
| @@ -37,8 +38,10 @@
|
| #include "content/public/browser/download_manager.h"
|
| #include "content/public/browser/notification_source.h"
|
| #include "content/public/browser/web_contents.h"
|
| +#include "content/public/browser/web_intents_dispatcher.h"
|
| #include "grit/generated_resources.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| +#include "webkit/glue/web_intent_data.h"
|
|
|
| #if !defined(OS_ANDROID)
|
| #include "chrome/browser/ui/browser.h"
|
| @@ -225,28 +228,60 @@ bool ChromeDownloadManagerDelegate::ShouldCompleteDownload(DownloadItem* item) {
|
| }
|
|
|
| bool ChromeDownloadManagerDelegate::ShouldOpenDownload(DownloadItem* item) {
|
| - if (!IsExtensionDownload(item)) {
|
| - return true;
|
| + if (IsExtensionDownload(item)) {
|
| + scoped_refptr<CrxInstaller> crx_installer =
|
| + download_crx_util::OpenChromeExtension(profile_, *item);
|
| +
|
| + // CRX_INSTALLER_DONE will fire when the install completes. Observe()
|
| + // will call DelayedDownloadOpened() on this item. If this DownloadItem is
|
| + // not around when CRX_INSTALLER_DONE fires, Complete() will not be called.
|
| + registrar_.Add(this,
|
| + chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| + content::Source<CrxInstaller>(crx_installer.get()));
|
| +
|
| + crx_installers_[crx_installer.get()] = item->GetId();
|
| + // The status text and percent complete indicator will change now
|
| + // that we are installing a CRX. Update observers so that they pick
|
| + // up the change.
|
| + item->UpdateObservers();
|
| + return false;
|
| + }
|
| +
|
| + if (ShouldOpenWithWebIntents(item)) {
|
| + OpenWithWebIntent(item);
|
| + item->DelayedDownloadOpened();
|
| + return false;
|
| }
|
|
|
| - scoped_refptr<CrxInstaller> crx_installer =
|
| - download_crx_util::OpenChromeExtension(profile_, *item);
|
| -
|
| - // CRX_INSTALLER_DONE will fire when the install completes. Observe()
|
| - // will call DelayedDownloadOpened() on this item. If this DownloadItem is
|
| - // not around when CRX_INSTALLER_DONE fires, Complete() will not be called.
|
| - registrar_.Add(this,
|
| - chrome::NOTIFICATION_CRX_INSTALLER_DONE,
|
| - content::Source<CrxInstaller>(crx_installer.get()));
|
| -
|
| - crx_installers_[crx_installer.get()] = item->GetId();
|
| - // The status text and percent complete indicator will change now
|
| - // that we are installing a CRX. Update observers so that they pick
|
| - // up the change.
|
| - item->UpdateObservers();
|
| + return true;
|
| +}
|
| +
|
| +bool ChromeDownloadManagerDelegate::ShouldOpenWithWebIntents(
|
| + const DownloadItem* item) {
|
| + std::string mime_type = item->GetMimeType();
|
| + if (mime_type == "application/rss+xml" ||
|
| + mime_type == "application/atom+xml") {
|
| + return true;
|
| + }
|
| return false;
|
| }
|
|
|
| +void ChromeDownloadManagerDelegate::OpenWithWebIntent(
|
| + const DownloadItem* item) {
|
| + webkit_glue::WebIntentData intent_data(
|
| + ASCIIToUTF16("http://webintents.org/view"),
|
| + ASCIIToUTF16(item->GetMimeType()),
|
| + item->GetFullPath().AsUTF8Unsafe(),
|
| + item->GetReceivedBytes());
|
| +
|
| + // TODO(gbillock): Should we pass this? RCH specifies that the receiver gets
|
| + // the url, but with web intents we don't need to pass it.
|
| + intent_data.extra_data.insert(make_pair(
|
| + ASCIIToUTF16("url"), ASCIIToUTF16(item->GetURL().spec())));
|
| +
|
| + content::DispatchInternalIntent(intent_data, item->GetWebContents());
|
| +}
|
| +
|
| bool ChromeDownloadManagerDelegate::GenerateFileHash() {
|
| #if defined(ENABLE_SAFE_BROWSING)
|
| return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) &&
|
|
|