| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/autofill/name_field.h" | 5 #include "chrome/browser/autofill/name_field.h" |
| 6 | 6 |
| 7 #include "base/logging.h" |
| 7 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
| 8 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/autofill/autofill_type.h" | 11 #include "chrome/browser/autofill/autofill_type.h" |
| 11 | 12 |
| 12 NameField* NameField::Parse(std::vector<AutoFillField*>::const_iterator* iter, | 13 NameField* NameField::Parse(std::vector<AutoFillField*>::const_iterator* iter, |
| 13 bool is_ecml) { | 14 bool is_ecml) { |
| 14 // Try FirstLastNameField first since it's more specific. | 15 // Try FirstLastNameField first since it's more specific. |
| 15 NameField* field = FirstLastNameField::Parse(iter, is_ecml); | 16 NameField* field = FirstLastNameField::Parse(iter, is_ecml); |
| 16 if (field == NULL && !is_ecml) | 17 if (field == NULL && !is_ecml) |
| 17 field = FullNameField::Parse(iter); | 18 field = FullNameField::Parse(iter); |
| 18 return field; | 19 return field; |
| 19 } | 20 } |
| 20 | 21 |
| 22 bool FullNameField::GetFieldInfo(FieldTypeMap* field_type_map) const { |
| 23 bool ok = Add(field_type_map, field_, AutoFillType(NAME_FULL)); |
| 24 DCHECK(ok); |
| 25 return true; |
| 26 } |
| 27 |
| 21 FullNameField* FullNameField::Parse( | 28 FullNameField* FullNameField::Parse( |
| 22 std::vector<AutoFillField*>::const_iterator* iter) { | 29 std::vector<AutoFillField*>::const_iterator* iter) { |
| 23 // Exclude labels containing the string "username", which typically | 30 // Exclude labels containing the string "username", which typically |
| 24 // denotes a login ID rather than the user's actual name. | 31 // denotes a login ID rather than the user's actual name. |
| 25 AutoFillField* field = **iter; | 32 AutoFillField* field = **iter; |
| 26 if (Match(field, ASCIIToUTF16("username"), false)) | 33 if (Match(field, ASCIIToUTF16("username"), false)) |
| 27 return NULL; | 34 return NULL; |
| 28 | 35 |
| 29 // Searching for any label containing the word "name" is too general; | 36 // Searching for any label containing the word "name" is too general; |
| 30 // for example, Travelocity_Edit travel profile.html contains a field | 37 // for example, Travelocity_Edit travel profile.html contains a field |
| 31 // "Travel Profile Name". | 38 // "Travel Profile Name". |
| 32 const string16 name_match = | 39 const string16 name_match = |
| 33 ASCIIToUTF16("^name|full *name|your name|customer name"); | 40 ASCIIToUTF16("^name|full *name|your name|customer name"); |
| 34 if (ParseText(iter, name_match, &field)) | 41 if (ParseText(iter, name_match, &field)) |
| 35 return new FullNameField(field); | 42 return new FullNameField(field); |
| 36 | 43 |
| 37 return NULL; | 44 return NULL; |
| 38 } | 45 } |
| 39 | 46 |
| 47 FullNameField::FullNameField(AutoFillField* field) |
| 48 : field_(field) { |
| 49 } |
| 50 |
| 40 FirstLastNameField* FirstLastNameField::Parse1( | 51 FirstLastNameField* FirstLastNameField::Parse1( |
| 41 std::vector<AutoFillField*>::const_iterator* iter) { | 52 std::vector<AutoFillField*>::const_iterator* iter) { |
| 42 // Some pages (e.g. Overstock_comBilling.html, SmithsonianCheckout.html) | 53 // Some pages (e.g. Overstock_comBilling.html, SmithsonianCheckout.html) |
| 43 // have the label "Name" followed by two or three text fields. | 54 // have the label "Name" followed by two or three text fields. |
| 44 scoped_ptr<FirstLastNameField> v(new FirstLastNameField); | 55 scoped_ptr<FirstLastNameField> v(new FirstLastNameField); |
| 45 std::vector<AutoFillField*>::const_iterator q = *iter; | 56 std::vector<AutoFillField*>::const_iterator q = *iter; |
| 46 | 57 |
| 47 AutoFillField* next; | 58 AutoFillField* next; |
| 48 if (ParseText(&q, ASCIIToUTF16("^name"), &v->first_name_) && | 59 if (ParseText(&q, ASCIIToUTF16("^name"), &v->first_name_) && |
| 49 ParseEmptyText(&q, &next)) { | 60 ParseEmptyText(&q, &next)) { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 return ok; | 163 return ok; |
| 153 } | 164 } |
| 154 | 165 |
| 155 FirstLastNameField::FirstLastNameField() | 166 FirstLastNameField::FirstLastNameField() |
| 156 : first_name_(NULL), | 167 : first_name_(NULL), |
| 157 middle_name_(NULL), | 168 middle_name_(NULL), |
| 158 last_name_(NULL), | 169 last_name_(NULL), |
| 159 middle_initial_(false) { | 170 middle_initial_(false) { |
| 160 } | 171 } |
| 161 | 172 |
| OLD | NEW |