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 "content/browser/web_contents/web_drag_dest_gtk.h" | 5 #include "content/browser/web_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/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 is_drop_target_ = false; | 114 is_drop_target_ = false; |
115 | 115 |
116 if (delegate()) | 116 if (delegate()) |
117 delegate()->DragInitialize(web_contents_); | 117 delegate()->DragInitialize(web_contents_); |
118 | 118 |
119 // text/plain must come before text/uri-list. This is a hack that works in | 119 // text/plain must come before text/uri-list. This is a hack that works in |
120 // conjunction with OnDragDataReceived. Since some file managers populate | 120 // conjunction with OnDragDataReceived. Since some file managers populate |
121 // text/plain with file URLs when dragging files, we want to handle | 121 // text/plain with file URLs when dragging files, we want to handle |
122 // text/uri-list after text/plain so that the plain text can be cleared if | 122 // text/uri-list after text/plain so that the plain text can be cleared if |
123 // it's a file drag. | 123 // it's a file drag. |
| 124 // Similarly, renderer taint must occur before anything else so we can |
| 125 // ignore potentially forged filenames when handling text/uri-list. |
124 static int supported_targets[] = { | 126 static int supported_targets[] = { |
| 127 ui::RENDERER_TAINT, |
125 ui::TEXT_PLAIN, | 128 ui::TEXT_PLAIN, |
126 ui::TEXT_URI_LIST, | 129 ui::TEXT_URI_LIST, |
127 ui::TEXT_HTML, | 130 ui::TEXT_HTML, |
128 ui::NETSCAPE_URL, | 131 ui::NETSCAPE_URL, |
129 ui::CHROME_NAMED_URL, | 132 ui::CHROME_NAMED_URL, |
130 // TODO(estade): support image drags? | 133 // TODO(estade): support image drags? |
131 ui::CUSTOM_DATA, | 134 ui::CUSTOM_DATA, |
132 }; | 135 }; |
133 | 136 |
134 // Add the delegate's requested target if applicable. Need to do this here | 137 // Add the delegate's requested target if applicable. Need to do this here |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 178 |
176 data_requests_--; | 179 data_requests_--; |
177 | 180 |
178 // Decode the data. | 181 // Decode the data. |
179 gint data_length = gtk_selection_data_get_length(data); | 182 gint data_length = gtk_selection_data_get_length(data); |
180 const guchar* raw_data = gtk_selection_data_get_data(data); | 183 const guchar* raw_data = gtk_selection_data_get_data(data); |
181 GdkAtom target = gtk_selection_data_get_target(data); | 184 GdkAtom target = gtk_selection_data_get_target(data); |
182 if (raw_data && data_length > 0) { | 185 if (raw_data && data_length > 0) { |
183 // If the source can't provide us with valid data for a requested target, | 186 // If the source can't provide us with valid data for a requested target, |
184 // raw_data will be NULL. | 187 // raw_data will be NULL. |
185 if (target == ui::GetAtomForTarget(ui::TEXT_PLAIN)) { | 188 if (target == ui::GetAtomForTarget(ui::RENDERER_TAINT)) { |
| 189 drop_data_->did_originate_from_renderer = true; |
| 190 } else if (target == ui::GetAtomForTarget(ui::TEXT_PLAIN)) { |
186 guchar* text = gtk_selection_data_get_text(data); | 191 guchar* text = gtk_selection_data_get_text(data); |
187 if (text) { | 192 if (text) { |
188 drop_data_->text = base::NullableString16( | 193 drop_data_->text = base::NullableString16( |
189 base::UTF8ToUTF16(std::string(reinterpret_cast<const char*>(text))), | 194 base::UTF8ToUTF16(std::string(reinterpret_cast<const char*>(text))), |
190 false); | 195 false); |
191 g_free(text); | 196 g_free(text); |
192 } | 197 } |
193 } else if (target == ui::GetAtomForTarget(ui::TEXT_URI_LIST)) { | 198 } else if (target == ui::GetAtomForTarget(ui::TEXT_URI_LIST)) { |
194 gchar** uris = gtk_selection_data_get_uris(data); | 199 gchar** uris = gtk_selection_data_get_uris(data); |
195 if (uris) { | 200 if (uris) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 gtk_drag_finish(context, is_drop_target_, FALSE, time); | 337 gtk_drag_finish(context, is_drop_target_, FALSE, time); |
333 | 338 |
334 return TRUE; | 339 return TRUE; |
335 } | 340 } |
336 | 341 |
337 RenderViewHostImpl* WebDragDestGtk::GetRenderViewHost() const { | 342 RenderViewHostImpl* WebDragDestGtk::GetRenderViewHost() const { |
338 return static_cast<RenderViewHostImpl*>(web_contents_->GetRenderViewHost()); | 343 return static_cast<RenderViewHostImpl*>(web_contents_->GetRenderViewHost()); |
339 } | 344 } |
340 | 345 |
341 } // namespace content | 346 } // namespace content |
OLD | NEW |