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

Side by Side Diff: content/browser/tab_contents/web_drag_dest_gtk.cc

Issue 9167002: Revert 116956 - GTK: Seal up GSEALs, focusing on GtkSelectionData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: 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 | Annotate | Revision Log
OLDNEW
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 "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 gint data_length = gtk_selection_data_get_length(data); 146 if (data->data && data->length > 0) {
147 const guchar* raw_data = gtk_selection_data_get_data(data);
148 if (raw_data && data_length > 0) {
149 // If the source can't provide us with valid data for a requested target, 147 // If the source can't provide us with valid data for a requested target,
150 // raw_data will be NULL. 148 // data->data will be NULL.
151 if (data->target == ui::GetAtomForTarget(ui::TEXT_PLAIN)) { 149 if (data->target == ui::GetAtomForTarget(ui::TEXT_PLAIN)) {
152 guchar* text = gtk_selection_data_get_text(data); 150 guchar* text = gtk_selection_data_get_text(data);
153 if (text) { 151 if (text) {
154 drop_data_->plain_text = 152 drop_data_->plain_text =
155 UTF8ToUTF16(std::string(reinterpret_cast<const char*>(text))); 153 UTF8ToUTF16(std::string(reinterpret_cast<char*>(text)));
156 g_free(text); 154 g_free(text);
157 } 155 }
158 } else if (data->target == ui::GetAtomForTarget(ui::TEXT_URI_LIST)) { 156 } else if (data->target == ui::GetAtomForTarget(ui::TEXT_URI_LIST)) {
159 gchar** uris = gtk_selection_data_get_uris(data); 157 gchar** uris = gtk_selection_data_get_uris(data);
160 if (uris) { 158 if (uris) {
161 drop_data_->url = GURL(); 159 drop_data_->url = GURL();
162 for (gchar** uri_iter = uris; *uri_iter; uri_iter++) { 160 for (gchar** uri_iter = uris; *uri_iter; uri_iter++) {
163 // Most file managers populate text/uri-list with file URLs when 161 // Most file managers populate text/uri-list with file URLs when
164 // dragging files. To avoid exposing file system paths to web content, 162 // dragging files. To avoid exposing file system paths to web content,
165 // file URLs are never set as the URL content for the drop. 163 // file URLs are never set as the URL content for the drop.
(...skipping 10 matching lines...) Expand all
176 } else if (!drop_data_->url.is_valid()) { 174 } else if (!drop_data_->url.is_valid()) {
177 // Also set the first non-file URL as the URL content for the drop. 175 // Also set the first non-file URL as the URL content for the drop.
178 drop_data_->url = url; 176 drop_data_->url = url;
179 } 177 }
180 } 178 }
181 g_strfreev(uris); 179 g_strfreev(uris);
182 } 180 }
183 } else if (data->target == ui::GetAtomForTarget(ui::TEXT_HTML)) { 181 } else if (data->target == ui::GetAtomForTarget(ui::TEXT_HTML)) {
184 // TODO(estade): Can the html have a non-UTF8 encoding? 182 // TODO(estade): Can the html have a non-UTF8 encoding?
185 drop_data_->text_html = 183 drop_data_->text_html =
186 UTF8ToUTF16(std::string(reinterpret_cast<const char*>(raw_data), 184 UTF8ToUTF16(std::string(reinterpret_cast<char*>(data->data),
187 data_length)); 185 data->length));
188 // We leave the base URL empty. 186 // We leave the base URL empty.
189 } else if (data->target == ui::GetAtomForTarget(ui::NETSCAPE_URL)) { 187 } else if (data->target == ui::GetAtomForTarget(ui::NETSCAPE_URL)) {
190 std::string netscape_url(reinterpret_cast<const char*>(raw_data), 188 std::string netscape_url(reinterpret_cast<char*>(data->data),
191 data_length); 189 data->length);
192 size_t split = netscape_url.find_first_of('\n'); 190 size_t split = netscape_url.find_first_of('\n');
193 if (split != std::string::npos) { 191 if (split != std::string::npos) {
194 drop_data_->url = GURL(netscape_url.substr(0, split)); 192 drop_data_->url = GURL(netscape_url.substr(0, split));
195 if (split < netscape_url.size() - 1) 193 if (split < netscape_url.size() - 1)
196 drop_data_->url_title = UTF8ToUTF16(netscape_url.substr(split + 1)); 194 drop_data_->url_title = UTF8ToUTF16(netscape_url.substr(split + 1));
197 } 195 }
198 } else if (data->target == ui::GetAtomForTarget(ui::CHROME_NAMED_URL)) { 196 } else if (data->target == ui::GetAtomForTarget(ui::CHROME_NAMED_URL)) {
199 ui::ExtractNamedURL(data, &drop_data_->url, &drop_data_->url_title); 197 ui::ExtractNamedURL(data, &drop_data_->url, &drop_data_->url_title);
200 } else if (data->target == ui::GetAtomForTarget(ui::CUSTOM_DATA)) { 198 } else if (data->target == ui::GetAtomForTarget(ui::CUSTOM_DATA)) {
201 ui::ReadCustomDataIntoMap( 199 ui::ReadCustomDataIntoMap(
202 raw_data, data_length, &drop_data_->custom_data); 200 data->data, data->length, &drop_data_->custom_data);
203 } 201 }
204 } 202 }
205 203
206 // For CHROME_BOOKMARK_ITEM, we have to handle the case where the drag source 204 // For CHROME_BOOKMARK_ITEM, we have to handle the case where the drag source
207 // doesn't have any data available for us. In this case we try to synthesize a 205 // doesn't have any data available for us. In this case we try to synthesize a
208 // URL bookmark. 206 // URL bookmark.
209 // Note that bookmark drag data is encoded in the same format for both 207 // Note that bookmark drag data is encoded in the same format for both
210 // GTK and Views, hence we can share the same logic here. 208 // GTK and Views, hence we can share the same logic here.
211 if (delegate() && data->target == delegate()->GetBookmarkTargetAtom()) { 209 if (delegate() && data->target == delegate()->GetBookmarkTargetAtom()) {
212 if (raw_data && data_length > 0) { 210 if (data->data && data->length > 0) {
213 delegate()->OnReceiveDataFromGtk(data); 211 delegate()->OnReceiveDataFromGtk(data);
214 } else { 212 } else {
215 delegate()->OnReceiveProcessedData(drop_data_->url, 213 delegate()->OnReceiveProcessedData(drop_data_->url,
216 drop_data_->url_title); 214 drop_data_->url_title);
217 } 215 }
218 } 216 }
219 217
220 if (data_requests_ == 0) { 218 if (data_requests_ == 0) {
221 // Tell the renderer about the drag. 219 // Tell the renderer about the drag.
222 // |x| and |y| are seemingly arbitrary at this point. 220 // |x| and |y| are seemingly arbitrary at this point.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 260
263 // The second parameter is just an educated guess as to whether or not the 261 // The second parameter is just an educated guess as to whether or not the
264 // drag succeeded, but at least we will get the drag-end animation right 262 // drag succeeded, but at least we will get the drag-end animation right
265 // sometimes. 263 // sometimes.
266 gtk_drag_finish(context, is_drop_target_, FALSE, time); 264 gtk_drag_finish(context, is_drop_target_, FALSE, time);
267 265
268 return TRUE; 266 return TRUE;
269 } 267 }
270 268
271 } // namespace content 269 } // 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