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