Index: Source/core/html/HTMLFormElement.cpp |
diff --git a/Source/core/html/HTMLFormElement.cpp b/Source/core/html/HTMLFormElement.cpp |
index 7e5a7859d87924d3238f3ac9ad3b22a6f35a131a..48d208acc3d5b3b822b7f9181d02d9973341aac4 100644 |
--- a/Source/core/html/HTMLFormElement.cpp |
+++ b/Source/core/html/HTMLFormElement.cpp |
@@ -303,13 +303,21 @@ bool HTMLFormElement::prepareForSubmission(Event* event) |
RefPtr<FormState> formState = FormState::create(this, controlNamesAndValues, &document(), NotSubmittedByJavaScript); |
frame->loader().client()->dispatchWillSendSubmitEvent(formState.release()); |
- if (dispatchEvent(Event::createCancelableBubble(EventTypeNames::submit))) |
- m_shouldSubmit = true; |
- |
+ // Set flag before submission as dispatchEvent could trigger another event |
m_isSubmittingOrPreparingForSubmission = false; |
- if (m_shouldSubmit) |
+ // http://www.whatwg.org/specs/web-apps/current-work/#concept-form-submit |
+ // Submit Event can be cancelled i.e. returned false or can explicitly declare default prevented |
+ // http://www.w3.org/TR/DOM-Level-3-Events/#event-flow-default-cancel. |
+ // Returning false is also considered as default prevented. |
+ if (!dispatchEvent(Event::createCancelableBubble(EventTypeNames::submit)) |
+ || event->defaultPrevented()) { |
keishi
2014/02/25 15:00:57
I think prepareForSubmission is always called from
|
+ return m_shouldSubmit; // i.e. do not proceed |
+ } |
+ if (!m_shouldSubmit) { |
+ m_shouldSubmit = true; |
submit(event, true, true, NotSubmittedByJavaScript); |
+ } |
return m_shouldSubmit; |
} |
@@ -358,14 +366,9 @@ void HTMLFormElement::submit(Event* event, bool activateSubmitButton, bool proce |
{ |
FrameView* view = document().view(); |
Frame* frame = document().frame(); |
- if (!view || !frame || !frame->page()) |
+ if (!view || !frame || !frame->page() || m_isSubmittingOrPreparingForSubmission) |
return; |
- if (m_isSubmittingOrPreparingForSubmission) { |
- m_shouldSubmit = true; |
- return; |
- } |
- |
m_isSubmittingOrPreparingForSubmission = true; |
m_wasUserSubmitted = processingUserGesture; |