Diff
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (293443 => 293444)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2022-04-26 19:25:35 UTC (rev 293443)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2022-04-26 19:31:41 UTC (rev 293444)
@@ -1,3 +1,13 @@
+2022-04-26 Ziran Sun <[email protected]>
+
+ Constructed FormData object should not contain an entry for the submit button that was used to submit the form
+ https://bugs.webkit.org/show_bug.cgi?id=239070
+
+ Reviewed by Chris Dumez.
+
+ Update test expectation as the sub-test is now passing.
+ * web-platform-tests/html/semantics/forms/form-submission-0/constructing-form-data-set-expected.txt:
+
2022-04-26 Youenn Fablet <[email protected]>
Service Worker loads should not expose some ResourceTiming information
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/constructing-form-data-set-expected.txt (293443 => 293444)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/constructing-form-data-set-expected.txt 2022-04-26 19:25:35 UTC (rev 293443)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/html/semantics/forms/form-submission-0/constructing-form-data-set-expected.txt 2022-04-26 19:31:41 UTC (rev 293444)
@@ -21,5 +21,5 @@
PASS "formData" IDL attribute should have entries for form-associated elements in the first event handler, and the second handler can read entries set by the first handler.
PASS Entries added to "formData" IDL attribute should be submitted.
PASS Entries added to the "formdata" IDL attribute shouldn't be newline normalized in the resulting FormData
-FAIL The constructed FormData object should not contain an entry for the submit button that was used to submit the form. assert_false: expected false got true
+PASS The constructed FormData object should not contain an entry for the submit button that was used to submit the form.
Modified: trunk/Source/WebCore/ChangeLog (293443 => 293444)
--- trunk/Source/WebCore/ChangeLog 2022-04-26 19:25:35 UTC (rev 293443)
+++ trunk/Source/WebCore/ChangeLog 2022-04-26 19:31:41 UTC (rev 293444)
@@ -1,3 +1,31 @@
+2022-04-26 Ziran Sun <[email protected]>
+
+ Constructed FormData object should not contain an entry for the submit button that was used to submit the form
+ https://bugs.webkit.org/show_bug.cgi?id=239070
+
+ Reviewed by Chris Dumez.
+
+ When the activedSubmit flag is set for a submit button, its value is appended to a FormData. In the case of form
+ submission called in submit event handler, we include submit button when build FormData. The submit button should
+ not be included though. This patch correct it by calling set the activatedSubmit flag just before or after building
+ FormData.
+
+ Part of the patch is an import of Chromium CL at
+ https://codereview.chromium.org/2340213002
+
+ * html/DOMFormData.cpp:
+ (WebCore::DOMFormData::create):
+ * html/HTMLButtonElement.cpp:
+ (WebCore::HTMLButtonElement::defaultEventHandler):
+ * html/HTMLFormElement.cpp:
+ (WebCore::HTMLFormElement::submit):
+ (WebCore::HTMLFormElement::constructEntryList):
+ * html/HTMLFormElement.h:
+ * html/SubmitInputType.cpp:
+ (WebCore::SubmitInputType::handleDOMActivateEvent):
+ * loader/FormSubmission.cpp:
+ (WebCore::FormSubmission::create):
+
2022-04-26 Simon Fraser <[email protected]>
Save a few drawing operations when painting layer contents
Modified: trunk/Source/WebCore/html/DOMFormData.cpp (293443 => 293444)
--- trunk/Source/WebCore/html/DOMFormData.cpp 2022-04-26 19:25:35 UTC (rev 293443)
+++ trunk/Source/WebCore/html/DOMFormData.cpp 2022-04-26 19:31:41 UTC (rev 293444)
@@ -48,7 +48,7 @@
if (!form)
return formData;
- auto result = form->constructEntryList(WTFMove(formData), nullptr);
+ auto result = form->constructEntryList(nullptr, WTFMove(formData), nullptr);
if (!result)
return Exception { InvalidStateError, "Already constructing Form entry list."_s };
Modified: trunk/Source/WebCore/html/HTMLButtonElement.cpp (293443 => 293444)
--- trunk/Source/WebCore/html/HTMLButtonElement.cpp 2022-04-26 19:25:35 UTC (rev 293443)
+++ trunk/Source/WebCore/html/HTMLButtonElement.cpp 2022-04-26 19:31:41 UTC (rev 293444)
@@ -141,10 +141,8 @@
document().updateLayoutIgnorePendingStylesheets();
if (auto currentForm = form()) {
- if (m_type == SUBMIT) {
- SetForScope activatedSubmitState(m_isActivatedSubmit, true);
+ if (m_type == SUBMIT)
currentForm->submitIfPossible(&event, this);
- }
if (m_type == RESET)
currentForm->reset();
Modified: trunk/Source/WebCore/html/HTMLFormElement.cpp (293443 => 293444)
--- trunk/Source/WebCore/html/HTMLFormElement.cpp 2022-04-26 19:25:35 UTC (rev 293443)
+++ trunk/Source/WebCore/html/HTMLFormElement.cpp 2022-04-26 19:31:41 UTC (rev 293444)
@@ -323,17 +323,17 @@
m_isSubmittingOrPreparingForSubmission = false;
if (m_shouldSubmit)
- submit(event, true, !submitter, trigger, submitter);
+ submit(event, !submitter, trigger, submitter);
}
void HTMLFormElement::submit()
{
- submit(nullptr, false, true, NotSubmittedByJavaScript);
+ submit(nullptr, true, NotSubmittedByJavaScript);
}
void HTMLFormElement::submitFromJavaScript()
{
- submit(nullptr, false, UserGestureIndicator::processingUserGesture(), SubmittedByJavaScript);
+ submit(nullptr, UserGestureIndicator::processingUserGesture(), SubmittedByJavaScript);
}
ExceptionOr<void> HTMLFormElement::requestSubmit(HTMLElement* submitter)
@@ -393,7 +393,7 @@
return firstSuccessfulSubmitButton;
}
-void HTMLFormElement::submit(Event* event, bool activateSubmitButton, bool processingUserGesture, FormSubmissionTrigger trigger, HTMLFormControlElement* submitter)
+void HTMLFormElement::submit(Event* event, bool processingUserGesture, FormSubmissionTrigger trigger, HTMLFormControlElement* submitter)
{
// The submitIfPossible function also does this check, but we need to do it here
// too, since there are some code paths that bypass that function.
@@ -416,9 +416,16 @@
m_isSubmittingOrPreparingForSubmission = true;
m_wasUserSubmitted = processingUserGesture;
- auto firstSuccessfulSubmitButton = findSubmitButton(submitter, activateSubmitButton);
- if (firstSuccessfulSubmitButton)
- firstSuccessfulSubmitButton->setActivatedSubmit(true);
+ if (event && !submitter) {
+ // In a case of implicit submission without a submit button, 'submit' event handler might add a submit button. We search for a submit button again.
+ auto associatedElements = copyAssociatedElementsVector();
+ for (auto& element : associatedElements) {
+ if (auto* control = dynamicDowncast<HTMLFormControlElement>(element.get()); control && control->isSuccessfulSubmitButton()) {
+ submitter = control;
+ break;
+ }
+ }
+ }
Ref protectedThis { *this }; // Form submission can execute arbitary _javascript_.
@@ -444,9 +451,6 @@
else
frame->loader().submitForm(WTFMove(formSubmission));
- if (firstSuccessfulSubmitButton)
- firstSuccessfulSubmitButton->setActivatedSubmit(false);
-
m_shouldSubmit = false;
m_isSubmittingOrPreparingForSubmission = false;
}
@@ -1016,7 +1020,7 @@
return equalLettersIgnoringASCIICase(attributeWithoutSynchronization(autocompleteAttr), "off") ? offAtom() : onAtom();
}
-RefPtr<DOMFormData> HTMLFormElement::constructEntryList(Ref<DOMFormData>&& domFormData, StringPairVector* formValues)
+RefPtr<DOMFormData> HTMLFormElement::constructEntryList(RefPtr<HTMLFormControlElement>&& submitter, Ref<DOMFormData>&& domFormData, StringPairVector* formValues)
{
// https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-form-data-set
ASSERT(isMainThread());
@@ -1025,6 +1029,9 @@
return nullptr;
SetForScope isConstructingEntryListScope(m_isConstructingEntryList, true);
+
+ if (submitter)
+ submitter->setActivatedSubmit(true);
for (auto& control : this->copyAssociatedElementsVector()) {
auto& element = control->asHTMLElement();
@@ -1040,6 +1047,9 @@
}
dispatchEvent(FormDataEvent::create(eventNames().formdataEvent, Event::CanBubble::Yes, Event::IsCancelable::No, Event::IsComposed::No, domFormData.copyRef()));
+
+ if (submitter)
+ submitter->setActivatedSubmit(false);
return domFormData->clone();
}
Modified: trunk/Source/WebCore/html/HTMLFormElement.h (293443 => 293444)
--- trunk/Source/WebCore/html/HTMLFormElement.h 2022-04-26 19:25:35 UTC (rev 293443)
+++ trunk/Source/WebCore/html/HTMLFormElement.h 2022-04-26 19:31:41 UTC (rev 293444)
@@ -127,7 +127,7 @@
static HTMLFormElement* findClosestFormAncestor(const Element&);
- RefPtr<DOMFormData> constructEntryList(Ref<DOMFormData>&&, StringPairVector*);
+ RefPtr<DOMFormData> constructEntryList(RefPtr<HTMLFormControlElement>&&, Ref<DOMFormData>&&, StringPairVector*);
private:
HTMLFormElement(const QualifiedName&, Document&);
@@ -146,7 +146,7 @@
void copyNonAttributePropertiesFromElement(const Element&) final;
- void submit(Event*, bool activateSubmitButton, bool processingUserGesture, FormSubmissionTrigger, HTMLFormControlElement* submitter = nullptr);
+ void submit(Event*, bool processingUserGesture, FormSubmissionTrigger, HTMLFormControlElement* submitter = nullptr);
void submitDialog(Ref<FormSubmission>&&);
Modified: trunk/Source/WebCore/html/SubmitInputType.cpp (293443 => 293444)
--- trunk/Source/WebCore/html/SubmitInputType.cpp 2022-04-26 19:25:35 UTC (rev 293443)
+++ trunk/Source/WebCore/html/SubmitInputType.cpp 2022-04-26 19:31:41 UTC (rev 293444)
@@ -74,10 +74,8 @@
// the Form or button relationships.
protectedElement->document().updateLayoutIgnorePendingStylesheets();
- protectedElement->setActivatedSubmit(true);
if (RefPtr currentForm = protectedElement->form())
currentForm->submitIfPossible(&event, element()); // Event handlers can run.
- protectedElement->setActivatedSubmit(false);
event.setDefaultHandled();
}
Modified: trunk/Source/WebCore/loader/FormSubmission.cpp (293443 => 293444)
--- trunk/Source/WebCore/loader/FormSubmission.cpp 2022-04-26 19:25:35 UTC (rev 293443)
+++ trunk/Source/WebCore/loader/FormSubmission.cpp 2022-04-26 19:31:41 UTC (rev 293444)
@@ -213,7 +213,7 @@
auto domFormData = DOMFormData::create(dataEncoding.encodingForFormSubmissionOrURLParsing());
StringPairVector formValues;
- auto result = form.constructEntryList(WTFMove(domFormData), &formValues);
+ auto result = form.constructEntryList(submitter.copyRef(), WTFMove(domFormData), &formValues);
RELEASE_ASSERT(result);
domFormData = result.releaseNonNull();