2 * Copyright (C) 2004, 2006, 2008, 2011 Apple Inc. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
23 #include "platform/blob/BlobData.h"
24 #include "platform/weborigin/KURL.h"
25 #include "wtf/Forward.h"
26 #include "wtf/RefCounted.h"
27 #include "wtf/Vector.h"
28 #include "wtf/text/WTFString.h"
38 class PLATFORM_EXPORT FormDataElement {
40 FormDataElement() : m_type(data) { }
41 explicit FormDataElement(const Vector<char>& array) : m_type(data), m_data(array) { }
43 FormDataElement(const String& filename, long long fileStart, long long fileLength, double expectedFileModificationTime) : m_type(encodedFile), m_filename(filename), m_fileStart(fileStart), m_fileLength(fileLength), m_expectedFileModificationTime(expectedFileModificationTime) { }
44 explicit FormDataElement(const String& blobUUID, PassRefPtr<BlobDataHandle> optionalHandle) : m_type(encodedBlob), m_blobUUID(blobUUID), m_optionalBlobDataHandle(optionalHandle) { }
45 FormDataElement(const KURL& fileSystemURL, long long start, long long length, double expectedFileModificationTime) : m_type(encodedFileSystemURL), m_fileSystemURL(fileSystemURL), m_fileStart(start), m_fileLength(length), m_expectedFileModificationTime(expectedFileModificationTime) { }
56 RefPtr<BlobDataHandle> m_optionalBlobDataHandle;
58 long long m_fileStart;
59 long long m_fileLength;
60 double m_expectedFileModificationTime;
63 inline bool operator==(const FormDataElement& a, const FormDataElement& b)
68 if (a.m_type != b.m_type)
70 if (a.m_type == FormDataElement::data)
71 return a.m_data == b.m_data;
72 if (a.m_type == FormDataElement::encodedFile)
73 return a.m_filename == b.m_filename && a.m_fileStart == b.m_fileStart && a.m_fileLength == b.m_fileLength && a.m_expectedFileModificationTime == b.m_expectedFileModificationTime;
74 if (a.m_type == FormDataElement::encodedBlob)
75 return a.m_blobUUID == b.m_blobUUID;
76 if (a.m_type == FormDataElement::encodedFileSystemURL)
77 return a.m_fileSystemURL == b.m_fileSystemURL;
82 inline bool operator!=(const FormDataElement& a, const FormDataElement& b)
87 class PLATFORM_EXPORT FormData : public RefCounted<FormData> {
90 FormURLEncoded, // for application/x-www-form-urlencoded
91 TextPlain, // for text/plain
92 MultipartFormData // for multipart/form-data
95 static PassRefPtr<FormData> create();
96 static PassRefPtr<FormData> create(const void*, size_t);
97 static PassRefPtr<FormData> create(const CString&);
98 static PassRefPtr<FormData> create(const Vector<char>&);
99 PassRefPtr<FormData> copy() const;
100 PassRefPtr<FormData> deepCopy() const;
103 void appendData(const void* data, size_t);
104 void appendFile(const String& filePath);
105 void appendFileRange(const String& filename, long long start, long long length, double expectedModificationTime);
106 void appendBlob(const String& blobUUID, PassRefPtr<BlobDataHandle> optionalHandle);
107 void appendFileSystemURL(const KURL&);
108 void appendFileSystemURLRange(const KURL&, long long start, long long length, double expectedModificationTime);
110 void flatten(Vector<char>&) const; // omits files
111 String flattenToString() const; // omits files
113 bool isEmpty() const { return m_elements.isEmpty(); }
114 const Vector<FormDataElement>& elements() const { return m_elements; }
116 const Vector<char>& boundary() const { return m_boundary; }
117 void setBoundary(Vector<char> boundary) { m_boundary = boundary; }
119 bool alwaysStream() const { return m_alwaysStream; }
120 void setAlwaysStream(bool alwaysStream) { m_alwaysStream = alwaysStream; }
122 // Identifies a particular form submission instance. A value of 0 is used
123 // to indicate an unspecified identifier.
124 void setIdentifier(int64_t identifier) { m_identifier = identifier; }
125 int64_t identifier() const { return m_identifier; }
127 bool containsPasswordData() const { return m_containsPasswordData; }
128 void setContainsPasswordData(bool containsPasswordData) { m_containsPasswordData = containsPasswordData; }
130 static EncodingType parseEncodingType(const String& type)
132 if (equalIgnoringCase(type, "text/plain"))
134 if (equalIgnoringCase(type, "multipart/form-data"))
135 return MultipartFormData;
136 return FormURLEncoded;
139 // Size of the elements making up the FormData.
140 unsigned long long sizeInBytes() const;
144 FormData(const FormData&);
146 Vector<FormDataElement> m_elements;
148 int64_t m_identifier;
150 Vector<char> m_boundary;
151 bool m_containsPasswordData;
154 inline bool operator==(const FormData& a, const FormData& b)
156 return a.elements() == b.elements();
159 inline bool operator!=(const FormData& a, const FormData& b)
164 } // namespace WebCore