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) |