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

Side by Side Diff: content/browser/tab_contents/web_drag_dest_gtk.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
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 "content/browser/tab_contents/web_drag_dest_gtk.h" 5 #include "content/browser/tab_contents/web_drag_dest_gtk.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 GtkWidget* sender, GdkDragContext* context, gint x, gint y, 136 GtkWidget* sender, GdkDragContext* context, gint x, gint y,
137 GtkSelectionData* data, guint info, guint time) { 137 GtkSelectionData* data, guint info, guint time) {
138 // We might get the data from an old get_data() request that we no longer 138 // We might get the data from an old get_data() request that we no longer
139 // care about. 139 // care about.
140 if (context != context_) 140 if (context != context_)
141 return; 141 return;
142 142
143 data_requests_--; 143 data_requests_--;
144 144
145 // Decode the data. 145 // Decode the data.
146 if (data->data && data->length > 0) { 146 gint data_length = gtk_selection_data_get_length(data);
147 const guchar* raw_data = gtk_selection_data_get_data(data);
148 if (raw_data && data_length > 0) {
147 // If the source can't provide us with valid data for a requested target, 149 // If the source can't provide us with valid data for a requested target,
148 // data->data will be NULL. 150 // raw_data will be NULL.
149 if (data->target == ui::GetAtomForTarget(ui::TEXT_PLAIN)) { 151 if (data->target == ui::GetAtomForTarget(ui::TEXT_PLAIN)) {
150 guchar* text = gtk_selection_data_get_text(data); 152 guchar* text = gtk_selection_data_get_text(data);
151 if (text) { 153 if (text) {
152 drop_data_->plain_text = 154 drop_data_->plain_text =
153 UTF8ToUTF16(std::string(reinterpret_cast<char*>(text))); 155 UTF8ToUTF16(std::string(reinterpret_cast<const char*>(text)));
154 g_free(text); 156 g_free(text);
155 } 157 }
156 } else if (data->target == ui::GetAtomForTarget(ui::TEXT_URI_LIST)) { 158 } else if (data->target == ui::GetAtomForTarget(ui::TEXT_URI_LIST)) {
157 gchar** uris = gtk_selection_data_get_uris(data); 159 gchar** uris = gtk_selection_data_get_uris(data);
158 if (uris) { 160 if (uris) {
159 drop_data_->url = GURL(); 161 drop_data_->url = GURL();
160 for (gchar** uri_iter = uris; *uri_iter; uri_iter++) { 162 for (gchar** uri_iter = uris; *uri_iter; uri_iter++) {
161 // Most file managers populate text/uri-list with file URLs when 163 // Most file managers populate text/uri-list with file URLs when
162 // dragging files. To avoid exposing file system paths to web content, 164 // dragging files. To avoid exposing file system paths to web content,
163 // file URLs are never set as the URL content for the drop. 165 // file URLs are never set as the URL content for the drop.
(...skipping 10 matching lines...) Expand all
174 } else if (!drop_data_->url.is_valid()) { 176 } else if (!drop_data_->url.is_valid()) {
175 // Also set the first non-file URL as the URL content for the drop. 177 // Also set the first non-file URL as the URL content for the drop.
176 drop_data_->url = url; 178 drop_data_->url = url;
177 } 179 }
178 } 180 }
179 g_strfreev(uris); 181 g_strfreev(uris);
180 } 182 }
181 } else if (data->target == ui::GetAtomForTarget(ui::TEXT_HTML)) { 183 } else if (data->target == ui::GetAtomForTarget(ui::TEXT_HTML)) {
182 // TODO(estade): Can the html have a non-UTF8 encoding? 184 // TODO(estade): Can the html have a non-UTF8 encoding?
183 drop_data_->text_html = 185 drop_data_->text_html =
184 UTF8ToUTF16(std::string(reinterpret_cast<char*>(data->data), 186 UTF8ToUTF16(std::string(reinterpret_cast<const char*>(raw_data),
185 data->length)); 187 data_length));
186 // We leave the base URL empty. 188 // We leave the base URL empty.
187 } else if (data->target == ui::GetAtomForTarget(ui::NETSCAPE_URL)) { 189 } else if (data->target == ui::GetAtomForTarget(ui::NETSCAPE_URL)) {
188 std::string netscape_url(reinterpret_cast<char*>(data->data), 190 std::string netscape_url(reinterpret_cast<const char*>(raw_data),
189 data->length); 191 data_length);
190 size_t split = netscape_url.find_first_of('\n'); 192 size_t split = netscape_url.find_first_of('\n');
191 if (split != std::string::npos) { 193 if (split != std::string::npos) {
192 drop_data_->url = GURL(netscape_url.substr(0, split)); 194 drop_data_->url = GURL(netscape_url.substr(0, split));
193 if (split < netscape_url.size() - 1) 195 if (split < netscape_url.size() - 1)
194 drop_data_->url_title = UTF8ToUTF16(netscape_url.substr(split + 1)); 196 drop_data_->url_title = UTF8ToUTF16(netscape_url.substr(split + 1));
195 } 197 }
196 } else if (data->target == ui::GetAtomForTarget(ui::CHROME_NAMED_URL)) { 198 } else if (data->target == ui::GetAtomForTarget(ui::CHROME_NAMED_URL)) {
197 ui::ExtractNamedURL(data, &drop_data_->url, &drop_data_->url_title); 199 ui::ExtractNamedURL(data, &drop_data_->url, &drop_data_->url_title);
198 } else if (data->target == ui::GetAtomForTarget(ui::CUSTOM_DATA)) { 200 } else if (data->target == ui::GetAtomForTarget(ui::CUSTOM_DATA)) {
199 ui::ReadCustomDataIntoMap( 201 ui::ReadCustomDataIntoMap(
200 data->data, data->length, &drop_data_->custom_data); 202 raw_data, data_length, &drop_data_->custom_data);
201 } 203 }
202 } 204 }
203 205
204 // For CHROME_BOOKMARK_ITEM, we have to handle the case where the drag source 206 // For CHROME_BOOKMARK_ITEM, we have to handle the case where the drag source
205 // doesn't have any data available for us. In this case we try to synthesize a 207 // doesn't have any data available for us. In this case we try to synthesize a
206 // URL bookmark. 208 // URL bookmark.
207 // Note that bookmark drag data is encoded in the same format for both 209 // Note that bookmark drag data is encoded in the same format for both
208 // GTK and Views, hence we can share the same logic here. 210 // GTK and Views, hence we can share the same logic here.
209 if (delegate() && data->target == delegate()->GetBookmarkTargetAtom()) { 211 if (delegate() && data->target == delegate()->GetBookmarkTargetAtom()) {
210 if (data->data && data->length > 0) { 212 if (raw_data && data_length > 0) {
211 delegate()->OnReceiveDataFromGtk(data); 213 delegate()->OnReceiveDataFromGtk(data);
212 } else { 214 } else {
213 delegate()->OnReceiveProcessedData(drop_data_->url, 215 delegate()->OnReceiveProcessedData(drop_data_->url,
214 drop_data_->url_title); 216 drop_data_->url_title);
215 } 217 }
216 } 218 }
217 219
218 if (data_requests_ == 0) { 220 if (data_requests_ == 0) {
219 // Tell the renderer about the drag. 221 // Tell the renderer about the drag.
220 // |x| and |y| are seemingly arbitrary at this point. 222 // |x| and |y| are seemingly arbitrary at this point.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 262
261 // The second parameter is just an educated guess as to whether or not the 263 // The second parameter is just an educated guess as to whether or not the
262 // drag succeeded, but at least we will get the drag-end animation right 264 // drag succeeded, but at least we will get the drag-end animation right
263 // sometimes. 265 // sometimes.
264 gtk_drag_finish(context, is_drop_target_, FALSE, time); 266 gtk_drag_finish(context, is_drop_target_, FALSE, time);
265 267
266 return TRUE; 268 return TRUE;
267 } 269 }
268 270
269 } // namespace content 271 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/gtk_im_context_wrapper.cc ('k') | content/browser/tab_contents/web_drag_source_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698