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 #ifndef WebDragData_h 32 #define WebDragData_h 33 34 #include "WebCommon.h" 35 #include "WebData.h" 36 #include "WebString.h" 37 #include "WebURL.h" 38 39 #if BLINK_IMPLEMENTATION 40 namespace WebCore { class ChromiumDataObject; } 41 namespace WTF { template <typename T> class PassRefPtr; } 42 #endif 43 44 namespace blink { 45 46 class WebDragDataPrivate; 47 template <typename T> class WebVector; 48 49 // Holds data that may be exchanged through a drag-n-drop operation. It is 50 // inexpensive to copy a WebDragData object. 51 class WebDragData { 52 public: 53 struct Item { 54 enum StorageType { 55 // String data with an associated MIME type. Depending on the MIME type, there may be 56 // optional metadata attributes as well. 57 StorageTypeString, 58 // Stores the name of one file being dragged into the renderer. 59 StorageTypeFilename, 60 // An image being dragged out of the renderer. Contains a buffer holding the image data 61 // as well as the suggested name for saving the image to. 62 StorageTypeBinaryData, 63 }; 64 65 StorageType storageType; 66 67 // Only valid when storageType == StorageTypeString. 68 WebString stringType; 69 WebString stringData; 70 71 // Only valid when storageType == StorageTypeFilename. 72 WebString filenameData; 73 WebString displayNameData; 74 75 // Only valid when storageType == StorageTypeBinaryData. 76 WebData binaryData; 77 78 // Title associated with a link when stringType == "text/uri-list". 79 // Filename when storageType == StorageTypeBinaryData. 80 WebString title; 81 82 // Only valid when stringType == "text/html". 83 WebURL baseURL; 84 }; 85 86 ~WebDragData() { reset(); } 87 88 WebDragData() : m_private(0) { } 89 WebDragData(const WebDragData& d) : m_private(0) { assign(d); } 90 WebDragData& operator=(const WebDragData& d) 91 { 92 assign(d); 93 return *this; 94 } 95 96 BLINK_EXPORT void initialize(); 97 BLINK_EXPORT void reset(); 98 BLINK_EXPORT void assign(const WebDragData&); 99 100 bool isNull() const { return !m_private; } 101 102 BLINK_EXPORT WebVector<Item> items() const; 103 BLINK_EXPORT void setItems(const WebVector<Item>&); 104 BLINK_EXPORT void addItem(const Item&); 105 106 BLINK_EXPORT WebString filesystemId() const; 107 BLINK_EXPORT void setFilesystemId(const WebString&); 108 109 #if BLINK_IMPLEMENTATION 110 WebDragData(const WTF::PassRefPtr<WebCore::ChromiumDataObject>&); 111 WebDragData& operator=(const WTF::PassRefPtr<WebCore::ChromiumDataObject>&); 112 operator WTF::PassRefPtr<WebCore::ChromiumDataObject>() const; 113 #endif 114 115 private: 116 void assign(WebDragDataPrivate*); 117 void ensureMutable(); 118 WebDragDataPrivate* m_private; 119 }; 120 121 } // namespace blink 122 123 #endif 124