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 WebHTTPBody_h 32 #define WebHTTPBody_h 33 34 #include "WebData.h" 35 #include "WebFileInfo.h" 36 #include "WebNonCopyable.h" 37 #include "WebString.h" 38 39 #if WEBKIT_IMPLEMENTATION 40 namespace WebCore { class FormData; } 41 namespace WTF { template <typename T> class PassRefPtr; } 42 #endif 43 44 namespace WebKit { 45 46 class WebHTTPBodyPrivate; 47 48 class WebHTTPBody { 49 public: 50 struct Element { 51 enum { TypeData, TypeFile } type; 52 WebData data; 53 WebString filePath; 54 long long fileStart; 55 long long fileLength; // -1 means to the end of the file. 56 WebFileInfo fileInfo; 57 }; 58 59 ~WebHTTPBody() { reset(); } 60 61 WebHTTPBody() : m_private(0) { } 62 WebHTTPBody(const WebHTTPBody& b) : m_private(0) { assign(b); } 63 WebHTTPBody& operator=(const WebHTTPBody& b) 64 { 65 assign(b); 66 return *this; 67 } 68 69 WEBKIT_API void initialize(); 70 WEBKIT_API void reset(); 71 WEBKIT_API void assign(const WebHTTPBody&); 72 73 bool isNull() const { return !m_private; } 74 75 // Returns the number of elements comprising the http body. 76 WEBKIT_API size_t elementCount() const; 77 78 // Sets the values of the element at the given index. Returns false if 79 // index is out of bounds. 80 WEBKIT_API bool elementAt(size_t index, Element&) const; 81 82 // Append to the list of elements. 83 WEBKIT_API void appendData(const WebData&); 84 WEBKIT_API void appendFile(const WebString&); // FIXME: to be removed. 85 // Passing -1 to fileLength means to the end of the file. 86 WEBKIT_API void appendFile(const WebString&, long long fileStart, long long fileLength, const WebFileInfo&); 87 88 // Identifies a particular form submission instance. A value of 0 is 89 // used to indicate an unspecified identifier. 90 WEBKIT_API long long identifier() const; 91 WEBKIT_API void setIdentifier(long long); 92 93 #if WEBKIT_IMPLEMENTATION 94 WebHTTPBody(const WTF::PassRefPtr<WebCore::FormData>&); 95 WebHTTPBody& operator=(const WTF::PassRefPtr<WebCore::FormData>&); 96 operator WTF::PassRefPtr<WebCore::FormData>() const; 97 #endif 98 99 private: 100 void assign(WebHTTPBodyPrivate*); 101 void ensureMutable(); 102 WebHTTPBodyPrivate* m_private; 103 }; 104 105 } // namespace WebKit 106 107 #endif 108