|
Lines 26-33
a/WebCore/html/HTMLFormElement.cpp_sec1
|
| 26 |
#include "HTMLFormElement.h" |
26 |
#include "HTMLFormElement.h" |
| 27 |
|
27 |
|
| 28 |
#include "CSSHelper.h" |
28 |
#include "CSSHelper.h" |
| 29 |
#include "Chrome.h" |
29 |
#include "DOMFormData.h" |
| 30 |
#include "ChromeClient.h" |
|
|
| 31 |
#include "Document.h" |
30 |
#include "Document.h" |
| 32 |
#include "Event.h" |
31 |
#include "Event.h" |
| 33 |
#include "EventNames.h" |
32 |
#include "EventNames.h" |
|
Lines 46-52
a/WebCore/html/HTMLFormElement.cpp_sec2
|
| 46 |
#include "ScriptEventListener.h" |
45 |
#include "ScriptEventListener.h" |
| 47 |
#include "MIMETypeRegistry.h" |
46 |
#include "MIMETypeRegistry.h" |
| 48 |
#include "MappedAttribute.h" |
47 |
#include "MappedAttribute.h" |
| 49 |
#include "Page.h" |
|
|
| 50 |
#include "RenderTextControl.h" |
48 |
#include "RenderTextControl.h" |
| 51 |
#include "ValidityState.h" |
49 |
#include "ValidityState.h" |
| 52 |
#include <limits> |
50 |
#include <limits> |
|
Lines 201-283
TextEncoding HTMLFormElement::dataEncoding() const
a/WebCore/html/HTMLFormElement.cpp_sec3
|
| 201 |
return m_formDataBuilder.dataEncoding(document()); |
199 |
return m_formDataBuilder.dataEncoding(document()); |
| 202 |
} |
200 |
} |
| 203 |
|
201 |
|
| 204 |
PassRefPtr<FormData> HTMLFormElement::createFormData(const CString& boundary) |
202 |
PassRefPtr<FormData> HTMLFormElement::createFormData() |
| 205 |
{ |
203 |
{ |
| 206 |
Vector<char> encodedData; |
204 |
RefPtr<DOMFormData> domFormData = createDOMFormData(); |
| 207 |
TextEncoding encoding = dataEncoding().encodingForFormSubmission(); |
|
|
| 208 |
|
205 |
|
| 209 |
RefPtr<FormData> result = FormData::create(); |
206 |
RefPtr<FormData> result = FormData::create(*domFormData, m_formDataBuilder.isMultiPartForm(), document()); |
| 210 |
|
|
|
| 211 |
for (unsigned i = 0; i < formElements.size(); ++i) { |
| 212 |
HTMLFormControlElement* control = formElements[i]; |
| 213 |
FormDataList list(encoding); |
| 214 |
|
| 215 |
if (!control->disabled() && control->appendFormData(list, m_formDataBuilder.isMultiPartForm())) { |
| 216 |
size_t formDataListSize = list.list().size(); |
| 217 |
ASSERT(formDataListSize % 2 == 0); |
| 218 |
for (size_t j = 0; j < formDataListSize; j += 2) { |
| 219 |
const FormDataList::Item& key = list.list()[j]; |
| 220 |
const FormDataList::Item& value = list.list()[j + 1]; |
| 221 |
if (!m_formDataBuilder.isMultiPartForm()) { |
| 222 |
// Omit the name "isindex" if it's the first form data element. |
| 223 |
// FIXME: Why is this a good rule? Is this obsolete now? |
| 224 |
if (encodedData.isEmpty() && key.data() == "isindex") |
| 225 |
FormDataBuilder::encodeStringAsFormData(encodedData, value.data()); |
| 226 |
else |
| 227 |
m_formDataBuilder.addKeyValuePairAsFormData(encodedData, key.data(), value.data()); |
| 228 |
} else { |
| 229 |
Vector<char> header; |
| 230 |
m_formDataBuilder.beginMultiPartHeader(header, boundary, key.data()); |
| 231 |
|
| 232 |
bool shouldGenerateFile = false; |
| 233 |
// if the current type is FILE, then we also need to include the filename |
| 234 |
if (value.file()) { |
| 235 |
const String& path = value.file()->path(); |
| 236 |
String fileName = value.file()->fileName(); |
| 237 |
|
| 238 |
// Let the application specify a filename if it's going to generate a replacement file for the upload. |
| 239 |
if (!path.isEmpty()) { |
| 240 |
if (Page* page = document()->page()) { |
| 241 |
String generatedFileName; |
| 242 |
shouldGenerateFile = page->chrome()->client()->shouldReplaceWithGeneratedFileForUpload(path, generatedFileName); |
| 243 |
if (shouldGenerateFile) |
| 244 |
fileName = generatedFileName; |
| 245 |
} |
| 246 |
} |
| 247 |
|
| 248 |
// We have to include the filename=".." part in the header, even if the filename is empty |
| 249 |
m_formDataBuilder.addFilenameToMultiPartHeader(header, encoding, fileName); |
| 250 |
|
| 251 |
if (!fileName.isEmpty()) { |
| 252 |
// FIXME: The MIMETypeRegistry function's name makes it sound like it takes a path, |
| 253 |
// not just a basename. But filename is not the path. But note that it's not safe to |
| 254 |
// just use path instead since in the generated-file case it will not reflect the |
| 255 |
// MIME type of the generated file. |
| 256 |
String mimeType = MIMETypeRegistry::getMIMETypeForPath(fileName); |
| 257 |
if (!mimeType.isEmpty()) |
| 258 |
m_formDataBuilder.addContentTypeToMultiPartHeader(header, mimeType.latin1()); |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
m_formDataBuilder.finishMultiPartHeader(header); |
| 263 |
|
| 264 |
// Append body |
| 265 |
result->appendData(header.data(), header.size()); |
| 266 |
if (size_t dataSize = value.data().length()) |
| 267 |
result->appendData(value.data().data(), dataSize); |
| 268 |
else if (value.file() && !value.file()->path().isEmpty()) |
| 269 |
result->appendFile(value.file()->path(), shouldGenerateFile); |
| 270 |
|
| 271 |
result->appendData("\r\n", 2); |
| 272 |
} |
| 273 |
} |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
if (m_formDataBuilder.isMultiPartForm()) |
| 278 |
m_formDataBuilder.addBoundaryToMultiPartHeader(encodedData, boundary, true); |
| 279 |
|
| 280 |
result->appendData(encodedData.data(), encodedData.size()); |
| 281 |
|
207 |
|
| 282 |
result->setIdentifier(generateFormDataIdentifier()); |
208 |
result->setIdentifier(generateFormDataIdentifier()); |
| 283 |
return result; |
209 |
return result; |
|
Lines 389-396
void HTMLFormElement::submit(Event* event, bool activateSubmitButton, bool lockH
a/WebCore/html/HTMLFormElement.cpp_sec4
|
| 389 |
ASSERT(!m_formDataBuilder.isMultiPartForm()); |
315 |
ASSERT(!m_formDataBuilder.isMultiPartForm()); |
| 390 |
} |
316 |
} |
| 391 |
|
317 |
|
|
|
318 |
RefPtr<FormData> data = createFormData(); |
| 392 |
if (!m_formDataBuilder.isMultiPartForm()) { |
319 |
if (!m_formDataBuilder.isMultiPartForm()) { |
| 393 |
RefPtr<FormData> data = createFormData(CString()); |
|
|
| 394 |
|
320 |
|
| 395 |
if (isMailtoForm()) { |
321 |
if (isMailtoForm()) { |
| 396 |
// Convert the form data into a string that we put into the URL. |
322 |
// Convert the form data into a string that we put into the URL. |
|
Lines 400-412
void HTMLFormElement::submit(Event* event, bool activateSubmitButton, bool lockH
a/WebCore/html/HTMLFormElement.cpp_sec5
|
| 400 |
} |
326 |
} |
| 401 |
|
327 |
|
| 402 |
frame->loader()->submitForm("POST", m_url, data.release(), m_target, m_formDataBuilder.encodingType(), String(), lockHistory, event, formState.release()); |
328 |
frame->loader()->submitForm("POST", m_url, data.release(), m_target, m_formDataBuilder.encodingType(), String(), lockHistory, event, formState.release()); |
| 403 |
} else { |
329 |
} else |
| 404 |
Vector<char> boundary = m_formDataBuilder.generateUniqueBoundaryString(); |
330 |
frame->loader()->submitForm("POST", m_url, data.get(), m_target, m_formDataBuilder.encodingType(), data->boundary().data(), lockHistory, event, formState.release()); |
| 405 |
frame->loader()->submitForm("POST", m_url, createFormData(boundary.data()), m_target, m_formDataBuilder.encodingType(), boundary.data(), lockHistory, event, formState.release()); |
|
|
| 406 |
} |
| 407 |
} else { |
331 |
} else { |
| 408 |
m_formDataBuilder.setIsMultiPartForm(false); |
332 |
m_formDataBuilder.setIsMultiPartForm(false); |
| 409 |
frame->loader()->submitForm("GET", m_url, createFormData(CString()), m_target, String(), String(), lockHistory, event, formState.release()); |
333 |
frame->loader()->submitForm("GET", m_url, createFormData(), m_target, String(), String(), lockHistory, event, formState.release()); |
| 410 |
} |
334 |
} |
| 411 |
|
335 |
|
| 412 |
if (needButtonActivation && firstSuccessfulSubmitButton) |
336 |
if (needButtonActivation && firstSuccessfulSubmitButton) |
|
Lines 685-688
void HTMLFormElement::didMoveToNewOwnerDocument()
a/WebCore/html/HTMLFormElement.cpp_sec6
|
| 685 |
HTMLElement::didMoveToNewOwnerDocument(); |
609 |
HTMLElement::didMoveToNewOwnerDocument(); |
| 686 |
} |
610 |
} |
| 687 |
|
611 |
|
|
|
612 |
PassRefPtr<DOMFormData> HTMLFormElement::createDOMFormData() |
| 613 |
{ |
| 614 |
FormDataList list(dataEncoding().encodingForFormSubmission()); |
| 615 |
for (unsigned i = 0; i < formElements.size(); ++i) { |
| 616 |
HTMLFormControlElement* control = formElements[i]; |
| 617 |
if (!control->disabled()) |
| 618 |
control->appendFormData(list, m_formDataBuilder.isMultiPartForm()); |
| 619 |
} |
| 620 |
return DOMFormData::create(list); |
| 621 |
} |
| 622 |
|
| 688 |
} // namespace |
623 |
} // namespace |