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

Side by Side Diff: content/browser/web_contents/web_contents_view_aura.cc

Issue 242643004: Support drag and drop of files with filesystem: URL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix SEGV during tests Created 6 years, 8 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) 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_contents_view_aura.h" 5 #include "content/browser/web_contents/web_contents_view_aura.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 download_url, 287 download_url,
288 Referrer(page_url, drop_data.referrer_policy), 288 Referrer(page_url, drop_data.referrer_policy),
289 page_encoding, 289 page_encoding,
290 web_contents); 290 web_contents);
291 ui::OSExchangeData::DownloadFileInfo file_download(base::FilePath(), 291 ui::OSExchangeData::DownloadFileInfo file_download(base::FilePath(),
292 download_file.get()); 292 download_file.get());
293 provider->SetDownloadFileInfo(file_download); 293 provider->SetDownloadFileInfo(file_download);
294 } 294 }
295 #endif // defined(OS_WIN) 295 #endif // defined(OS_WIN)
296 296
297 // Returns the CustomFormat to store file system files.
298 const ui::OSExchangeData::CustomFormat& GetFileSystemFileCustomFormat() {
299 static const char kFormatString[] = "chromium/x-file-system-files";
300 CR_DEFINE_STATIC_LOCAL(ui::OSExchangeData::CustomFormat,
301 format,
302 (ui::Clipboard::GetFormatType(kFormatString)));
303 return format;
304 }
305
306 // Writes file system files to the pickle.
307 void WriteFileSystemFilesToPickle(
308 const std::vector<DropData::FileSystemFileInfo>& file_system_files,
309 Pickle* pickle) {
310 pickle->WriteUInt64(file_system_files.size());
311 for (size_t i = 0; i < file_system_files.size(); ++i) {
312 pickle->WriteString(file_system_files[i].url.spec());
313 pickle->WriteInt64(file_system_files[i].size);
314 }
315 }
316
317 // Reads file system files from the pickle.
318 bool ReadFileSystemFilesFromPickle(
319 const Pickle& pickle,
320 std::vector<DropData::FileSystemFileInfo>* file_system_files) {
321 PickleIterator iter(pickle);
322
323 uint64 num_files = 0;
324 if (!pickle.ReadUInt64(&iter, &num_files))
325 return false;
326 file_system_files->resize(num_files);
327
328 for (uint64 i = 0; i < num_files; ++i) {
329 std::string url_string;
330 int64 size = 0;
331 if (!pickle.ReadString(&iter, &url_string) ||
332 !pickle.ReadInt64(&iter, &size))
333 return false;
334
335 GURL url(url_string);
336 if (!url.is_valid())
337 return false;
338
339 (*file_system_files)[i].url = url;
340 (*file_system_files)[i].size = size;
341 }
342 return true;
343 }
344
297 // Utility to fill a ui::OSExchangeDataProvider object from DropData. 345 // Utility to fill a ui::OSExchangeDataProvider object from DropData.
298 void PrepareDragData(const DropData& drop_data, 346 void PrepareDragData(const DropData& drop_data,
299 ui::OSExchangeData::Provider* provider, 347 ui::OSExchangeData::Provider* provider,
300 WebContentsImpl* web_contents) { 348 WebContentsImpl* web_contents) {
301 provider->MarkOriginatedFromRenderer(); 349 provider->MarkOriginatedFromRenderer();
302 #if defined(OS_WIN) 350 #if defined(OS_WIN)
303 // Put download before file contents to prefer the download of a image over 351 // Put download before file contents to prefer the download of a image over
304 // its thumbnail link. 352 // its thumbnail link.
305 if (!drop_data.download_metadata.empty()) 353 if (!drop_data.download_metadata.empty())
306 PrepareDragForDownload(drop_data, provider, web_contents); 354 PrepareDragForDownload(drop_data, provider, web_contents);
307 #endif 355 #endif
308 #if (!defined(OS_CHROMEOS) && defined(USE_X11)) || defined(OS_WIN) 356 #if (!defined(OS_CHROMEOS) && defined(USE_X11)) || defined(OS_WIN)
309 // We set the file contents before the URL because the URL also sets file 357 // We set the file contents before the URL because the URL also sets file
310 // contents (to a .URL shortcut). We want to prefer file content data over 358 // contents (to a .URL shortcut). We want to prefer file content data over
311 // a shortcut so we add it first. 359 // a shortcut so we add it first.
312 if (!drop_data.file_contents.empty()) 360 if (!drop_data.file_contents.empty())
313 PrepareDragForFileContents(drop_data, provider); 361 PrepareDragForFileContents(drop_data, provider);
314 #endif 362 #endif
315 if (!drop_data.text.string().empty()) 363 if (!drop_data.text.string().empty())
316 provider->SetString(drop_data.text.string()); 364 provider->SetString(drop_data.text.string());
317 if (drop_data.url.is_valid()) 365 if (drop_data.url.is_valid())
318 provider->SetURL(drop_data.url, drop_data.url_title); 366 provider->SetURL(drop_data.url, drop_data.url_title);
319 if (!drop_data.html.string().empty()) 367 if (!drop_data.html.string().empty())
320 provider->SetHtml(drop_data.html.string(), drop_data.html_base_url); 368 provider->SetHtml(drop_data.html.string(), drop_data.html_base_url);
321 if (!drop_data.filenames.empty()) 369 if (!drop_data.filenames.empty())
322 provider->SetFilenames(drop_data.filenames); 370 provider->SetFilenames(drop_data.filenames);
371 if (!drop_data.file_system_files.empty()) {
372 Pickle pickle;
373 WriteFileSystemFilesToPickle(drop_data.file_system_files, &pickle);
374 provider->SetPickledData(GetFileSystemFileCustomFormat(), pickle);
375 }
323 if (!drop_data.custom_data.empty()) { 376 if (!drop_data.custom_data.empty()) {
324 Pickle pickle; 377 Pickle pickle;
325 ui::WriteCustomDataToPickle(drop_data.custom_data, &pickle); 378 ui::WriteCustomDataToPickle(drop_data.custom_data, &pickle);
326 provider->SetPickledData(ui::Clipboard::GetWebCustomDataFormatType(), 379 provider->SetPickledData(ui::Clipboard::GetWebCustomDataFormatType(),
327 pickle); 380 pickle);
328 } 381 }
329 } 382 }
330 383
331 // Utility to fill a DropData object from ui::OSExchangeData. 384 // Utility to fill a DropData object from ui::OSExchangeData.
332 void PrepareDropData(DropData* drop_data, const ui::OSExchangeData& data) { 385 void PrepareDropData(DropData* drop_data, const ui::OSExchangeData& data) {
(...skipping 17 matching lines...) Expand all
350 GURL html_base_url; 403 GURL html_base_url;
351 data.GetHtml(&html, &html_base_url); 404 data.GetHtml(&html, &html_base_url);
352 if (!html.empty()) 405 if (!html.empty())
353 drop_data->html = base::NullableString16(html, false); 406 drop_data->html = base::NullableString16(html, false);
354 if (html_base_url.is_valid()) 407 if (html_base_url.is_valid())
355 drop_data->html_base_url = html_base_url; 408 drop_data->html_base_url = html_base_url;
356 409
357 data.GetFilenames(&drop_data->filenames); 410 data.GetFilenames(&drop_data->filenames);
358 411
359 Pickle pickle; 412 Pickle pickle;
413 std::vector<DropData::FileSystemFileInfo> file_system_files;
414 if (data.GetPickledData(GetFileSystemFileCustomFormat(), &pickle) &&
415 ReadFileSystemFilesFromPickle(pickle, &file_system_files))
416 drop_data->file_system_files = file_system_files;
417
360 if (data.GetPickledData(ui::Clipboard::GetWebCustomDataFormatType(), &pickle)) 418 if (data.GetPickledData(ui::Clipboard::GetWebCustomDataFormatType(), &pickle))
361 ui::ReadCustomDataIntoMap( 419 ui::ReadCustomDataIntoMap(
362 pickle.data(), pickle.size(), &drop_data->custom_data); 420 pickle.data(), pickle.size(), &drop_data->custom_data);
363 } 421 }
364 422
365 // Utilities to convert between blink::WebDragOperationsMask and 423 // Utilities to convert between blink::WebDragOperationsMask and
366 // ui::DragDropTypes. 424 // ui::DragDropTypes.
367 int ConvertFromWeb(blink::WebDragOperationsMask ops) { 425 int ConvertFromWeb(blink::WebDragOperationsMask ops) {
368 int drag_op = ui::DragDropTypes::DRAG_NONE; 426 int drag_op = ui::DragDropTypes::DRAG_NONE;
369 if (ops & blink::WebDragOperationCopy) 427 if (ops & blink::WebDragOperationCopy)
(...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1477 event.location(), 1535 event.location(),
1478 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(), 1536 gfx::Screen::GetScreenFor(GetNativeView())->GetCursorScreenPoint(),
1479 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags())); 1537 ConvertAuraEventFlagsToWebInputEventModifiers(event.flags()));
1480 if (drag_dest_delegate_) 1538 if (drag_dest_delegate_)
1481 drag_dest_delegate_->OnDrop(); 1539 drag_dest_delegate_->OnDrop();
1482 current_drop_data_.reset(); 1540 current_drop_data_.reset();
1483 return ConvertFromWeb(current_drag_op_); 1541 return ConvertFromWeb(current_drag_op_);
1484 } 1542 }
1485 1543
1486 } // namespace content 1544 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698