Chromium Code Reviews| Index: content/browser/web_contents/web_contents_view_aura.cc |
| diff --git a/content/browser/web_contents/web_contents_view_aura.cc b/content/browser/web_contents/web_contents_view_aura.cc |
| index fc7c928c41e4c1df4c184480c8114ea446680663..12cd2e7e2e976b58d03056f39cb65a6e0cfbfb81 100644 |
| --- a/content/browser/web_contents/web_contents_view_aura.cc |
| +++ b/content/browser/web_contents/web_contents_view_aura.cc |
| @@ -35,6 +35,7 @@ |
| #include "content/public/browser/web_drag_dest_delegate.h" |
| #include "content/public/common/content_switches.h" |
| #include "content/public/common/drop_data.h" |
| +#include "net/base/net_util.h" |
| #include "third_party/WebKit/public/web/WebInputEvent.h" |
| #include "ui/aura/client/aura_constants.h" |
| #include "ui/aura/client/drag_drop_client.h" |
| @@ -235,9 +236,35 @@ class WebDragSourceAura : public base::MessageLoopForUI::Observer, |
| DISALLOW_COPY_AND_ASSIGN(WebDragSourceAura); |
| }; |
| +void PrepareDragForFileContents(const DropData& drop_data, |
|
sky
2013/09/05 15:42:02
Add a description.
|
| + ui::OSExchangeData::Provider* provider) { |
| + static const int kMaxFilenameLength = 255; // FAT and NTFS |
|
sky
2013/09/05 15:42:02
Isn't this win specific? Also, isn't there an OS c
|
| + base::FilePath file_name(drop_data.file_description_filename); |
| + |
| + // 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.BaseName().RemoveExtension().empty()) { |
| + const string16 extension = file_name.Extension(); |
| + // Retrieve the name from the URL. |
| + file_name = base::FilePath( |
| + net::GetSuggestedFilename(drop_data.url, "", "", "", "", "")); |
| + if (file_name.value().size() + extension.size() > kMaxFilenameLength) { |
| + file_name = base::FilePath(file_name.value().substr( |
| + 0, kMaxFilenameLength - extension.size())); |
|
sky
2013/09/05 15:42:02
What if extension.size() > kMaxFilenameLength?
|
| + } |
| + file_name = file_name.ReplaceExtension(extension); |
| + } |
| + provider->SetFileContents(file_name, drop_data.file_contents); |
| +} |
| + |
| // Utility to fill a ui::OSExchangeDataProvider object from DropData. |
| void PrepareDragData(const DropData& drop_data, |
| ui::OSExchangeData::Provider* provider) { |
| + // We set the file contents before the URL because the URL also sets file |
| + // contents (to a .URL shortcut). We want to prefer file content data over |
| + // a shortcut so we add it first. |
| + if (!drop_data.file_contents.empty()) |
| + PrepareDragForFileContents(drop_data, provider); |
| if (!drop_data.text.string().empty()) |
| provider->SetString(drop_data.text.string()); |
| if (drop_data.url.is_valid()) |