Bug 1742714 - Get rid of nsIFormSubmitObserver; r=geckoview-reviewers,agi,smaug

Differential Revision: https://phabricator.services.mozilla.com/D132091
This commit is contained in:
Edgar Chen
2021-12-06 12:23:08 +00:00
parent 9e8f198faf
commit 5fad53737d
13 changed files with 202 additions and 373 deletions

View File

@@ -51,8 +51,6 @@
#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/StaticPrefs_prompts.h"
#include "mozilla/StaticPrefs_signon.h"
#include "nsIFormSubmitObserver.h"
#include "nsIObserverService.h"
#include "nsCategoryManagerUtils.h"
#include "nsIContentInlines.h"
#include "nsISimpleEnumerator.h"
@@ -1876,27 +1874,18 @@ bool HTMLFormElement::CheckValidFormSubmission() {
* invalid controls in the form.
* This should not be done if the form has been submitted with .submit().
*
* NOTE: for the moment, we are also checking that there is an observer for
* NS_INVALIDFORMSUBMIT_SUBJECT so it will prevent blocking form submission
* if the browser does not have implemented a UI yet.
* NOTE: for the moment, we are also checking that whether the MozInvalidForm
* event gets prevented default so it will prevent blocking form submission if
* the browser does not have implemented a UI yet.
*
* TODO: the check for observer should be removed later when HTML5 Forms will
* be spread enough and authors will assume forms can't be submitted when
* invalid. See bug 587671.
* TODO: the check for MozInvalidForm event should be removed later when HTML5
* Forms will be spread enough and authors will assume forms can't be
* submitted when invalid. See bug 587671.
*/
NS_ASSERTION(!HasAttr(kNameSpaceID_None, nsGkAtoms::novalidate),
"We shouldn't be there if novalidate is set!");
// When .submit() is called aEvent = nullptr so we can rely on that to know if
// we have to check the validity of the form.
nsCOMPtr<nsIObserverService> service =
mozilla::services::GetObserverService();
if (!service) {
NS_WARNING("No observer service available!");
return true;
}
AutoTArray<RefPtr<Element>, 32> invalidElements;
if (CheckFormValidity(&invalidElements)) {
return true;
@@ -1962,39 +1951,7 @@ bool HTMLFormElement::CheckValidFormSubmission() {
DispatchEvent(*event);
bool result = !event->DefaultPrevented();
nsCOMPtr<nsISimpleEnumerator> theEnum;
nsresult rv = service->EnumerateObservers(NS_INVALIDFORMSUBMIT_SUBJECT,
getter_AddRefs(theEnum));
NS_ENSURE_SUCCESS(rv, result);
bool hasObserver = false;
rv = theEnum->HasMoreElements(&hasObserver);
if (NS_SUCCEEDED(rv) && hasObserver) {
result = false;
nsCOMPtr<nsISupports> inst;
nsCOMPtr<nsIFormSubmitObserver> observer;
bool more = true;
while (NS_SUCCEEDED(theEnum->HasMoreElements(&more)) && more) {
theEnum->GetNext(getter_AddRefs(inst));
observer = do_QueryInterface(inst);
if (observer) {
observer->NotifyInvalidSubmit(this, invalidElements);
}
}
}
if (result) {
NS_WARNING(
"There is no observer for \"invalidformsubmit\". \
One should be implemented!");
}
return result;
return !event->DefaultPrevented();
}
void HTMLFormElement::UpdateValidity(bool aElementValidity) {