Bug 1638311 - [1.1] Ignore input type=hidden elements for autofill. r=geckoview-reviewers,MattN,agi

Differential Revision: https://phabricator.services.mozilla.com/D78557
This commit is contained in:
Eugen Sawin 2020-06-09 20:34:18 +00:00
parent a886b3e138
commit 3834bcff96
3 changed files with 12 additions and 10 deletions

View File

@ -272,11 +272,12 @@ class AutofillDelegateTest : BaseSessionTest() {
countAutofillNodes({ it.focused }), equalTo(1))
// The focused field, its siblings, its parent, and the root node should
// be visible.
// Hidden elements are ignored.
// TODO: Is this actually correct? Should the whole focused branch be
// visible or just the nodes as described above?
assertThat("Should have seven visible nodes",
countAutofillNodes({ node -> node.visible }),
equalTo(7))
equalTo(6))
mainSession.evaluateJS("document.querySelector('#pass2').blur()")
sessionRule.waitUntilCalled(object : Callbacks.AutofillDelegate {

View File

@ -34,7 +34,7 @@ import org.mozilla.gecko.util.GeckoBundle;
import org.mozilla.gecko.util.ThreadUtils;
public class Autofill {
private static final boolean DEBUG = true;
private static final boolean DEBUG = false;
public static final class Notify {
private Notify() {}
@ -651,8 +651,6 @@ public class Autofill {
Log.d(LOGTAG, "fillViewStructure");
final Node root = getRoot();
if (Build.VERSION.SDK_INT >= 26) {
structure.setAutofillId(view.getAutofillId(), getId());
structure.setWebDomain(getDomain());
@ -1026,11 +1024,13 @@ public class Autofill {
final CharSequence value = values.valueAt(i);
if (DEBUG) {
Log.d(LOGTAG, "autofill(" + id + ')');
Log.d(LOGTAG, "Process autofill for id=" + id + ", value=" + value);
}
int rootId = id;
for (int currentId = id; currentId != View.NO_ID; ) {
final Node elem = getAutofillSession().getNode(currentId);
if (elem == null) {
return;
}

View File

@ -201,11 +201,12 @@ class GeckoViewAutofill {
rootInfo.children = aFormLike.elements
.filter(
element =>
!usernameField ||
element.type != "text" ||
element == usernameField ||
(element.getAutocompleteInfo() &&
element.getAutocompleteInfo().fieldName == "email")
element.type != "hidden" &&
(!usernameField ||
element.type != "text" ||
element == usernameField ||
(element.getAutocompleteInfo() &&
element.getAutocompleteInfo().fieldName == "email"))
)
.map(element => {
sendFocusEvent |= element === focusedElement;