Skip to content

Commit

Permalink
Issue 121063 fixed: Drag and dropping a file named [something].[andmo…
Browse files Browse the repository at this point in the history
…re].[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 <alexkorep@gmail.com>.

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@139386 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
dcheng@chromium.org committed May 29, 2012
1 parent 9ed07f8 commit a8b7972
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,4 @@ Eric Rescorla <ekr@rtfm.com>
Alexandre Abreu <wiss1976@gmail.com>
Erik Sjölund <erik.sjolund@gmail.com>
Simon Arlott <simon.arlott@gmail.com>
Alexey Korepanov <alexkorep@gmail.com>
8 changes: 4 additions & 4 deletions content/browser/web_contents/web_contents_drag_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,20 +234,20 @@ 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, "", "", "", "", ""));
if (file_name.value().size() + extension.size() > kMaxFilenameLength) {
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);
}

Expand Down
6 changes: 3 additions & 3 deletions content/browser/web_contents/web_drag_source_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,19 @@ 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.
if (file_name.empty()) {
// 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
Expand Down

0 comments on commit a8b7972

Please sign in to comment.