Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(757)

Unified Diff: Source/core/html/HTMLFormElement.cpp

Issue 449823003: Form submitted from JS should not submit double values (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/html/HTMLFormElement.cpp
diff --git a/Source/core/html/HTMLFormElement.cpp b/Source/core/html/HTMLFormElement.cpp
index 985b37cff00ef4c8949a3ade7c54d9a1fecdeca4..e2b4178dc5ffa527ee7943e7d01982c87a789d35 100644
--- a/Source/core/html/HTMLFormElement.cpp
+++ b/Source/core/html/HTMLFormElement.cpp
@@ -71,6 +71,8 @@ HTMLFormElement::HTMLFormElement(Document& document)
, m_hasElementsAssociatedByParser(false)
, m_didFinishParsingChildren(false)
, m_wasUserSubmitted(false)
+ , m_isSubmittingOrInUserJSSubmitEvent(false)
+ , m_shouldSubmit(false)
, m_isInResetFunction(false)
, m_wasDemoted(false)
, m_pendingAutocompleteEventsQueue(GenericEventQueue::create(this))
@@ -318,16 +320,24 @@ void HTMLFormElement::prepareForSubmission(Event* event)
{
RefPtrWillBeRawPtr<HTMLFormElement> protector(this);
LocalFrame* frame = document().frame();
- if (!frame)
+ if (!frame || m_isSubmittingOrInUserJSSubmitEvent)
return;
// Interactive validation must be done before dispatching the submit event.
if (!validateInteractively(event))
return;
+ m_isSubmittingOrInUserJSSubmitEvent = true;
+ m_shouldSubmit = false;
+
frame->loader().client()->dispatchWillSendSubmitEvent(this);
if (dispatchEvent(Event::createCancelableBubble(EventTypeNames::submit)))
+ m_shouldSubmit = true;
+
+ m_isSubmittingOrInUserJSSubmitEvent = false;
+
+ if (m_shouldSubmit)
submit(event, true, true, NotSubmittedByJavaScript);
}
@@ -358,6 +368,12 @@ void HTMLFormElement::submit(Event* event, bool activateSubmitButton, bool proce
if (!view || !frame || !frame->page())
return;
+ if (m_isSubmittingOrInUserJSSubmitEvent) {
+ m_shouldSubmit = true;
+ return;
+ }
+
+ m_isSubmittingOrInUserJSSubmitEvent = true;
m_wasUserSubmitted = processingUserGesture;
RefPtrWillBeRawPtr<HTMLFormControlElement> firstSuccessfulSubmitButton = nullptr;
@@ -389,6 +405,9 @@ void HTMLFormElement::submit(Event* event, bool activateSubmitButton, bool proce
if (needButtonActivation && firstSuccessfulSubmitButton)
firstSuccessfulSubmitButton->setActivatedSubmit(false);
+
+ m_shouldSubmit = false;
+ m_isSubmittingOrInUserJSSubmitEvent = false;
}
void HTMLFormElement::scheduleFormSubmission(PassRefPtrWillBeRawPtr<FormSubmission> submission)
« LayoutTests/fast/forms/submit-add-remove-element.html ('K') | « Source/core/html/HTMLFormElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698