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

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

Issue 10836164: Change policy to not trigger dangerous download UI for web intents dispatched files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add extension; delete file when done Created 8 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 27e59881521ac0ba41c96157ac707ef5ae9cdfb3..8b5982d991fed58afb5d8256e051fe85cf62e196 100644
--- a/chrome/browser/download/chrome_download_manager_delegate.cc
+++ b/chrome/browser/download/chrome_download_manager_delegate.cc
@@ -47,6 +47,7 @@
#include "net/base/net_util.h"
#include "ui/base/l10n/l10n_util.h"
#include "webkit/glue/web_intent_data.h"
+#include "webkit/glue/web_intent_reply_data.h"
#if !defined(OS_ANDROID)
#include "chrome/browser/ui/browser.h"
@@ -372,6 +373,8 @@ bool ChromeDownloadManagerDelegate::ShouldOpenWithWebIntents(
const DownloadItem* item) {
if (!item->GetWebContents() || !item->GetWebContents()->GetDelegate())
return false;
+ if (!item->GetForcedFilePath().empty())
+ return false;
std::string mime_type = item->GetMimeType();
if (mime_type == "application/rss+xml" ||
@@ -396,6 +399,20 @@ bool ChromeDownloadManagerDelegate::ShouldOpenWithWebIntents(
return false;
}
+// Needed to give PostTask a void closure in OnWebIntentDispatchCompleted.
+void DeleteFile(const FilePath& file_path) {
asanka 2012/08/16 18:27:25 Nit: Move to anonymous namespace.
Greg Billock 2012/08/16 21:29:51 Done.
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ file_util::Delete(file_path, false);
+}
+
+// Called when the web intents dispatch has completed. Deletes the |file_path|.
+void OnWebIntentDispatchCompleted(
asanka 2012/08/16 18:27:25 Nit: This as well.
Greg Billock 2012/08/16 21:29:51 Done.
+ const FilePath& file_path,
+ webkit_glue::WebIntentReplyType intent_reply) {
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
+ base::Bind(&DeleteFile, file_path));
+}
+
void ChromeDownloadManagerDelegate::OpenWithWebIntent(
const DownloadItem* item) {
webkit_glue::WebIntentData intent_data(
@@ -410,12 +427,16 @@ void ChromeDownloadManagerDelegate::OpenWithWebIntent(
ASCIIToUTF16("url"), ASCIIToUTF16(item->GetURL().spec())));
// Pass the downloaded filename to the service app as the name hint.
- intent_data.extra_data.insert(
- make_pair(ASCIIToUTF16("filename"),
- item->GetFileNameToReportUser().LossyDisplayName()));
+ string16 display_name = item->GetFileNameToReportUser().LossyDisplayName();
+ ReplaceFirstSubstringAfterOffset(&display_name, display_name.length() - 11,
asanka 2012/08/16 18:27:25 See comment below about display names.
Greg Billock 2012/08/16 21:29:51 Done.
+ ASCIIToUTF16(".webintents"), string16());
+ intent_data.extra_data.insert(make_pair(ASCIIToUTF16("filename"),
+ display_name));
content::WebIntentsDispatcher* dispatcher =
content::WebIntentsDispatcher::Create(intent_data);
+ dispatcher->RegisterReplyNotification(
+ base::Bind(&OnWebIntentDispatchCompleted, item->GetFullPath()));
// TODO(gbillock): try to get this to be able to delegate to the Browser
// object directly, passing a NULL WebContents?
item->GetWebContents()->GetDelegate()->WebIntentDispatch(
@@ -697,6 +718,13 @@ void ChromeDownloadManagerDelegate::CheckVisitedReferrerBeforeDone(
suggested_path = download->GetForcedFilePath();
}
+ // If we will open the file with a web intents dispatch,
+ // give it a name that will not allow the OS to open it using usual
+ // associated apps.
+ if (ShouldOpenWithWebIntents(download)) {
+ suggested_path = suggested_path.AddExtension(".webintents");
asanka 2012/08/16 18:27:25 I suggest calling download->SetDisplayName(suggest
asanka 2012/08/16 18:27:25 Also, consider using a named constant for the ".we
Greg Billock 2012/08/16 21:29:51 Done.
Greg Billock 2012/08/16 21:29:51 Got it. Yes. That's very nice. On 2012/08/16 18:2
+ }
+
// If the download hasn't already been marked dangerous (could be
// DANGEROUS_URL), check if it is a dangerous file.
if (danger_type == content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698