| 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 gint data_length = gtk_selection_data_get_length(data); | 179 gint data_length = gtk_selection_data_get_length(data); |
| 180 const guchar* raw_data = gtk_selection_data_get_data(data); | 180 const guchar* raw_data = gtk_selection_data_get_data(data); |
| 181 GdkAtom target = gtk_selection_data_get_target(data); | 181 GdkAtom target = gtk_selection_data_get_target(data); |
| 182 if (raw_data && data_length > 0) { | 182 if (raw_data && data_length > 0) { |
| 183 // If the source can't provide us with valid data for a requested target, | 183 // If the source can't provide us with valid data for a requested target, |
| 184 // raw_data will be NULL. | 184 // raw_data will be NULL. |
| 185 if (target == ui::GetAtomForTarget(ui::TEXT_PLAIN)) { | 185 if (target == ui::GetAtomForTarget(ui::TEXT_PLAIN)) { |
| 186 guchar* text = gtk_selection_data_get_text(data); | 186 guchar* text = gtk_selection_data_get_text(data); |
| 187 if (text) { | 187 if (text) { |
| 188 drop_data_->text = base::NullableString16( | 188 drop_data_->text = base::NullableString16( |
| 189 UTF8ToUTF16(std::string(reinterpret_cast<const char*>(text))), | 189 base::UTF8ToUTF16(std::string(reinterpret_cast<const char*>(text))), |
| 190 false); | 190 false); |
| 191 g_free(text); | 191 g_free(text); |
| 192 } | 192 } |
| 193 } else if (target == ui::GetAtomForTarget(ui::TEXT_URI_LIST)) { | 193 } else if (target == ui::GetAtomForTarget(ui::TEXT_URI_LIST)) { |
| 194 gchar** uris = gtk_selection_data_get_uris(data); | 194 gchar** uris = gtk_selection_data_get_uris(data); |
| 195 if (uris) { | 195 if (uris) { |
| 196 drop_data_->url = GURL(); | 196 drop_data_->url = GURL(); |
| 197 for (gchar** uri_iter = uris; *uri_iter; uri_iter++) { | 197 for (gchar** uri_iter = uris; *uri_iter; uri_iter++) { |
| 198 // Most file managers populate text/uri-list with file URLs when | 198 // Most file managers populate text/uri-list with file URLs when |
| 199 // dragging files. To avoid exposing file system paths to web content, | 199 // dragging files. To avoid exposing file system paths to web content, |
| 200 // file URLs are never set as the URL content for the drop. | 200 // file URLs are never set as the URL content for the drop. |
| 201 // TODO(estade): Can the filenames have a non-UTF8 encoding? | 201 // TODO(estade): Can the filenames have a non-UTF8 encoding? |
| 202 GURL url(*uri_iter); | 202 GURL url(*uri_iter); |
| 203 base::FilePath file_path; | 203 base::FilePath file_path; |
| 204 if (url.SchemeIs(chrome::kFileScheme) && | 204 if (url.SchemeIs(chrome::kFileScheme) && |
| 205 net::FileURLToFilePath(url, &file_path)) { | 205 net::FileURLToFilePath(url, &file_path)) { |
| 206 drop_data_->filenames.push_back( | 206 drop_data_->filenames.push_back( |
| 207 DropData::FileInfo(UTF8ToUTF16(file_path.value()), | 207 DropData::FileInfo(base::UTF8ToUTF16(file_path.value()), |
| 208 base::string16())); | 208 base::string16())); |
| 209 // This is a hack. Some file managers also populate text/plain with | 209 // This is a hack. Some file managers also populate text/plain with |
| 210 // a file URL when dragging files, so we clear it to avoid exposing | 210 // a file URL when dragging files, so we clear it to avoid exposing |
| 211 // it to the web content. | 211 // it to the web content. |
| 212 drop_data_->text = base::NullableString16(); | 212 drop_data_->text = base::NullableString16(); |
| 213 } else if (!drop_data_->url.is_valid()) { | 213 } else if (!drop_data_->url.is_valid()) { |
| 214 // Also set the first non-file URL as the URL content for the drop. | 214 // Also set the first non-file URL as the URL content for the drop. |
| 215 drop_data_->url = url; | 215 drop_data_->url = url; |
| 216 } | 216 } |
| 217 } | 217 } |
| 218 g_strfreev(uris); | 218 g_strfreev(uris); |
| 219 } | 219 } |
| 220 } else if (target == ui::GetAtomForTarget(ui::TEXT_HTML)) { | 220 } else if (target == ui::GetAtomForTarget(ui::TEXT_HTML)) { |
| 221 // TODO(estade): Can the html have a non-UTF8 encoding? | 221 // TODO(estade): Can the html have a non-UTF8 encoding? |
| 222 drop_data_->html = base::NullableString16( | 222 drop_data_->html = base::NullableString16( |
| 223 UTF8ToUTF16(std::string(reinterpret_cast<const char*>(raw_data), | 223 base::UTF8ToUTF16(std::string(reinterpret_cast<const char*>(raw_data), |
| 224 data_length)), | 224 data_length)), |
| 225 false); | 225 false); |
| 226 // We leave the base URL empty. | 226 // We leave the base URL empty. |
| 227 } else if (target == ui::GetAtomForTarget(ui::NETSCAPE_URL)) { | 227 } else if (target == ui::GetAtomForTarget(ui::NETSCAPE_URL)) { |
| 228 std::string netscape_url(reinterpret_cast<const char*>(raw_data), | 228 std::string netscape_url(reinterpret_cast<const char*>(raw_data), |
| 229 data_length); | 229 data_length); |
| 230 size_t split = netscape_url.find_first_of('\n'); | 230 size_t split = netscape_url.find_first_of('\n'); |
| 231 if (split != std::string::npos) { | 231 if (split != std::string::npos) { |
| 232 drop_data_->url = GURL(netscape_url.substr(0, split)); | 232 drop_data_->url = GURL(netscape_url.substr(0, split)); |
| 233 if (split < netscape_url.size() - 1) | 233 if (split < netscape_url.size() - 1) { |
| 234 drop_data_->url_title = UTF8ToUTF16(netscape_url.substr(split + 1)); | 234 drop_data_->url_title = |
| 235 base::UTF8ToUTF16(netscape_url.substr(split + 1)); |
| 236 } |
| 235 } | 237 } |
| 236 } else if (target == ui::GetAtomForTarget(ui::CHROME_NAMED_URL)) { | 238 } else if (target == ui::GetAtomForTarget(ui::CHROME_NAMED_URL)) { |
| 237 ui::ExtractNamedURL(data, &drop_data_->url, &drop_data_->url_title); | 239 ui::ExtractNamedURL(data, &drop_data_->url, &drop_data_->url_title); |
| 238 } else if (target == ui::GetAtomForTarget(ui::CUSTOM_DATA)) { | 240 } else if (target == ui::GetAtomForTarget(ui::CUSTOM_DATA)) { |
| 239 ui::ReadCustomDataIntoMap( | 241 ui::ReadCustomDataIntoMap( |
| 240 raw_data, data_length, &drop_data_->custom_data); | 242 raw_data, data_length, &drop_data_->custom_data); |
| 241 } | 243 } |
| 242 } | 244 } |
| 243 | 245 |
| 244 if (data_requests_ == 0) { | 246 if (data_requests_ == 0) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 gtk_drag_finish(context, is_drop_target_, FALSE, time); | 332 gtk_drag_finish(context, is_drop_target_, FALSE, time); |
| 331 | 333 |
| 332 return TRUE; | 334 return TRUE; |
| 333 } | 335 } |
| 334 | 336 |
| 335 RenderViewHostImpl* WebDragDestGtk::GetRenderViewHost() const { | 337 RenderViewHostImpl* WebDragDestGtk::GetRenderViewHost() const { |
| 336 return static_cast<RenderViewHostImpl*>(web_contents_->GetRenderViewHost()); | 338 return static_cast<RenderViewHostImpl*>(web_contents_->GetRenderViewHost()); |
| 337 } | 339 } |
| 338 | 340 |
| 339 } // namespace content | 341 } // namespace content |
| OLD | NEW |