Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 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 14 matching lines...) Expand all Loading... | |
| 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 | 32 |
| 33 #include "core/clipboard/DataObject.h" | 33 #include "core/clipboard/DataObject.h" |
| 34 #include "core/clipboard/DataTransferItem.h" | 34 #include "core/clipboard/DataTransferItem.h" |
| 35 #include "heap/Handle.h" | |
| 35 #include "modules/filesystem/DraggedIsolatedFileSystem.h" | 36 #include "modules/filesystem/DraggedIsolatedFileSystem.h" |
| 36 #include "platform/clipboard/ClipboardMimeTypes.h" | 37 #include "platform/clipboard/ClipboardMimeTypes.h" |
| 37 #include "public/platform/WebData.h" | 38 #include "public/platform/WebData.h" |
| 38 #include "public/platform/WebDragData.h" | 39 #include "public/platform/WebDragData.h" |
| 39 #include "public/platform/WebString.h" | 40 #include "public/platform/WebString.h" |
| 40 #include "public/platform/WebURL.h" | 41 #include "public/platform/WebURL.h" |
| 41 #include "public/platform/WebVector.h" | 42 #include "public/platform/WebVector.h" |
| 42 #include "wtf/HashMap.h" | 43 #include "wtf/HashMap.h" |
| 43 #include "wtf/PassRefPtr.h" | 44 #include "wtf/PassRefPtr.h" |
| 44 | 45 |
| 45 using namespace WebCore; | 46 using namespace WebCore; |
| 46 | 47 |
| 47 namespace blink { | 48 namespace blink { |
| 48 | 49 |
| 49 class WebDragDataPrivate : public DataObject { | 50 WebDragData::WebDragData(const WebDragData& object) |
| 50 }; | 51 { |
| 52 assign(object); | |
| 53 } | |
| 54 | |
| 55 WebDragData::~WebDragData() | |
| 56 { | |
| 57 reset(); | |
| 58 } | |
| 59 | |
| 60 WebDragData& WebDragData::operator=(const WebDragData& object) | |
| 61 { | |
| 62 assign(object); | |
| 63 return *this; | |
| 64 } | |
| 65 | |
| 66 bool WebDragData::isNull() const | |
| 67 { | |
| 68 return m_private.isNull(); | |
| 69 } | |
| 51 | 70 |
| 52 void WebDragData::initialize() | 71 void WebDragData::initialize() |
| 53 { | 72 { |
| 54 assign(static_cast<WebDragDataPrivate*>(DataObject::create().leakRef())); | 73 m_private = DataObject::create(); |
| 55 } | 74 } |
| 56 | 75 |
| 57 void WebDragData::reset() | 76 void WebDragData::reset() |
| 58 { | 77 { |
| 59 assign(0); | 78 m_private.reset(); |
| 60 } | 79 } |
| 61 | 80 |
| 62 void WebDragData::assign(const WebDragData& other) | 81 void WebDragData::assign(const WebDragData& other) |
| 63 { | 82 { |
| 64 WebDragDataPrivate* p = const_cast<WebDragDataPrivate*>(other.m_private); | 83 m_private = other.m_private; |
| 65 if (p) | 84 } |
| 66 p->ref(); | 85 |
| 67 assign(p); | 86 WebDragData::WebDragData(const PassRefPtrWillBeRawPtr<WebCore::DataObject>& obje ct) |
| 87 { | |
| 88 assign(object); | |
| 89 } | |
| 90 | |
| 91 WebDragData& WebDragData::operator=(const PassRefPtrWillBeRawPtr<WebCore::DataOb ject>& object) | |
| 92 { | |
| 93 assign(object); | |
| 94 return *this; | |
| 95 } | |
| 96 | |
| 97 DataObject* WebDragData::getValue() const | |
|
sof
2014/02/19 08:30:24
I'm not sure getValue() is worth having in this se
haraken
2014/02/19 08:37:12
Yeah, this might be unnecessary.
In the experimen
| |
| 98 { | |
| 99 return m_private.get(); | |
| 100 } | |
| 101 | |
| 102 void WebDragData::ensureMutable() | |
| 103 { | |
| 104 ASSERT(!isNull()); | |
| 68 } | 105 } |
| 69 | 106 |
| 70 WebVector<WebDragData::Item> WebDragData::items() const | 107 WebVector<WebDragData::Item> WebDragData::items() const |
| 71 { | 108 { |
| 72 Vector<Item> itemList; | 109 Vector<Item> itemList; |
| 73 for (size_t i = 0; i < m_private->length(); ++i) { | 110 for (size_t i = 0; i < getValue()->length(); ++i) { |
| 74 DataObjectItem* originalItem = m_private->item(i).get(); | 111 DataObjectItem* originalItem = getValue()->item(i).get(); |
| 75 WebDragData::Item item; | 112 WebDragData::Item item; |
| 76 if (originalItem->kind() == DataObjectItem::StringKind) { | 113 if (originalItem->kind() == DataObjectItem::StringKind) { |
| 77 item.storageType = Item::StorageTypeString; | 114 item.storageType = Item::StorageTypeString; |
| 78 item.stringType = originalItem->type(); | 115 item.stringType = originalItem->type(); |
| 79 item.stringData = originalItem->getAsString(); | 116 item.stringData = originalItem->getAsString(); |
| 80 } else if (originalItem->kind() == DataObjectItem::FileKind) { | 117 } else if (originalItem->kind() == DataObjectItem::FileKind) { |
| 81 if (originalItem->sharedBuffer()) { | 118 if (originalItem->sharedBuffer()) { |
| 82 item.storageType = Item::StorageTypeBinaryData; | 119 item.storageType = Item::StorageTypeBinaryData; |
| 83 item.binaryData = originalItem->sharedBuffer(); | 120 item.binaryData = originalItem->sharedBuffer(); |
| 84 } else if (originalItem->isFilename()) { | 121 } else if (originalItem->isFilename()) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 96 ASSERT_NOT_REACHED(); | 133 ASSERT_NOT_REACHED(); |
| 97 item.title = originalItem->title(); | 134 item.title = originalItem->title(); |
| 98 item.baseURL = originalItem->baseURL(); | 135 item.baseURL = originalItem->baseURL(); |
| 99 itemList.append(item); | 136 itemList.append(item); |
| 100 } | 137 } |
| 101 return itemList; | 138 return itemList; |
| 102 } | 139 } |
| 103 | 140 |
| 104 void WebDragData::setItems(const WebVector<Item>& itemList) | 141 void WebDragData::setItems(const WebVector<Item>& itemList) |
| 105 { | 142 { |
| 106 m_private->clearAll(); | 143 getValue()->clearAll(); |
| 107 for (size_t i = 0; i < itemList.size(); ++i) | 144 for (size_t i = 0; i < itemList.size(); ++i) |
| 108 addItem(itemList[i]); | 145 addItem(itemList[i]); |
| 109 } | 146 } |
| 110 | 147 |
| 111 void WebDragData::addItem(const Item& item) | 148 void WebDragData::addItem(const Item& item) |
| 112 { | 149 { |
| 113 ensureMutable(); | 150 ensureMutable(); |
| 114 switch (item.storageType) { | 151 switch (item.storageType) { |
| 115 case Item::StorageTypeString: | 152 case Item::StorageTypeString: |
| 116 if (String(item.stringType) == mimeTypeTextURIList) | 153 if (String(item.stringType) == mimeTypeTextURIList) |
| 117 m_private->setURLAndTitle(item.stringData, item.title); | 154 getValue()->setURLAndTitle(item.stringData, item.title); |
| 118 else if (String(item.stringType) == mimeTypeTextHTML) | 155 else if (String(item.stringType) == mimeTypeTextHTML) |
| 119 m_private->setHTMLAndBaseURL(item.stringData, item.baseURL); | 156 getValue()->setHTMLAndBaseURL(item.stringData, item.baseURL); |
| 120 else | 157 else |
| 121 m_private->setData(item.stringType, item.stringData); | 158 getValue()->setData(item.stringType, item.stringData); |
| 122 return; | 159 return; |
| 123 case Item::StorageTypeFilename: | 160 case Item::StorageTypeFilename: |
| 124 m_private->addFilename(item.filenameData, item.displayNameData); | 161 getValue()->addFilename(item.filenameData, item.displayNameData); |
| 125 return; | 162 return; |
| 126 case Item::StorageTypeBinaryData: | 163 case Item::StorageTypeBinaryData: |
| 127 // This should never happen when dragging in. | 164 // This should never happen when dragging in. |
| 128 ASSERT_NOT_REACHED(); | 165 ASSERT_NOT_REACHED(); |
| 129 } | 166 } |
| 130 } | 167 } |
| 131 | 168 |
| 132 WebString WebDragData::filesystemId() const | 169 WebString WebDragData::filesystemId() const |
| 133 { | 170 { |
| 134 ASSERT(!isNull()); | 171 ASSERT(!isNull()); |
| 135 DraggedIsolatedFileSystem* filesystem = DraggedIsolatedFileSystem::from(m_pr ivate); | 172 DraggedIsolatedFileSystem* filesystem = DraggedIsolatedFileSystem::from(getV alue()); |
| 136 if (filesystem) | 173 if (filesystem) |
| 137 return filesystem->filesystemId(); | 174 return filesystem->filesystemId(); |
| 138 return WebString(); | 175 return WebString(); |
| 139 } | 176 } |
| 140 | 177 |
| 141 void WebDragData::setFilesystemId(const WebString& filesystemId) | 178 void WebDragData::setFilesystemId(const WebString& filesystemId) |
| 142 { | 179 { |
| 143 // The ID is an opaque string, given by and validated by chromium port. | 180 // The ID is an opaque string, given by and validated by chromium port. |
| 144 ensureMutable(); | 181 ensureMutable(); |
| 145 DraggedIsolatedFileSystem::provideTo(m_private, DraggedIsolatedFileSystem::s upplementName(), DraggedIsolatedFileSystem::create(filesystemId)); | 182 DraggedIsolatedFileSystem::provideTo(getValue(), DraggedIsolatedFileSystem:: supplementName(), DraggedIsolatedFileSystem::create(filesystemId)); |
| 146 } | |
| 147 | |
| 148 WebDragData::WebDragData(const WTF::PassRefPtr<WebCore::DataObject>& data) | |
| 149 : m_private(static_cast<WebDragDataPrivate*>(data.leakRef())) | |
| 150 { | |
| 151 } | |
| 152 | |
| 153 WebDragData& WebDragData::operator=(const WTF::PassRefPtr<WebCore::DataObject>& data) | |
| 154 { | |
| 155 assign(static_cast<WebDragDataPrivate*>(data.leakRef())); | |
| 156 return *this; | |
| 157 } | |
| 158 | |
| 159 WebDragData::operator WTF::PassRefPtr<WebCore::DataObject>() const | |
| 160 { | |
| 161 return PassRefPtr<DataObject>(const_cast<WebDragDataPrivate*>(m_private)); | |
| 162 } | |
| 163 | |
| 164 void WebDragData::assign(WebDragDataPrivate* p) | |
| 165 { | |
| 166 // p is already ref'd for us by the caller | |
| 167 if (m_private) | |
| 168 m_private->deref(); | |
| 169 m_private = p; | |
| 170 } | |
| 171 | |
| 172 void WebDragData::ensureMutable() | |
| 173 { | |
| 174 ASSERT(!isNull()); | |
| 175 ASSERT(m_private->hasOneRef()); | |
| 176 } | 183 } |
| 177 | 184 |
| 178 } // namespace blink | 185 } // namespace blink |
| OLD | NEW |