| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/gtk/bookmark_utils_gtk.h" | 5 #include "chrome/browser/gtk/bookmark_utils_gtk.h" |
| 6 | 6 |
| 7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "base/gfx/gtk_util.h" | 8 #include "base/gfx/gtk_util.h" |
| 9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "chrome/browser/bookmarks/bookmark_drag_data.h" | 11 #include "chrome/browser/bookmarks/bookmark_drag_data.h" |
| 12 #include "chrome/browser/bookmarks/bookmark_model.h" | 12 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 13 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 13 #include "chrome/browser/gtk/gtk_chrome_button.h" | 14 #include "chrome/browser/gtk/gtk_chrome_button.h" |
| 14 #include "chrome/browser/gtk/gtk_dnd_util.h" | 15 #include "chrome/browser/gtk/gtk_dnd_util.h" |
| 15 #include "chrome/browser/gtk/gtk_theme_provider.h" | 16 #include "chrome/browser/gtk/gtk_theme_provider.h" |
| 16 #include "chrome/browser/profile.h" | 17 #include "chrome/browser/profile.h" |
| 17 #include "grit/app_resources.h" | 18 #include "grit/app_resources.h" |
| 18 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 19 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 static_cast<const guchar*>(pickle.data()), | 203 static_cast<const guchar*>(pickle.data()), |
| 203 pickle.size()); | 204 pickle.size()); |
| 204 break; | 205 break; |
| 205 } | 206 } |
| 206 case GtkDndUtil::TEXT_URI_LIST: { | 207 case GtkDndUtil::TEXT_URI_LIST: { |
| 207 gchar** uris = reinterpret_cast<gchar**>(malloc(sizeof(gchar*) * | 208 gchar** uris = reinterpret_cast<gchar**>(malloc(sizeof(gchar*) * |
| 208 (nodes.size() + 1))); | 209 (nodes.size() + 1))); |
| 209 for (size_t i = 0; i < nodes.size(); ++i) { | 210 for (size_t i = 0; i < nodes.size(); ++i) { |
| 210 // If the node is a folder, this will be empty. TODO(estade): figure out | 211 // If the node is a folder, this will be empty. TODO(estade): figure out |
| 211 // if there are any ramifications to passing an empty URI. After a | 212 // if there are any ramifications to passing an empty URI. After a |
| 212 // lttle testing, it seems fine. | 213 // little testing, it seems fine. |
| 213 const GURL& url = nodes[i]->GetURL(); | 214 const GURL& url = nodes[i]->GetURL(); |
| 214 // This const cast should be safe as gtk_selection_data_set_uris() | 215 // This const cast should be safe as gtk_selection_data_set_uris() |
| 215 // makes copies. | 216 // makes copies. |
| 216 uris[i] = const_cast<gchar*>(url.spec().c_str()); | 217 uris[i] = const_cast<gchar*>(url.spec().c_str()); |
| 217 } | 218 } |
| 218 uris[nodes.size()] = NULL; | 219 uris[nodes.size()] = NULL; |
| 219 | 220 |
| 220 gtk_selection_data_set_uris(selection_data, uris); | 221 gtk_selection_data_set_uris(selection_data, uris); |
| 221 free(uris); | 222 free(uris); |
| 222 break; | 223 break; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 } | 262 } |
| 262 | 263 |
| 263 bool CreateNewBookmarkFromNamedUrl(GtkSelectionData* selection_data, | 264 bool CreateNewBookmarkFromNamedUrl(GtkSelectionData* selection_data, |
| 264 BookmarkModel* model, const BookmarkNode* parent, int idx) { | 265 BookmarkModel* model, const BookmarkNode* parent, int idx) { |
| 265 Pickle data(reinterpret_cast<char*>(selection_data->data), | 266 Pickle data(reinterpret_cast<char*>(selection_data->data), |
| 266 selection_data->length); | 267 selection_data->length); |
| 267 void* iter = NULL; | 268 void* iter = NULL; |
| 268 std::string title_utf8, url_utf8; | 269 std::string title_utf8, url_utf8; |
| 269 bool rv = data.ReadString(&iter, &title_utf8); | 270 bool rv = data.ReadString(&iter, &title_utf8); |
| 270 rv = rv && data.ReadString(&iter, &url_utf8); | 271 rv = rv && data.ReadString(&iter, &url_utf8); |
| 271 if (rv) | 272 if (rv) { |
| 272 model->AddURL(parent, idx, UTF8ToWide(title_utf8), GURL(url_utf8)); | 273 GURL url(url_utf8); |
| 274 if (title_utf8.empty()) |
| 275 title_utf8 = GetNameForURL(url); |
| 276 model->AddURL(parent, idx, UTF8ToWide(title_utf8), url); |
| 277 } |
| 273 return rv; | 278 return rv; |
| 274 } | 279 } |
| 275 | 280 |
| 281 bool CreateNewBookmarksFromURIList(GtkSelectionData* selection_data, |
| 282 BookmarkModel* model, const BookmarkNode* parent, int idx) { |
| 283 gchar** uris = gtk_selection_data_get_uris(selection_data); |
| 284 if (!uris) { |
| 285 NOTREACHED(); |
| 286 return false; |
| 287 } |
| 288 |
| 289 for (size_t i = 0; uris[i] != NULL; ++i) { |
| 290 GURL url(uris[i]); |
| 291 std::string title = GetNameForURL(url); |
| 292 model->AddURL(parent, idx++, UTF8ToWide(title), url); |
| 293 } |
| 294 |
| 295 g_strfreev(uris); |
| 296 return true; |
| 297 } |
| 298 |
| 276 } // namespace bookmark_utils | 299 } // namespace bookmark_utils |
| OLD | NEW |