Bug 1708455 - P4. Add DOMFormHasPossibleUsernameField event to notify the password manager when a form has a text input or an email input. r=sfoster,tgiles,smaug

Right now, we limit the type of a username field in username-only forms to be either text or email.
This is different from what the password manager currently support in LoginHelper.isUsernameFieldType.
This is because text and email type are the most common cases for a username field, and we want to focus
on the cases that are more likely a username field.

This patch adds "DOMFormHasPossibleUsername" event to notify the password manager when a form has a possible
username field (text or email). The event works similar to the existing "DOMFormHasPassword" event.

Depends on D113797

Differential Revision: https://phabricator.services.mozilla.com/D113798
This commit is contained in:
Dimi Lee
2021-06-11 11:56:03 +00:00
parent 0b1e79b89f
commit f6bacb0875
6 changed files with 263 additions and 0 deletions

View File

@@ -159,6 +159,8 @@ NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(HTMLFormElement,
void HTMLFormElement::AsyncEventRunning(AsyncEventDispatcher* aEvent) {
if (mFormPasswordEventDispatcher == aEvent) {
mFormPasswordEventDispatcher = nullptr;
} else if (mFormPossibleUsernameEventDispatcher == aEvent) {
mFormPossibleUsernameEventDispatcher = nullptr;
}
}
@@ -1182,6 +1184,18 @@ void HTMLFormElement::PostPasswordEvent() {
mFormPasswordEventDispatcher->PostDOMEvent();
}
void HTMLFormElement::PostPossibleUsernameEvent() {
// Don't fire another event if we have a pending event.
if (mFormPossibleUsernameEventDispatcher) {
return;
}
mFormPossibleUsernameEventDispatcher =
new AsyncEventDispatcher(this, u"DOMFormHasPossibleUsername"_ns,
CanBubble::eYes, ChromeOnlyDispatch::eYes);
mFormPossibleUsernameEventDispatcher->PostDOMEvent();
}
namespace {
struct FormComparator {
@@ -1259,6 +1273,11 @@ nsresult HTMLFormElement::AddElement(nsGenericHTMLFormElement* aChild,
// If it is a password control, inform the password manager.
if (type == FormControlType::InputPassword) {
PostPasswordEvent();
// If the type is email or text, it is a username compatible input,
// inform the password manager.
} else if (type == FormControlType::InputEmail ||
type == FormControlType::InputText) {
PostPossibleUsernameEvent();
}
// Default submit element handling