Chromium Code Reviews| 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..0440de15fb94f2d1e3d833e80075cf591b1f95e5 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,63 @@ 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::WebIntentsDispatcher* dispatcher = |
| + content::WebIntentsDispatcher::Create(intent_data); |
| + item->GetWebContents()->GetDelegate()->WebIntentDispatch( |
| + item->GetWebContents(), dispatcher); |
|
Randy Smith (Not in Mondays)
2012/03/29 18:47:24
Is there no way to get the web contents delegate m
Greg Billock
2012/03/29 20:53:01
Perhaps a better thing to do here is
Browser* act
|
| +} |
| + |
| bool ChromeDownloadManagerDelegate::GenerateFileHash() { |
| #if defined(ENABLE_SAFE_BROWSING) |
| return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) && |