OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 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 | 20 |
21 #include "config.h" | 21 #include "config.h" |
22 #include "core/html/FormDataList.h" | 22 #include "core/html/FormDataList.h" |
23 | 23 |
24 #include "core/fileapi/File.h" | 24 #include "core/fileapi/File.h" |
25 #include "platform/network/FormDataBuilder.h" | 25 #include "platform/network/FormDataEncoder.h" |
26 #include "platform/text/LineEnding.h" | 26 #include "platform/text/LineEnding.h" |
27 #include "wtf/CurrentTime.h" | 27 #include "wtf/CurrentTime.h" |
28 | 28 |
29 namespace blink { | 29 namespace blink { |
30 | 30 |
31 FormDataList::FormDataList(const WTF::TextEncoding& c) | 31 FormDataList::FormDataList(const WTF::TextEncoding& c) |
32 : m_encoding(c) | 32 : m_encoding(c) |
33 { | 33 { |
34 } | 34 } |
35 | 35 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 bool FormDataList::hasEntry(const String& key) const | 114 bool FormDataList::hasEntry(const String& key) const |
115 { | 115 { |
116 const CString keyData = encodeAndNormalize(key); | 116 const CString keyData = encodeAndNormalize(key); |
117 for (const Item& item : items()) { | 117 for (const Item& item : items()) { |
118 if (item.key() == keyData) | 118 if (item.key() == keyData) |
119 return true; | 119 return true; |
120 } | 120 } |
121 return false; | 121 return false; |
122 } | 122 } |
123 | 123 |
124 PassRefPtr<FormData> FormDataList::createFormData(FormData::EncodingType encodin gType) | 124 PassRefPtr<EncodedFormData> FormDataList::createFormData(EncodedFormData::Encodi ngType encodingType) |
125 { | 125 { |
126 RefPtr<FormData> result = FormData::create(); | 126 RefPtr<EncodedFormData> result = EncodedFormData::create(); |
127 appendKeyValuePairItemsTo(result.get(), m_encoding, false, encodingType); | 127 appendKeyValuePairItemsTo(result.get(), m_encoding, false, encodingType); |
128 return result.release(); | 128 return result.release(); |
129 } | 129 } |
130 | 130 |
131 PassRefPtr<FormData> FormDataList::createMultiPartFormData() | 131 PassRefPtr<EncodedFormData> FormDataList::createMultiPartFormData() |
132 { | 132 { |
133 RefPtr<FormData> result = FormData::create(); | 133 RefPtr<EncodedFormData> result = EncodedFormData::create(); |
134 appendKeyValuePairItemsTo(result.get(), m_encoding, true); | 134 appendKeyValuePairItemsTo(result.get(), m_encoding, true); |
135 return result.release(); | 135 return result.release(); |
136 } | 136 } |
137 | 137 |
138 void FormDataList::appendKeyValuePairItemsTo(FormData* formData, const WTF::Text Encoding& encoding, bool isMultiPartForm, FormData::EncodingType encodingType) | 138 void FormDataList::appendKeyValuePairItemsTo(EncodedFormData* formData, const WT F::TextEncoding& encoding, bool isMultiPartForm, EncodedFormData::EncodingType e ncodingType) |
139 { | 139 { |
140 if (isMultiPartForm) | 140 if (isMultiPartForm) |
141 formData->setBoundary(FormDataBuilder::generateUniqueBoundaryString()); | 141 formData->setBoundary(FormDataEncoder::generateUniqueBoundaryString()); |
142 | 142 |
143 Vector<char> encodedData; | 143 Vector<char> encodedData; |
144 | 144 |
145 for (const Item& item : items()) { | 145 for (const Item& item : items()) { |
146 if (isMultiPartForm) { | 146 if (isMultiPartForm) { |
147 Vector<char> header; | 147 Vector<char> header; |
148 FormDataBuilder::beginMultiPartHeader(header, formData->boundary().d ata(), item.key()); | 148 FormDataEncoder::beginMultiPartHeader(header, formData->boundary().d ata(), item.key()); |
149 | 149 |
150 // If the current type is blob, then we also need to include the fil ename | 150 // If the current type is blob, then we also need to include the fil ename |
151 if (item.blob()) { | 151 if (item.blob()) { |
152 String name; | 152 String name; |
153 if (item.blob()->isFile()) { | 153 if (item.blob()->isFile()) { |
154 File* file = toFile(item.blob()); | 154 File* file = toFile(item.blob()); |
155 // For file blob, use the filename (or relative path if it i s present) as the name. | 155 // For file blob, use the filename (or relative path if it i s present) as the name. |
156 name = file->webkitRelativePath().isEmpty() ? file->name() : file->webkitRelativePath(); | 156 name = file->webkitRelativePath().isEmpty() ? file->name() : file->webkitRelativePath(); |
157 | 157 |
158 // If a filename is passed in FormData.append(), use it inst ead of the file blob's name. | 158 // If a filename is passed in FormData.append(), use it inst ead of the file blob's name. |
yhirano
2015/09/09 02:14:21
Please update the comment.
tkent
2015/09/09 02:22:18
This |FormData| means the IDL interface |FormData|
yhirano
2015/09/09 02:25:51
I see, thanks.
| |
159 if (!item.filename().isNull()) | 159 if (!item.filename().isNull()) |
160 name = item.filename(); | 160 name = item.filename(); |
161 } else { | 161 } else { |
162 // For non-file blob, use the filename if it is passed in Fo rmData.append(). | 162 // For non-file blob, use the filename if it is passed in Fo rmData.append(). |
yhirano
2015/09/09 02:14:21
ditto
tkent
2015/09/09 02:22:18
Ditto.
| |
163 if (!item.filename().isNull()) | 163 if (!item.filename().isNull()) |
164 name = item.filename(); | 164 name = item.filename(); |
165 else | 165 else |
166 name = "blob"; | 166 name = "blob"; |
167 } | 167 } |
168 | 168 |
169 // We have to include the filename=".." part in the header, even if the filename is empty | 169 // We have to include the filename=".." part in the header, even if the filename is empty |
170 FormDataBuilder::addFilenameToMultiPartHeader(header, encoding, name); | 170 FormDataEncoder::addFilenameToMultiPartHeader(header, encoding, name); |
171 | 171 |
172 // Add the content type if available, or "application/octet-stre am" otherwise (RFC 1867). | 172 // Add the content type if available, or "application/octet-stre am" otherwise (RFC 1867). |
173 String contentType; | 173 String contentType; |
174 if (item.blob()->type().isEmpty()) | 174 if (item.blob()->type().isEmpty()) |
175 contentType = "application/octet-stream"; | 175 contentType = "application/octet-stream"; |
176 else | 176 else |
177 contentType = item.blob()->type(); | 177 contentType = item.blob()->type(); |
178 FormDataBuilder::addContentTypeToMultiPartHeader(header, content Type.latin1()); | 178 FormDataEncoder::addContentTypeToMultiPartHeader(header, content Type.latin1()); |
179 } | 179 } |
180 | 180 |
181 FormDataBuilder::finishMultiPartHeader(header); | 181 FormDataEncoder::finishMultiPartHeader(header); |
182 | 182 |
183 // Append body | 183 // Append body |
184 formData->appendData(header.data(), header.size()); | 184 formData->appendData(header.data(), header.size()); |
185 if (item.blob()) { | 185 if (item.blob()) { |
186 if (item.blob()->hasBackingFile()) { | 186 if (item.blob()->hasBackingFile()) { |
187 File* file = toFile(item.blob()); | 187 File* file = toFile(item.blob()); |
188 // Do not add the file if the path is empty. | 188 // Do not add the file if the path is empty. |
189 if (!file->path().isEmpty()) | 189 if (!file->path().isEmpty()) |
190 formData->appendFile(file->path()); | 190 formData->appendFile(file->path()); |
191 if (!file->fileSystemURL().isEmpty()) | 191 if (!file->fileSystemURL().isEmpty()) |
192 formData->appendFileSystemURL(file->fileSystemURL()); | 192 formData->appendFileSystemURL(file->fileSystemURL()); |
193 } else { | 193 } else { |
194 formData->appendBlob(item.blob()->uuid(), item.blob()->blobD ataHandle()); | 194 formData->appendBlob(item.blob()->uuid(), item.blob()->blobD ataHandle()); |
195 } | 195 } |
196 } else { | 196 } else { |
197 formData->appendData(item.data().data(), item.data().length()); | 197 formData->appendData(item.data().data(), item.data().length()); |
198 } | 198 } |
199 formData->appendData("\r\n", 2); | 199 formData->appendData("\r\n", 2); |
200 } else { | 200 } else { |
201 FormDataBuilder::addKeyValuePairAsFormData(encodedData, item.key(), item.data(), encodingType); | 201 FormDataEncoder::addKeyValuePairAsFormData(encodedData, item.key(), item.data(), encodingType); |
202 } | 202 } |
203 } | 203 } |
204 | 204 |
205 if (isMultiPartForm) | 205 if (isMultiPartForm) |
206 FormDataBuilder::addBoundaryToMultiPartHeader(encodedData, formData->bou ndary().data(), true); | 206 FormDataEncoder::addBoundaryToMultiPartHeader(encodedData, formData->bou ndary().data(), true); |
207 | 207 |
208 formData->appendData(encodedData.data(), encodedData.size()); | 208 formData->appendData(encodedData.data(), encodedData.size()); |
209 } | 209 } |
210 | 210 |
211 CString FormDataList::encodeAndNormalize(const String& string) const | 211 CString FormDataList::encodeAndNormalize(const String& string) const |
212 { | 212 { |
213 CString encodedString = m_encoding.encode(string, WTF::EntitiesForUnencodabl es); | 213 CString encodedString = m_encoding.encode(string, WTF::EntitiesForUnencodabl es); |
214 return normalizeLineEndingsToCRLF(encodedString); | 214 return normalizeLineEndingsToCRLF(encodedString); |
215 } | 215 } |
216 | 216 |
217 DEFINE_TRACE(FormDataList) | 217 DEFINE_TRACE(FormDataList) |
218 { | 218 { |
219 visitor->trace(m_items); | 219 visitor->trace(m_items); |
220 } | 220 } |
221 | 221 |
222 | 222 |
223 DEFINE_TRACE(FormDataList::Entry) | 223 DEFINE_TRACE(FormDataList::Entry) |
224 { | 224 { |
225 visitor->trace(m_file); | 225 visitor->trace(m_file); |
226 } | 226 } |
227 | 227 |
228 DEFINE_TRACE(FormDataList::Item) | 228 DEFINE_TRACE(FormDataList::Item) |
229 { | 229 { |
230 visitor->trace(m_blob); | 230 visitor->trace(m_blob); |
231 } | 231 } |
232 | 232 |
233 } // namespace blink | 233 } // namespace blink |
OLD | NEW |