Commit 9af47e86 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Share code between FormSubmission::Create() and FormData constructor.

This CL has no behavior changes.

Bug: 825684
Change-Id: Ie54a02067aa896ec6ff386cfd6283f482217a238
Reviewed-on: https://chromium-review.googlesource.com/997194
Commit-Queue: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548703}
parent 42033d6a
......@@ -34,7 +34,6 @@
#include "core/fileapi/Blob.h"
#include "core/fileapi/File.h"
#include "core/frame/UseCounter.h"
#include "core/html/forms/FormDataEvent.h"
#include "core/html/forms/HTMLFormElement.h"
#include "platform/bindings/ScriptState.h"
#include "platform/network/FormDataEncoder.h"
......@@ -84,18 +83,8 @@ class FormDataIterationSource final
FormData::FormData(const WTF::TextEncoding& encoding) : encoding_(encoding) {}
FormData::FormData(HTMLFormElement* form) : encoding_(UTF8Encoding()) {
if (!form)
return;
// TODO(tkent): Share the following code with FormSubmission::Create().
if (RuntimeEnabledFeatures::FormDataEventEnabled())
form->DispatchEvent(FormDataEvent::Create(*this));
for (unsigned i = 0; i < form->ListedElements().size(); ++i) {
ListedElement* element = form->ListedElements()[i];
if (!ToHTMLElement(element)->IsDisabledFormControl())
element->AppendToFormData(*this);
}
if (form)
form->ConstructFormDataSet(nullptr, *this);
}
void FormData::Trace(blink::Visitor* visitor) {
......
......@@ -86,6 +86,11 @@ class CORE_EXPORT FormData final
void append(const String& name, Blob*, const String& filename = String());
String Decode(const CString& data) const;
// This flag is true if this FormData is created with a <form>, and its
// associated elements contain a non-empty password field.
bool ContainsPasswordData() const { return contains_password_data_; }
void SetContainsPasswordData(bool flag) { contains_password_data_ = flag; }
scoped_refptr<EncodedFormData> EncodeFormData(
EncodedFormData::EncodingType = EncodedFormData::kFormURLEncoded);
scoped_refptr<EncodedFormData> EncodeMultiPartFormData();
......@@ -100,6 +105,7 @@ class CORE_EXPORT FormData final
WTF::TextEncoding encoding_;
// Entry pointers in m_entries never be nullptr.
HeapVector<Member<const Entry>> entries_;
bool contains_password_data_ = false;
};
// Represents entry, which is a pair of a name and a value.
......
......@@ -47,10 +47,13 @@
#include "core/html/HTMLImageElement.h"
#include "core/html/HTMLObjectElement.h"
#include "core/html/forms/FormController.h"
#include "core/html/forms/FormData.h"
#include "core/html/forms/FormDataEvent.h"
#include "core/html/forms/HTMLFormControlsCollection.h"
#include "core/html/forms/HTMLInputElement.h"
#include "core/html/forms/RadioNodeList.h"
#include "core/html_names.h"
#include "core/input_type_names.h"
#include "core/inspector/ConsoleMessage.h"
#include "core/layout/LayoutObject.h"
#include "core/loader/FormSubmission.h"
......@@ -432,6 +435,31 @@ void HTMLFormElement::Submit(Event* event,
}
}
void HTMLFormElement::ConstructFormDataSet(
HTMLFormControlElement* submit_button,
FormData& form_data) {
// TODO(tkent): We might move the event dispatching later than the
// ListedElements iteration.
if (RuntimeEnabledFeatures::FormDataEventEnabled())
DispatchEvent(FormDataEvent::Create(form_data));
if (submit_button)
submit_button->SetActivatedSubmit(true);
for (ListedElement* control : ListedElements()) {
DCHECK(control);
HTMLElement& element = ToHTMLElement(*control);
if (!element.IsDisabledFormControl())
control->AppendToFormData(form_data);
if (auto* input = ToHTMLInputElementOrNull(element)) {
if (input->type() == InputTypeNames::password &&
!input->value().IsEmpty())
form_data.SetContainsPasswordData(true);
}
}
if (submit_button)
submit_button->SetActivatedSubmit(false);
}
void HTMLFormElement::ScheduleFormSubmission(FormSubmission* submission) {
DCHECK(submission->Method() == FormSubmission::kPostMethod ||
submission->Method() == FormSubmission::kGetMethod);
......
......@@ -107,6 +107,11 @@ class CORE_EXPORT HTMLFormElement final : public HTMLElement {
void AnonymousNamedGetter(const AtomicString& name, RadioNodeListOrElement&);
void InvalidateDefaultButtonStyle() const;
// 'construct the form data set'
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-the-form-data-set
void ConstructFormDataSet(HTMLFormControlElement* submit_button,
FormData& form_data);
private:
explicit HTMLFormElement(Document&);
......
......@@ -34,13 +34,10 @@
#include "core/dom/events/Event.h"
#include "core/frame/UseCounter.h"
#include "core/html/forms/FormData.h"
#include "core/html/forms/FormDataEvent.h"
#include "core/html/forms/HTMLFormControlElement.h"
#include "core/html/forms/HTMLFormElement.h"
#include "core/html/forms/HTMLInputElement.h"
#include "core/html/parser/HTMLParserIdioms.h"
#include "core/html_names.h"
#include "core/input_type_names.h"
#include "core/loader/FrameLoadRequest.h"
#include "core/loader/FrameLoader.h"
#include "platform/heap/Handle.h"
......@@ -226,29 +223,7 @@ FormSubmission* FormSubmission::Create(HTMLFormElement* form,
copied_attributes.AcceptCharset(), document.Encoding());
FormData* dom_form_data =
FormData::Create(data_encoding.EncodingForFormSubmission());
// TODO(tkent): We might move the event dispatching later than the
// ListedElements iteration.
if (RuntimeEnabledFeatures::FormDataEventEnabled())
form->DispatchEvent(FormDataEvent::Create(*dom_form_data));
if (submit_button)
submit_button->SetActivatedSubmit(true);
bool contains_password_data = false;
for (unsigned i = 0; i < form->ListedElements().size(); ++i) {
ListedElement* control = form->ListedElements()[i];
DCHECK(control);
HTMLElement& element = ToHTMLElement(*control);
if (!element.IsDisabledFormControl())
control->AppendToFormData(*dom_form_data);
if (auto* input = ToHTMLInputElementOrNull(element)) {
if (input->type() == InputTypeNames::password &&
!input->value().IsEmpty())
contains_password_data = true;
}
}
if (submit_button)
submit_button->SetActivatedSubmit(false);
form->ConstructFormDataSet(submit_button, *dom_form_data);
scoped_refptr<EncodedFormData> form_data;
String boundary;
......@@ -269,7 +244,7 @@ FormSubmission* FormSubmission::Create(HTMLFormElement* form,
}
form_data->SetIdentifier(GenerateFormDataIdentifier());
form_data->SetContainsPasswordData(contains_password_data);
form_data->SetContainsPasswordData(dom_form_data->ContainsPasswordData());
AtomicString target_or_base_target = copied_attributes.Target().IsEmpty()
? document.BaseTarget()
: copied_attributes.Target();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment