Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: ui/base/dragdrop/gtk_dnd_util.cc

Issue 9151007: GTK: Seal up GSEALs, focusing on GtkSelectionData. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add gtk_widget_style_attach to make minimal version 2.18 Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/base/clipboard/clipboard_gtk.cc ('k') | ui/base/gtk/focus_store_gtk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 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"
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
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 selection_data->target, 195 gtk_selection_data_get_target(selection_data),
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 || selection_data->length <= 0) 212 if (!selection_data || gtk_selection_data_get_length(selection_data) <= 0)
213 return false; 213 return false;
214 214
215 Pickle data(reinterpret_cast<char*>(selection_data->data), 215 Pickle data(
216 selection_data->length); 216 reinterpret_cast<const char*>(
217 gtk_selection_data_get_data(selection_data)),
218 gtk_selection_data_get_length(selection_data));
217 void* iter = NULL; 219 void* iter = NULL;
218 std::string title_utf8, url_utf8; 220 std::string title_utf8, url_utf8;
219 if (!data.ReadString(&iter, &title_utf8) || 221 if (!data.ReadString(&iter, &title_utf8) ||
220 !data.ReadString(&iter, &url_utf8)) { 222 !data.ReadString(&iter, &url_utf8)) {
221 return false; 223 return false;
222 } 224 }
223 225
224 GURL gurl(url_utf8); 226 GURL gurl(url_utf8);
225 if (!gurl.is_valid()) 227 if (!gurl.is_valid())
226 return false; 228 return false;
(...skipping 14 matching lines...) Expand all
241 urls->push_back(url); 243 urls->push_back(url);
242 } 244 }
243 245
244 g_strfreev(uris); 246 g_strfreev(uris);
245 return true; 247 return true;
246 } 248 }
247 249
248 bool ExtractNetscapeURL(GtkSelectionData* selection_data, 250 bool ExtractNetscapeURL(GtkSelectionData* selection_data,
249 GURL* url, 251 GURL* url,
250 string16* title) { 252 string16* title) {
251 if (!selection_data || selection_data->length <= 0) 253 if (!selection_data || gtk_selection_data_get_length(selection_data) <= 0)
252 return false; 254 return false;
253 255
254 // 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
255 // the title. 257 // the title.
256 std::string data(reinterpret_cast<char*>(selection_data->data), 258 std::string data(
257 selection_data->length); 259 reinterpret_cast<const char*>(
260 gtk_selection_data_get_data(selection_data)),
261 gtk_selection_data_get_length(selection_data));
258 std::string::size_type newline = data.find('\n'); 262 std::string::size_type newline = data.find('\n');
259 if (newline == std::string::npos) 263 if (newline == std::string::npos)
260 return false; 264 return false;
261 265
262 GURL gurl(data.substr(0, newline)); 266 GURL gurl(data.substr(0, newline));
263 if (!gurl.is_valid()) 267 if (!gurl.is_valid())
264 return false; 268 return false;
265 269
266 *url = gurl; 270 *url = gurl;
267 *title = UTF8ToUTF16(data.substr(newline + 1)); 271 *title = UTF8ToUTF16(data.substr(newline + 1));
268 return true; 272 return true;
269 } 273 }
270 274
271 } // namespace ui 275 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/clipboard/clipboard_gtk.cc ('k') | ui/base/gtk/focus_store_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698