| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 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. | |
| 29 */ | |
| 30 | |
| 31 #include "config.h" | |
| 32 | |
| 33 #include "core/clipboard/DataObject.h" | |
| 34 #include "core/clipboard/DataTransferItem.h" | |
| 35 #include "modules/filesystem/DraggedIsolatedFileSystem.h" | |
| 36 #include "platform/clipboard/ClipboardMimeTypes.h" | |
| 37 #include "platform/heap/Handle.h" | |
| 38 #include "public/platform/WebData.h" | |
| 39 #include "public/platform/WebDragData.h" | |
| 40 #include "public/platform/WebString.h" | |
| 41 #include "public/platform/WebURL.h" | |
| 42 #include "public/platform/WebVector.h" | |
| 43 #include "wtf/HashMap.h" | |
| 44 #include "wtf/PassRefPtr.h" | |
| 45 | |
| 46 namespace blink { | |
| 47 | |
| 48 void WebDragData::initialize() | |
| 49 { | |
| 50 m_private = DataObject::create(); | |
| 51 } | |
| 52 | |
| 53 void WebDragData::reset() | |
| 54 { | |
| 55 m_private.reset(); | |
| 56 } | |
| 57 | |
| 58 void WebDragData::assign(const WebDragData& other) | |
| 59 { | |
| 60 m_private = other.m_private; | |
| 61 } | |
| 62 | |
| 63 WebDragData::WebDragData(const PassRefPtrWillBeRawPtr<DataObject>& object) | |
| 64 { | |
| 65 m_private = object; | |
| 66 } | |
| 67 | |
| 68 WebDragData& WebDragData::operator=(const PassRefPtrWillBeRawPtr<DataObject>& ob
ject) | |
| 69 { | |
| 70 m_private = object; | |
| 71 return *this; | |
| 72 } | |
| 73 | |
| 74 DataObject* WebDragData::getValue() const | |
| 75 { | |
| 76 return m_private.get(); | |
| 77 } | |
| 78 | |
| 79 void WebDragData::ensureMutable() | |
| 80 { | |
| 81 ASSERT(!isNull()); | |
| 82 } | |
| 83 | |
| 84 WebVector<WebDragData::Item> WebDragData::items() const | |
| 85 { | |
| 86 Vector<Item> itemList; | |
| 87 for (size_t i = 0; i < m_private->length(); ++i) { | |
| 88 DataObjectItem* originalItem = m_private->item(i).get(); | |
| 89 WebDragData::Item item; | |
| 90 if (originalItem->kind() == DataObjectItem::StringKind) { | |
| 91 item.storageType = Item::StorageTypeString; | |
| 92 item.stringType = originalItem->type(); | |
| 93 item.stringData = originalItem->getAsString(); | |
| 94 } else if (originalItem->kind() == DataObjectItem::FileKind) { | |
| 95 if (originalItem->sharedBuffer()) { | |
| 96 item.storageType = Item::StorageTypeBinaryData; | |
| 97 item.binaryData = originalItem->sharedBuffer(); | |
| 98 } else if (originalItem->isFilename()) { | |
| 99 Blob* blob = originalItem->getAsFile(); | |
| 100 if (blob->isFile()) { | |
| 101 File* file = toFile(blob); | |
| 102 if (file->hasBackingFile()) { | |
| 103 item.storageType = Item::StorageTypeFilename; | |
| 104 item.filenameData = file->path(); | |
| 105 item.displayNameData = file->name(); | |
| 106 } else if (!file->fileSystemURL().isEmpty()) { | |
| 107 item.storageType = Item::StorageTypeFileSystemFile; | |
| 108 item.fileSystemURL = file->fileSystemURL(); | |
| 109 item.fileSystemFileSize = file->size(); | |
| 110 } else { | |
| 111 // FIXME: support dragging constructed Files across rend
erers, see http://crbug.com/394955 | |
| 112 item.storageType = Item::StorageTypeString; | |
| 113 item.stringType = "text/plain"; | |
| 114 item.stringData = file->name(); | |
| 115 } | |
| 116 } else { | |
| 117 ASSERT_NOT_REACHED(); | |
| 118 } | |
| 119 } else { | |
| 120 ASSERT_NOT_REACHED(); | |
| 121 } | |
| 122 } else { | |
| 123 ASSERT_NOT_REACHED(); | |
| 124 } | |
| 125 item.title = originalItem->title(); | |
| 126 item.baseURL = originalItem->baseURL(); | |
| 127 itemList.append(item); | |
| 128 } | |
| 129 return itemList; | |
| 130 } | |
| 131 | |
| 132 void WebDragData::setItems(const WebVector<Item>& itemList) | |
| 133 { | |
| 134 m_private->clearAll(); | |
| 135 for (size_t i = 0; i < itemList.size(); ++i) | |
| 136 addItem(itemList[i]); | |
| 137 } | |
| 138 | |
| 139 void WebDragData::addItem(const Item& item) | |
| 140 { | |
| 141 ensureMutable(); | |
| 142 switch (item.storageType) { | |
| 143 case Item::StorageTypeString: | |
| 144 if (String(item.stringType) == mimeTypeTextURIList) | |
| 145 m_private->setURLAndTitle(item.stringData, item.title); | |
| 146 else if (String(item.stringType) == mimeTypeTextHTML) | |
| 147 m_private->setHTMLAndBaseURL(item.stringData, item.baseURL); | |
| 148 else | |
| 149 m_private->setData(item.stringType, item.stringData); | |
| 150 return; | |
| 151 case Item::StorageTypeFilename: | |
| 152 m_private->addFilename(item.filenameData, item.displayNameData); | |
| 153 return; | |
| 154 case Item::StorageTypeBinaryData: | |
| 155 // This should never happen when dragging in. | |
| 156 ASSERT_NOT_REACHED(); | |
| 157 return; | |
| 158 case Item::StorageTypeFileSystemFile: | |
| 159 { | |
| 160 // FIXME: The file system URL may refer a user visible file, see htt
p://crbug.com/429077 | |
| 161 FileMetadata fileMetadata; | |
| 162 fileMetadata.length = item.fileSystemFileSize; | |
| 163 m_private->add(File::createForFileSystemFile(item.fileSystemURL, fil
eMetadata, File::IsNotUserVisible)); | |
| 164 } | |
| 165 return; | |
| 166 } | |
| 167 } | |
| 168 | |
| 169 WebString WebDragData::filesystemId() const | |
| 170 { | |
| 171 ASSERT(!isNull()); | |
| 172 return m_private.get()->filesystemId(); | |
| 173 } | |
| 174 | |
| 175 void WebDragData::setFilesystemId(const WebString& filesystemId) | |
| 176 { | |
| 177 // The ID is an opaque string, given by and validated by chromium port. | |
| 178 ensureMutable(); | |
| 179 DraggedIsolatedFileSystem::provideTo(*m_private.get(), DraggedIsolatedFileSy
stem::supplementName(), DraggedIsolatedFileSystem::create(*m_private.get(), file
systemId)); | |
| 180 } | |
| 181 | |
| 182 } // namespace blink | |
| OLD | NEW |