OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Library General Public License for more details. | 12 * Library General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 * Boston, MA 02110-1301, USA. | 17 * Boston, MA 02110-1301, USA. |
18 */ | 18 */ |
19 | 19 |
20 #ifndef FormData_h | 20 #ifndef FormData_h |
21 #define FormData_h | 21 #define FormData_h |
22 | 22 |
| 23 #include "BlobItem.h" |
23 #include "PlatformString.h" | 24 #include "PlatformString.h" |
24 #include <wtf/RefCounted.h> | 25 #include <wtf/RefCounted.h> |
25 #include <wtf/Vector.h> | 26 #include <wtf/Vector.h> |
26 | 27 |
27 namespace WebCore { | 28 namespace WebCore { |
28 | 29 |
29 class DOMFormData; | |
30 class Document; | 30 class Document; |
| 31 class TextEncoding; |
31 | 32 |
| 33 // A wrapper class of BlobItem for FormData. |
32 class FormDataElement { | 34 class FormDataElement { |
33 public: | 35 public: |
34 FormDataElement() : m_type(data) { } | 36 FormDataElement() : m_data(0) { } |
35 FormDataElement(const Vector<char>& array) : m_type(data), m_data(array) { } | 37 FormDataElement(const Vector<char>& array) : m_type(data), m_data(array) { } |
| 38 |
36 #if ENABLE(BLOB_SLICE) | 39 #if ENABLE(BLOB_SLICE) |
37 FormDataElement(const String& filename, long long fileStart, long long fileL
ength, double expectedFileModificationTime, bool shouldGenerateFile) : m_type(en
codedFile), m_filename(filename), m_fileStart(fileStart), m_fileLength(fileLengt
h), m_expectedFileModificationTime(expectedFileModificationTime), m_shouldGenera
teFile(shouldGenerateFile) { } | 40 FormDataElement(const String& filename, long long fileStart, long long fileL
ength, double expectedFileModificationTime, bool shouldGenerateFile) : m_type(en
codedFile), m_filename(filename), m_fileStart(fileStart), m_fileLength(fileLengt
h), m_expectedFileModificationTime(expectedFileModificationTime), m_shouldGenera
teFile(shouldGenerateFile) { |
| 41 } |
38 #else | 42 #else |
39 FormDataElement(const String& filename, bool shouldGenerateFile) : m_type(en
codedFile), m_filename(filename), m_shouldGenerateFile(shouldGenerateFile) { } | 43 FormDataElement(const String& filename, bool shouldGenerateFile) : m_type(en
codedFile), m_filename(filename), m_shouldGenerateFile(shouldGenerateFile) { } |
40 #endif | 44 #endif |
41 | 45 |
42 enum { data, encodedFile } m_type; | 46 enum { data, encodedFile } m_type; |
43 Vector<char> m_data; | 47 Vector<char> m_data; |
44 String m_filename; | 48 String m_filename; |
45 #if ENABLE(BLOB_SLICE) | 49 #if ENABLE(BLOB_SLICE) |
46 long long m_fileStart; | 50 long long m_fileStart; |
47 long long m_fileLength; | 51 long long m_fileLength; |
48 double m_expectedFileModificationTime; | 52 double m_expectedFileModificationTime; |
| 53 |
| 54 static const long long toEndOfFile; |
| 55 static const double doNotCheckFileChange; |
49 #endif | 56 #endif |
50 String m_generatedFilename; | 57 String m_generatedFilename; |
51 bool m_shouldGenerateFile; | 58 bool m_shouldGenerateFile; |
52 }; | 59 }; |
53 | 60 |
54 inline bool operator==(const FormDataElement& a, const FormDataElement& b) | 61 inline bool operator==(const FormDataElement& a, const FormDataElement& b) |
55 { | 62 { |
56 if (&a == &b) | 63 if (&a == &b) |
57 return true; | 64 return true; |
58 | 65 |
59 if (a.m_type != b.m_type) | 66 if (a.m_type != b.m_type) |
60 return false; | 67 return false; |
61 if (a.m_data != b.m_data) | 68 if (a.m_data != b.m_data) |
62 return false; | 69 return false; |
63 #if ENABLE(BLOB_SLICE) | 70 #if ENABLE(BLOB_SLICE) |
64 if (a.m_filename != b.m_filename || a.m_fileStart != b.m_fileStart || a.m_fi
leLength != b.m_fileLength || a.m_expectedFileModificationTime != b.m_expectedFi
leModificationTime) | 71 if (a.m_filename != b.m_filename || a.m_fileStart != b.m_fileStart || a.m_fi
leLength != b.m_fileLength || a.m_expectedFileModificationTime != b.m_expectedFi
leModificationTime) |
65 #else | 72 #else |
66 if (a.m_filename != b.m_filename) | 73 if (a.m_filename != b.m_filename) |
67 #endif | 74 #endif |
68 return false; | 75 return false; |
69 | 76 |
70 return true; | 77 return true; |
71 } | 78 } |
72 | 79 |
73 inline bool operator!=(const FormDataElement& a, const FormDataElement& b) | 80 inline bool operator!=(const FormDataElement& a, const FormDataElement& b) |
74 { | 81 { |
75 return !(a == b); | 82 return !(a == b); |
76 } | 83 } |
77 | 84 |
78 class FormData : public RefCounted<FormData> { | 85 class FormData : public RefCounted<FormData> { |
79 public: | 86 public: |
80 static PassRefPtr<FormData> create(); | 87 static PassRefPtr<FormData> create(); |
81 static PassRefPtr<FormData> create(const void*, size_t); | 88 static PassRefPtr<FormData> create(const void*, size_t); |
82 static PassRefPtr<FormData> create(const WTF::CString&); | 89 static PassRefPtr<FormData> create(const WTF::CString&); |
83 static PassRefPtr<FormData> create(const Vector<char>&); | 90 static PassRefPtr<FormData> create(const Vector<char>&); |
84 static PassRefPtr<FormData> create(const DOMFormData&); | 91 static PassRefPtr<FormData> create(const BlobItemList&, const TextEncoding&)
; |
85 static PassRefPtr<FormData> createMultiPart(const DOMFormData&, Document*); | 92 static PassRefPtr<FormData> createMultiPart(const BlobItemList&, const TextE
ncoding&, Document*); |
86 PassRefPtr<FormData> copy() const; | 93 PassRefPtr<FormData> copy() const; |
87 PassRefPtr<FormData> deepCopy() const; | 94 PassRefPtr<FormData> deepCopy() const; |
88 ~FormData(); | 95 ~FormData(); |
89 | 96 |
90 void appendData(const void* data, size_t); | 97 void appendData(const void* data, size_t); |
| 98 void appendItems(const BlobItemList&); |
91 void appendFile(const String& filename, bool shouldGenerateFile = false); | 99 void appendFile(const String& filename, bool shouldGenerateFile = false); |
92 #if ENABLE(BLOB_SLICE) | 100 #if ENABLE(BLOB_SLICE) |
93 void appendFileRange(const String& filename, long long start, long long leng
th, double expectedModificationTime, bool shouldGenerateFile = false); | 101 void appendFileRange(const String& filename, long long start, long long leng
th, double expectedModificationTime, bool shouldGenerateFile = false); |
94 #endif | 102 #endif |
95 | 103 |
96 void flatten(Vector<char>&) const; // omits files | 104 void flatten(Vector<char>&) const; // omits files |
97 String flattenToString() const; // omits files | 105 String flattenToString() const; // omits files |
98 | 106 |
99 bool isEmpty() const { return m_elements.isEmpty(); } | 107 bool isEmpty() const { return m_elements.isEmpty(); } |
100 const Vector<FormDataElement>& elements() const { return m_elements; } | 108 const Vector<FormDataElement>& elements() const { return m_elements; } |
101 const Vector<char>& boundary() const { return m_boundary; } | 109 const Vector<char>& boundary() const { return m_boundary; } |
102 | 110 |
103 void generateFiles(Document*); | 111 void generateFiles(Document*); |
104 void removeGeneratedFilesIfNeeded(); | 112 void removeGeneratedFilesIfNeeded(); |
105 | 113 |
106 bool alwaysStream() const { return m_alwaysStream; } | 114 bool alwaysStream() const { return m_alwaysStream; } |
107 void setAlwaysStream(bool alwaysStream) { m_alwaysStream = alwaysStream; } | 115 void setAlwaysStream(bool alwaysStream) { m_alwaysStream = alwaysStream; } |
108 | 116 |
109 // Identifies a particular form submission instance. A value of 0 is used | 117 // Identifies a particular form submission instance. A value of 0 is used |
110 // to indicate an unspecified identifier. | 118 // to indicate an unspecified identifier. |
111 void setIdentifier(int64_t identifier) { m_identifier = identifier; } | 119 void setIdentifier(int64_t identifier) { m_identifier = identifier; } |
112 int64_t identifier() const { return m_identifier; } | 120 int64_t identifier() const { return m_identifier; } |
113 | 121 |
114 private: | 122 private: |
115 FormData(); | 123 FormData(); |
116 FormData(const FormData&); | 124 FormData(const FormData&); |
117 | 125 |
118 void appendDOMFormData(const DOMFormData& domFormData, bool isMultiPartForm,
Document* document); | 126 void appendItem(const BlobItem*, bool shouldGenerateFile); |
| 127 void appendKeyValuePairItems(const BlobItemList&, const TextEncoding&, bool
isMultiPartForm, Document*); |
119 | 128 |
120 Vector<FormDataElement> m_elements; | 129 Vector<FormDataElement> m_elements; |
| 130 |
121 int64_t m_identifier; | 131 int64_t m_identifier; |
122 bool m_hasGeneratedFiles; | 132 bool m_hasGeneratedFiles; |
123 bool m_alwaysStream; | 133 bool m_alwaysStream; |
124 Vector<char> m_boundary; | 134 Vector<char> m_boundary; |
125 }; | 135 }; |
126 | 136 |
127 inline bool operator==(const FormData& a, const FormData& b) | 137 inline bool operator==(const FormData& a, const FormData& b) |
128 { | 138 { |
129 return a.elements() == b.elements(); | 139 return a.elements() == b.elements(); |
130 } | 140 } |
131 | 141 |
132 inline bool operator!=(const FormData& a, const FormData& b) | 142 inline bool operator!=(const FormData& a, const FormData& b) |
133 { | 143 { |
134 return a.elements() != b.elements(); | 144 return !(a == b); |
135 } | 145 } |
136 | 146 |
137 } // namespace WebCore | 147 } // namespace WebCore |
138 | 148 |
139 #endif | 149 #endif |
OLD | NEW |