Bug 1330111 - Automatically open login autocomplete from username fields if the form isn't filled. r=johannh

MozReview-Commit-ID: BWJcc0ZaA3K

--HG--
extra : rebase_source : f41155377fda00024b001bb8e6dd7e86ac41beaf
This commit is contained in:
Matthew Noorenberghe 2017-02-03 12:41:51 -08:00
Родитель 3026b4859f
Коммит b357018ae6
1 изменённых файлов: 57 добавлений и 5 удалений

Просмотреть файл

@ -44,6 +44,7 @@ var observer = {
QueryInterface : XPCOMUtils.generateQI([Ci.nsIObserver,
Ci.nsIFormSubmitObserver,
Ci.nsIWebProgressListener,
Ci.nsIDOMEventListener,
Ci.nsISupportsWeakReference]),
// nsIFormSubmitObserver
@ -108,6 +109,24 @@ var observer = {
log("onStateChange handled:", channel);
LoginManagerContent._onNavigation(aWebProgress.DOMWindow.document);
},
handleEvent(aEvent) {
if (!aEvent.isTrusted) {
return;
}
if (!gEnabled) {
return;
}
switch (aEvent.type) {
// Only used for username fields.
case "focus": {
LoginManagerContent._onUsernameFocus(aEvent);
break;
}
}
},
};
Services.obs.addObserver(observer, "earlyformsubmit", false);
@ -526,9 +545,31 @@ var LoginManagerContent = {
this._fillForm(form, autofillForm, false, false, false, loginsFound, recipes);
},
/*
* onUsernameInput
*
/**
* Focus event handler for username fields to decide whether to show autocomplete.
* @param {FocusEvent} event
*/
_onUsernameFocus(event) {
let focusedField = event.target;
if (!focusedField.mozIsTextField(true) || focusedField.readOnly) {
return;
}
if (this._isLoginAlreadyFilled(focusedField)) {
log("_onUsernameFocus: Already filled");
return;
}
let formFillFocused = this._formFillService.focusedInput;
if (formFillFocused == focusedField) {
log("_onUsernameFocus: Opening the autocomplete popup");
this._formFillService.showPopup();
} else {
log("_onUsernameFocus: FormFillController has a different focused input");
}
},
/**
* Listens for DOMAutoComplete and blur events on an input field.
*/
onUsernameInput(event) {
@ -987,8 +1028,6 @@ var LoginManagerContent = {
return;
}
this._formFillService.markAsLoginManagerField(passwordField);
// If the password field is disabled or read-only, there's nothing to do.
if (passwordField.disabled || passwordField.readOnly) {
log("not filling form, password field disabled or read-only");
@ -1174,6 +1213,19 @@ var LoginManagerContent = {
if (!userTriggered) {
// Ignore fills as a result of user action for this probe.
Services.telemetry.getHistogramById("PWMGR_FORM_AUTOFILL_RESULT").add(autofillResult);
if (usernameField) {
let focusedElement = this._formFillService.focusedInput;
if (usernameField == focusedElement &&
autofillResult !== AUTOFILL_RESULT.FILLED) {
log("_fillForm: Opening username autocomplete popup since the form wasn't autofilled");
this._formFillService.showPopup();
}
}
}
if (usernameField) {
usernameField.addEventListener("focus", observer);
}
Services.obs.notifyObservers(form.rootElement, "passwordmgr-processed-form", null);