From a8b7972ea8835724e353d20e6fd85ebb0fb1d2e3 Mon Sep 17 00:00:00 2001 From: "dcheng@chromium.org" Date: Tue, 29 May 2012 21:55:35 +0000 Subject: [PATCH] Issue 121063 fixed: Drag and dropping a file named [something].[andmore].[ext] from Chrome to a folder results in a filename named [something].[ext] Method WebContentsDragWin::PrepareDragForFileContents has been updated to deal with filenames like [something].[andmore].[ext] correctly. BUG=121063 TEST=1. Find a file named with the following pattern [something].[andmore].[ext] 2. Drag and drop the file(picture) to a folder You can use the picture attached to the issue page at http://code.google.com/p/chromium/issues/detail?id=121063 Review URL: https://chromiumcodereview.appspot.com/10257025 Patch from Alexey Korepanov . git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139386 0039d316-1c4b-4281-b951-d872f2087c98 --- AUTHORS | 1 + content/browser/web_contents/web_contents_drag_win.cc | 8 ++++---- content/browser/web_contents/web_drag_source_mac.mm | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/AUTHORS b/AUTHORS index 9c870435beceb4..45d562d4310d42 100644 --- a/AUTHORS +++ b/AUTHORS @@ -175,3 +175,4 @@ Eric Rescorla Alexandre Abreu Erik Sjölund Simon Arlott +Alexey Korepanov diff --git a/content/browser/web_contents/web_contents_drag_win.cc b/content/browser/web_contents/web_contents_drag_win.cc index a07c61f7d019fd..4dbac90526b943 100644 --- a/content/browser/web_contents/web_contents_drag_win.cc +++ b/content/browser/web_contents/web_contents_drag_win.cc @@ -234,11 +234,11 @@ void WebContentsDragWin::PrepareDragForFileContents( const WebDropData& drop_data, ui::OSExchangeData* data) { static const int kMaxFilenameLength = 255; // FAT and NTFS FilePath file_name(drop_data.file_description_filename); - string16 extension = file_name.Extension(); - file_name = file_name.BaseName().RemoveExtension(); + // Images without ALT text will only have a file extension so we need to // synthesize one from the provided extension and URL. - if (file_name.value().empty()) { + if (file_name.BaseName().RemoveExtension().empty()) { + const string16 extension = file_name.Extension(); // Retrieve the name from the URL. file_name = FilePath( net::GetSuggestedFilename(drop_data.url, "", "", "", "", "")); @@ -246,8 +246,8 @@ void WebContentsDragWin::PrepareDragForFileContents( file_name = FilePath(file_name.value().substr( 0, kMaxFilenameLength - extension.size())); } + file_name = file_name.ReplaceExtension(extension); } - file_name = file_name.ReplaceExtension(extension); data->SetFileContents(file_name, drop_data.file_contents); } diff --git a/content/browser/web_contents/web_drag_source_mac.mm b/content/browser/web_contents/web_drag_source_mac.mm index 98a21204e79e69..21e05c34938fa4 100644 --- a/content/browser/web_contents/web_drag_source_mac.mm +++ b/content/browser/web_contents/web_drag_source_mac.mm @@ -57,8 +57,6 @@ FilePath FilePathFromFilename(const string16& filename) { // and move it somewhere sensible. FilePath GetFileNameFromDragData(const WebDropData& drop_data) { FilePath file_name(FilePathFromFilename(drop_data.file_description_filename)); - std::string extension = file_name.Extension(); - file_name = file_name.BaseName().RemoveExtension(); // Images without ALT text will only have a file extension so we need to // synthesize one from the provided extension and URL. @@ -66,10 +64,12 @@ FilePath GetFileNameFromDragData(const WebDropData& drop_data) { // Retrieve the name from the URL. string16 suggested_filename = net::GetSuggestedFilename(drop_data.url, "", "", "", "", ""); + const std::string extension = file_name.Extension(); file_name = FilePathFromFilename(suggested_filename); + file_name = file_name.ReplaceExtension(extension); } - return file_name.ReplaceExtension(extension); + return file_name; } // This helper's sole task is to write out data for a promised file; the caller