| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/autofill/core/browser/name_field.h" | 5 #include "components/autofill/core/browser/name_field.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "components/autofill/core/browser/autofill_regex_constants.h" | 10 #include "components/autofill/core/browser/autofill_regex_constants.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 | 66 |
| 67 // Try FirstLastNameField first since it's more specific. | 67 // Try FirstLastNameField first since it's more specific. |
| 68 scoped_ptr<FormField> field = FirstLastNameField::Parse(scanner); | 68 scoped_ptr<FormField> field = FirstLastNameField::Parse(scanner); |
| 69 if (!field) | 69 if (!field) |
| 70 field = FullNameField::Parse(scanner); | 70 field = FullNameField::Parse(scanner); |
| 71 return field; | 71 return field; |
| 72 } | 72 } |
| 73 | 73 |
| 74 // This is overriden in concrete subclasses. | 74 // This is overriden in concrete subclasses. |
| 75 bool NameField::ClassifyField(ServerFieldTypeMap* map) const { | 75 bool NameField::ClassifyField(ServerFieldTypeMap* map) const { |
| 76 NOTREACHED(); |
| 76 return false; | 77 return false; |
| 77 } | 78 } |
| 78 | 79 |
| 79 // static | 80 // static |
| 80 scoped_ptr<FullNameField> FullNameField::Parse(AutofillScanner* scanner) { | 81 scoped_ptr<FullNameField> FullNameField::Parse(AutofillScanner* scanner) { |
| 81 // Exclude e.g. "username" or "nickname" fields. | 82 // Exclude e.g. "username" or "nickname" fields. |
| 82 scanner->SaveCursor(); | 83 scanner->SaveCursor(); |
| 83 bool should_ignore = ParseField(scanner, UTF8ToUTF16(kNameIgnoredRe), NULL); | 84 bool should_ignore = ParseField(scanner, UTF8ToUTF16(kNameIgnoredRe), NULL); |
| 84 scanner->Rewind(); | 85 scanner->Rewind(); |
| 85 if (should_ignore) | 86 if (should_ignore) |
| 86 return NULL; | 87 return NULL; |
| 87 | 88 |
| 88 // Searching for any label containing the word "name" is too general; | 89 // Searching for any label containing the word "name" is too general; |
| 89 // for example, Travelocity_Edit travel profile.html contains a field | 90 // for example, Travelocity_Edit travel profile.html contains a field |
| 90 // "Travel Profile Name". | 91 // "Travel Profile Name". |
| 91 AutofillField* field = NULL; | 92 AutofillField* field = NULL; |
| 92 if (ParseField(scanner, UTF8ToUTF16(kNameRe), &field)) | 93 if (ParseField(scanner, UTF8ToUTF16(kNameRe), &field)) |
| 93 return make_scoped_ptr(new FullNameField(field)); | 94 return make_scoped_ptr(new FullNameField(field)); |
| 94 | 95 |
| 95 return NULL; | 96 return NULL; |
| 96 } | 97 } |
| 97 | 98 |
| 98 bool FullNameField::ClassifyField(ServerFieldTypeMap* map) const { | 99 bool FullNameField::ClassifyField(ServerFieldTypeMap* map) const { |
| 99 return AddClassification(field_, NAME_FULL, map); | 100 return AddClassification(field_, NAME_FULL, map); |
| 100 } | 101 } |
| 101 | 102 |
| 102 FullNameField::FullNameField(AutofillField* field) : field_(field) { | 103 FullNameField::FullNameField(AutofillField* field) : field_(field) { |
| 104 DCHECK(field); |
| 103 } | 105 } |
| 104 | 106 |
| 105 scoped_ptr<FirstLastNameField> FirstLastNameField::ParseSpecificName( | 107 scoped_ptr<FirstLastNameField> FirstLastNameField::ParseSpecificName( |
| 106 AutofillScanner* scanner) { | 108 AutofillScanner* scanner) { |
| 107 // Some pages (e.g. Overstock_comBilling.html, SmithsonianCheckout.html) | 109 // Some pages (e.g. Overstock_comBilling.html, SmithsonianCheckout.html) |
| 108 // have the label "Name" followed by two or three text fields. | 110 // have the label "Name" followed by two or three text fields. |
| 109 scoped_ptr<FirstLastNameField> v(new FirstLastNameField); | 111 scoped_ptr<FirstLastNameField> v(new FirstLastNameField); |
| 110 scanner->SaveCursor(); | 112 scanner->SaveCursor(); |
| 111 | 113 |
| 112 AutofillField* next = NULL; | 114 AutofillField* next = NULL; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 | 210 |
| 209 bool FirstLastNameField::ClassifyField(ServerFieldTypeMap* map) const { | 211 bool FirstLastNameField::ClassifyField(ServerFieldTypeMap* map) const { |
| 210 bool ok = AddClassification(first_name_, NAME_FIRST, map); | 212 bool ok = AddClassification(first_name_, NAME_FIRST, map); |
| 211 ok = ok && AddClassification(last_name_, NAME_LAST, map); | 213 ok = ok && AddClassification(last_name_, NAME_LAST, map); |
| 212 ServerFieldType type = middle_initial_ ? NAME_MIDDLE_INITIAL : NAME_MIDDLE; | 214 ServerFieldType type = middle_initial_ ? NAME_MIDDLE_INITIAL : NAME_MIDDLE; |
| 213 ok = ok && AddClassification(middle_name_, type, map); | 215 ok = ok && AddClassification(middle_name_, type, map); |
| 214 return ok; | 216 return ok; |
| 215 } | 217 } |
| 216 | 218 |
| 217 } // namespace autofill | 219 } // namespace autofill |
| OLD | NEW |