summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-22 01:34:38 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-22 01:34:38 +0000
commit5870da810ab64cbc2510172aef3727333397a671 (patch)
tree1e1724c34dca7efc9f09cc352c58d6fd1a9aef22
parent64ec639d3feceeb6735831ed8eff34ebb07a8d1d (diff)
downloadchromium_src-5870da810ab64cbc2510172aef3727333397a671.zip
chromium_src-5870da810ab64cbc2510172aef3727333397a671.tar.gz
chromium_src-5870da810ab64cbc2510172aef3727333397a671.tar.bz2
When a web contents drag has a URL but no title, make up a title for it.
BUG=17393 TEST=drag nntp thumbnail to bookmark bar Review URL: http://codereview.chromium.org/155900 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21255 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/tab_contents/tab_contents_view_gtk.cc44
1 files changed, 30 insertions, 14 deletions
diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/tab_contents/tab_contents_view_gtk.cc
index bcb7d9c..5368233 100644
--- a/chrome/browser/tab_contents/tab_contents_view_gtk.cc
+++ b/chrome/browser/tab_contents/tab_contents_view_gtk.cc
@@ -8,6 +8,7 @@
#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
+#include "app/l10n_util.h"
#include "base/mime_util.h"
#include "base/gfx/point.h"
#include "base/gfx/rect.h"
@@ -33,11 +34,13 @@
#include "chrome/common/notification_service.h"
#include "chrome/common/notification_source.h"
#include "chrome/common/notification_type.h"
+#include "grit/app_strings.h"
+#include "net/base/net_util.h"
#include "webkit/glue/webdropdata.h"
namespace {
-// TODO(erg): I have no idea how to progromatically figure out how wide the
+// TODO(erg): I have no idea how to programatically figure out how wide the
// vertical scrollbar is. Hack it with a hardcoded value for now.
const int kScrollbarWidthHack = 25;
@@ -786,54 +789,67 @@ void TabContentsViewGtk::OnDragDataGet(
GdkDragContext* context, GtkSelectionData* selection_data,
guint target_type, guint time, TabContentsViewGtk* view) {
const int bits_per_byte = 8;
- // We must make these initializations here or gcc complains about jumping past
- // it in the switch statement.
- std::string utf8_text;
- Pickle pickle;
switch (target_type) {
- case GtkDndUtil::TEXT_PLAIN:
- utf8_text = UTF16ToUTF8(view->drop_data_->plain_text);
+ case GtkDndUtil::TEXT_PLAIN: {
+ std::string utf8_text = UTF16ToUTF8(view->drop_data_->plain_text);
gtk_selection_data_set_text(selection_data, utf8_text.c_str(),
utf8_text.length());
break;
+ }
- case GtkDndUtil::TEXT_URI_LIST:
+ case GtkDndUtil::TEXT_URI_LIST: {
gchar* uri_array[2];
uri_array[0] = strdup(view->drop_data_->url.spec().c_str());
uri_array[1] = NULL;
gtk_selection_data_set_uris(selection_data, uri_array);
free(uri_array[0]);
break;
+ }
- case GtkDndUtil::TEXT_HTML:
+ case GtkDndUtil::TEXT_HTML: {
// TODO(estade): change relative links to be absolute using
// |html_base_url|.
- utf8_text = UTF16ToUTF8(view->drop_data_->text_html);
+ std::string utf8_text = UTF16ToUTF8(view->drop_data_->text_html);
gtk_selection_data_set(selection_data,
GtkDndUtil::GetAtomForTarget(GtkDndUtil::TEXT_HTML),
bits_per_byte,
reinterpret_cast<const guchar*>(utf8_text.c_str()),
utf8_text.length());
break;
+ }
- case GtkDndUtil::CHROME_NAMED_URL:
- pickle.WriteString(UTF16ToUTF8(view->drop_data_->url_title));
- pickle.WriteString(view->drop_data_->url.spec());
+ case GtkDndUtil::CHROME_NAMED_URL: {
+ std::string name;
+ const GURL& url = view->drop_data_->url;
+ if (!view->drop_data_->url_title.empty()) {
+ name = UTF16ToUTF8(view->drop_data_->url_title);
+ } else if (url.is_valid()) {
+ name = WideToUTF8(net::GetSuggestedFilename(
+ url, std::string(), std::string(), std::wstring()));
+ } else {
+ // Nothing else can be done, just use a default.
+ name = l10n_util::GetStringUTF8(IDS_APP_UNTITLED_SHORTCUT_FILE_NAME);
+ }
+ Pickle pickle;
+ pickle.WriteString(name);
+ pickle.WriteString(url.spec());
gtk_selection_data_set(selection_data,
GtkDndUtil::GetAtomForTarget(GtkDndUtil::CHROME_NAMED_URL),
bits_per_byte,
reinterpret_cast<const guchar*>(pickle.data()),
pickle.size());
break;
+ }
- case GtkDndUtil::CHROME_WEBDROP_FILE_CONTENTS:
+ case GtkDndUtil::CHROME_WEBDROP_FILE_CONTENTS: {
gtk_selection_data_set(selection_data,
view->drag_file_mime_type_, bits_per_byte,
reinterpret_cast<const guchar*>(
view->drop_data_->file_contents.data()),
view->drop_data_->file_contents.length());
break;
+ }
default:
NOTREACHED();