diff --git a/dom/html/HTMLFormElement.cpp b/dom/html/HTMLFormElement.cpp
index 9863605c5295..0ea559a5859c 100644
--- a/dom/html/HTMLFormElement.cpp
+++ b/dom/html/HTMLFormElement.cpp
@@ -860,44 +860,16 @@ nsresult HTMLFormElement::NotifySubmitObservers(nsIURI* aActionURL,
}
}
- // Notify observers that the form is being submitted.
- nsCOMPtr service =
- mozilla::services::GetObserverService();
- if (!service) return NS_ERROR_FAILURE;
-
- nsCOMPtr theEnum;
- nsresult rv = service->EnumerateObservers(
- aEarlyNotify ? NS_EARLYFORMSUBMIT_SUBJECT : NS_FORMSUBMIT_SUBJECT,
- getter_AddRefs(theEnum));
- NS_ENSURE_SUCCESS(rv, rv);
-
- if (theEnum) {
- nsCOMPtr inst;
- *aCancelSubmit = false;
-
- // XXXbz what do the submit observers actually want? The window
- // of the document this is shown in? Or something else?
- // sXBL/XBL2 issue
- nsCOMPtr window = OwnerDoc()->GetWindow();
-
- bool loop = true;
- while (NS_SUCCEEDED(theEnum->HasMoreElements(&loop)) && loop) {
- theEnum->GetNext(getter_AddRefs(inst));
-
- nsCOMPtr formSubmitObserver(
- do_QueryInterface(inst));
- if (formSubmitObserver) {
- rv = formSubmitObserver->Notify(
- this, window ? window->GetCurrentInnerWindow() : nullptr,
- aActionURL, aCancelSubmit);
- NS_ENSURE_SUCCESS(rv, rv);
- }
- if (*aCancelSubmit) {
- return NS_OK;
- }
- }
+ bool defaultAction = true;
+ nsresult rv = nsContentUtils::DispatchEventOnlyToChrome(
+ OwnerDoc(), static_cast(this),
+ aEarlyNotify ? NS_LITERAL_STRING("DOMFormBeforeSubmit")
+ : NS_LITERAL_STRING("DOMFormSubmit"),
+ CanBubble::eYes, Cancelable::eYes, &defaultAction);
+ *aCancelSubmit = !defaultAction;
+ if (*aCancelSubmit) {
+ return NS_OK;
}
-
return rv;
}
diff --git a/dom/html/nsIFormSubmitObserver.idl b/dom/html/nsIFormSubmitObserver.idl
index 36ee240f37f4..1394fb546e81 100644
--- a/dom/html/nsIFormSubmitObserver.idl
+++ b/dom/html/nsIFormSubmitObserver.idl
@@ -16,14 +16,10 @@ webidl Element;
[scriptable, uuid(867cb7e7-835d-408b-9788-d2834d284e03)]
interface nsIFormSubmitObserver: nsISupports
{
- void notify(in HTMLFormElement formNode, in mozIDOMWindow window, in nsIURI actionURL, out boolean cancelSubmit);
-
void notifyInvalidSubmit(in HTMLFormElement formNode,
in Array invalidElements);
};
%{C++
-#define NS_FORMSUBMIT_SUBJECT "formsubmit"
-#define NS_EARLYFORMSUBMIT_SUBJECT "earlyformsubmit"
#define NS_INVALIDFORMSUBMIT_SUBJECT "invalidformsubmit"
%}