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 "app/l10n_util.h" |
7 #include "base/logging.h" | 8 #include "base/logging.h" |
8 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
9 #include "base/string_util.h" | 10 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
11 #include "chrome/browser/autofill/autofill_type.h" | 12 #include "chrome/browser/autofill/autofill_type.h" |
| 13 #include "grit/autofill_resources.h" |
12 | 14 |
13 NameField* NameField::Parse(std::vector<AutoFillField*>::const_iterator* iter, | 15 NameField* NameField::Parse(std::vector<AutoFillField*>::const_iterator* iter, |
14 bool is_ecml) { | 16 bool is_ecml) { |
15 // Try FirstLastNameField first since it's more specific. | 17 // Try FirstLastNameField first since it's more specific. |
16 NameField* field = FirstLastNameField::Parse(iter, is_ecml); | 18 NameField* field = FirstLastNameField::Parse(iter, is_ecml); |
17 if (field == NULL && !is_ecml) | 19 if (field == NULL && !is_ecml) |
18 field = FullNameField::Parse(iter); | 20 field = FullNameField::Parse(iter); |
19 return field; | 21 return field; |
20 } | 22 } |
21 | 23 |
22 bool FullNameField::GetFieldInfo(FieldTypeMap* field_type_map) const { | 24 bool FullNameField::GetFieldInfo(FieldTypeMap* field_type_map) const { |
23 bool ok = Add(field_type_map, field_, AutoFillType(NAME_FULL)); | 25 bool ok = Add(field_type_map, field_, AutoFillType(NAME_FULL)); |
24 DCHECK(ok); | 26 DCHECK(ok); |
25 return true; | 27 return true; |
26 } | 28 } |
27 | 29 |
28 FullNameField* FullNameField::Parse( | 30 FullNameField* FullNameField::Parse( |
29 std::vector<AutoFillField*>::const_iterator* iter) { | 31 std::vector<AutoFillField*>::const_iterator* iter) { |
30 // Exclude labels containing the string "username", which typically | 32 // Exclude labels containing the string "username", which typically |
31 // denotes a login ID rather than the user's actual name. | 33 // denotes a login ID rather than the user's actual name. |
32 AutoFillField* field = **iter; | 34 AutoFillField* field = **iter; |
33 if (Match(field, ASCIIToUTF16("username"), false)) | 35 if (Match(field, l10n_util::GetStringUTF16(IDS_AUTOFILL_USERNAME_RE), false)) |
34 return NULL; | 36 return NULL; |
35 | 37 |
36 // Searching for any label containing the word "name" is too general; | 38 // Searching for any label containing the word "name" is too general; |
37 // for example, Travelocity_Edit travel profile.html contains a field | 39 // for example, Travelocity_Edit travel profile.html contains a field |
38 // "Travel Profile Name". | 40 // "Travel Profile Name". |
39 const string16 name_match = | 41 const string16 name_match = l10n_util::GetStringUTF16(IDS_AUTOFILL_NAME_RE); |
40 ASCIIToUTF16("^name|full *name|your name|customer name"); | |
41 if (ParseText(iter, name_match, &field)) | 42 if (ParseText(iter, name_match, &field)) |
42 return new FullNameField(field); | 43 return new FullNameField(field); |
43 | 44 |
44 return NULL; | 45 return NULL; |
45 } | 46 } |
46 | 47 |
47 FullNameField::FullNameField(AutoFillField* field) | 48 FullNameField::FullNameField(AutoFillField* field) |
48 : field_(field) { | 49 : field_(field) { |
49 } | 50 } |
50 | 51 |
51 FirstLastNameField* FirstLastNameField::Parse1( | 52 FirstLastNameField* FirstLastNameField::Parse1( |
52 std::vector<AutoFillField*>::const_iterator* iter) { | 53 std::vector<AutoFillField*>::const_iterator* iter) { |
53 // Some pages (e.g. Overstock_comBilling.html, SmithsonianCheckout.html) | 54 // Some pages (e.g. Overstock_comBilling.html, SmithsonianCheckout.html) |
54 // have the label "Name" followed by two or three text fields. | 55 // have the label "Name" followed by two or three text fields. |
55 scoped_ptr<FirstLastNameField> v(new FirstLastNameField); | 56 scoped_ptr<FirstLastNameField> v(new FirstLastNameField); |
56 std::vector<AutoFillField*>::const_iterator q = *iter; | 57 std::vector<AutoFillField*>::const_iterator q = *iter; |
57 | 58 |
58 AutoFillField* next; | 59 AutoFillField* next; |
59 if (ParseText(&q, ASCIIToUTF16("^name"), &v->first_name_) && | 60 if (ParseText(&q, |
| 61 l10n_util::GetStringUTF16(IDS_AUTOFILL_NAME_SPECIFIC_RE), |
| 62 &v->first_name_) && |
60 ParseEmptyText(&q, &next)) { | 63 ParseEmptyText(&q, &next)) { |
61 if (ParseEmptyText(&q, &v->last_name_)) { | 64 if (ParseEmptyText(&q, &v->last_name_)) { |
62 // There are three name fields; assume that the middle one is a | 65 // There are three name fields; assume that the middle one is a |
63 // middle initial (it is, at least, on SmithsonianCheckout.html). | 66 // middle initial (it is, at least, on SmithsonianCheckout.html). |
64 v->middle_name_ = next; | 67 v->middle_name_ = next; |
65 v->middle_initial_ = true; | 68 v->middle_initial_ = true; |
66 } else { // only two name fields | 69 } else { // only two name fields |
67 v->last_name_ = next; | 70 v->last_name_ = next; |
68 } | 71 } |
69 | 72 |
(...skipping 10 matching lines...) Expand all Loading... |
80 std::vector<AutoFillField*>::const_iterator q = *iter; | 83 std::vector<AutoFillField*>::const_iterator q = *iter; |
81 | 84 |
82 // A fair number of pages use the names "fname" and "lname" for naming | 85 // A fair number of pages use the names "fname" and "lname" for naming |
83 // first and last name fields (examples from the test suite: | 86 // first and last name fields (examples from the test suite: |
84 // BESTBUY_COM - Sign In2.html; Crate and Barrel Check Out.html; | 87 // BESTBUY_COM - Sign In2.html; Crate and Barrel Check Out.html; |
85 // dell_checkout1.html). At least one UK page (The China Shop2.html) | 88 // dell_checkout1.html). At least one UK page (The China Shop2.html) |
86 // asks, in stuffy English style, for just initials and a surname, | 89 // asks, in stuffy English style, for just initials and a surname, |
87 // so we match "initials" here (and just fill in a first name there, | 90 // so we match "initials" here (and just fill in a first name there, |
88 // American-style). | 91 // American-style). |
89 // The ".*first$" matches fields ending in "first" (example in sample8.html). | 92 // The ".*first$" matches fields ending in "first" (example in sample8.html). |
90 string16 match = | 93 string16 match = l10n_util::GetStringUTF16(IDS_AUTOFILL_FIRST_NAME_RE); |
91 ASCIIToUTF16("first *name|first_name|initials|fname|first$"); | |
92 if (!ParseText(&q, match, &v->first_name_)) | 94 if (!ParseText(&q, match, &v->first_name_)) |
93 return NULL; | 95 return NULL; |
94 | 96 |
95 // We check for a middle initial before checking for a middle name | 97 // We check for a middle initial before checking for a middle name |
96 // because at least one page (PC Connection.html) has a field marked | 98 // because at least one page (PC Connection.html) has a field marked |
97 // as both (the label text is "MI" and the element name is | 99 // as both (the label text is "MI" and the element name is |
98 // "txtmiddlename"); such a field probably actually represents a | 100 // "txtmiddlename"); such a field probably actually represents a |
99 // middle initial. | 101 // middle initial. |
100 match = ASCIIToUTF16("middle *initial|middle_initial|m\\.i\\.|mi$"); | 102 match = l10n_util::GetStringUTF16(IDS_AUTOFILL_MIDDLE_INITIAL_RE); |
101 if (ParseText(&q, match, &v->middle_name_)) { | 103 if (ParseText(&q, match, &v->middle_name_)) { |
102 v->middle_initial_ = true; | 104 v->middle_initial_ = true; |
103 } else { | 105 } else { |
104 match = ASCIIToUTF16("middle *name|middle_name|mname|middle$"); | 106 match = l10n_util::GetStringUTF16(IDS_AUTOFILL_MIDDLE_NAME_RE); |
105 ParseText(&q, match, &v->middle_name_); | 107 ParseText(&q, match, &v->middle_name_); |
106 } | 108 } |
107 | 109 |
108 // The ".*last$" matches fields ending in "last" (example in sample8.html). | 110 // The ".*last$" matches fields ending in "last" (example in sample8.html). |
109 match = ASCIIToUTF16("last *name|last_name|lname|surname|last$"); | 111 match = l10n_util::GetStringUTF16(IDS_AUTOFILL_LAST_NAME_RE); |
110 if (!ParseText(&q, match, &v->last_name_)) | 112 if (!ParseText(&q, match, &v->last_name_)) |
111 return NULL; | 113 return NULL; |
112 | 114 |
113 *iter = q; | 115 *iter = q; |
114 return v.release(); | 116 return v.release(); |
115 } | 117 } |
116 | 118 |
117 FirstLastNameField* FirstLastNameField::ParseEcmlName( | 119 FirstLastNameField* FirstLastNameField::ParseEcmlName( |
118 std::vector<AutoFillField*>::const_iterator* iter) { | 120 std::vector<AutoFillField*>::const_iterator* iter) { |
119 scoped_ptr<FirstLastNameField> field(new FirstLastNameField); | 121 scoped_ptr<FirstLastNameField> field(new FirstLastNameField); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 return ok; | 165 return ok; |
164 } | 166 } |
165 | 167 |
166 FirstLastNameField::FirstLastNameField() | 168 FirstLastNameField::FirstLastNameField() |
167 : first_name_(NULL), | 169 : first_name_(NULL), |
168 middle_name_(NULL), | 170 middle_name_(NULL), |
169 last_name_(NULL), | 171 last_name_(NULL), |
170 middle_initial_(false) { | 172 middle_initial_(false) { |
171 } | 173 } |
172 | 174 |
OLD | NEW |