OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/base/dragdrop/gtk_dnd_util.h" | 5 #include "ui/base/dragdrop/gtk_dnd_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 for (size_t i = 0; target_codes[i] != -1; ++i) { | 147 for (size_t i = 0; target_codes[i] != -1; ++i) { |
148 AddTargetToList(targets, target_codes[i]); | 148 AddTargetToList(targets, target_codes[i]); |
149 } | 149 } |
150 | 150 |
151 gtk_drag_dest_set_target_list(dest, targets); | 151 gtk_drag_dest_set_target_list(dest, targets); |
152 gtk_target_list_unref(targets); | 152 gtk_target_list_unref(targets); |
153 } | 153 } |
154 | 154 |
155 void WriteURLWithName(GtkSelectionData* selection_data, | 155 void WriteURLWithName(GtkSelectionData* selection_data, |
156 const GURL& url, | 156 const GURL& url, |
157 string16 title, | 157 base::string16 title, |
158 int type) { | 158 int type) { |
159 if (title.empty()) { | 159 if (title.empty()) { |
160 // We prefer to not have empty titles. Set it to the filename extracted | 160 // We prefer to not have empty titles. Set it to the filename extracted |
161 // from the URL. | 161 // from the URL. |
162 title = UTF8ToUTF16(url.ExtractFileName()); | 162 title = UTF8ToUTF16(url.ExtractFileName()); |
163 } | 163 } |
164 | 164 |
165 switch (type) { | 165 switch (type) { |
166 case TEXT_PLAIN: { | 166 case TEXT_PLAIN: { |
167 gtk_selection_data_set_text(selection_data, url.spec().c_str(), | 167 gtk_selection_data_set_text(selection_data, url.spec().c_str(), |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 | 201 |
202 default: { | 202 default: { |
203 NOTREACHED(); | 203 NOTREACHED(); |
204 break; | 204 break; |
205 } | 205 } |
206 } | 206 } |
207 } | 207 } |
208 | 208 |
209 bool ExtractNamedURL(GtkSelectionData* selection_data, | 209 bool ExtractNamedURL(GtkSelectionData* selection_data, |
210 GURL* url, | 210 GURL* url, |
211 string16* title) { | 211 base::string16* title) { |
212 if (!selection_data || gtk_selection_data_get_length(selection_data) <= 0) | 212 if (!selection_data || gtk_selection_data_get_length(selection_data) <= 0) |
213 return false; | 213 return false; |
214 | 214 |
215 Pickle data( | 215 Pickle data( |
216 reinterpret_cast<const char*>( | 216 reinterpret_cast<const char*>( |
217 gtk_selection_data_get_data(selection_data)), | 217 gtk_selection_data_get_data(selection_data)), |
218 gtk_selection_data_get_length(selection_data)); | 218 gtk_selection_data_get_length(selection_data)); |
219 PickleIterator iter(data); | 219 PickleIterator iter(data); |
220 std::string title_utf8, url_utf8; | 220 std::string title_utf8, url_utf8; |
221 if (!data.ReadString(&iter, &title_utf8) || | 221 if (!data.ReadString(&iter, &title_utf8) || |
(...skipping 20 matching lines...) Expand all Loading... |
242 if (url.is_valid()) | 242 if (url.is_valid()) |
243 urls->push_back(url); | 243 urls->push_back(url); |
244 } | 244 } |
245 | 245 |
246 g_strfreev(uris); | 246 g_strfreev(uris); |
247 return true; | 247 return true; |
248 } | 248 } |
249 | 249 |
250 bool ExtractNetscapeURL(GtkSelectionData* selection_data, | 250 bool ExtractNetscapeURL(GtkSelectionData* selection_data, |
251 GURL* url, | 251 GURL* url, |
252 string16* title) { | 252 base::string16* title) { |
253 if (!selection_data || gtk_selection_data_get_length(selection_data) <= 0) | 253 if (!selection_data || gtk_selection_data_get_length(selection_data) <= 0) |
254 return false; | 254 return false; |
255 | 255 |
256 // Find the first '\n' in the data. It is the separator between the url and | 256 // Find the first '\n' in the data. It is the separator between the url and |
257 // the title. | 257 // the title. |
258 std::string data( | 258 std::string data( |
259 reinterpret_cast<const char*>( | 259 reinterpret_cast<const char*>( |
260 gtk_selection_data_get_data(selection_data)), | 260 gtk_selection_data_get_data(selection_data)), |
261 gtk_selection_data_get_length(selection_data)); | 261 gtk_selection_data_get_length(selection_data)); |
262 std::string::size_type newline = data.find('\n'); | 262 std::string::size_type newline = data.find('\n'); |
263 if (newline == std::string::npos) | 263 if (newline == std::string::npos) |
264 return false; | 264 return false; |
265 | 265 |
266 GURL gurl(data.substr(0, newline)); | 266 GURL gurl(data.substr(0, newline)); |
267 if (!gurl.is_valid()) | 267 if (!gurl.is_valid()) |
268 return false; | 268 return false; |
269 | 269 |
270 *url = gurl; | 270 *url = gurl; |
271 *title = UTF8ToUTF16(data.substr(newline + 1)); | 271 *title = UTF8ToUTF16(data.substr(newline + 1)); |
272 return true; | 272 return true; |
273 } | 273 } |
274 | 274 |
275 } // namespace ui | 275 } // namespace ui |
OLD | NEW |