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