diff options
author | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-19 00:36:58 +0000 |
---|---|---|
committer | jianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-19 00:36:58 +0000 |
commit | 8ada5e06e95dd941314a0665da2948448fefa820 (patch) | |
tree | a76c5f54eaf16c29f595af2b76d5e5c2e0327b07 /chrome/browser/cocoa/web_drag_source.mm | |
parent | 595d56c647fc96cc9b6a5b8ec5b4787e719f981c (diff) | |
download | chromium_src-8ada5e06e95dd941314a0665da2948448fefa820.zip chromium_src-8ada5e06e95dd941314a0665da2948448fefa820.tar.gz chromium_src-8ada5e06e95dd941314a0665da2948448fefa820.tar.bz2 |
Support dragging a virtual file out of the browser on Linux. This is based on the discussion of drag-out feature on whatwg: http://list.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-August/022122.html
BUG=none
TEST=To test, drag an element that adds the DownloadURL format data via event.DataTransfer.setData, to the desktop or a folder.
Review URL: http://codereview.chromium.org/600154
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39405 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/web_drag_source.mm')
-rw-r--r-- | chrome/browser/cocoa/web_drag_source.mm | 75 |
1 files changed, 8 insertions, 67 deletions
diff --git a/chrome/browser/cocoa/web_drag_source.mm b/chrome/browser/cocoa/web_drag_source.mm index b7818a6..1408db9 100644 --- a/chrome/browser/cocoa/web_drag_source.mm +++ b/chrome/browser/cocoa/web_drag_source.mm @@ -5,7 +5,6 @@ #import "chrome/browser/cocoa/web_drag_source.h" #include "base/file_path.h" -#include "base/file_util.h" #include "base/nsimage_cache_mac.h" #include "base/string_util.h" #include "base/sys_string_conversions.h" @@ -19,7 +18,6 @@ #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view_mac.h" #include "net/base/file_stream.h" -#include "net/base/net_errors.h" #include "net/base/net_util.h" #import "third_party/mozilla/include/NSPasteboard+Utils.h" #include "webkit/glue/webdropdata.h" @@ -104,42 +102,6 @@ void PromiseWriterTask::Run() { // Let our destructor take care of business. } -class PromiseFileFinalizer : public DownloadFileObserver { - public: - PromiseFileFinalizer(DragDownloadFile* drag_file_downloader) - : drag_file_downloader_(drag_file_downloader) { - } - virtual ~PromiseFileFinalizer() { } - - // DownloadFileObserver methods. - virtual void OnDownloadCompleted(const FilePath& file_path); - virtual void OnDownloadAborted(); - - private: - void Cleanup(); - - scoped_refptr<DragDownloadFile> drag_file_downloader_; - - DISALLOW_COPY_AND_ASSIGN(PromiseFileFinalizer); -}; - -void PromiseFileFinalizer::Cleanup() { - if (drag_file_downloader_.get()) - drag_file_downloader_ = NULL; -} - -void PromiseFileFinalizer::OnDownloadCompleted(const FilePath& file_path) { - ChromeThread::PostTask( - ChromeThread::UI, FROM_HERE, - NewRunnableMethod(this, &PromiseFileFinalizer::Cleanup)); -} - -void PromiseFileFinalizer::OnDownloadAborted() { - ChromeThread::PostTask( - ChromeThread::UI, FROM_HERE, - NewRunnableMethod(this, &PromiseFileFinalizer::Cleanup)); -} - } // namespace @@ -310,35 +272,14 @@ void PromiseFileFinalizer::OnDownloadAborted() { return nil; } - FileStream* fileStream = new FileStream; - DCHECK(fileStream); - if (!fileStream) - return nil; - - FilePath baseFileName = downloadFileName_.empty() ? + FilePath fileName = downloadFileName_.empty() ? GetFileNameFromDragData(*dropData_) : downloadFileName_; - FilePath pathName(SysNSStringToUTF8(path)); - FilePath fileName; - FilePath filePath; - unsigned seq; - const unsigned kMaxSeq = 99; - for (seq = 0; seq <= kMaxSeq; seq++) { - fileName = (seq == 0) ? baseFileName : - baseFileName.InsertBeforeExtension( - std::string("-") + UintToString(seq)); - filePath = pathName.Append(fileName); - - // Explicitly (and redundantly check) for file -- despite the fact that our - // open won't overwrite -- just to avoid log spew. - if (!file_util::PathExists(filePath) && - fileStream->Open(filePath, - base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE) == net::OK) - break; - } - if (seq > kMaxSeq) { - delete fileStream; + FilePath filePath(SysNSStringToUTF8(path)); + filePath = filePath.Append(fileName); + FileStream* fileStream = + drag_download_util::CreateFileStreamForDrop(&filePath); + if (!fileStream) return nil; - } if (downloadURL_.is_valid()) { TabContents* tabContents = [contentsView_ tabContents]; @@ -352,7 +293,7 @@ void PromiseFileFinalizer::OnDownloadAborted() { // The finalizer will take care of closing and deletion. dragFileDownloader->Start( - new PromiseFileFinalizer(dragFileDownloader)); + new drag_download_util::PromiseFileFinalizer(dragFileDownloader)); } else { // The writer will take care of closing and deletion. g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE, @@ -360,7 +301,7 @@ void PromiseFileFinalizer::OnDownloadAborted() { } // Once we've created the file, we should return the file name. - return SysUTF8ToNSString(fileName.value()); + return SysUTF8ToNSString(filePath.BaseName().value()); } @end // @implementation WebDragSource |