OLD | NEW |
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 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "core/clipboard/DataObject.h" | 32 #include "core/clipboard/DataObject.h" |
33 | 33 |
| 34 #include "core/clipboard/DraggedIsolatedFileSystem.h" |
34 #include "core/clipboard/Pasteboard.h" | 35 #include "core/clipboard/Pasteboard.h" |
35 #include "platform/clipboard/ClipboardMimeTypes.h" | 36 #include "platform/clipboard/ClipboardMimeTypes.h" |
36 #include "platform/clipboard/ClipboardUtilities.h" | 37 #include "platform/clipboard/ClipboardUtilities.h" |
37 #include "public/platform/Platform.h" | 38 #include "public/platform/Platform.h" |
38 #include "public/platform/WebClipboard.h" | 39 #include "public/platform/WebClipboard.h" |
| 40 #include "public/platform/WebDragData.h" |
39 | 41 |
40 namespace blink { | 42 namespace blink { |
41 | 43 |
42 PassRefPtrWillBeRawPtr<DataObject> DataObject::createFromPasteboard(PasteMode pa
steMode) | 44 PassRefPtrWillBeRawPtr<DataObject> DataObject::createFromPasteboard(PasteMode pa
steMode) |
43 { | 45 { |
44 RefPtrWillBeRawPtr<DataObject> dataObject = create(); | 46 RefPtrWillBeRawPtr<DataObject> dataObject = create(); |
45 blink::WebClipboard::Buffer buffer = Pasteboard::generalPasteboard()->buffer
(); | 47 blink::WebClipboard::Buffer buffer = Pasteboard::generalPasteboard()->buffer
(); |
46 uint64_t sequenceNumber = blink::Platform::current()->clipboard()->sequenceN
umber(buffer); | 48 uint64_t sequenceNumber = blink::Platform::current()->clipboard()->sequenceN
umber(buffer); |
47 bool ignored; | 49 bool ignored; |
48 blink::WebVector<blink::WebString> webTypes = blink::Platform::current()->cl
ipboard()->readAvailableTypes(buffer, &ignored); | 50 blink::WebVector<blink::WebString> webTypes = blink::Platform::current()->cl
ipboard()->readAvailableTypes(buffer, &ignored); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 } | 249 } |
248 | 250 |
249 DEFINE_TRACE(DataObject) | 251 DEFINE_TRACE(DataObject) |
250 { | 252 { |
251 #if ENABLE(OILPAN) | 253 #if ENABLE(OILPAN) |
252 visitor->trace(m_itemList); | 254 visitor->trace(m_itemList); |
253 HeapSupplementable<DataObject>::trace(visitor); | 255 HeapSupplementable<DataObject>::trace(visitor); |
254 #endif | 256 #endif |
255 } | 257 } |
256 | 258 |
| 259 PassRefPtrWillBeRawPtr<DataObject> DataObject::createFromWebDragData(WebDragData
data) |
| 260 { |
| 261 RefPtrWillBeRawPtr<DataObject> dataObject = create(); |
| 262 |
| 263 WebVector<WebDragData::Item> items = data.items(); |
| 264 for (unsigned i = 0; i < items.size(); ++i) { |
| 265 WebDragData::Item item = items[i]; |
| 266 |
| 267 switch (item.storageType) { |
| 268 case WebDragData::Item::StorageTypeString: |
| 269 if (String(item.stringType) == mimeTypeTextURIList) |
| 270 dataObject->setURLAndTitle(item.stringData, item.title); |
| 271 else if (String(item.stringType) == mimeTypeTextHTML) |
| 272 dataObject->setHTMLAndBaseURL(item.stringData, item.baseURL); |
| 273 else |
| 274 dataObject->setData(item.stringType, item.stringData); |
| 275 break; |
| 276 case WebDragData::Item::StorageTypeFilename: |
| 277 dataObject->addFilename(item.filenameData, item.displayNameData); |
| 278 break; |
| 279 case WebDragData::Item::StorageTypeBinaryData: |
| 280 // This should never happen when dragging in. |
| 281 break; |
| 282 case WebDragData::Item::StorageTypeFileSystemFile: |
| 283 { |
| 284 // FIXME: The file system URL may refer a user visible file, see
http://crbug.com/429077 |
| 285 FileMetadata fileMetadata; |
| 286 fileMetadata.length = item.fileSystemFileSize; |
| 287 dataObject->add(File::createForFileSystemFile(item.fileSystemURL
, fileMetadata, File::IsNotUserVisible)); |
| 288 } |
| 289 break; |
| 290 } |
| 291 } |
| 292 |
| 293 if (!data.filesystemId().isNull()) |
| 294 DraggedIsolatedFileSystem::prepareForDataObject(dataObject.get(), data.f
ilesystemId()); |
| 295 return dataObject.release(); |
| 296 } |
| 297 |
| 298 WebDragData DataObject::toWebDragData() |
| 299 { |
| 300 WebDragData data; |
| 301 data.initialize(); |
| 302 Vector<WebDragData::Item> itemList; |
| 303 for (size_t i = 0; i < length(); ++i) { |
| 304 DataObjectItem* originalItem = item(i).get(); |
| 305 WebDragData::Item item; |
| 306 if (originalItem->kind() == DataObjectItem::StringKind) { |
| 307 item.storageType = WebDragData::Item::StorageTypeString; |
| 308 item.stringType = originalItem->type(); |
| 309 item.stringData = originalItem->getAsString(); |
| 310 } else if (originalItem->kind() == DataObjectItem::FileKind) { |
| 311 if (originalItem->sharedBuffer()) { |
| 312 item.storageType = WebDragData::Item::StorageTypeBinaryData; |
| 313 item.binaryData = originalItem->sharedBuffer(); |
| 314 } else if (originalItem->isFilename()) { |
| 315 Blob* blob = originalItem->getAsFile(); |
| 316 if (blob->isFile()) { |
| 317 File* file = toFile(blob); |
| 318 if (file->hasBackingFile()) { |
| 319 item.storageType = WebDragData::Item::StorageTypeFilenam
e; |
| 320 item.filenameData = file->path(); |
| 321 item.displayNameData = file->name(); |
| 322 } else if (!file->fileSystemURL().isEmpty()) { |
| 323 item.storageType = WebDragData::Item::StorageTypeFileSys
temFile; |
| 324 item.fileSystemURL = file->fileSystemURL(); |
| 325 item.fileSystemFileSize = file->size(); |
| 326 } else { |
| 327 // FIXME: support dragging constructed Files across rend
erers, see http://crbug.com/394955 |
| 328 item.storageType = WebDragData::Item::StorageTypeString; |
| 329 item.stringType = "text/plain"; |
| 330 item.stringData = file->name(); |
| 331 } |
| 332 } else { |
| 333 ASSERT_NOT_REACHED(); |
| 334 } |
| 335 } else { |
| 336 ASSERT_NOT_REACHED(); |
| 337 } |
| 338 } else { |
| 339 ASSERT_NOT_REACHED(); |
| 340 } |
| 341 item.title = originalItem->title(); |
| 342 item.baseURL = originalItem->baseURL(); |
| 343 itemList.append(item); |
| 344 } |
| 345 data.setItems(itemList); |
| 346 return data; |
| 347 } |
| 348 |
257 } // namespace blink | 349 } // namespace blink |
OLD | NEW |