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

Side by Side Diff: third_party/WebKit/Source/core/clipboard/DataObject.cpp

Issue 2674953003: Only generate suggested filenames when actually dragging an image. (Closed)
Patch Set: rebase Created 3 years, 10 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2008, 2009, 2012 Google Inc. All rights reserved. 2 * Copyright (c) 2008, 2009, 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 return results; 215 return results;
216 } 216 }
217 217
218 void DataObject::addFilename(const String& filename, 218 void DataObject::addFilename(const String& filename,
219 const String& displayName, 219 const String& displayName,
220 const String& fileSystemId) { 220 const String& fileSystemId) {
221 internalAddFileItem(DataObjectItem::createFromFileWithFileSystemId( 221 internalAddFileItem(DataObjectItem::createFromFileWithFileSystemId(
222 File::createForUserProvidedFile(filename, displayName), fileSystemId)); 222 File::createForUserProvidedFile(filename, displayName), fileSystemId));
223 } 223 }
224 224
225 void DataObject::addSharedBuffer(const String& name, 225 void DataObject::addSharedBuffer(PassRefPtr<SharedBuffer> buffer,
226 PassRefPtr<SharedBuffer> buffer) { 226 const KURL& sourceURL,
227 internalAddFileItem( 227 const String& filenameExtension,
228 DataObjectItem::createFromSharedBuffer(name, std::move(buffer))); 228 const AtomicString& contentDisposition) {
229 internalAddFileItem(DataObjectItem::createFromSharedBuffer(
230 std::move(buffer), sourceURL, filenameExtension, contentDisposition));
229 } 231 }
230 232
231 DataObject::DataObject() : m_modifiers(0) {} 233 DataObject::DataObject() : m_modifiers(0) {}
232 234
233 DataObjectItem* DataObject::findStringItem(const String& type) const { 235 DataObjectItem* DataObject::findStringItem(const String& type) const {
234 for (size_t i = 0; i < m_itemList.size(); ++i) { 236 for (size_t i = 0; i < m_itemList.size(); ++i) {
235 if (m_itemList[i]->kind() == DataObjectItem::StringKind && 237 if (m_itemList[i]->kind() == DataObjectItem::StringKind &&
236 m_itemList[i]->type() == type) 238 m_itemList[i]->type() == type)
237 return m_itemList[i]; 239 return m_itemList[i];
238 } 240 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 data.setModifierKeyState(m_modifiers); 317 data.setModifierKeyState(m_modifiers);
316 WebVector<WebDragData::Item> itemList(length()); 318 WebVector<WebDragData::Item> itemList(length());
317 319
318 for (size_t i = 0; i < length(); ++i) { 320 for (size_t i = 0; i < length(); ++i) {
319 DataObjectItem* originalItem = item(i); 321 DataObjectItem* originalItem = item(i);
320 WebDragData::Item item; 322 WebDragData::Item item;
321 if (originalItem->kind() == DataObjectItem::StringKind) { 323 if (originalItem->kind() == DataObjectItem::StringKind) {
322 item.storageType = WebDragData::Item::StorageTypeString; 324 item.storageType = WebDragData::Item::StorageTypeString;
323 item.stringType = originalItem->type(); 325 item.stringType = originalItem->type();
324 item.stringData = originalItem->getAsString(); 326 item.stringData = originalItem->getAsString();
327 item.title = originalItem->title();
328 item.baseURL = originalItem->baseURL();
325 } else if (originalItem->kind() == DataObjectItem::FileKind) { 329 } else if (originalItem->kind() == DataObjectItem::FileKind) {
326 if (originalItem->sharedBuffer()) { 330 if (originalItem->sharedBuffer()) {
327 item.storageType = WebDragData::Item::StorageTypeBinaryData; 331 item.storageType = WebDragData::Item::StorageTypeBinaryData;
328 item.binaryData = originalItem->sharedBuffer(); 332 item.binaryData = originalItem->sharedBuffer();
333 item.binaryDataSourceURL = originalItem->baseURL();
334 item.binaryDataFilenameExtension = originalItem->filenameExtension();
335 item.binaryDataContentDisposition = originalItem->title();
329 } else if (originalItem->isFilename()) { 336 } else if (originalItem->isFilename()) {
330 Blob* blob = originalItem->getAsFile(); 337 Blob* blob = originalItem->getAsFile();
331 if (blob->isFile()) { 338 if (blob->isFile()) {
332 File* file = toFile(blob); 339 File* file = toFile(blob);
333 if (file->hasBackingFile()) { 340 if (file->hasBackingFile()) {
334 item.storageType = WebDragData::Item::StorageTypeFilename; 341 item.storageType = WebDragData::Item::StorageTypeFilename;
335 item.filenameData = file->path(); 342 item.filenameData = file->path();
336 item.displayNameData = file->name(); 343 item.displayNameData = file->name();
337 } else if (!file->fileSystemURL().isEmpty()) { 344 } else if (!file->fileSystemURL().isEmpty()) {
338 item.storageType = WebDragData::Item::StorageTypeFileSystemFile; 345 item.storageType = WebDragData::Item::StorageTypeFileSystemFile;
339 item.fileSystemURL = file->fileSystemURL(); 346 item.fileSystemURL = file->fileSystemURL();
340 item.fileSystemFileSize = file->size(); 347 item.fileSystemFileSize = file->size();
341 item.fileSystemId = originalItem->fileSystemId(); 348 item.fileSystemId = originalItem->fileSystemId();
342 } else { 349 } else {
343 // FIXME: support dragging constructed Files across renderers, see 350 // FIXME: support dragging constructed Files across renderers, see
344 // http://crbug.com/394955 351 // http://crbug.com/394955
345 item.storageType = WebDragData::Item::StorageTypeString; 352 item.storageType = WebDragData::Item::StorageTypeString;
346 item.stringType = "text/plain"; 353 item.stringType = "text/plain";
347 item.stringData = file->name(); 354 item.stringData = file->name();
348 } 355 }
349 } else { 356 } else {
350 ASSERT_NOT_REACHED(); 357 ASSERT_NOT_REACHED();
351 } 358 }
352 } else { 359 } else {
353 ASSERT_NOT_REACHED(); 360 ASSERT_NOT_REACHED();
354 } 361 }
355 } else { 362 } else {
356 ASSERT_NOT_REACHED(); 363 ASSERT_NOT_REACHED();
357 } 364 }
358 item.title = originalItem->title();
359 item.baseURL = originalItem->baseURL();
360 itemList[i] = item; 365 itemList[i] = item;
361 } 366 }
362 data.swapItems(itemList); 367 data.swapItems(itemList);
363 return data; 368 return data;
364 } 369 }
365 370
366 } // namespace blink 371 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/clipboard/DataObject.h ('k') | third_party/WebKit/Source/core/clipboard/DataObjectItem.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698