| 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/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 // Decode the data. | 169 // Decode the data. |
| 170 gint data_length = gtk_selection_data_get_length(data); | 170 gint data_length = gtk_selection_data_get_length(data); |
| 171 const guchar* raw_data = gtk_selection_data_get_data(data); | 171 const guchar* raw_data = gtk_selection_data_get_data(data); |
| 172 GdkAtom target = gtk_selection_data_get_target(data); | 172 GdkAtom target = gtk_selection_data_get_target(data); |
| 173 if (raw_data && data_length > 0) { | 173 if (raw_data && data_length > 0) { |
| 174 // If the source can't provide us with valid data for a requested target, | 174 // If the source can't provide us with valid data for a requested target, |
| 175 // raw_data will be NULL. | 175 // raw_data will be NULL. |
| 176 if (target == ui::GetAtomForTarget(ui::TEXT_PLAIN)) { | 176 if (target == ui::GetAtomForTarget(ui::TEXT_PLAIN)) { |
| 177 guchar* text = gtk_selection_data_get_text(data); | 177 guchar* text = gtk_selection_data_get_text(data); |
| 178 if (text) { | 178 if (text) { |
| 179 drop_data_->plain_text = | 179 drop_data_->text = NullableString16( |
| 180 UTF8ToUTF16(std::string(reinterpret_cast<const char*>(text))); | 180 UTF8ToUTF16(std::string(reinterpret_cast<const char*>(text))), |
| 181 false); |
| 181 g_free(text); | 182 g_free(text); |
| 182 } | 183 } |
| 183 } else if (target == ui::GetAtomForTarget(ui::TEXT_URI_LIST)) { | 184 } else if (target == ui::GetAtomForTarget(ui::TEXT_URI_LIST)) { |
| 184 gchar** uris = gtk_selection_data_get_uris(data); | 185 gchar** uris = gtk_selection_data_get_uris(data); |
| 185 if (uris) { | 186 if (uris) { |
| 186 drop_data_->url = GURL(); | 187 drop_data_->url = GURL(); |
| 187 for (gchar** uri_iter = uris; *uri_iter; uri_iter++) { | 188 for (gchar** uri_iter = uris; *uri_iter; uri_iter++) { |
| 188 // Most file managers populate text/uri-list with file URLs when | 189 // Most file managers populate text/uri-list with file URLs when |
| 189 // dragging files. To avoid exposing file system paths to web content, | 190 // dragging files. To avoid exposing file system paths to web content, |
| 190 // file URLs are never set as the URL content for the drop. | 191 // file URLs are never set as the URL content for the drop. |
| 191 // TODO(estade): Can the filenames have a non-UTF8 encoding? | 192 // TODO(estade): Can the filenames have a non-UTF8 encoding? |
| 192 GURL url(*uri_iter); | 193 GURL url(*uri_iter); |
| 193 FilePath file_path; | 194 FilePath file_path; |
| 194 if (url.SchemeIs(chrome::kFileScheme) && | 195 if (url.SchemeIs(chrome::kFileScheme) && |
| 195 net::FileURLToFilePath(url, &file_path)) { | 196 net::FileURLToFilePath(url, &file_path)) { |
| 196 drop_data_->filenames.push_back( | 197 drop_data_->filenames.push_back( |
| 197 WebDropData::FileInfo(UTF8ToUTF16(file_path.value()), | 198 WebDropData::FileInfo(UTF8ToUTF16(file_path.value()), |
| 198 string16())); | 199 string16())); |
| 199 // This is a hack. Some file managers also populate text/plain with | 200 // This is a hack. Some file managers also populate text/plain with |
| 200 // a file URL when dragging files, so we clear it to avoid exposing | 201 // a file URL when dragging files, so we clear it to avoid exposing |
| 201 // it to the web content. | 202 // it to the web content. |
| 202 drop_data_->plain_text.clear(); | 203 drop_data_->text = NullableString16(true); |
| 203 } else if (!drop_data_->url.is_valid()) { | 204 } else if (!drop_data_->url.is_valid()) { |
| 204 // Also set the first non-file URL as the URL content for the drop. | 205 // Also set the first non-file URL as the URL content for the drop. |
| 205 drop_data_->url = url; | 206 drop_data_->url = url; |
| 206 } | 207 } |
| 207 } | 208 } |
| 208 g_strfreev(uris); | 209 g_strfreev(uris); |
| 209 } | 210 } |
| 210 } else if (target == ui::GetAtomForTarget(ui::TEXT_HTML)) { | 211 } else if (target == ui::GetAtomForTarget(ui::TEXT_HTML)) { |
| 211 // TODO(estade): Can the html have a non-UTF8 encoding? | 212 // TODO(estade): Can the html have a non-UTF8 encoding? |
| 212 drop_data_->text_html = | 213 drop_data_->html = NullableString16( |
| 213 UTF8ToUTF16(std::string(reinterpret_cast<const char*>(raw_data), | 214 UTF8ToUTF16(std::string(reinterpret_cast<const char*>(raw_data), |
| 214 data_length)); | 215 data_length)), |
| 216 false); |
| 215 // We leave the base URL empty. | 217 // We leave the base URL empty. |
| 216 } else if (target == ui::GetAtomForTarget(ui::NETSCAPE_URL)) { | 218 } else if (target == ui::GetAtomForTarget(ui::NETSCAPE_URL)) { |
| 217 std::string netscape_url(reinterpret_cast<const char*>(raw_data), | 219 std::string netscape_url(reinterpret_cast<const char*>(raw_data), |
| 218 data_length); | 220 data_length); |
| 219 size_t split = netscape_url.find_first_of('\n'); | 221 size_t split = netscape_url.find_first_of('\n'); |
| 220 if (split != std::string::npos) { | 222 if (split != std::string::npos) { |
| 221 drop_data_->url = GURL(netscape_url.substr(0, split)); | 223 drop_data_->url = GURL(netscape_url.substr(0, split)); |
| 222 if (split < netscape_url.size() - 1) | 224 if (split < netscape_url.size() - 1) |
| 223 drop_data_->url_title = UTF8ToUTF16(netscape_url.substr(split + 1)); | 225 drop_data_->url_title = UTF8ToUTF16(netscape_url.substr(split + 1)); |
| 224 } | 226 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 gtk_drag_finish(context, is_drop_target_, FALSE, time); | 297 gtk_drag_finish(context, is_drop_target_, FALSE, time); |
| 296 | 298 |
| 297 return TRUE; | 299 return TRUE; |
| 298 } | 300 } |
| 299 | 301 |
| 300 RenderViewHostImpl* WebDragDestGtk::GetRenderViewHost() const { | 302 RenderViewHostImpl* WebDragDestGtk::GetRenderViewHost() const { |
| 301 return static_cast<RenderViewHostImpl*>(web_contents_->GetRenderViewHost()); | 303 return static_cast<RenderViewHostImpl*>(web_contents_->GetRenderViewHost()); |
| 302 } | 304 } |
| 303 | 305 |
| 304 } // namespace content | 306 } // namespace content |
| OLD | NEW |