1 /* 2 * Copyright (c) 2008, 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 #ifndef DataObject_h 32 #define DataObject_h 33 34 #include "core/clipboard/DataObjectItem.h" 35 #include "platform/PasteMode.h" 36 #include "platform/Supplementable.h" 37 #include "platform/heap/Handle.h" 38 #include "wtf/ListHashSet.h" 39 #include "wtf/RefCounted.h" 40 #include "wtf/RefPtr.h" 41 #include "wtf/Vector.h" 42 #include "wtf/text/StringHash.h" 43 #include "wtf/text/WTFString.h" 44 45 namespace blink { 46 47 class KURL; 48 class SharedBuffer; 49 50 // A data object for holding data that would be in a clipboard or moved 51 // during a drag-n-drop operation. This is the data that WebCore is aware 52 // of and is not specific to a platform. 53 class DataObject : public RefCountedWillBeGarbageCollectedFinalized<DataObject>, public WillBeHeapSupplementable<DataObject> { 54 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(DataObject); 55 public: 56 static PassRefPtrWillBeRawPtr<DataObject> createFromPasteboard(PasteMode); 57 static PassRefPtrWillBeRawPtr<DataObject> create(); 58 59 PassRefPtrWillBeRawPtr<DataObject> copy() const; 60 61 virtual ~DataObject(); 62 63 // DataTransferItemList support. 64 size_t length() const; 65 PassRefPtrWillBeRawPtr<DataObjectItem> item(unsigned long index); 66 // FIXME: Implement V8DataTransferItemList::indexedPropertyDeleter to get this called. 67 void deleteItem(unsigned long index); 68 void clearAll(); 69 // Returns null if an item already exists with the provided type. 70 PassRefPtrWillBeRawPtr<DataObjectItem> add(const String& data, const String& type); 71 PassRefPtrWillBeRawPtr<DataObjectItem> add(PassRefPtrWillBeRawPtr<File>); 72 73 // WebCore helpers. 74 void clearData(const String& type); 75 76 ListHashSet<String> types() const; 77 String getData(const String& type) const; 78 void setData(const String& type, const String& data); 79 80 void urlAndTitle(String& url, String* title = 0) const; 81 void setURLAndTitle(const String& url, const String& title); 82 void htmlAndBaseURL(String& html, KURL& baseURL) const; 83 void setHTMLAndBaseURL(const String& html, const KURL& baseURL); 84 85 // Used for dragging in files from the desktop. 86 bool containsFilenames() const; 87 Vector<String> filenames() const; 88 void addFilename(const String& filename, const String& displayName); 89 90 // Used for dragging in filesystem from the desktop. 91 void setFilesystemId(const String& fileSystemId) { m_filesystemId = fileSystemId; } 92 const String& filesystemId() const { ASSERT(!m_filesystemId.isEmpty()); return m_filesystemId; } 93 94 // Used to handle files (images) being dragged out. 95 void addSharedBuffer(const String& name, PassRefPtr<SharedBuffer>); 96 97 int modifierKeyState() const { return m_modifierKeyState; } 98 void setModifierKeyState(int modifierKeyState) { m_modifierKeyState = modifierKeyState; } 99 100 void trace(Visitor*); 101 102 private: 103 DataObject(); 104 explicit DataObject(const DataObject&); 105 106 PassRefPtrWillBeRawPtr<DataObjectItem> findStringItem(const String& type) const; 107 bool internalAddStringItem(PassRefPtrWillBeRawPtr<DataObjectItem>); 108 void internalAddFileItem(PassRefPtrWillBeRawPtr<DataObjectItem>); 109 110 WillBeHeapVector<RefPtrWillBeMember<DataObjectItem> > m_itemList; 111 112 // State of Shift/Ctrl/Alt/Meta keys. 113 int m_modifierKeyState; 114 String m_filesystemId; 115 }; 116 117 } // namespace blink 118 119 #endif 120