summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-01 18:08:22 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-01 18:08:22 +0000
commita33dffb1c6ab617ba2edb92908a497d619e639fd (patch)
tree0c5c141a26a2990a5513295beab419650bf3c175
parent9a968be67e07764043dddc9b1451a5c6c849dd25 (diff)
downloadchromium_src-a33dffb1c6ab617ba2edb92908a497d619e639fd.zip
chromium_src-a33dffb1c6ab617ba2edb92908a497d619e639fd.tar.gz
chromium_src-a33dffb1c6ab617ba2edb92908a497d619e639fd.tar.bz2
GTK: Parse NETSCAPE_URL types in drags to the bookmark bar.
This allows us to keep the original Firefox title of the bookmark. BUG=34375 TEST=Drag a bookmark from the Firefox bookmark bar to the Chrome bookmark bar. It should maintain the title instead of turning to the filename/url. Review URL: http://codereview.chromium.org/5292013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67872 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--app/gtk_dnd_util.cc23
-rw-r--r--app/gtk_dnd_util.h5
-rw-r--r--chrome/browser/gtk/bookmark_bar_gtk.cc7
-rw-r--r--chrome/browser/gtk/bookmark_utils_gtk.cc11
-rw-r--r--chrome/browser/gtk/bookmark_utils_gtk.h7
5 files changed, 53 insertions, 0 deletions
diff --git a/app/gtk_dnd_util.cc b/app/gtk_dnd_util.cc
index 92797a6..5df8151 100644
--- a/app/gtk_dnd_util.cc
+++ b/app/gtk_dnd_util.cc
@@ -237,4 +237,27 @@ bool ExtractURIList(GtkSelectionData* selection_data, std::vector<GURL>* urls) {
return true;
}
+bool ExtractNetscapeURL(GtkSelectionData* selection_data,
+ GURL* url,
+ string16* title) {
+ if (!selection_data || selection_data->length <= 0)
+ return false;
+
+ // Find the first '\n' in the data. It is the separator between the url and
+ // the title.
+ std::string data(reinterpret_cast<char*>(selection_data->data),
+ selection_data->length);
+ std::string::size_type newline = data.find('\n');
+ if (newline == std::string::npos)
+ return false;
+
+ GURL gurl(data.substr(0, newline));
+ if (!gurl.is_valid())
+ return false;
+
+ *url = gurl;
+ *title = UTF8ToUTF16(data.substr(newline + 1));
+ return true;
+}
+
} // namespace gtk_dnd_util
diff --git a/app/gtk_dnd_util.h b/app/gtk_dnd_util.h
index 06acb0f..2e6c275 100644
--- a/app/gtk_dnd_util.h
+++ b/app/gtk_dnd_util.h
@@ -78,6 +78,11 @@ bool ExtractNamedURL(GtkSelectionData* selection_data,
bool ExtractURIList(GtkSelectionData* selection_data,
std::vector<GURL>* urls);
+// Extracts a Netscape URL (url\ntitle) from |selection_data|.
+bool ExtractNetscapeURL(GtkSelectionData* selection_data,
+ GURL* url,
+ string16* title);
+
} // namespace gtk_dnd_util
#endif // APP_GTK_DND_UTIL_H_
diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc
index 362dbd6..1f6a59e 100644
--- a/chrome/browser/gtk/bookmark_bar_gtk.cc
+++ b/chrome/browser/gtk/bookmark_bar_gtk.cc
@@ -86,6 +86,7 @@ const double kTopBorderColor[] =
const int kDestTargetList[] = { gtk_dnd_util::CHROME_BOOKMARK_ITEM,
gtk_dnd_util::CHROME_NAMED_URL,
gtk_dnd_util::TEXT_URI_LIST,
+ gtk_dnd_util::NETSCAPE_URL,
gtk_dnd_util::TEXT_PLAIN, -1 };
// Acceptable drag actions for the bookmark bar drag destinations.
@@ -1271,6 +1272,12 @@ void BookmarkBarGtk::OnDragReceived(GtkWidget* widget,
break;
}
+ case gtk_dnd_util::NETSCAPE_URL: {
+ dnd_success = bookmark_utils::CreateNewBookmarkFromNetscapeURL(
+ selection_data, model_, dest_node, index);
+ break;
+ }
+
case gtk_dnd_util::TEXT_PLAIN: {
guchar* text = gtk_selection_data_get_text(selection_data);
if (!text)
diff --git a/chrome/browser/gtk/bookmark_utils_gtk.cc b/chrome/browser/gtk/bookmark_utils_gtk.cc
index fa7505c..baf0430 100644
--- a/chrome/browser/gtk/bookmark_utils_gtk.cc
+++ b/chrome/browser/gtk/bookmark_utils_gtk.cc
@@ -427,4 +427,15 @@ bool CreateNewBookmarksFromURIList(GtkSelectionData* selection_data,
return true;
}
+bool CreateNewBookmarkFromNetscapeURL(GtkSelectionData* selection_data,
+ BookmarkModel* model, const BookmarkNode* parent, int idx) {
+ GURL url;
+ string16 title;
+ if (!gtk_dnd_util::ExtractNetscapeURL(selection_data, &url, &title))
+ return false;
+
+ model->AddURL(parent, idx, title, url);
+ return true;
+}
+
} // namespace bookmark_utils
diff --git a/chrome/browser/gtk/bookmark_utils_gtk.h b/chrome/browser/gtk/bookmark_utils_gtk.h
index 0e666c7..1ebc627 100644
--- a/chrome/browser/gtk/bookmark_utils_gtk.h
+++ b/chrome/browser/gtk/bookmark_utils_gtk.h
@@ -98,6 +98,13 @@ bool CreateNewBookmarksFromURIList(
const BookmarkNode* parent,
int idx);
+// Add the "url\ntitle" combination into the model at the given position.
+bool CreateNewBookmarkFromNetscapeURL(
+ GtkSelectionData* selection_data,
+ BookmarkModel* model,
+ const BookmarkNode* parent,
+ int idx);
+
} // namespace bookmark_utils
#endif // CHROME_BROWSER_GTK_BOOKMARK_UTILS_GTK_H_