summaryrefslogtreecommitdiffstats
path: root/chrome/browser/download
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-27 12:10:34 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-27 12:10:34 +0000
commit0622875abd5a1328a5f892fef55a60f8c0eaeecd (patch)
treea8ca7ca2536d765bbfa9dd4c4dd11872a307655c /chrome/browser/download
parentd349d55831e9bf3af45636e5e60a8ef8ead54217 (diff)
downloadchromium_src-0622875abd5a1328a5f892fef55a60f8c0eaeecd.zip
chromium_src-0622875abd5a1328a5f892fef55a60f8c0eaeecd.tar.gz
chromium_src-0622875abd5a1328a5f892fef55a60f8c0eaeecd.tar.bz2
Use the suggested name from an anchor's 'download' attribute.
This uses the feature added in WebKit: https://bugs.webkit.org/show_bug.cgi?id=64580 BUG=89346 TEST=manually Review URL: http://codereview.chromium.org/7484061 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@94274 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/download')
-rw-r--r--chrome/browser/download/download_create_info.h3
-rw-r--r--chrome/browser/download/download_item.cc1
-rw-r--r--chrome/browser/download/download_item.h5
-rw-r--r--chrome/browser/download/download_manager.cc5
-rw-r--r--chrome/browser/download/download_types.cc6
-rw-r--r--chrome/browser/download/download_types.h1
-rw-r--r--chrome/browser/download/download_util.cc15
-rw-r--r--chrome/browser/download/download_util.h5
8 files changed, 19 insertions, 22 deletions
diff --git a/chrome/browser/download/download_create_info.h b/chrome/browser/download/download_create_info.h
index a9f5ec1..50ac880 100644
--- a/chrome/browser/download/download_create_info.h
+++ b/chrome/browser/download/download_create_info.h
@@ -46,9 +46,6 @@ struct DownloadCreateInfo {
// The URL that referred us.
GURL referrer_url;
- // The default path for the download (may be overridden).
- FilePath suggested_path;
-
// A number that should be added to the suggested path to make it unique.
// 0 means no number should be appended. Not actually stored in the db.
int path_uniquifier;
diff --git a/chrome/browser/download/download_item.cc b/chrome/browser/download/download_item.cc
index 293e64c..7c2fd01 100644
--- a/chrome/browser/download/download_item.cc
+++ b/chrome/browser/download/download_item.cc
@@ -162,6 +162,7 @@ DownloadItem::DownloadItem(DownloadManager* download_manager,
full_path_(info.path),
url_chain_(info.url_chain),
referrer_url_(info.referrer_url),
+ suggested_filename_(UTF16ToUTF8(info.save_info.suggested_name)),
content_disposition_(info.content_disposition),
mime_type_(info.mime_type),
original_mime_type_(info.original_mime_type),
diff --git a/chrome/browser/download/download_item.h b/chrome/browser/download/download_item.h
index 64704dd..5596b53 100644
--- a/chrome/browser/download/download_item.h
+++ b/chrome/browser/download/download_item.h
@@ -266,6 +266,7 @@ class DownloadItem : public NotificationObserver {
const std::vector<GURL>& url_chain() const { return url_chain_; }
const GURL& original_url() const { return url_chain_.front(); }
const GURL& referrer_url() const { return referrer_url_; }
+ std::string suggested_filename() const { return suggested_filename_; }
std::string content_disposition() const { return content_disposition_; }
std::string mime_type() const { return mime_type_; }
std::string original_mime_type() const { return original_mime_type_; }
@@ -394,6 +395,10 @@ class DownloadItem : public NotificationObserver {
// The URL of the page that initiated the download.
GURL referrer_url_;
+ // Suggested filename in 'download' attribute of an anchor. Details:
+ // http://www.whatwg.org/specs/web-apps/current-work/#downloading-hyperlinks
+ std::string suggested_filename_;
+
// Information from the request.
// Content-disposition field from the header.
std::string content_disposition_;
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc
index 54c21b4..fc42b17c 100644
--- a/chrome/browser/download/download_manager.cc
+++ b/chrome/browser/download/download_manager.cc
@@ -358,10 +358,7 @@ void DownloadManager::CheckVisitedReferrerBeforeDone(
if (state.force_file_name.empty()) {
FilePath generated_name;
- download_util::GenerateFileNameFromRequest(download->GetURL(),
- download->content_disposition(),
- download->referrer_charset(),
- download->mime_type(),
+ download_util::GenerateFileNameFromRequest(*download,
&generated_name);
// Freeze the user's preference for showing a Save As dialog. We're going
diff --git a/chrome/browser/download/download_types.cc b/chrome/browser/download/download_types.cc
index 543555c..0634ab6 100644
--- a/chrome/browser/download/download_types.cc
+++ b/chrome/browser/download/download_types.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -15,7 +15,8 @@ DownloadSaveInfo::DownloadSaveInfo() {
DownloadSaveInfo::DownloadSaveInfo(const DownloadSaveInfo& info)
: file_path(info.file_path),
- file_stream(info.file_stream) {
+ file_stream(info.file_stream),
+ suggested_name(info.suggested_name) {
}
DownloadSaveInfo::~DownloadSaveInfo() {
@@ -24,5 +25,6 @@ DownloadSaveInfo::~DownloadSaveInfo() {
DownloadSaveInfo& DownloadSaveInfo::operator=(const DownloadSaveInfo& info) {
file_path = info.file_path;
file_stream = info.file_stream;
+ suggested_name = info.suggested_name;
return *this;
}
diff --git a/chrome/browser/download/download_types.h b/chrome/browser/download/download_types.h
index ff82b5c..77ca39b 100644
--- a/chrome/browser/download/download_types.h
+++ b/chrome/browser/download/download_types.h
@@ -41,6 +41,7 @@ struct DownloadSaveInfo {
FilePath file_path;
linked_ptr<net::FileStream> file_stream;
+ string16 suggested_name;
};
#endif // CHROME_BROWSER_DOWNLOAD_DOWNLOAD_TYPES_H_
diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc
index 2abf2d1..e1db3ff 100644
--- a/chrome/browser/download/download_util.cc
+++ b/chrome/browser/download/download_util.cc
@@ -288,16 +288,13 @@ void GenerateExtension(const FilePath& file_name,
generated_extension->swap(extension);
}
-void GenerateFileNameFromRequest(const GURL& url,
- const std::string& content_disposition,
- const std::string& referrer_charset,
- const std::string& mime_type,
+void GenerateFileNameFromRequest(const DownloadItem& download_item,
FilePath* generated_name) {
- GenerateFileNameInternal(url,
- content_disposition,
- referrer_charset,
- std::string(),
- mime_type,
+ GenerateFileNameInternal(download_item.GetURL(),
+ download_item.content_disposition(),
+ download_item.referrer_charset(),
+ download_item.suggested_filename(),
+ download_item.mime_type(),
generated_name);
}
diff --git a/chrome/browser/download/download_util.h b/chrome/browser/download/download_util.h
index 90f669a..644853f 100644
--- a/chrome/browser/download/download_util.h
+++ b/chrome/browser/download/download_util.h
@@ -66,10 +66,7 @@ void GenerateExtension(const FilePath& file_name,
FilePath::StringType* generated_extension);
// Create a file name based on the response from the server.
-void GenerateFileNameFromRequest(const GURL& url,
- const std::string& content_disposition,
- const std::string& referrer_charset,
- const std::string& mime_type,
+void GenerateFileNameFromRequest(const DownloadItem& download_item,
FilePath* generated_name);
void GenerateFileNameFromSuggestedName(const GURL& url,