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

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: Use the ChromeRenderViewHostTestHarness Created 8 years, 3 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 | chrome/browser/download/chrome_download_manager_delegate_unittest.cc » ('j') | 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 e6b670dbadd8595560693478f59858d47c00bc38..fe7f81fbf5d1378b2ab4de062ad1721a20deb3b2 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"
@@ -74,6 +75,11 @@ namespace {
// a download item.
static const char safe_browsing_id[] = "Safe Browsing ID";
+// String pointer used to set the local file extension to be used when a
+// download is going to be dispatched with web intents.
+static const FilePath::CharType kWebIntentsFileExtension[] =
+ FILE_PATH_LITERAL(".webintents");
+
// The state of a safebrowsing check.
class SafeBrowsingState : public DownloadCompletionBlocker {
public:
@@ -118,6 +124,20 @@ void GenerateFileNameFromRequest(const DownloadItem& download_item,
default_file_name);
}
+// Needed to give PostTask a void closure in OnWebIntentDispatchCompleted.
+void DeleteFile(const FilePath& file_path) {
+ 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(
+ const FilePath& file_path,
+ webkit_glue::WebIntentReplyType intent_reply) {
+ BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
+ base::Bind(&DeleteFile, file_path));
+}
+
} // namespace
ChromeDownloadManagerDelegate::ChromeDownloadManagerDelegate(Profile* profile)
@@ -371,6 +391,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" ||
@@ -436,6 +458,8 @@ void ChromeDownloadManagerDelegate::OpenWithWebIntent(
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(
@@ -724,6 +748,14 @@ 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)) {
+ download->SetDisplayName(suggested_path.BaseName());
+ suggested_path = suggested_path.AddExtension(kWebIntentsFileExtension);
+ }
+
// 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 | chrome/browser/download/chrome_download_manager_delegate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698