bool HTMLTextAreaElement::appendFormData(FormDataList& encoding, bool) { if (name().isEmpty()) return false; document()->updateLayout(); const String& text = (m_wrap == HardWrap) ? valueWithHardLineBreaks() : value(); encoding.appendData(name(), text); const AtomicString& dirnameAttrValue = fastGetAttribute(dirnameAttr); if (!dirnameAttrValue.isNull()) encoding.appendData(dirnameAttrValue, directionForFormData()); return true; }
bool HTMLButtonElement::appendFormData(FormDataList& formData, bool) { if (m_type != SUBMIT || name().isEmpty() || !m_isActivatedSubmit) return false; formData.appendData(name(), value()); return true; }
bool BaseCheckableInputType::appendFormData(FormDataList& encoding, bool) const { if (!element()->checked()) return false; encoding.appendData(element()->name(), element()->value()); return true; }
bool SubmitInputType::appendFormData(FormDataList& encoding, bool) const { if (!element()->isActivatedSubmit()) return false; encoding.appendData(element()->name(), element()->valueWithDefault()); return true; }
bool HTMLButtonElement::appendFormData(FormDataList& encoding, bool /*multipart*/) { if (m_type != SUBMIT || name().isEmpty() || !m_activeSubmit) return false; encoding.appendData(name(), m_currValue); return true; }
bool WMLInputElement::appendFormData(FormDataList& encoding, bool) { if (formControlName().isEmpty()) return false; encoding.appendData(formControlName(), value()); return true; }
bool TextFieldInputType::appendFormData(FormDataList& list, bool multipart) const { InputType::appendFormData(list, multipart); const AtomicString& dirnameAttrValue = element().fastGetAttribute(dirnameAttr); if (!dirnameAttrValue.isNull()) list.appendData(dirnameAttrValue, element().directionForFormData()); return true; }
bool HTMLTextAreaElement::appendFormData(FormDataList& encoding, bool) { if (name().isEmpty()) return false; bool hardWrap = renderer() && wrap() == ta_Physical; String v = hardWrap ? static_cast<RenderTextControl*>(renderer())->textWithHardLineBreaks() : value(); encoding.appendData(name(), v); return true; }
bool ImageInputType::appendFormData(FormDataList& encoding, bool) const { if (!element()->isActivatedSubmit()) return false; const AtomicString& name = element()->name(); if (name.isEmpty()) { encoding.appendData("x", m_clickLocation.x()); encoding.appendData("y", m_clickLocation.y()); return true; } DEFINE_STATIC_LOCAL(String, dotXString, (ASCIILiteral(".x"))); DEFINE_STATIC_LOCAL(String, dotYString, (ASCIILiteral(".y"))); encoding.appendData(name + dotXString, m_clickLocation.x()); encoding.appendData(name + dotYString, m_clickLocation.y()); if (!element()->value().isEmpty()) encoding.appendData(name, element()->value()); return true; }
bool HTMLKeygenElement::appendFormData(FormDataList& encoded_values, bool) { // Only RSA is supported at this time. if (!m_keyType.isNull() && !equalIgnoringCase(m_keyType, "rsa")) return false; String value = signedPublicKeyAndChallengeString(shadowSelect()->selectedIndex(), m_challenge, document()->baseURL()); if (value.isNull()) return false; encoded_values.appendData(name(), value.utf8()); return true; }
bool HTMLTextAreaElement::appendFormData(FormDataList& encoding, bool) { if (name().isEmpty()) return false; document()->updateLayout(); const String& text = (m_wrap == HardWrap) ? valueWithHardLineBreaks() : value(); encoding.appendData(name(), text); return true; }
bool HTMLKeygenElement::appendFormData(FormDataList& encoding, bool) { // Only RSA is supported at this time. const AtomicString& keyType = fastGetAttribute(keytypeAttr); if (!keyType.isNull() && !equalIgnoringCase(keyType, "rsa")) return false; String value = signedPublicKeyAndChallengeString(shadowSelect()->selectedIndex(), fastGetAttribute(challengeAttr), document().baseURL()); if (value.isNull()) return false; encoding.appendData(name(), value.utf8()); return true; }
bool HTMLTextAreaElement::appendFormData(FormDataList& encoding, bool) { if (name().isEmpty()) return false; // FIXME: It's not acceptable to ignore the HardWrap setting when there is no renderer. // While we have no evidence this has ever been a practical problem, it would be best to fix it some day. RenderTextControl* control = toRenderTextControl(renderer()); const String& text = (m_wrap == HardWrap && control) ? control->textWithHardLineBreaks() : value(); encoding.appendData(name(), text); return true; }
bool HTMLObjectElement::appendFormData(FormDataList& encoding, bool) { if (name().isEmpty()) return false; Widget* widget = pluginWidget(); if (!is<PluginViewBase>(widget)) return false; String value; if (!downcast<PluginViewBase>(*widget).getFormValue(value)) return false; encoding.appendData(name(), value); return true; }
bool HTMLObjectElement::appendFormData(FormDataList& encoding, bool) { if (name().isEmpty()) return false; Widget* widget = pluginWidget(); if (!widget || !widget->isPluginView()) return false; String value; if (!toPluginView(widget)->getFormValue(value)) return false; encoding.appendData(name(), value); return true; }
bool HTMLObjectElement::appendFormData(FormDataList& encoding, bool) { if (name().isEmpty()) return false; // Widget is needed immediately to satisfy cases like // LayoutTests/plugins/form-value.html. Widget* widget = pluginWidgetForJSBindings(); if (!widget || !widget->isPluginView()) return false; String value; if (!toPluginView(widget)->getFormValue(value)) return false; encoding.appendData(name(), value); return true; }
bool InputType::appendFormData(FormDataList& encoding, bool) const { // Always successful. encoding.appendData(element()->name(), element()->value()); return true; }
void FormData::appendKeyValuePairItems(const FormDataList& list, const TextEncoding& encoding, bool isMultiPartForm, Document* document, EncodingType encodingType) { if (isMultiPartForm) m_boundary = FormDataBuilder::generateUniqueBoundaryString(); Vector<char> encodedData; const Vector<FormDataList::Item>& items = list.items(); size_t formDataListSize = items.size(); ASSERT(!(formDataListSize % 2)); for (size_t i = 0; i < formDataListSize; i += 2) { const FormDataList::Item& key = items[i]; const FormDataList::Item& value = items[i + 1]; if (isMultiPartForm) { Vector<char> header; FormDataBuilder::beginMultiPartHeader(header, m_boundary.data(), key.data()); bool shouldGenerateFile = false; // If the current type is blob, then we also need to include the filename if (value.blob()) { String name; if (value.blob()->isFile()) { File* file = toFile(value.blob()); name = file->name(); // Let the application specify a filename if it's going to generate a replacement file for the upload. const String& path = file->path(); if (!path.isEmpty()) { if (Page* page = document->page()) { String generatedFileName; shouldGenerateFile = page->chrome().client().shouldReplaceWithGeneratedFileForUpload(path, generatedFileName); if (shouldGenerateFile) name = generatedFileName; } } // If a filename is passed in FormData.append(), use it instead of the file blob's name. if (!value.filename().isNull()) name = value.filename(); } else { // For non-file blob, use the filename if it is passed in FormData.append(). if (!value.filename().isNull()) name = value.filename(); else name = "blob"; } // We have to include the filename=".." part in the header, even if the filename is empty FormDataBuilder::addFilenameToMultiPartHeader(header, encoding, name); // Add the content type if available, or "application/octet-stream" otherwise (RFC 1867). String contentType = value.blob()->type(); if (contentType.isEmpty()) contentType = "application/octet-stream"; ASSERT(Blob::isNormalizedContentType(contentType)); FormDataBuilder::addContentTypeToMultiPartHeader(header, contentType.ascii()); } FormDataBuilder::finishMultiPartHeader(header); // Append body appendData(header.data(), header.size()); if (value.blob()) { if (value.blob()->isFile()) { File* file = toFile(value.blob()); // Do not add the file if the path is empty. if (!file->path().isEmpty()) appendFile(file->path(), shouldGenerateFile); } else appendBlob(value.blob()->url()); } else appendData(value.data().data(), value.data().length()); appendData("\r\n", 2); } else { // Omit the name "isindex" if it's the first form data element. // FIXME: Why is this a good rule? Is this obsolete now? if (encodedData.isEmpty() && key.data() == "isindex") FormDataBuilder::encodeStringAsFormData(encodedData, value.data()); else FormDataBuilder::addKeyValuePairAsFormData(encodedData, key.data(), value.data(), encodingType); } } if (isMultiPartForm) FormDataBuilder::addBoundaryToMultiPartHeader(encodedData, m_boundary.data(), true); appendData(encodedData.data(), encodedData.size()); }
void FormData::appendKeyValuePairItems(const FormDataList& list, const TextEncoding& encoding, bool isMultiPartForm, Document* document) { if (isMultiPartForm) m_boundary = FormDataBuilder::generateUniqueBoundaryString(); Vector<char> encodedData; const Vector<FormDataList::Item>& items = list.items(); size_t formDataListSize = items.size(); ASSERT(!(formDataListSize % 2)); for (size_t i = 0; i < formDataListSize; i += 2) { const FormDataList::Item& key = items[i]; const FormDataList::Item& value = items[i + 1]; if (isMultiPartForm) { Vector<char> header; FormDataBuilder::beginMultiPartHeader(header, m_boundary.data(), key.data()); bool shouldGenerateFile = false; // If the current type is blob, then we also need to include the filename if (value.blob()) { String name; if (value.blob()->isFile()) { // For file blob, use the filename (or relative path if it is present) as the name. File* file = static_cast<File*>(value.blob()); #if ENABLE(DIRECTORY_UPLOAD) name = file->webkitRelativePath().isEmpty() ? file->name() : file->webkitRelativePath(); #else name = file->name(); #endif // Let the application specify a filename if it's going to generate a replacement file for the upload. if (Page* page = document->page()) { String generatedFileName; shouldGenerateFile = page->chrome()->client()->shouldReplaceWithGeneratedFileForUpload(file->path(), generatedFileName); if (shouldGenerateFile) name = generatedFileName; } } else { // For non-file blob, use the identifier part of the URL as the name. name = "Blob" + BlobURL::getIdentifier(value.blob()->url()); name = name.replace("-", ""); // For safety, remove '-' from the filename since some servers may not like it. } // We have to include the filename=".." part in the header, even if the filename is empty FormDataBuilder::addFilenameToMultiPartHeader(header, encoding, name); // Add the content type if available, or "application/octet-stream" otherwise (RFC 1867). String contentType; if (value.blob()->type().isEmpty()) contentType = "application/octet-stream"; else contentType = value.blob()->type(); FormDataBuilder::addContentTypeToMultiPartHeader(header, contentType.latin1()); } FormDataBuilder::finishMultiPartHeader(header); // Append body appendData(header.data(), header.size()); if (value.blob()) { if (value.blob()->isFile()) { // Do not add the file if the path is empty. if (!static_cast<File*>(value.blob())->path().isEmpty()) appendFile(static_cast<File*>(value.blob())->path(), shouldGenerateFile); } #if ENABLE(BLOB) else appendBlob(value.blob()->url()); #endif } else appendData(value.data().data(), value.data().length()); appendData("\r\n", 2); } else { // Omit the name "isindex" if it's the first form data element. // FIXME: Why is this a good rule? Is this obsolete now? if (encodedData.isEmpty() && key.data() == "isindex") FormDataBuilder::encodeStringAsFormData(encodedData, value.data()); else FormDataBuilder::addKeyValuePairAsFormData(encodedData, key.data(), value.data()); } } if (isMultiPartForm) FormDataBuilder::addBoundaryToMultiPartHeader(encodedData, m_boundary.data(), true); appendData(encodedData.data(), encodedData.size()); }
void FormData::appendKeyValuePairItems(const FormDataList& list, const WTF::TextEncoding& encoding, bool isMultiPartForm, Document* document, EncodingType encodingType) { if (isMultiPartForm) m_boundary = FormDataBuilder::generateUniqueBoundaryString(); Vector<char> encodedData; const Vector<FormDataList::Item>& items = list.items(); size_t formDataListSize = items.size(); ASSERT(!(formDataListSize % 2)); for (size_t i = 0; i < formDataListSize; i += 2) { const FormDataList::Item& key = items[i]; const FormDataList::Item& value = items[i + 1]; if (isMultiPartForm) { Vector<char> header; FormDataBuilder::beginMultiPartHeader(header, m_boundary.data(), key.data()); // If the current type is blob, then we also need to include the filename if (value.blob()) { String name; if (value.blob()->isFile()) { File* file = toFile(value.blob()); // For file blob, use the filename (or relative path if it is present) as the name. name = file->webkitRelativePath().isEmpty() ? file->name() : file->webkitRelativePath(); // If a filename is passed in FormData.append(), use it instead of the file blob's name. if (!value.filename().isNull()) name = value.filename(); } else { // For non-file blob, use the filename if it is passed in FormData.append(). if (!value.filename().isNull()) name = value.filename(); else name = "blob"; } // We have to include the filename=".." part in the header, even if the filename is empty FormDataBuilder::addFilenameToMultiPartHeader(header, encoding, name); // Add the content type if available, or "application/octet-stream" otherwise (RFC 1867). String contentType; if (value.blob()->type().isEmpty()) contentType = "application/octet-stream"; else contentType = value.blob()->type(); FormDataBuilder::addContentTypeToMultiPartHeader(header, contentType.latin1()); } FormDataBuilder::finishMultiPartHeader(header); // Append body appendData(header.data(), header.size()); if (value.blob()) { if (value.blob()->isFile()) { File* file = toFile(value.blob()); // Do not add the file if the path is empty. if (!file->path().isEmpty()) appendFile(file->path()); if (!file->fileSystemURL().isEmpty()) appendURL(file->fileSystemURL()); } else appendBlob(value.blob()->url()); } else appendData(value.data().data(), value.data().length()); appendData("\r\n", 2); } else { // Omit the name "isindex" if it's the first form data element. // FIXME: Why is this a good rule? Is this obsolete now? if (encodedData.isEmpty() && key.data() == "isindex") FormDataBuilder::encodeStringAsFormData(encodedData, value.data()); else FormDataBuilder::addKeyValuePairAsFormData(encodedData, key.data(), value.data(), encodingType); } } if (isMultiPartForm) FormDataBuilder::addBoundaryToMultiPartHeader(encodedData, m_boundary.data(), true); appendData(encodedData.data(), encodedData.size()); }