Bug 1750072 - Allow to prevent password revealing/unrevealing. r=mtigley

The idea is that chrome code would be able to call preventDefault(),
then run primary password authentication when needed, then setRevealPassword
again.

Differential Revision: https://phabricator.services.mozilla.com/D173491
This commit is contained in:
Emilio Cobos Álvarez
2023-03-27 23:30:33 +00:00
parent 4118c1c5ca
commit 18811e46d5
2 changed files with 15 additions and 1 deletions

View File

@@ -6876,6 +6876,20 @@ void HTMLInputElement::SetRevealPassword(bool aValue) {
if (NS_WARN_IF(mType != FormControlType::InputPassword)) {
return;
}
if (aValue == State().HasState(ElementState::REVEALED)) {
return;
}
RefPtr doc = OwnerDoc();
// We allow chrome code to prevent this. This is important for about:logins,
// which may need to run some OS-dependent authentication code before
// revealing the saved passwords.
bool defaultAction = true;
nsContentUtils::DispatchEventOnlyToChrome(
doc, ToSupports(this), u"MozWillToggleReveal"_ns, CanBubble::eYes,
Cancelable::eYes, &defaultAction);
if (NS_WARN_IF(!defaultAction)) {
return;
}
if (aValue) {
AddStates(ElementState::REVEALED);
} else {