]> git.saurik.com Git - iphone-api.git/blob - WebCore/FormData.h
Add support for new WinterBoard Settings features.
[iphone-api.git] / WebCore / FormData.h
1 /*
2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved.
3 *
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.
8 *
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.
13 *
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.
18 */
19
20 #ifndef FormData_h
21 #define FormData_h
22
23 #include "PlatformString.h"
24 #include <wtf/RefCounted.h>
25 #include <wtf/Vector.h>
26
27 namespace WebCore {
28
29 class ChromeClient;
30
31 class FormDataElement {
32 public:
33 FormDataElement() : m_type(data) { }
34 FormDataElement(const Vector<char>& array) : m_type(data), m_data(array) { }
35 FormDataElement(const String& filename, bool shouldGenerateFile) : m_type(encodedFile), m_filename(filename), m_shouldGenerateFile(shouldGenerateFile) { }
36
37 enum { data, encodedFile } m_type;
38 Vector<char> m_data;
39 String m_filename;
40 String m_generatedFilename;
41 bool m_shouldGenerateFile;
42 };
43
44 inline bool operator==(const FormDataElement& a, const FormDataElement& b)
45 {
46 if (&a == &b)
47 return true;
48
49 if (a.m_type != b.m_type)
50 return false;
51 if (a.m_data != b.m_data)
52 return false;
53 if (a.m_filename != b.m_filename)
54 return false;
55
56 return true;
57 }
58
59 inline bool operator!=(const FormDataElement& a, const FormDataElement& b)
60 {
61 return !(a == b);
62 }
63
64 class FormData : public RefCounted<FormData> {
65 public:
66 static PassRefPtr<FormData> create();
67 static PassRefPtr<FormData> create(const void*, size_t);
68 static PassRefPtr<FormData> create(const CString&);
69 static PassRefPtr<FormData> create(const Vector<char>&);
70 PassRefPtr<FormData> copy() const;
71 PassRefPtr<FormData> deepCopy() const;
72 ~FormData();
73
74 void appendData(const void* data, size_t);
75 void appendFile(const String& filename, bool shouldGenerateFile = false);
76
77 void flatten(Vector<char>&) const; // omits files
78 String flattenToString() const; // omits files
79
80 bool isEmpty() const { return m_elements.isEmpty(); }
81 const Vector<FormDataElement>& elements() const { return m_elements; }
82
83 void generateFiles(ChromeClient*);
84 void removeGeneratedFilesIfNeeded();
85
86 bool alwaysStream() const { return m_alwaysStream; }
87 void setAlwaysStream(bool alwaysStream) { m_alwaysStream = alwaysStream; }
88
89 private:
90 FormData();
91 FormData(const FormData&);
92
93 Vector<FormDataElement> m_elements;
94 bool m_hasGeneratedFiles;
95 bool m_alwaysStream;
96 };
97
98 inline bool operator==(const FormData& a, const FormData& b)
99 {
100 return a.elements() == b.elements();
101 }
102
103 inline bool operator!=(const FormData& a, const FormData& b)
104 {
105 return a.elements() != b.elements();
106 }
107
108 } // namespace WebCore
109
110 #endif