Exemple #1
0
void FileInputType::appendToFormData(FormData& formData) const {
  FileList* fileList = element().files();
  unsigned numFiles = fileList->length();
  if (numFiles == 0) {
    formData.append(element().name(), File::create(""));
    return;
  }

  for (unsigned i = 0; i < numFiles; ++i)
    formData.append(element().name(), fileList->item(i));
}
void HTMLTextAreaElement::appendToFormData(FormData& formData) {
  if (name().isEmpty())
    return;

  document().updateStyleAndLayout();

  const String& text =
      (m_wrap == HardWrap) ? valueWithHardLineBreaks() : value();
  formData.append(name(), text);

  const AtomicString& dirnameAttrValue = fastGetAttribute(dirnameAttr);
  if (!dirnameAttrValue.isNull())
    formData.append(dirnameAttrValue, directionForFormData());
}
Exemple #3
0
void TextFieldInputType::appendToFormData(FormData& formData) const {
  InputType::appendToFormData(formData);
  const AtomicString& dirnameAttrValue =
      element().fastGetAttribute(dirnameAttr);
  if (!dirnameAttrValue.isNull())
    formData.append(dirnameAttrValue, element().directionForFormData());
}
Exemple #4
0
TEST(FormDataTest, has) {
    FormData* fd = FormData::create(UTF8Encoding());
    fd->append("name1", "value1");

    EXPECT_TRUE(fd->has("name1"));
    EXPECT_EQ(1u, fd->size());
}
Exemple #5
0
void HiddenInputType::appendToFormData(FormData& formData) const
{
    if (equalIgnoringCase(element().name(), "_charset_")) {
        formData.append(element().name(), String(formData.encoding().name()));
        return;
    }
    InputType::appendToFormData(formData);
}
PassRefPtr<EncodedFormData> PasswordCredential::encodeFormData(
    String& contentType) const {
  if (m_additionalData.isURLSearchParams()) {
    // If |additionalData| is a 'URLSearchParams' object, build a urlencoded
    // response.
    URLSearchParams* params = URLSearchParams::create(URLSearchParamsInit());
    URLSearchParams* additionalData = m_additionalData.getAsURLSearchParams();
    for (const auto& param : additionalData->params()) {
      const String& name = param.first;
      if (name != idName() && name != passwordName())
        params->append(name, param.second);
    }
    params->append(idName(), id());
    params->append(passwordName(), password());

    contentType =
        AtomicString("application/x-www-form-urlencoded;charset=UTF-8");

    return params->toEncodedFormData();
  }

  // Otherwise, we'll build a multipart response.
  FormData* formData = FormData::create(nullptr);
  if (m_additionalData.isFormData()) {
    FormData* additionalData = m_additionalData.getAsFormData();
    for (const FormData::Entry* entry : additionalData->entries()) {
      const String& name = formData->decode(entry->name());
      if (name == idName() || name == passwordName())
        continue;

      if (entry->blob())
        formData->append(name, entry->blob(), entry->filename());
      else
        formData->append(name, formData->decode(entry->value()));
    }
  }
  formData->append(idName(), id());
  formData->append(passwordName(), password());

  RefPtr<EncodedFormData> encodedData = formData->encodeMultiPartFormData();
  contentType = AtomicString("multipart/form-data; boundary=") +
                encodedData->boundary().data();
  return encodedData.release();
}
Exemple #7
0
TEST(FormDataTest, getAll) {
    FormData* fd = FormData::create(UTF8Encoding());
    fd->append("name1", "value1");

    HeapVector<FormDataEntryValue> results = fd->getAll("name1");
    EXPECT_EQ(1u, results.size());
    EXPECT_TRUE(results[0].isUSVString());
    EXPECT_EQ("value1", results[0].getAsUSVString());

    EXPECT_EQ(1u, fd->size());
}
void HTMLObjectElement::appendToFormData(FormData& formData)
{
    if (name().isEmpty())
        return;

    Widget* widget = pluginWidget();
    if (!widget || !widget->isPluginView())
        return;
    String value;
    if (toPluginView(widget)->getFormValue(value))
        formData.append(name(), value);
}
void HTMLKeygenElement::appendToFormData(FormData& formData) {
  // Only RSA is supported at this time.
  const AtomicString& keyType = fastGetAttribute(keytypeAttr);
  if (!keyType.isNull() && !equalIgnoringCase(keyType, "rsa"))
    return;
  SecurityOrigin* topOrigin =
      document().frame()->tree().top()->securityContext()->getSecurityOrigin();
  String value = Platform::current()->signedPublicKeyAndChallengeString(
      shadowSelect()->selectedIndex(), fastGetAttribute(challengeAttr),
      document().baseURL(), KURL(KURL(), topOrigin->toString()));
  if (!value.isNull())
    formData.append(name(), value);
}
Exemple #10
0
TEST(FormDataTest, get) {
    FormData* fd = FormData::create(UTF8Encoding());
    fd->append("name1", "value1");

    FileOrUSVString result;
    fd->get("name1", result);
    EXPECT_TRUE(result.isUSVString());
    EXPECT_EQ("value1", result.getAsUSVString());

    const FormData::Entry& entry = *fd->entries()[0];
    EXPECT_STREQ("name1", entry.name().data());
    EXPECT_STREQ("value1", entry.value().data());
}
Exemple #11
0
void SubmitInputType::appendToFormData(FormData& formData) const {
  if (element().isActivatedSubmit())
    formData.append(element().name(), element().valueOrDefaultLabel());
}
void InputType::appendToFormData(FormData& formData) const
{
    formData.append(element().name(), element().value());
}
Exemple #13
0
void HTMLButtonElement::appendToFormData(FormData& formData)
{
    if (m_type == SUBMIT && !name().isEmpty() && m_isActivatedSubmit)
        formData.append(name(), value());
}
void BaseCheckableInputType::appendToFormData(FormData& formData) const
{
    if (element().checked())
        formData.append(element().name(), element().value());
}