Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(561)

Side by Side Diff: Source/core/html/FormDataList.cpp

Issue 1311923004: Rename FormData/FormDataBuilder to EncodedFormData/FormDataEncoder respectively. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: update comments Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/html/FormDataList.h ('k') | Source/core/html/parser/XSSAuditor.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 DOMFormData.append(), use it
159 // instead of the file blob's name.
159 if (!item.filename().isNull()) 160 if (!item.filename().isNull())
160 name = item.filename(); 161 name = item.filename();
161 } else { 162 } else {
162 // For non-file blob, use the filename if it is passed in Fo rmData.append(). 163 // For non-file blob, use the filename if it is passed in
164 // DOMFormData.append().
163 if (!item.filename().isNull()) 165 if (!item.filename().isNull())
164 name = item.filename(); 166 name = item.filename();
165 else 167 else
166 name = "blob"; 168 name = "blob";
167 } 169 }
168 170
169 // We have to include the filename=".." part in the header, even if the filename is empty 171 // We have to include the filename=".." part in the header, even if the filename is empty
170 FormDataBuilder::addFilenameToMultiPartHeader(header, encoding, name); 172 FormDataEncoder::addFilenameToMultiPartHeader(header, encoding, name);
171 173
172 // Add the content type if available, or "application/octet-stre am" otherwise (RFC 1867). 174 // Add the content type if available, or "application/octet-stre am" otherwise (RFC 1867).
173 String contentType; 175 String contentType;
174 if (item.blob()->type().isEmpty()) 176 if (item.blob()->type().isEmpty())
175 contentType = "application/octet-stream"; 177 contentType = "application/octet-stream";
176 else 178 else
177 contentType = item.blob()->type(); 179 contentType = item.blob()->type();
178 FormDataBuilder::addContentTypeToMultiPartHeader(header, content Type.latin1()); 180 FormDataEncoder::addContentTypeToMultiPartHeader(header, content Type.latin1());
179 } 181 }
180 182
181 FormDataBuilder::finishMultiPartHeader(header); 183 FormDataEncoder::finishMultiPartHeader(header);
182 184
183 // Append body 185 // Append body
184 formData->appendData(header.data(), header.size()); 186 formData->appendData(header.data(), header.size());
185 if (item.blob()) { 187 if (item.blob()) {
186 if (item.blob()->hasBackingFile()) { 188 if (item.blob()->hasBackingFile()) {
187 File* file = toFile(item.blob()); 189 File* file = toFile(item.blob());
188 // Do not add the file if the path is empty. 190 // Do not add the file if the path is empty.
189 if (!file->path().isEmpty()) 191 if (!file->path().isEmpty())
190 formData->appendFile(file->path()); 192 formData->appendFile(file->path());
191 if (!file->fileSystemURL().isEmpty()) 193 if (!file->fileSystemURL().isEmpty())
192 formData->appendFileSystemURL(file->fileSystemURL()); 194 formData->appendFileSystemURL(file->fileSystemURL());
193 } else { 195 } else {
194 formData->appendBlob(item.blob()->uuid(), item.blob()->blobD ataHandle()); 196 formData->appendBlob(item.blob()->uuid(), item.blob()->blobD ataHandle());
195 } 197 }
196 } else { 198 } else {
197 formData->appendData(item.data().data(), item.data().length()); 199 formData->appendData(item.data().data(), item.data().length());
198 } 200 }
199 formData->appendData("\r\n", 2); 201 formData->appendData("\r\n", 2);
200 } else { 202 } else {
201 FormDataBuilder::addKeyValuePairAsFormData(encodedData, item.key(), item.data(), encodingType); 203 FormDataEncoder::addKeyValuePairAsFormData(encodedData, item.key(), item.data(), encodingType);
202 } 204 }
203 } 205 }
204 206
205 if (isMultiPartForm) 207 if (isMultiPartForm)
206 FormDataBuilder::addBoundaryToMultiPartHeader(encodedData, formData->bou ndary().data(), true); 208 FormDataEncoder::addBoundaryToMultiPartHeader(encodedData, formData->bou ndary().data(), true);
207 209
208 formData->appendData(encodedData.data(), encodedData.size()); 210 formData->appendData(encodedData.data(), encodedData.size());
209 } 211 }
210 212
211 CString FormDataList::encodeAndNormalize(const String& string) const 213 CString FormDataList::encodeAndNormalize(const String& string) const
212 { 214 {
213 CString encodedString = m_encoding.encode(string, WTF::EntitiesForUnencodabl es); 215 CString encodedString = m_encoding.encode(string, WTF::EntitiesForUnencodabl es);
214 return normalizeLineEndingsToCRLF(encodedString); 216 return normalizeLineEndingsToCRLF(encodedString);
215 } 217 }
216 218
217 DEFINE_TRACE(FormDataList) 219 DEFINE_TRACE(FormDataList)
218 { 220 {
219 visitor->trace(m_items); 221 visitor->trace(m_items);
220 } 222 }
221 223
222 224
223 DEFINE_TRACE(FormDataList::Entry) 225 DEFINE_TRACE(FormDataList::Entry)
224 { 226 {
225 visitor->trace(m_file); 227 visitor->trace(m_file);
226 } 228 }
227 229
228 DEFINE_TRACE(FormDataList::Item) 230 DEFINE_TRACE(FormDataList::Item)
229 { 231 {
230 visitor->trace(m_blob); 232 visitor->trace(m_blob);
231 } 233 }
232 234
233 } // namespace blink 235 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/html/FormDataList.h ('k') | Source/core/html/parser/XSSAuditor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698