From 7db655c1268cca8f2e06eedb2e3ed7a0d01a9aeb Mon Sep 17 00:00:00 2001 From: thestig Date: Tue, 10 Feb 2015 16:27:25 -0800 Subject: [PATCH] Autofill: Do not infer labels from divs with autofillable fields. The label finding algorithm looks at previous divs to see if they contain text, and uses that text as the label. While this works for many webpages, not all webpages are structured this way. For a given field, when the neighbor divs contain input fields, they are likely not to be the label text. BUG=454366 Review URL: https://codereview.chromium.org/906443002 Cr-Commit-Position: refs/heads/master@{#315688} --- .../data/autofill/heuristics/input/bug_454366.html | 81 ++++++++++++++++++++++ .../data/autofill/heuristics/output/bug_454366.out | 3 + .../content/renderer/form_autofill_util.cc | 17 +++-- 3 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 chrome/test/data/autofill/heuristics/input/bug_454366.html create mode 100644 chrome/test/data/autofill/heuristics/output/bug_454366.out diff --git a/chrome/test/data/autofill/heuristics/input/bug_454366.html b/chrome/test/data/autofill/heuristics/input/bug_454366.html new file mode 100644 index 000000000000..6ebcd47dace4 --- /dev/null +++ b/chrome/test/data/autofill/heuristics/input/bug_454366.html @@ -0,0 +1,81 @@ + + + + +
+
+
+
+
+ + + +
+
+ +
+ + + Add names, circles, or email addresses + + +
+ +
+ +
+ + diff --git a/chrome/test/data/autofill/heuristics/output/bug_454366.out b/chrome/test/data/autofill/heuristics/output/bug_454366.out new file mode 100644 index 000000000000..8d7d1985cc97 --- /dev/null +++ b/chrome/test/data/autofill/heuristics/output/bug_454366.out @@ -0,0 +1,3 @@ +UNKNOWN_TYPE | hist_state | | | hist_state_1-default +UNKNOWN_TYPE | sbdp | + Add names, circles, or email addresses | | hist_state_1-default +UNKNOWN_TYPE | | | | hist_state_1-default diff --git a/components/autofill/content/renderer/form_autofill_util.cc b/components/autofill/content/renderer/form_autofill_util.cc index cc72f7ea8461..c62cf0c17721 100644 --- a/components/autofill/content/renderer/form_autofill_util.cc +++ b/components/autofill/content/renderer/form_autofill_util.cc @@ -416,8 +416,18 @@ base::string16 InferLabelFromDivTable(const WebFormControlElement& element) { CR_DEFINE_STATIC_LOCAL(WebString, kFieldSet, ("fieldset")); while (inferred_label.empty() && !node.isNull()) { if (HasTagName(node, kDiv)) { - looking_for_parent = false; inferred_label = FindChildText(node); + // Avoid sibling DIVs that contain autofillable fields. + if (!looking_for_parent && !inferred_label.empty()) { + CR_DEFINE_STATIC_LOCAL(WebString, kSelector, + ("input, select, textarea")); + blink::WebExceptionCode ec = 0; + WebElement result_element = node.querySelector(kSelector, ec); + if (!result_element.isNull()) + inferred_label.clear(); + } + + looking_for_parent = false; } else if (looking_for_parent && (HasTagName(node, kTable) || HasTagName(node, kFieldSet))) { // If the element is in a table or fieldset, its label most likely is too. @@ -429,10 +439,7 @@ base::string16 InferLabelFromDivTable(const WebFormControlElement& element) { looking_for_parent = true; } - if (looking_for_parent) - node = node.parentNode(); - else - node = node.previousSibling(); + node = looking_for_parent ? node.parentNode() : node.previousSibling(); } return inferred_label; -- 2.11.4.GIT