Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1029)

Unified Diff: chrome/browser/download/chrome_download_manager_delegate.cc

Issue 9651020: Pass content-type resources to web intents. Goes through download, then invokes the p… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove includes Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 6737e09914bc328eefb317eec5495e0aa82ddbac..527de4ed65ff0dc05e96f66ce10f9f0de911ddd7 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"
@@ -226,28 +229,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) {
return false;
}
+void ChromeDownloadManagerDelegate::OpenWithWebIntent(
+ const DownloadItem* item) {
+ webkit_glue::WebIntentData intent_data(
+ ASCIIToUTF16("http://webintents.org/view"),
+ ASCIIToUTF16(item->GetMimeType()),
+ item->GetFullPath(),
+ 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);
+ // TODO(gbillock): try to get this to be able to delegate to the Browser
+ // object directly, passing a NULL WebContents?
+ item->GetWebContents()->GetDelegate()->WebIntentDispatch(
+ item->GetWebContents(), dispatcher);
+}
+
bool ChromeDownloadManagerDelegate::GenerateFileHash() {
#if defined(ENABLE_SAFE_BROWSING)
return profile_->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) &&
« no previous file with comments | « chrome/browser/download/chrome_download_manager_delegate.h ('k') | content/browser/intents/intent_injector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698