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 23 matching lines...) Expand all Loading... |
34 #include "core/clipboard/DraggedIsolatedFileSystem.h" | 34 #include "core/clipboard/DraggedIsolatedFileSystem.h" |
35 #include "core/clipboard/Pasteboard.h" | 35 #include "core/clipboard/Pasteboard.h" |
36 #include "platform/clipboard/ClipboardMimeTypes.h" | 36 #include "platform/clipboard/ClipboardMimeTypes.h" |
37 #include "platform/clipboard/ClipboardUtilities.h" | 37 #include "platform/clipboard/ClipboardUtilities.h" |
38 #include "public/platform/Platform.h" | 38 #include "public/platform/Platform.h" |
39 #include "public/platform/WebClipboard.h" | 39 #include "public/platform/WebClipboard.h" |
40 #include "public/platform/WebDragData.h" | 40 #include "public/platform/WebDragData.h" |
41 | 41 |
42 namespace blink { | 42 namespace blink { |
43 | 43 |
44 PassRefPtrWillBeRawPtr<DataObject> DataObject::createFromPasteboard(PasteMode pa
steMode) | 44 DataObject* DataObject::createFromPasteboard(PasteMode pasteMode) |
45 { | 45 { |
46 RefPtrWillBeRawPtr<DataObject> dataObject = create(); | 46 DataObject* dataObject = create(); |
47 blink::WebClipboard::Buffer buffer = Pasteboard::generalPasteboard()->buffer
(); | 47 blink::WebClipboard::Buffer buffer = Pasteboard::generalPasteboard()->buffer
(); |
48 uint64_t sequenceNumber = blink::Platform::current()->clipboard()->sequenceN
umber(buffer); | 48 uint64_t sequenceNumber = blink::Platform::current()->clipboard()->sequenceN
umber(buffer); |
49 bool ignored; | 49 bool ignored; |
50 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); |
51 ListHashSet<String> types; | 51 ListHashSet<String> types; |
52 for (size_t i = 0; i < webTypes.size(); ++i) | 52 for (size_t i = 0; i < webTypes.size(); ++i) |
53 types.add(webTypes[i]); | 53 types.add(webTypes[i]); |
54 for (const String& type : types) { | 54 for (const String& type : types) { |
55 if (pasteMode == PlainTextOnly && type != mimeTypeTextPlain) | 55 if (pasteMode == PlainTextOnly && type != mimeTypeTextPlain) |
56 continue; | 56 continue; |
57 dataObject->m_itemList.append(DataObjectItem::createFromPasteboard(type,
sequenceNumber)); | 57 dataObject->m_itemList.append(DataObjectItem::createFromPasteboard(type,
sequenceNumber)); |
58 } | 58 } |
59 return dataObject.release(); | 59 return dataObject; |
60 } | 60 } |
61 | 61 |
62 PassRefPtrWillBeRawPtr<DataObject> DataObject::create() | 62 DataObject* DataObject::create() |
63 { | 63 { |
64 return adoptRefWillBeNoop(new DataObject()); | 64 return new DataObject; |
65 } | 65 } |
66 | 66 |
67 DataObject::~DataObject() | 67 DataObject::~DataObject() |
68 { | 68 { |
69 } | 69 } |
70 | 70 |
71 size_t DataObject::length() const | 71 size_t DataObject::length() const |
72 { | 72 { |
73 return m_itemList.size(); | 73 return m_itemList.size(); |
74 } | 74 } |
75 | 75 |
76 PassRefPtrWillBeRawPtr<DataObjectItem> DataObject::item(unsigned long index) | 76 DataObjectItem* DataObject::item(unsigned long index) |
77 { | 77 { |
78 if (index >= length()) | 78 if (index >= length()) |
79 return nullptr; | 79 return nullptr; |
80 return m_itemList[index]; | 80 return m_itemList[index]; |
81 } | 81 } |
82 | 82 |
83 void DataObject::deleteItem(unsigned long index) | 83 void DataObject::deleteItem(unsigned long index) |
84 { | 84 { |
85 if (index >= length()) | 85 if (index >= length()) |
86 return; | 86 return; |
87 m_itemList.remove(index); | 87 m_itemList.remove(index); |
88 } | 88 } |
89 | 89 |
90 void DataObject::clearAll() | 90 void DataObject::clearAll() |
91 { | 91 { |
92 m_itemList.clear(); | 92 m_itemList.clear(); |
93 } | 93 } |
94 | 94 |
95 PassRefPtrWillBeRawPtr<DataObjectItem> DataObject::add(const String& data, const
String& type) | 95 DataObjectItem* DataObject::add(const String& data, const String& type) |
96 { | 96 { |
97 RefPtrWillBeRawPtr<DataObjectItem> item = DataObjectItem::createFromString(t
ype, data); | 97 DataObjectItem* item = DataObjectItem::createFromString(type, data); |
98 if (!internalAddStringItem(item)) | 98 if (!internalAddStringItem(item)) |
99 return nullptr; | 99 return nullptr; |
100 return item; | 100 return item; |
101 } | 101 } |
102 | 102 |
103 PassRefPtrWillBeRawPtr<DataObjectItem> DataObject::add(File* file) | 103 DataObjectItem* DataObject::add(File* file) |
104 { | 104 { |
105 if (!file) | 105 if (!file) |
106 return nullptr; | 106 return nullptr; |
107 | 107 |
108 RefPtrWillBeRawPtr<DataObjectItem> item = DataObjectItem::createFromFile(fil
e); | 108 DataObjectItem* item = DataObjectItem::createFromFile(file); |
109 m_itemList.append(item); | 109 m_itemList.append(item); |
110 return item; | 110 return item; |
111 } | 111 } |
112 | 112 |
113 void DataObject::clearData(const String& type) | 113 void DataObject::clearData(const String& type) |
114 { | 114 { |
115 for (size_t i = 0; i < m_itemList.size(); ++i) { | 115 for (size_t i = 0; i < m_itemList.size(); ++i) { |
116 if (m_itemList[i]->kind() == DataObjectItem::StringKind && m_itemList[i]
->type() == type) { | 116 if (m_itemList[i]->kind() == DataObjectItem::StringKind && m_itemList[i]
->type() == type) { |
117 // Per the spec, type must be unique among all items of kind 'string
'. | 117 // Per the spec, type must be unique among all items of kind 'string
'. |
118 m_itemList.remove(i); | 118 m_itemList.remove(i); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 | 151 |
152 void DataObject::setData(const String& type, const String& data) | 152 void DataObject::setData(const String& type, const String& data) |
153 { | 153 { |
154 clearData(type); | 154 clearData(type); |
155 if (!add(data, type)) | 155 if (!add(data, type)) |
156 ASSERT_NOT_REACHED(); | 156 ASSERT_NOT_REACHED(); |
157 } | 157 } |
158 | 158 |
159 void DataObject::urlAndTitle(String& url, String* title) const | 159 void DataObject::urlAndTitle(String& url, String* title) const |
160 { | 160 { |
161 RefPtrWillBeRawPtr<DataObjectItem> item = findStringItem(mimeTypeTextURIList
); | 161 DataObjectItem* item = findStringItem(mimeTypeTextURIList); |
162 if (!item) | 162 if (!item) |
163 return; | 163 return; |
164 url = convertURIListToURL(item->getAsString()); | 164 url = convertURIListToURL(item->getAsString()); |
165 if (title) | 165 if (title) |
166 *title = item->title(); | 166 *title = item->title(); |
167 } | 167 } |
168 | 168 |
169 void DataObject::setURLAndTitle(const String& url, const String& title) | 169 void DataObject::setURLAndTitle(const String& url, const String& title) |
170 { | 170 { |
171 clearData(mimeTypeTextURIList); | 171 clearData(mimeTypeTextURIList); |
172 internalAddStringItem(DataObjectItem::createFromURL(url, title)); | 172 internalAddStringItem(DataObjectItem::createFromURL(url, title)); |
173 } | 173 } |
174 | 174 |
175 void DataObject::htmlAndBaseURL(String& html, KURL& baseURL) const | 175 void DataObject::htmlAndBaseURL(String& html, KURL& baseURL) const |
176 { | 176 { |
177 RefPtrWillBeRawPtr<DataObjectItem> item = findStringItem(mimeTypeTextHTML); | 177 DataObjectItem* item = findStringItem(mimeTypeTextHTML); |
178 if (!item) | 178 if (!item) |
179 return; | 179 return; |
180 html = item->getAsString(); | 180 html = item->getAsString(); |
181 baseURL = item->baseURL(); | 181 baseURL = item->baseURL(); |
182 } | 182 } |
183 | 183 |
184 void DataObject::setHTMLAndBaseURL(const String& html, const KURL& baseURL) | 184 void DataObject::setHTMLAndBaseURL(const String& html, const KURL& baseURL) |
185 { | 185 { |
186 clearData(mimeTypeTextHTML); | 186 clearData(mimeTypeTextHTML); |
187 internalAddStringItem(DataObjectItem::createFromHTML(html, baseURL)); | 187 internalAddStringItem(DataObjectItem::createFromHTML(html, baseURL)); |
(...skipping 26 matching lines...) Expand all Loading... |
214 void DataObject::addSharedBuffer(const String& name, PassRefPtr<SharedBuffer> bu
ffer) | 214 void DataObject::addSharedBuffer(const String& name, PassRefPtr<SharedBuffer> bu
ffer) |
215 { | 215 { |
216 internalAddFileItem(DataObjectItem::createFromSharedBuffer(name, buffer)); | 216 internalAddFileItem(DataObjectItem::createFromSharedBuffer(name, buffer)); |
217 } | 217 } |
218 | 218 |
219 DataObject::DataObject() | 219 DataObject::DataObject() |
220 : m_modifiers(0) | 220 : m_modifiers(0) |
221 { | 221 { |
222 } | 222 } |
223 | 223 |
224 PassRefPtrWillBeRawPtr<DataObjectItem> DataObject::findStringItem(const String&
type) const | 224 DataObjectItem* DataObject::findStringItem(const String& type) const |
225 { | 225 { |
226 for (size_t i = 0; i < m_itemList.size(); ++i) { | 226 for (size_t i = 0; i < m_itemList.size(); ++i) { |
227 if (m_itemList[i]->kind() == DataObjectItem::StringKind && m_itemList[i]
->type() == type) | 227 if (m_itemList[i]->kind() == DataObjectItem::StringKind && m_itemList[i]
->type() == type) |
228 return m_itemList[i]; | 228 return m_itemList[i]; |
229 } | 229 } |
230 return nullptr; | 230 return nullptr; |
231 } | 231 } |
232 | 232 |
233 bool DataObject::internalAddStringItem(PassRefPtrWillBeRawPtr<DataObjectItem> it
em) | 233 bool DataObject::internalAddStringItem(DataObjectItem* item) |
234 { | 234 { |
235 ASSERT(item->kind() == DataObjectItem::StringKind); | 235 ASSERT(item->kind() == DataObjectItem::StringKind); |
236 for (size_t i = 0; i < m_itemList.size(); ++i) { | 236 for (size_t i = 0; i < m_itemList.size(); ++i) { |
237 if (m_itemList[i]->kind() == DataObjectItem::StringKind && m_itemList[i]
->type() == item->type()) | 237 if (m_itemList[i]->kind() == DataObjectItem::StringKind && m_itemList[i]
->type() == item->type()) |
238 return false; | 238 return false; |
239 } | 239 } |
240 | 240 |
241 m_itemList.append(item); | 241 m_itemList.append(item); |
242 return true; | 242 return true; |
243 } | 243 } |
244 | 244 |
245 void DataObject::internalAddFileItem(PassRefPtrWillBeRawPtr<DataObjectItem> item
) | 245 void DataObject::internalAddFileItem(DataObjectItem* item) |
246 { | 246 { |
247 ASSERT(item->kind() == DataObjectItem::FileKind); | 247 ASSERT(item->kind() == DataObjectItem::FileKind); |
248 m_itemList.append(item); | 248 m_itemList.append(item); |
249 } | 249 } |
250 | 250 |
251 DEFINE_TRACE(DataObject) | 251 DEFINE_TRACE(DataObject) |
252 { | 252 { |
253 #if ENABLE(OILPAN) | |
254 visitor->trace(m_itemList); | 253 visitor->trace(m_itemList); |
255 HeapSupplementable<DataObject>::trace(visitor); | 254 HeapSupplementable<DataObject>::trace(visitor); |
256 #endif | |
257 } | 255 } |
258 | 256 |
259 PassRefPtrWillBeRawPtr<DataObject> DataObject::create(WebDragData data) | 257 DataObject* DataObject::create(WebDragData data) |
260 { | 258 { |
261 RefPtrWillBeRawPtr<DataObject> dataObject = create(); | 259 DataObject* dataObject = create(); |
262 | 260 |
263 WebVector<WebDragData::Item> items = data.items(); | 261 WebVector<WebDragData::Item> items = data.items(); |
264 for (unsigned i = 0; i < items.size(); ++i) { | 262 for (unsigned i = 0; i < items.size(); ++i) { |
265 WebDragData::Item item = items[i]; | 263 WebDragData::Item item = items[i]; |
266 | 264 |
267 switch (item.storageType) { | 265 switch (item.storageType) { |
268 case WebDragData::Item::StorageTypeString: | 266 case WebDragData::Item::StorageTypeString: |
269 if (String(item.stringType) == mimeTypeTextURIList) | 267 if (String(item.stringType) == mimeTypeTextURIList) |
270 dataObject->setURLAndTitle(item.stringData, item.title); | 268 dataObject->setURLAndTitle(item.stringData, item.title); |
271 else if (String(item.stringType) == mimeTypeTextHTML) | 269 else if (String(item.stringType) == mimeTypeTextHTML) |
(...skipping 12 matching lines...) Expand all Loading... |
284 // FIXME: The file system URL may refer a user visible file, see
http://crbug.com/429077 | 282 // FIXME: The file system URL may refer a user visible file, see
http://crbug.com/429077 |
285 FileMetadata fileMetadata; | 283 FileMetadata fileMetadata; |
286 fileMetadata.length = item.fileSystemFileSize; | 284 fileMetadata.length = item.fileSystemFileSize; |
287 dataObject->add(File::createForFileSystemFile(item.fileSystemURL
, fileMetadata, File::IsNotUserVisible)); | 285 dataObject->add(File::createForFileSystemFile(item.fileSystemURL
, fileMetadata, File::IsNotUserVisible)); |
288 } | 286 } |
289 break; | 287 break; |
290 } | 288 } |
291 } | 289 } |
292 | 290 |
293 if (!data.filesystemId().isNull()) | 291 if (!data.filesystemId().isNull()) |
294 DraggedIsolatedFileSystem::prepareForDataObject(dataObject.get(), data.f
ilesystemId()); | 292 DraggedIsolatedFileSystem::prepareForDataObject(dataObject, data.filesys
temId()); |
295 return dataObject.release(); | 293 return dataObject; |
296 } | 294 } |
297 | 295 |
298 WebDragData DataObject::toWebDragData() | 296 WebDragData DataObject::toWebDragData() |
299 { | 297 { |
300 WebDragData data; | 298 WebDragData data; |
301 data.initialize(); | 299 data.initialize(); |
302 WebVector<WebDragData::Item> itemList(length()); | 300 WebVector<WebDragData::Item> itemList(length()); |
303 | 301 |
304 for (size_t i = 0; i < length(); ++i) { | 302 for (size_t i = 0; i < length(); ++i) { |
305 DataObjectItem* originalItem = item(i).get(); | 303 DataObjectItem* originalItem = item(i); |
306 WebDragData::Item item; | 304 WebDragData::Item item; |
307 if (originalItem->kind() == DataObjectItem::StringKind) { | 305 if (originalItem->kind() == DataObjectItem::StringKind) { |
308 item.storageType = WebDragData::Item::StorageTypeString; | 306 item.storageType = WebDragData::Item::StorageTypeString; |
309 item.stringType = originalItem->type(); | 307 item.stringType = originalItem->type(); |
310 item.stringData = originalItem->getAsString(); | 308 item.stringData = originalItem->getAsString(); |
311 } else if (originalItem->kind() == DataObjectItem::FileKind) { | 309 } else if (originalItem->kind() == DataObjectItem::FileKind) { |
312 if (originalItem->sharedBuffer()) { | 310 if (originalItem->sharedBuffer()) { |
313 item.storageType = WebDragData::Item::StorageTypeBinaryData; | 311 item.storageType = WebDragData::Item::StorageTypeBinaryData; |
314 item.binaryData = originalItem->sharedBuffer(); | 312 item.binaryData = originalItem->sharedBuffer(); |
315 } else if (originalItem->isFilename()) { | 313 } else if (originalItem->isFilename()) { |
(...skipping 25 matching lines...) Expand all Loading... |
341 } | 339 } |
342 item.title = originalItem->title(); | 340 item.title = originalItem->title(); |
343 item.baseURL = originalItem->baseURL(); | 341 item.baseURL = originalItem->baseURL(); |
344 itemList[i] = item; | 342 itemList[i] = item; |
345 } | 343 } |
346 data.swapItems(itemList); | 344 data.swapItems(itemList); |
347 return data; | 345 return data; |
348 } | 346 } |
349 | 347 |
350 } // namespace blink | 348 } // namespace blink |
OLD | NEW |