diff options
author | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-10 00:00:32 +0000 |
---|---|---|
committer | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-10 00:00:32 +0000 |
commit | 8af9d0341d6c00ee537adc089f938b120d1d8d34 (patch) | |
tree | 334fcf5a09c2b3e12face9d46ae4f25ee62921eb /chrome/browser/views | |
parent | 8d292399e6dcdfa776a1de94da07841bf1487f5b (diff) | |
download | chromium_src-8af9d0341d6c00ee537adc089f938b120d1d8d34.zip chromium_src-8af9d0341d6c00ee537adc089f938b120d1d8d34.tar.gz chromium_src-8af9d0341d6c00ee537adc089f938b120d1d8d34.tar.bz2 |
Refactor DragDownloadFile so that it can be used by both Windows and MacOSX.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/572014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38545 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r-- | chrome/browser/views/tab_contents/tab_contents_drag_win.cc | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/chrome/browser/views/tab_contents/tab_contents_drag_win.cc b/chrome/browser/views/tab_contents/tab_contents_drag_win.cc index 013dd40..59ddfd3 100644 --- a/chrome/browser/views/tab_contents/tab_contents_drag_win.cc +++ b/chrome/browser/views/tab_contents/tab_contents_drag_win.cc @@ -10,10 +10,12 @@ #include "base/message_loop.h" #include "base/task.h" #include "base/thread.h" +#include "base/utf_string_conversions.h" #include "base/win_util.h" #include "chrome/browser/bookmarks/bookmark_drag_data.h" #include "chrome/browser/chrome_thread.h" -#include "chrome/browser/download/drag_download_file_win.h" +#include "chrome/browser/download/drag_download_file.h" +#include "chrome/browser/download/drag_download_util.h" #include "chrome/browser/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/web_drag_source_win.h" @@ -112,7 +114,7 @@ void TabContentsDragWin::StartDragging(const WebDropData& drop_data, const std::string& page_encoding = view_->tab_contents()->encoding(); // If it is not drag-out, do the drag-and-drop in the current UI thread. - if (!drop_data.download_url.is_valid()) { + if (drop_data.download_metadata.empty()) { DoDragging(drop_data, ops, page_url, page_encoding); EndDragging(false); return; @@ -171,17 +173,38 @@ void TabContentsDragWin::PrepareDragForDownload( OSExchangeData* data, const GURL& page_url, const std::string& page_encoding) { + // Parse the download metadata. + string16 mime_type; + FilePath file_name; + GURL download_url; + if (!drag_download_util::ParseDownloadMetadata(drop_data.download_metadata, + &mime_type, + &file_name, + &download_url)) + return; + + // Generate the download filename. + std::string content_disposition = + "attachment; filename=" + UTF16ToUTF8(file_name.value()); + FilePath generated_file_name; + DownloadManager::GenerateFileName(download_url, + content_disposition, + std::string(), + UTF16ToUTF8(mime_type), + &generated_file_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(drop_data.download_url, + new DragDownloadFile(generated_file_name, + empty_file_stream, + download_url, page_url, page_encoding, view_->tab_contents()); - OSExchangeData::DownloadFileInfo* file_download = - new OSExchangeData::DownloadFileInfo(FilePath(), - 0, - download_file.get()); + OSExchangeData::DownloadFileInfo file_download(FilePath(), + download_file.get()); data->SetDownloadFileInfo(file_download); // Enable asynchronous operation. @@ -238,7 +261,7 @@ void TabContentsDragWin::DoDragging(const WebDropData& drop_data, // TODO(tc): Generate an appropriate drag image. - if (drop_data.download_url.is_valid()) { + if (!drop_data.download_metadata.empty()) { PrepareDragForDownload(drop_data, &data, page_url, page_encoding); // Set the observer. |