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 |
| 50 #if ENABLE(OILPAN) |
| 51 class WebDragDataPrivate { |
| 52 explicit WebDragDataPrivate(DataObject* dragData) : m_dragData(dragData) { } |
| 53 Persistent<DataObject> m_dragData; |
| 54 friend class WebDragData; |
| 55 }; |
| 56 |
| 57 WebDragData::~WebDragData() |
| 58 { |
| 59 delete m_private; |
| 60 } |
| 61 |
| 62 WebDragData::WebDragData() |
| 63 : m_private(new WebDragDataPrivate(0)) |
| 64 { |
| 65 } |
| 66 |
| 67 WebDragData::WebDragData(const WebDragData& other) |
| 68 : m_private(new WebDragDataPrivate(other.getValue())) |
| 69 { |
| 70 } |
| 71 |
| 72 WebDragData& WebDragData::operator=(const WebDragData& dragData) |
| 73 { |
| 74 assign(dragData); |
| 75 return *this; |
| 76 } |
| 77 |
| 78 void WebDragData::initialize() |
| 79 { |
| 80 m_private->m_dragData = DataObject::create(); |
| 81 } |
| 82 |
| 83 void WebDragData::reset() |
| 84 { |
| 85 m_private->m_dragData.clear(); |
| 86 } |
| 87 |
| 88 void WebDragData::assign(const WebDragData& other) |
| 89 { |
| 90 m_private->m_dragData = other.m_private->m_dragData; |
| 91 } |
| 92 |
| 93 WebDragData::WebDragData(const WTF::RawPtr<WebCore::DataObject>& data) |
| 94 { |
| 95 assign(data); |
| 96 } |
| 97 |
| 98 WebDragData& WebDragData::operator=(const WTF::RawPtr<WebCore::DataObject>& othe
r) |
| 99 { |
| 100 assign(other); |
| 101 return *this; |
| 102 } |
| 103 |
| 104 DataObject* WebDragData::getValue() const |
| 105 { |
| 106 return m_private->m_dragData; |
| 107 } |
| 108 |
| 109 // FIXME: oilpan: Remove this once we remove the oilpan flag. |
| 110 void WebDragData::assign(WebDragDataPrivate*) |
| 111 { |
| 112 ASSERT_NOT_REACHED(); |
| 113 } |
| 114 |
| 115 void WebDragData::ensureMutable() |
| 116 { |
| 117 ASSERT(!isNull()); |
| 118 ASSERT(m_private); |
| 119 } |
| 120 |
| 121 #else |
49 class WebDragDataPrivate : public DataObject { | 122 class WebDragDataPrivate : public DataObject { |
50 }; | 123 }; |
51 | 124 |
| 125 ~WebDragData() |
| 126 { |
| 127 reset(); |
| 128 } |
| 129 |
| 130 WebDragData() : m_private(0) |
| 131 { |
| 132 } |
| 133 |
| 134 WebDragData(const WebDragData& dragData) : m_private(0) |
| 135 { |
| 136 assign(dragData); |
| 137 } |
| 138 |
| 139 WebDragData& operator=(const WebDragData& dragData) |
| 140 { |
| 141 assign(dragData); |
| 142 return *this; |
| 143 } |
| 144 |
52 void WebDragData::initialize() | 145 void WebDragData::initialize() |
53 { | 146 { |
54 assign(static_cast<WebDragDataPrivate*>(DataObject::create().leakRef())); | 147 assign(static_cast<WebDragDataPrivate*>(DataObject::create().leakRef())); |
55 } | 148 } |
56 | 149 |
57 void WebDragData::reset() | 150 void WebDragData::reset() |
58 { | 151 { |
59 assign(0); | 152 assign(0); |
60 } | 153 } |
61 | 154 |
62 void WebDragData::assign(const WebDragData& other) | 155 void WebDragData::assign(const WebDragData& other) |
63 { | 156 { |
64 WebDragDataPrivate* p = const_cast<WebDragDataPrivate*>(other.m_private); | 157 WebDragDataPrivate* p = const_cast<WebDragDataPrivate*>(other.m_private); |
65 if (p) | 158 if (p) |
66 p->ref(); | 159 p->ref(); |
67 assign(p); | 160 assign(p); |
68 } | 161 } |
69 | 162 |
| 163 WebDragData::WebDragData(const WTF::PassRefPtr<WebCore::DataObject>& data) |
| 164 : m_private(static_cast<WebDragDataPrivate*>(data.leakRef())) |
| 165 { |
| 166 } |
| 167 |
| 168 WebDragData& WebDragData::operator=(const WTF::PassRefPtr<WebCore::DataObject>&
data) |
| 169 { |
| 170 assign(static_cast<WebDragDataPrivate*>(data.leakRef())); |
| 171 return *this; |
| 172 } |
| 173 |
| 174 DataObject* WebDragData::getValue() const |
| 175 { |
| 176 return m_private; |
| 177 } |
| 178 |
| 179 void WebDragData::assign(WebDragDataPrivate* p) |
| 180 { |
| 181 // p is already ref'd for us by the caller |
| 182 if (m_private) |
| 183 m_private->deref(); |
| 184 m_private = p; |
| 185 } |
| 186 |
| 187 void WebDragData::ensureMutable() |
| 188 { |
| 189 ASSERT(!isNull()); |
| 190 ASSERT(m_private->hasOneRef()); |
| 191 } |
| 192 #endif // ENABLE(OILPAN) |
| 193 |
70 WebVector<WebDragData::Item> WebDragData::items() const | 194 WebVector<WebDragData::Item> WebDragData::items() const |
71 { | 195 { |
72 Vector<Item> itemList; | 196 Vector<Item> itemList; |
73 for (size_t i = 0; i < m_private->length(); ++i) { | 197 for (size_t i = 0; i < getValue()->length(); ++i) { |
74 DataObjectItem* originalItem = m_private->item(i).get(); | 198 DataObjectItem* originalItem = getValue()->item(i).get(); |
75 WebDragData::Item item; | 199 WebDragData::Item item; |
76 if (originalItem->kind() == DataObjectItem::StringKind) { | 200 if (originalItem->kind() == DataObjectItem::StringKind) { |
77 item.storageType = Item::StorageTypeString; | 201 item.storageType = Item::StorageTypeString; |
78 item.stringType = originalItem->type(); | 202 item.stringType = originalItem->type(); |
79 item.stringData = originalItem->getAsString(); | 203 item.stringData = originalItem->getAsString(); |
80 } else if (originalItem->kind() == DataObjectItem::FileKind) { | 204 } else if (originalItem->kind() == DataObjectItem::FileKind) { |
81 if (originalItem->sharedBuffer()) { | 205 if (originalItem->sharedBuffer()) { |
82 item.storageType = Item::StorageTypeBinaryData; | 206 item.storageType = Item::StorageTypeBinaryData; |
83 item.binaryData = originalItem->sharedBuffer(); | 207 item.binaryData = originalItem->sharedBuffer(); |
84 } else if (originalItem->isFilename()) { | 208 } else if (originalItem->isFilename()) { |
(...skipping 11 matching lines...) Expand all Loading... |
96 ASSERT_NOT_REACHED(); | 220 ASSERT_NOT_REACHED(); |
97 item.title = originalItem->title(); | 221 item.title = originalItem->title(); |
98 item.baseURL = originalItem->baseURL(); | 222 item.baseURL = originalItem->baseURL(); |
99 itemList.append(item); | 223 itemList.append(item); |
100 } | 224 } |
101 return itemList; | 225 return itemList; |
102 } | 226 } |
103 | 227 |
104 void WebDragData::setItems(const WebVector<Item>& itemList) | 228 void WebDragData::setItems(const WebVector<Item>& itemList) |
105 { | 229 { |
106 m_private->clearAll(); | 230 getValue()->clearAll(); |
107 for (size_t i = 0; i < itemList.size(); ++i) | 231 for (size_t i = 0; i < itemList.size(); ++i) |
108 addItem(itemList[i]); | 232 addItem(itemList[i]); |
109 } | 233 } |
110 | 234 |
111 void WebDragData::addItem(const Item& item) | 235 void WebDragData::addItem(const Item& item) |
112 { | 236 { |
113 ensureMutable(); | 237 ensureMutable(); |
114 switch (item.storageType) { | 238 switch (item.storageType) { |
115 case Item::StorageTypeString: | 239 case Item::StorageTypeString: |
116 if (String(item.stringType) == mimeTypeTextURIList) | 240 if (String(item.stringType) == mimeTypeTextURIList) |
117 m_private->setURLAndTitle(item.stringData, item.title); | 241 getValue()->setURLAndTitle(item.stringData, item.title); |
118 else if (String(item.stringType) == mimeTypeTextHTML) | 242 else if (String(item.stringType) == mimeTypeTextHTML) |
119 m_private->setHTMLAndBaseURL(item.stringData, item.baseURL); | 243 getValue()->setHTMLAndBaseURL(item.stringData, item.baseURL); |
120 else | 244 else |
121 m_private->setData(item.stringType, item.stringData); | 245 getValue()->setData(item.stringType, item.stringData); |
122 return; | 246 return; |
123 case Item::StorageTypeFilename: | 247 case Item::StorageTypeFilename: |
124 m_private->addFilename(item.filenameData, item.displayNameData); | 248 getValue()->addFilename(item.filenameData, item.displayNameData); |
125 return; | 249 return; |
126 case Item::StorageTypeBinaryData: | 250 case Item::StorageTypeBinaryData: |
127 // This should never happen when dragging in. | 251 // This should never happen when dragging in. |
128 ASSERT_NOT_REACHED(); | 252 ASSERT_NOT_REACHED(); |
129 } | 253 } |
130 } | 254 } |
131 | 255 |
132 WebString WebDragData::filesystemId() const | 256 WebString WebDragData::filesystemId() const |
133 { | 257 { |
134 ASSERT(!isNull()); | 258 ASSERT(!isNull()); |
135 DraggedIsolatedFileSystem* filesystem = DraggedIsolatedFileSystem::from(m_pr
ivate); | 259 DraggedIsolatedFileSystem* filesystem = DraggedIsolatedFileSystem::from(getV
alue()); |
136 if (filesystem) | 260 if (filesystem) |
137 return filesystem->filesystemId(); | 261 return filesystem->filesystemId(); |
138 return WebString(); | 262 return WebString(); |
139 } | 263 } |
140 | 264 |
141 void WebDragData::setFilesystemId(const WebString& filesystemId) | 265 void WebDragData::setFilesystemId(const WebString& filesystemId) |
142 { | 266 { |
143 // The ID is an opaque string, given by and validated by chromium port. | 267 // The ID is an opaque string, given by and validated by chromium port. |
144 ensureMutable(); | 268 ensureMutable(); |
145 DraggedIsolatedFileSystem::provideTo(m_private, DraggedIsolatedFileSystem::s
upplementName(), DraggedIsolatedFileSystem::create(filesystemId)); | 269 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 } | 270 } |
177 | 271 |
178 } // namespace blink | 272 } // namespace blink |
OLD | NEW |