summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorpaulg@google.com <paulg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-29 01:53:05 +0000
committerpaulg@google.com <paulg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-29 01:53:05 +0000
commita6c712d9b9f2459273ad7616e03ee5f823d539ca (patch)
tree23e12a6a9613eb38ce7ccf4461084edef6b5e588 /chrome/browser
parent5a6e27ee83d4cc43959f10145b66a1115cfe6e96 (diff)
downloadchromium_src-a6c712d9b9f2459273ad7616e03ee5f823d539ca.zip
chromium_src-a6c712d9b9f2459273ad7616e03ee5f823d539ca.tar.gz
chromium_src-a6c712d9b9f2459273ad7616e03ee5f823d539ca.tar.bz2
Generate a proper file name when dragging an image from a
web page to the desktop. We receive information about the image from WebKit in the render which includes the image URL, MIME type and a guess as to what the file name is. If the filename is empty, we synthesize a file name based on the URL. In all cases, we set the file extension to the MIME type that was detected by WebKit. This change is the Chromium portion of image dragging. The WebKit portion has been committed as: http://trac.webkit.org/changeset/40294 BUG=6481 (http://crbug.com/6481) Review URL: http://codereview.chromium.org/19417 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8854 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/tab_contents/web_contents_view_win.cc14
1 files changed, 12 insertions, 2 deletions
diff --git a/chrome/browser/tab_contents/web_contents_view_win.cc b/chrome/browser/tab_contents/web_contents_view_win.cc
index 9f6ee1a..f2cee8b 100644
--- a/chrome/browser/tab_contents/web_contents_view_win.cc
+++ b/chrome/browser/tab_contents/web_contents_view_win.cc
@@ -24,6 +24,7 @@
#include "chrome/browser/views/sad_tab_view.h"
#include "chrome/common/gfx/chrome_canvas.h"
#include "chrome/common/os_exchange_data.h"
+#include "net/base/net_util.h"
#include "webkit/glue/plugins/webplugin_delegate_impl.h"
namespace {
@@ -96,8 +97,17 @@ void WebContentsViewWin::StartDragging(const WebDropData& drop_data) {
// 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()) {
- data->SetFileContents(drop_data.file_description_filename,
- drop_data.file_contents);
+ // Images without ALT text will only have a file extension so we need to
+ // synthesize one from the provided extension and URL.
+ FilePath file_name(drop_data.file_description_filename);
+ file_name = file_name.BaseName().RemoveExtension();
+ if (file_name.value().empty()) {
+ // Retrieve the name from the URL.
+ file_name = FilePath::FromWStringHack(
+ net::GetSuggestedFilename(drop_data.url, L"", L""));
+ }
+ file_name = file_name.ReplaceExtension(drop_data.file_extension);
+ data->SetFileContents(file_name.value(), drop_data.file_contents);
}
if (!drop_data.text_html.empty())
data->SetHtml(drop_data.text_html, drop_data.html_base_url);