| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008 Apple 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 263 |
| 264 LayoutImage* image = toLayoutImage(layoutObject); | 264 LayoutImage* image = toLayoutImage(layoutObject); |
| 265 if (image->cachedImage() && !image->cachedImage()->errorOccurred()) | 265 if (image->cachedImage() && !image->cachedImage()->errorOccurred()) |
| 266 return image->cachedImage(); | 266 return image->cachedImage(); |
| 267 | 267 |
| 268 return 0; | 268 return 0; |
| 269 } | 269 } |
| 270 | 270 |
| 271 static void writeImageToDataObject(DataObject* dataObject, | 271 static void writeImageToDataObject(DataObject* dataObject, |
| 272 Element* element, | 272 Element* element, |
| 273 const KURL& url) { | 273 const KURL& imageURL) { |
| 274 // Shove image data into a DataObject for use as a file | 274 // Shove image data into a DataObject for use as a file |
| 275 ImageResourceContent* cachedImage = getImageResourceContent(element); | 275 ImageResourceContent* cachedImage = getImageResourceContent(element); |
| 276 if (!cachedImage || !cachedImage->getImage() || !cachedImage->isLoaded()) | 276 if (!cachedImage || !cachedImage->getImage() || !cachedImage->isLoaded()) |
| 277 return; | 277 return; |
| 278 | 278 |
| 279 RefPtr<SharedBuffer> imageBuffer = cachedImage->getImage()->data(); | 279 RefPtr<SharedBuffer> imageBuffer = cachedImage->getImage()->data(); |
| 280 if (!imageBuffer || !imageBuffer->size()) | 280 if (!imageBuffer || !imageBuffer->size()) |
| 281 return; | 281 return; |
| 282 | 282 |
| 283 String imageExtension = cachedImage->getImage()->filenameExtension(); | 283 dataObject->addSharedBuffer(imageBuffer, imageURL, |
| 284 ASSERT(!imageExtension.isEmpty()); | 284 cachedImage->getImage()->filenameExtension(), |
| 285 | 285 cachedImage->response().httpHeaderFields().get( |
| 286 // Determine the filename for the file contents of the image. | 286 HTTPNames::Content_Disposition)); |
| 287 String filename = cachedImage->response().suggestedFilename(); | |
| 288 if (filename.isEmpty()) | |
| 289 filename = url.lastPathComponent(); | |
| 290 | |
| 291 String fileExtension; | |
| 292 if (filename.isEmpty()) { | |
| 293 filename = element->getAttribute(HTMLNames::altAttr); | |
| 294 } else { | |
| 295 // Strip any existing extension. Assume that alt text is usually not a | |
| 296 // filename. | |
| 297 int extensionIndex = filename.reverseFind('.'); | |
| 298 if (extensionIndex != -1) { | |
| 299 fileExtension = filename.substring(extensionIndex + 1); | |
| 300 filename.truncate(extensionIndex); | |
| 301 } | |
| 302 } | |
| 303 | |
| 304 if (!fileExtension.isEmpty() && fileExtension != imageExtension) { | |
| 305 String imageMimeType = | |
| 306 MIMETypeRegistry::getMIMETypeForExtension(imageExtension); | |
| 307 ASSERT(imageMimeType.startsWith("image/")); | |
| 308 // Use the file extension only if it has imageMimeType: it's untrustworthy | |
| 309 // otherwise. | |
| 310 if (imageMimeType == | |
| 311 MIMETypeRegistry::getMIMETypeForExtension(fileExtension)) | |
| 312 imageExtension = fileExtension; | |
| 313 } | |
| 314 | |
| 315 imageExtension = "." + imageExtension; | |
| 316 validateFilename(filename, imageExtension); | |
| 317 | |
| 318 dataObject->addSharedBuffer(filename + imageExtension, imageBuffer); | |
| 319 } | 287 } |
| 320 | 288 |
| 321 void DataTransfer::declareAndWriteDragImage(Element* element, | 289 void DataTransfer::declareAndWriteDragImage(Element* element, |
| 322 const KURL& url, | 290 const KURL& linkURL, |
| 291 const KURL& imageURL, |
| 323 const String& title) { | 292 const String& title) { |
| 324 if (!m_dataObject) | 293 if (!m_dataObject) |
| 325 return; | 294 return; |
| 326 | 295 |
| 327 m_dataObject->setURLAndTitle(url, title); | 296 m_dataObject->setURLAndTitle(linkURL.isValid() ? linkURL : imageURL, title); |
| 328 | 297 |
| 329 // Write the bytes in the image to the file format. | 298 // Write the bytes in the image to the file format. |
| 330 writeImageToDataObject(m_dataObject.get(), element, url); | 299 writeImageToDataObject(m_dataObject.get(), element, imageURL); |
| 331 | 300 |
| 332 // Put img tag on the clipboard referencing the image | 301 // Put img tag on the clipboard referencing the image |
| 333 m_dataObject->setData(mimeTypeTextHTML, | 302 m_dataObject->setData(mimeTypeTextHTML, |
| 334 createMarkup(element, IncludeNode, ResolveAllURLs)); | 303 createMarkup(element, IncludeNode, ResolveAllURLs)); |
| 335 } | 304 } |
| 336 | 305 |
| 337 void DataTransfer::writeURL(Node* node, const KURL& url, const String& title) { | 306 void DataTransfer::writeURL(Node* node, const KURL& url, const String& title) { |
| 338 if (!m_dataObject) | 307 if (!m_dataObject) |
| 339 return; | 308 return; |
| 340 ASSERT(!url.isEmpty()); | 309 ASSERT(!url.isEmpty()); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 } | 476 } |
| 508 } | 477 } |
| 509 | 478 |
| 510 DEFINE_TRACE(DataTransfer) { | 479 DEFINE_TRACE(DataTransfer) { |
| 511 visitor->trace(m_dataObject); | 480 visitor->trace(m_dataObject); |
| 512 visitor->trace(m_dragImage); | 481 visitor->trace(m_dragImage); |
| 513 visitor->trace(m_dragImageElement); | 482 visitor->trace(m_dragImageElement); |
| 514 } | 483 } |
| 515 | 484 |
| 516 } // namespace blink | 485 } // namespace blink |
| OLD | NEW |