2 * Copyright (C) 2004, 2006, 2008 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 "PlatformString.h"
24 #include <wtf/RefCounted.h>
25 #include <wtf/Vector.h>
31 class FormDataElement
{
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
) { }
37 enum { data
, encodedFile
} m_type
;
40 String m_generatedFilename
;
41 bool m_shouldGenerateFile
;
44 inline bool operator==(const FormDataElement
& a
, const FormDataElement
& b
)
49 if (a
.m_type
!= b
.m_type
)
51 if (a
.m_data
!= b
.m_data
)
53 if (a
.m_filename
!= b
.m_filename
)
59 inline bool operator!=(const FormDataElement
& a
, const FormDataElement
& b
)
64 class FormData
: public RefCounted
<FormData
> {
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;
74 void appendData(const void* data
, size_t);
75 void appendFile(const String
& filename
, bool shouldGenerateFile
= false);
77 void flatten(Vector
<char>&) const; // omits files
78 String
flattenToString() const; // omits files
80 bool isEmpty() const { return m_elements
.isEmpty(); }
81 const Vector
<FormDataElement
>& elements() const { return m_elements
; }
83 void generateFiles(ChromeClient
*);
84 void removeGeneratedFilesIfNeeded();
86 bool alwaysStream() const { return m_alwaysStream
; }
87 void setAlwaysStream(bool alwaysStream
) { m_alwaysStream
= alwaysStream
; }
91 FormData(const FormData
&);
93 Vector
<FormDataElement
> m_elements
;
94 bool m_hasGeneratedFiles
;
98 inline bool operator==(const FormData
& a
, const FormData
& b
)
100 return a
.elements() == b
.elements();
103 inline bool operator!=(const FormData
& a
, const FormData
& b
)
105 return a
.elements() != b
.elements();
108 } // namespace WebCore