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

Unified Diff: chrome/browser/autofill/address_field.cc

Issue 7531023: Improve Autofill heuristics when detecting labels from previous elements. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 9 years, 5 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
Index: chrome/browser/autofill/address_field.cc
diff --git a/chrome/browser/autofill/address_field.cc b/chrome/browser/autofill/address_field.cc
index 2c4ce9398995287a36397071a027c1f1adb20d2f..025911d371ee60964d1c661c8090b8bf485c308e 100644
--- a/chrome/browser/autofill/address_field.cc
+++ b/chrome/browser/autofill/address_field.cc
@@ -24,8 +24,8 @@ FormField* AddressField::Parse(AutofillScanner* scanner, bool is_ecml) {
return NULL;
scoped_ptr<AddressField> address_field(new AddressField);
- const AutofillField* initial_field = scanner->Cursor();
- scanner->SaveCursor();
+ const AutofillField* const initial_field = scanner->Cursor();
+ size_t saved_cursor = scanner->SaveCursor();
string16 attention_ignored =
l10n_util::GetStringUTF16(IDS_AUTOFILL_ATTENTION_IGNORED_RE);
@@ -33,13 +33,17 @@ FormField* AddressField::Parse(AutofillScanner* scanner, bool is_ecml) {
l10n_util::GetStringUTF16(IDS_AUTOFILL_REGION_IGNORED_RE);
// Allow address fields to appear in any order.
+ size_t begin_trailing_non_labeled_fields = 0;
+ bool has_trailing_non_labeled_fields = false;
while (!scanner->IsEnd()) {
+ const size_t cursor = scanner->SaveCursor();
if (ParseAddressLines(scanner, is_ecml, address_field.get()) ||
ParseCity(scanner, is_ecml, address_field.get()) ||
ParseState(scanner, is_ecml, address_field.get()) ||
ParseZipCode(scanner, is_ecml, address_field.get()) ||
ParseCountry(scanner, is_ecml, address_field.get()) ||
ParseCompany(scanner, is_ecml, address_field.get())) {
+ has_trailing_non_labeled_fields = false;
continue;
} else if (ParseField(scanner, attention_ignored, NULL) ||
ParseField(scanner, region_ignored, NULL)) {
@@ -56,6 +60,11 @@ FormField* AddressField::Parse(AutofillScanner* scanner, bool is_ecml) {
// types after any non-labeled fields, and we want email address fields to
// have precedence since some pages contain fields labeled
// "Email address".
+ if (!has_trailing_non_labeled_fields) {
+ has_trailing_non_labeled_fields = true;
+ begin_trailing_non_labeled_fields = cursor;
+ }
+
continue;
} else {
// No field found.
@@ -70,11 +79,15 @@ FormField* AddressField::Parse(AutofillScanner* scanner, bool is_ecml) {
address_field->city_ != NULL || address_field->state_ != NULL ||
address_field->zip_ != NULL || address_field->zip4_ ||
address_field->country_ != NULL) {
+ // Don't slurp non-labeled fields at the end into the address.
+ if (has_trailing_non_labeled_fields)
+ scanner->RewindTo(begin_trailing_non_labeled_fields);
+
address_field->type_ = address_field->FindType();
return address_field.release();
}
- scanner->Rewind();
+ scanner->RewindTo(saved_cursor);
return NULL;
}
« no previous file with comments | « no previous file | chrome/browser/autofill/autofill_resources.grd » ('j') | chrome/renderer/autofill/form_manager.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698