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 "WebNonCopyable.h" 36#include "WebString.h" 37#include "WebURL.h" 38 39#if WEBKIT_IMPLEMENTATION 40namespace WebCore { class FormData; } 41namespace WTF { template <typename T> class PassRefPtr; } 42#endif 43 44namespace WebKit { 45 46class WebHTTPBodyPrivate; 47 48class WebHTTPBody { 49public: 50 struct Element { 51 enum Type { TypeData, TypeFile, TypeBlob, TypeURL } type; 52 WebData data; 53 WebString filePath; 54 long long fileStart; 55 long long fileLength; // -1 means to the end of the file. 56 double modificationTime; 57 WebURL url; // For TypeBlob or TypeURL. 58 59 // FIXME: deprecate this. 60 WebURL blobURL; 61 }; 62 63 ~WebHTTPBody() { reset(); } 64 65 WebHTTPBody() : m_private(0) { } 66 WebHTTPBody(const WebHTTPBody& b) : m_private(0) { assign(b); } 67 WebHTTPBody& operator=(const WebHTTPBody& b) 68 { 69 assign(b); 70 return *this; 71 } 72 73 WEBKIT_EXPORT void initialize(); 74 WEBKIT_EXPORT void reset(); 75 WEBKIT_EXPORT void assign(const WebHTTPBody&); 76 77 bool isNull() const { return !m_private; } 78 79 // Returns the number of elements comprising the http body. 80 WEBKIT_EXPORT size_t elementCount() const; 81 82 // Sets the values of the element at the given index. Returns false if 83 // index is out of bounds. 84 WEBKIT_EXPORT bool elementAt(size_t index, Element&) const; 85 86 // Append to the list of elements. 87 WEBKIT_EXPORT void appendData(const WebData&); 88 WEBKIT_EXPORT void appendFile(const WebString&); 89 // Passing -1 to fileLength means to the end of the file. 90 WEBKIT_EXPORT void appendFileRange(const WebString&, long long fileStart, long long fileLength, double modificationTime); 91 WEBKIT_EXPORT void appendBlob(const WebURL&); 92 93 // Append a resource which is identified by URL. Currently we only support FileSystem URL. 94 WEBKIT_EXPORT void appendURLRange(const WebURL&, long long start, long long length, double modificationTime); 95 96 // Identifies a particular form submission instance. A value of 0 is 97 // used to indicate an unspecified identifier. 98 WEBKIT_EXPORT long long identifier() const; 99 WEBKIT_EXPORT void setIdentifier(long long); 100 101 WEBKIT_EXPORT bool containsPasswordData() const; 102 WEBKIT_EXPORT void setContainsPasswordData(bool); 103 104#if WEBKIT_IMPLEMENTATION 105 WebHTTPBody(const WTF::PassRefPtr<WebCore::FormData>&); 106 WebHTTPBody& operator=(const WTF::PassRefPtr<WebCore::FormData>&); 107 operator WTF::PassRefPtr<WebCore::FormData>() const; 108#endif 109 110private: 111 void assign(WebHTTPBodyPrivate*); 112 void ensureMutable(); 113 WebHTTPBodyPrivate* m_private; 114}; 115 116} // namespace WebKit 117 118#endif 119