summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/gtk_dnd_util.cc42
-rw-r--r--app/gtk_dnd_util.h6
2 files changed, 47 insertions, 1 deletions
diff --git a/app/gtk_dnd_util.cc b/app/gtk_dnd_util.cc
index e8ca0af..3e87f32 100644
--- a/app/gtk_dnd_util.cc
+++ b/app/gtk_dnd_util.cc
@@ -9,6 +9,8 @@
#include "base/pickle.h"
#include "googleurl/src/gurl.h"
+static const int kBitsPerByte = 8;
+
// static
GdkAtom GtkDndUtil::GetAtomForTarget(int target) {
switch (target) {
@@ -112,6 +114,44 @@ void GtkDndUtil::AddTargetToList(GtkTargetList* targets, int target_code) {
}
// static
+void GtkDndUtil::WriteURLWithName(GtkSelectionData* selection_data,
+ const GURL& url,
+ const string16& title,
+ int type) {
+ switch (type) {
+ case TEXT_PLAIN: {
+ gtk_selection_data_set_text(selection_data, url.spec().c_str(),
+ url.spec().length());
+ break;
+ }
+ case TEXT_URI_LIST: {
+ gchar* uri_array[2];
+ uri_array[0] = strdup(url.spec().c_str());
+ uri_array[1] = NULL;
+ gtk_selection_data_set_uris(selection_data, uri_array);
+ free(uri_array[0]);
+ break;
+ }
+ case CHROME_NAMED_URL: {
+ Pickle pickle;
+ pickle.WriteString(UTF16ToUTF8(title));
+ pickle.WriteString(url.spec());
+ gtk_selection_data_set(
+ selection_data,
+ GetAtomForTarget(GtkDndUtil::CHROME_NAMED_URL),
+ kBitsPerByte,
+ reinterpret_cast<const guchar*>(pickle.data()),
+ pickle.size());
+ break;
+ }
+ default: {
+ NOTREACHED();
+ break;
+ }
+ }
+}
+
+// static
bool GtkDndUtil::ExtractNamedURL(GtkSelectionData* selection_data,
GURL* url,
string16* title) {
@@ -133,7 +173,7 @@ bool GtkDndUtil::ExtractNamedURL(GtkSelectionData* selection_data,
return true;
}
-// static void
+// static
bool GtkDndUtil::ExtractURIList(GtkSelectionData* selection_data,
std::vector<GURL>* urls) {
gchar** uris = gtk_selection_data_get_uris(selection_data);
diff --git a/app/gtk_dnd_util.h b/app/gtk_dnd_util.h
index 0698d57..7365cec 100644
--- a/app/gtk_dnd_util.h
+++ b/app/gtk_dnd_util.h
@@ -50,6 +50,12 @@ class GtkDndUtil {
// be sorted in preference order and should be terminated with -1.
static void SetDestTargetList(GtkWidget* dest, const int* target_codes);
+ // Write a URL to the selection in the given type.
+ static void WriteURLWithName(GtkSelectionData* selection_data,
+ const GURL& url,
+ const string16& title,
+ int type);
+
// Extracts data of type CHROME_NAMED_URL from |selection_data| into
// |url| and |title|. Returns true if the url/title were safely extracted
// and the url is valid.