Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Unified Diff: components/autofill/content/renderer/form_autofill_util.cc

Issue 675883002: Autofill: Consider placeholder text when inferring an input's label. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@staples
Patch Set: rebase expectations Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/test/data/autofill/heuristics/output/20_checkout_staples.com.out ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/autofill/content/renderer/form_autofill_util.cc
diff --git a/components/autofill/content/renderer/form_autofill_util.cc b/components/autofill/content/renderer/form_autofill_util.cc
index dde537997b4f56380c0cc1111f82015300db6f99..88694a72f8f43f7f928e2abbb1bf476a2604f6f9 100644
--- a/components/autofill/content/renderer/form_autofill_util.cc
+++ b/components/autofill/content/renderer/form_autofill_util.cc
@@ -274,6 +274,16 @@ base::string16 InferLabelFromPrevious(const WebFormControlElement& element) {
}
// Helper for |InferLabelForElement()| that infers a label, if possible, from
+// placeholder text,
+base::string16 InferLabelFromPlaceholder(const WebFormControlElement& element) {
+ CR_DEFINE_STATIC_LOCAL(WebString, kPlaceholder, ("placeholder"));
+ if (element.hasAttribute(kPlaceholder))
+ return element.getAttribute(kPlaceholder);
+
+ return base::string16();
+}
+
+// Helper for |InferLabelForElement()| that infers a label, if possible, from
// enclosing list item,
// e.g. <li>Some Text<input ...><input ...><input ...></tr>
base::string16 InferLabelFromListItem(const WebFormControlElement& element) {
@@ -421,6 +431,11 @@ base::string16 InferLabelForElement(const WebFormControlElement& element) {
if (!inferred_label.empty())
return inferred_label;
+ // If we didn't find a label, check for placeholder text.
+ inferred_label = InferLabelFromPlaceholder(element);
+ if (!inferred_label.empty())
+ return inferred_label;
+
// If we didn't find a label, check for list item case.
inferred_label = InferLabelFromListItem(element);
if (!inferred_label.empty())
« no previous file with comments | « chrome/test/data/autofill/heuristics/output/20_checkout_staples.com.out ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698