OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 GetAtomForTarget(ui::CHROME_NAMED_URL), | 185 GetAtomForTarget(ui::CHROME_NAMED_URL), |
186 kBitsPerByte, | 186 kBitsPerByte, |
187 reinterpret_cast<const guchar*>(pickle.data()), | 187 reinterpret_cast<const guchar*>(pickle.data()), |
188 pickle.size()); | 188 pickle.size()); |
189 break; | 189 break; |
190 } | 190 } |
191 case NETSCAPE_URL: { | 191 case NETSCAPE_URL: { |
192 // _NETSCAPE_URL format is URL + \n + title. | 192 // _NETSCAPE_URL format is URL + \n + title. |
193 std::string utf8_text = url.spec() + "\n" + UTF16ToUTF8(title); | 193 std::string utf8_text = url.spec() + "\n" + UTF16ToUTF8(title); |
194 gtk_selection_data_set(selection_data, | 194 gtk_selection_data_set(selection_data, |
195 gtk_selection_data_get_target(selection_data), | 195 selection_data->target, |
196 kBitsPerByte, | 196 kBitsPerByte, |
197 reinterpret_cast<const guchar*>(utf8_text.c_str()), | 197 reinterpret_cast<const guchar*>(utf8_text.c_str()), |
198 utf8_text.length()); | 198 utf8_text.length()); |
199 break; | 199 break; |
200 } | 200 } |
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 string16* title) { |
212 if (!selection_data || gtk_selection_data_get_length(selection_data) <= 0) | 212 if (!selection_data || selection_data->length <= 0) |
213 return false; | 213 return false; |
214 | 214 |
215 Pickle data( | 215 Pickle data(reinterpret_cast<char*>(selection_data->data), |
216 reinterpret_cast<const char*>( | 216 selection_data->length); |
217 gtk_selection_data_get_data(selection_data)), | |
218 gtk_selection_data_get_length(selection_data)); | |
219 void* iter = NULL; | 217 void* iter = NULL; |
220 std::string title_utf8, url_utf8; | 218 std::string title_utf8, url_utf8; |
221 if (!data.ReadString(&iter, &title_utf8) || | 219 if (!data.ReadString(&iter, &title_utf8) || |
222 !data.ReadString(&iter, &url_utf8)) { | 220 !data.ReadString(&iter, &url_utf8)) { |
223 return false; | 221 return false; |
224 } | 222 } |
225 | 223 |
226 GURL gurl(url_utf8); | 224 GURL gurl(url_utf8); |
227 if (!gurl.is_valid()) | 225 if (!gurl.is_valid()) |
228 return false; | 226 return false; |
(...skipping 14 matching lines...) Expand all Loading... |
243 urls->push_back(url); | 241 urls->push_back(url); |
244 } | 242 } |
245 | 243 |
246 g_strfreev(uris); | 244 g_strfreev(uris); |
247 return true; | 245 return true; |
248 } | 246 } |
249 | 247 |
250 bool ExtractNetscapeURL(GtkSelectionData* selection_data, | 248 bool ExtractNetscapeURL(GtkSelectionData* selection_data, |
251 GURL* url, | 249 GURL* url, |
252 string16* title) { | 250 string16* title) { |
253 if (!selection_data || gtk_selection_data_get_length(selection_data) <= 0) | 251 if (!selection_data || selection_data->length <= 0) |
254 return false; | 252 return false; |
255 | 253 |
256 // Find the first '\n' in the data. It is the separator between the url and | 254 // Find the first '\n' in the data. It is the separator between the url and |
257 // the title. | 255 // the title. |
258 std::string data( | 256 std::string data(reinterpret_cast<char*>(selection_data->data), |
259 reinterpret_cast<const char*>( | 257 selection_data->length); |
260 gtk_selection_data_get_data(selection_data)), | |
261 gtk_selection_data_get_length(selection_data)); | |
262 std::string::size_type newline = data.find('\n'); | 258 std::string::size_type newline = data.find('\n'); |
263 if (newline == std::string::npos) | 259 if (newline == std::string::npos) |
264 return false; | 260 return false; |
265 | 261 |
266 GURL gurl(data.substr(0, newline)); | 262 GURL gurl(data.substr(0, newline)); |
267 if (!gurl.is_valid()) | 263 if (!gurl.is_valid()) |
268 return false; | 264 return false; |
269 | 265 |
270 *url = gurl; | 266 *url = gurl; |
271 *title = UTF8ToUTF16(data.substr(newline + 1)); | 267 *title = UTF8ToUTF16(data.substr(newline + 1)); |
272 return true; | 268 return true; |
273 } | 269 } |
274 | 270 |
275 } // namespace ui | 271 } // namespace ui |
OLD | NEW |