diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-25 14:09:45 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-25 14:09:45 +0000 |
commit | 2d81b66fd8a968ef8d40e4de8bb2068d589f42d2 (patch) | |
tree | 11079a98fa6f2e9ab5be0d5dbd31fbb3fa981875 | |
parent | eb5bc9758ab821209d8bcc3ab9ade9ffc4f4af07 (diff) | |
download | chromium_src-2d81b66fd8a968ef8d40e4de8bb2068d589f42d2.zip chromium_src-2d81b66fd8a968ef8d40e4de8bb2068d589f42d2.tar.gz chromium_src-2d81b66fd8a968ef8d40e4de8bb2068d589f42d2.tar.bz2 |
Make all drag sources not depend on download_util.
Apply the same change as r106124 to Mac/Win.
BUG=95573
TEST=no change
Review URL: http://codereview.chromium.org/8380021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@107112 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/download/download_util.cc | 40 | ||||
-rw-r--r-- | chrome/browser/download/download_util.h | 8 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/tab_contents/web_drag_source.mm | 18 | ||||
-rw-r--r-- | chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc | 21 |
4 files changed, 32 insertions, 55 deletions
diff --git a/chrome/browser/download/download_util.cc b/chrome/browser/download/download_util.cc index 7b11a12..d70d650 100644 --- a/chrome/browser/download/download_util.cc +++ b/chrome/browser/download/download_util.cc @@ -88,24 +88,6 @@ namespace download_util { // so that the animation ends faded out. static const int kCompleteAnimationCycles = 5; -namespace { - -void GenerateFileNameInternal(const GURL& url, - const std::string& content_disposition, - const std::string& referrer_charset, - const std::string& suggested_name, - const std::string& mime_type, - FilePath* generated_name) { - std::string default_file_name( - l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); - - *generated_name = net::GenerateFileName(url, content_disposition, - referrer_charset, suggested_name, - mime_type, default_file_name); -} - -} // namespace - // Download temporary file creation -------------------------------------------- class DefaultDownloadDirectory { @@ -144,21 +126,15 @@ bool DownloadPathIsDangerous(const FilePath& download_path) { void GenerateFileNameFromRequest(const DownloadItem& download_item, FilePath* generated_name) { - GenerateFileNameInternal(download_item.GetURL(), - download_item.content_disposition(), - download_item.referrer_charset(), - download_item.suggested_filename(), - download_item.mime_type(), - generated_name); -} + std::string default_file_name( + l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME)); -void GenerateFileNameFromSuggestedName(const GURL& url, - const std::string& suggested_name, - const std::string& mime_type, - FilePath* generated_name) { - // TODO(asanka): We should pass in a valid referrer_charset here. - GenerateFileNameInternal(url, std::string(), std::string(), - suggested_name, mime_type, generated_name); + *generated_name = net::GenerateFileName(download_item.GetURL(), + download_item.content_disposition(), + download_item.referrer_charset(), + download_item.suggested_filename(), + download_item.mime_type(), + default_file_name); } // Download progress painting -------------------------------------------------- diff --git a/chrome/browser/download/download_util.h b/chrome/browser/download/download_util.h index f71590a..3367fda 100644 --- a/chrome/browser/download/download_util.h +++ b/chrome/browser/download/download_util.h @@ -61,14 +61,6 @@ bool DownloadPathIsDangerous(const FilePath& download_path); void GenerateFileNameFromRequest(const DownloadItem& download_item, FilePath* generated_name); -// Generate a filename based on the URL, a suggested name and a MIME -// type. Similar in operation to net::GenerateFileName(), but uses a -// localized default name. -void GenerateFileNameFromSuggestedName(const GURL& url, - const std::string& suggested_name, - const std::string& mime_type, - FilePath* generated_name); - // Download progress animations ------------------------------------------------ // Arc sweep angle for use with downloads of unknown size diff --git a/chrome/browser/ui/cocoa/tab_contents/web_drag_source.mm b/chrome/browser/ui/cocoa/tab_contents/web_drag_source.mm index fbd762a..12c401b 100644 --- a/chrome/browser/ui/cocoa/tab_contents/web_drag_source.mm +++ b/chrome/browser/ui/cocoa/tab_contents/web_drag_source.mm @@ -14,12 +14,12 @@ #include "base/threading/thread_restrictions.h" #include "base/utf_string_conversions.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/download/download_util.h" #include "chrome/browser/tab_contents/tab_contents_view_mac.h" #include "content/browser/download/drag_download_file.h" #include "content/browser/download/drag_download_util.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/tab_contents/tab_contents.h" +#include "content/public/browser/content_browser_client.h" #include "content/public/common/url_constants.h" #include "net/base/file_stream.h" #include "net/base/net_util.h" @@ -402,11 +402,17 @@ void PromiseWriterTask::Run() { &mimeType, &fileName, &downloadURL_)) { - download_util::GenerateFileNameFromSuggestedName( - downloadURL_, - fileName.value(), - UTF16ToUTF8(mimeType), - &downloadFileName_); + // Generate the file name based on both mime type and proposed file + // name. + std::string defaultName = + content::GetContentClient()->browser()->GetDefaultDownloadName(); + downloadFileName_ = + net::GenerateFileName(downloadURL_, + std::string(), + std::string(), + fileName.value(), + UTF16ToUTF8(mimeType), + defaultName); fileExtension = SysUTF8ToNSString(downloadFileName_.Extension()); } } diff --git a/chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc b/chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc index 7857c4b..8eac87b 100644 --- a/chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc +++ b/chrome/browser/ui/views/tab_contents/tab_contents_drag_win.cc @@ -16,7 +16,6 @@ #include "base/threading/thread.h" #include "base/utf_string_conversions.h" #include "chrome/browser/bookmarks/bookmark_node_data.h" -#include "chrome/browser/download/download_util.h" #include "chrome/browser/tab_contents/web_drag_source_win.h" #include "chrome/browser/tab_contents/web_drag_utils_win.h" #include "chrome/browser/tab_contents/web_drop_target_win.h" @@ -26,6 +25,7 @@ #include "content/browser/download/drag_download_file.h" #include "content/browser/download/drag_download_util.h" #include "content/browser/tab_contents/tab_contents.h" +#include "content/public/browser/content_browser_client.h" #include "net/base/net_util.h" #include "views/drag_utils.h" #include "webkit/glue/webdropdata.h" @@ -197,19 +197,22 @@ void TabContentsDragWin::PrepareDragForDownload( &download_url)) return; - // Generate the download filename. - FilePath generated_file_name; - download_util::GenerateFileNameFromSuggestedName( - download_url, - UTF16ToUTF8(file_name.value()), - UTF16ToUTF8(mime_type), - &generated_file_name); + // Generate the file name based on both mime type and proposed file name. + std::string default_name = + content::GetContentClient()->browser()->GetDefaultDownloadName(); + FilePath generated_download_file_name = + net::GenerateFileName(download_url, + std::string(), + std::string(), + UTF16ToUTF8(file_name.value()), + UTF16ToUTF8(mime_type), + default_name); // Provide the data as file (CF_HDROP). A temporary download file with the // Zone.Identifier ADS (Alternate Data Stream) attached will be created. linked_ptr<net::FileStream> empty_file_stream; scoped_refptr<DragDownloadFile> download_file = - new DragDownloadFile(generated_file_name, + new DragDownloadFile(generated_download_file_name, empty_file_stream, download_url, page_url, |