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

Unified Diff: content/browser/download/download_item_impl.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: Move dispatch logic client-side. 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: content/browser/download/download_item_impl.cc
diff --git a/content/browser/download/download_item_impl.cc b/content/browser/download/download_item_impl.cc
index d8a808b8db6d6d17cc75a6f987b9ad7f3300b33a..30a0232f69d82a91e9f35f3050e7aa375dc906a5 100644
--- a/content/browser/download/download_item_impl.cc
+++ b/content/browser/download/download_item_impl.cc
@@ -23,11 +23,18 @@
#include "content/browser/download/download_interrupt_reasons_impl.h"
#include "content/browser/download/download_request_handle.h"
#include "content/browser/download/download_stats.h"
+#include "content/browser/intents/internal_web_intents_dispatcher.h"
#include "content/browser/tab_contents/tab_contents.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/download_persistent_store_info.h"
+#include "content/public/browser/resource_context.h"
+#include "content/public/browser/web_contents_delegate.h"
+#include "content/public/browser/web_intents_dispatcher.h"
#include "net/base/net_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::DownloadFile;
@@ -771,6 +778,12 @@ void DownloadItemImpl::OnDownloadRenamedToFinalName(const FilePath& full_path) {
Rename(full_path);
+ if (delegate_->ShouldOpenWithWebIntent(this)) {
+ DispatchAsWebIntent();
+ Completed();
+ return;
+ }
+
if (delegate_->ShouldOpenDownload(this)) {
Completed();
} else {
@@ -778,6 +791,26 @@ void DownloadItemImpl::OnDownloadRenamedToFinalName(const FilePath& full_path) {
}
}
+void DownloadItemImpl::DispatchAsWebIntent() {
+ // TODO(gbillock): should this read non-binary files and pass them
+ // as unserialized text? Probably so...
+ webkit_glue::WebIntentData intent_data(
+ ASCIIToUTF16("http://webintents.org/view"),
+ ASCIIToUTF16(GetMimeType()),
+ GetFullPath().AsUTF8Unsafe(),
+ GetReceivedBytes());
+ intent_data.extra_data.insert(make_pair(
+ ASCIIToUTF16("url"), ASCIIToUTF16(GetURL().spec())));
+
+ // TODO(gbillock): need to ChildProcessSecurityPolicy::GrantReadFile(someone)
+ // here? Or on the receiving end?
+
+ content::WebIntentsDispatcher* dispatcher =
+ new InternalWebIntentsDispatcher(intent_data);
+ GetWebContents()->GetDelegate()->WebIntentDispatch(GetWebContents(),
+ dispatcher);
+}
+
bool DownloadItemImpl::MatchesQuery(const string16& query) const {
if (query.empty())
return true;

Powered by Google App Engine
This is Rietveld 408576698