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 d9436600b45a4eb9e1fb897612ed368216095e33..6e95171de355a181d5fafbcadfc28e5db6e40162 100644 |
| --- a/chrome/browser/download/chrome_download_manager_delegate.cc |
| +++ b/chrome/browser/download/chrome_download_manager_delegate.cc |
| @@ -12,6 +12,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" |
| @@ -33,12 +34,18 @@ |
| #include "chrome/common/chrome_paths.h" |
| #include "chrome/common/extensions/user_script.h" |
| #include "chrome/common/pref_names.h" |
| +#include "content/browser/intents/internal_web_intents_dispatcher.h" |
| #include "content/public/browser/download_item.h" |
| #include "content/public/browser/download_manager.h" |
| #include "content/public/browser/notification_source.h" |
| +#include "content/public/browser/resource_context.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/blob/blob_data.h" |
| +#include "webkit/blob/blob_storage_controller.h" |
| +#include "webkit/glue/web_intent_data.h" |
| using content::BrowserThread; |
| using content::DownloadId; |
| @@ -72,6 +79,7 @@ ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile) |
| ChromeDownloadManagerDelegate::~ChromeDownloadManagerDelegate() { |
| } |
| +// static |
| bool ChromeDownloadManagerDelegate::IsExtensionDownload( |
| const DownloadItem* item) { |
| if (item->PromptUserForSaveLocation()) |
| @@ -81,6 +89,24 @@ bool ChromeDownloadManagerDelegate::IsExtensionDownload( |
| UserScript::IsURLUserScript(item->GetURL(), item->GetMimeType()); |
| } |
| +// static |
| +bool ChromeDownloadManagerDelegate::ShouldWebIntentsHandle( |
|
jam
2012/03/13 20:05:01
why is this stuff in chrome vs content? it seems g
Greg Billock
2012/03/13 20:53:56
It could be defined more generically in DownloadMa
|
| + const DownloadItem& item) { |
| + std::string mime_type = item.GetMimeType(); |
| + LOG(INFO) << "Testing " << mime_type << " for web intents"; |
| + |
| + // TODO: Check for explicit user-caused download? |
|
michaeln
2012/03/12 21:16:12
Should this also check for mimes for which there a
Greg Billock
2012/03/13 17:56:10
Yes, it needs refinement. Checking the registry fo
|
| + |
| + if (mime_type == "application/rss+xml" || |
| + mime_type == "application/atom+xml" || |
| + mime_type == "application/ms-word" || |
| + mime_type == "appliation/pdf") { |
| + return true; |
| + } |
| + |
| + return false; |
| +} |
| + |
| void ChromeDownloadManagerDelegate::SetDownloadManager(DownloadManager* dm) { |
| download_manager_ = dm; |
| download_history_.reset(new DownloadHistory(profile_)); |
| @@ -198,27 +224,80 @@ bool ChromeDownloadManagerDelegate::ShouldCompleteDownload(DownloadItem* item) { |
| return true; |
| } |
| +// Helper method for ShouldOpenDownload. |
| +content::WebIntentsDispatcher* CreateWebIntentsDispatcherFor( |
|
michaeln
2012/03/12 21:16:12
At this point, we've fully downloaded a file to th
Greg Billock
2012/03/13 17:56:10
Yes, that's right.
|
| + const DownloadItem& item, |
| + webkit_blob::BlobStorageController* blob_controller) { |
| + // This blob url format is not the same as that prepared internally in webkit. |
| + // It shouldn't matter, however. |
| + GURL blob_url(StringPrintf("blob:chrome-internal/%llux", |
| + static_cast<long long unsigned int>(base::RandUint64()))); |
| + |
| + blob_controller->StartBuildingBlob(blob_url); |
| + webkit_blob::BlobData::Item blob_item; |
| + // Need to get the item file time. item.GetLastModifiedTime() is a string |
| + // and unset. :-( |
| + blob_item.SetToFile(item.GetFullPath(), |
| + 0, |
| + item.GetReceivedBytes(), |
| + base::Time::Now()); |
|
michaeln
2012/03/12 21:16:12
just use base::Time() here to indicate "doesn't ma
Greg Billock
2012/03/13 17:56:10
Done.
|
| + blob_controller->AppendBlobDataItem(blob_url, blob_item); |
| + blob_controller->FinishBuildingBlob(blob_url, item.GetMimeType()); |
| + |
| + webkit_glue::WebIntentData intent_data( |
| + ASCIIToUTF16("http://webintents.org/view"), |
| + ASCIIToUTF16(item.GetMimeType()), |
| + ASCIIToUTF16(item.GetURL().spec())); |
| + |
| + /* |
| + // TODO: need to actually serialize this blob url, but can't really |
| + // do that in-browser-process. Need to figure out what to do here. |
| + // Hidden params in WebIntentData? |
| + intent_data.data = ASCIIToUTF16(blob_url.spec()); |
| + |
| + // For now, send the url as extra. Need to re-examine this... |
| + intent_data.extra_data.put(ASCIIToUTF16("url"), |
| + ASCIIToUTF16(item.GetURL()).spec()); |
| + */ |
| + |
| + return new InternalWebIntentsDispatcher(intent_data); |
| +} |
| + |
| 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; |
| } |
| - 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 (ShouldWebIntentsHandle(*item)) { |
| + content::WebContents* web_contents = item->GetWebContents(); |
| + |
| + webkit_blob::BlobStorageController* blob_controller = |
| + content::ResourceContext::GetBlobStorageController( |
| + profile_->GetResourceContext()); |
| + content::WebIntentsDispatcher* dispatcher = |
| + CreateWebIntentsDispatcherFor(*item, blob_controller); |
| + web_contents->GetDelegate()->WebIntentDispatch(web_contents, dispatcher); |
| + // Update text/completion indicator on shelf. |
|
michaeln
2012/03/12 21:16:12
just curious... what will the shelf indicator say
Greg Billock
2012/03/13 17:56:10
Not sure yet...
|
| + item->UpdateObservers(); |
| + return false; |
| + } |
| + |
| + return true; |
| } |
| bool ChromeDownloadManagerDelegate::GenerateFileHash() { |