OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/contact_info.h" | 5 #include "chrome/browser/autofill/contact_info.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/autofill/autofill_type.h" | 10 #include "chrome/browser/autofill/autofill_type.h" |
11 #include "chrome/browser/autofill/field_types.h" | 11 #include "chrome/browser/autofill/field_types.h" |
12 | 12 |
13 static const string16 kNameSplitChars = ASCIIToUTF16("-'. "); | 13 static const string16 kNameSplitChars = ASCIIToUTF16("-'. "); |
14 | 14 |
15 static const AutofillFieldType kAutoFillContactInfoTypes[] = { | 15 static const AutofillFieldType kAutoFillNameInfoTypes[] = { |
16 NAME_FIRST, | 16 NAME_FIRST, |
17 NAME_MIDDLE, | 17 NAME_MIDDLE, |
18 NAME_LAST, | 18 NAME_LAST |
19 EMAIL_ADDRESS, | |
20 COMPANY_NAME, | |
21 }; | 19 }; |
22 | 20 |
23 static const size_t kAutoFillContactInfoLength = | 21 static const size_t kAutoFillNameInfoLength = |
24 arraysize(kAutoFillContactInfoTypes); | 22 arraysize(kAutoFillNameInfoTypes); |
25 | 23 |
26 ContactInfo::ContactInfo() {} | 24 NameInfo::NameInfo() {} |
27 | 25 |
28 ContactInfo::~ContactInfo() {} | 26 NameInfo::NameInfo(const NameInfo& info) : FormGroup() { |
29 | 27 *this = info; |
30 FormGroup* ContactInfo::Clone() const { | |
31 return new ContactInfo(*this); | |
32 } | 28 } |
33 | 29 |
34 void ContactInfo::GetPossibleFieldTypes(const string16& text, | 30 NameInfo::~NameInfo() {} |
31 | |
32 NameInfo& NameInfo::operator=(const NameInfo& info) { | |
33 if (this == &info) | |
34 return *this; | |
35 | |
36 first_tokens_ = info.first_tokens_; | |
37 middle_tokens_ = info.middle_tokens_; | |
38 last_tokens_ = info.last_tokens_; | |
39 first_ = info.first_; | |
40 middle_ = info.middle_; | |
41 last_ = info.last_; | |
42 return *this; | |
43 } | |
44 | |
45 void NameInfo::GetPossibleFieldTypes(const string16& text, | |
35 FieldTypeSet* possible_types) const { | 46 FieldTypeSet* possible_types) const { |
36 DCHECK(possible_types); | 47 DCHECK(possible_types); |
37 | 48 |
38 if (IsFirstName(text)) | 49 if (IsFirstName(text)) |
39 possible_types->insert(NAME_FIRST); | 50 possible_types->insert(NAME_FIRST); |
40 | 51 |
41 if (IsMiddleName(text)) | 52 if (IsMiddleName(text)) |
42 possible_types->insert(NAME_MIDDLE); | 53 possible_types->insert(NAME_MIDDLE); |
43 | 54 |
44 if (IsLastName(text)) | 55 if (IsLastName(text)) |
45 possible_types->insert(NAME_LAST); | 56 possible_types->insert(NAME_LAST); |
46 | 57 |
47 if (IsMiddleInitial(text)) | 58 if (IsMiddleInitial(text)) |
48 possible_types->insert(NAME_MIDDLE_INITIAL); | 59 possible_types->insert(NAME_MIDDLE_INITIAL); |
49 | 60 |
50 if (IsSuffix(text)) | |
51 possible_types->insert(NAME_SUFFIX); | |
52 | |
53 if (IsFullName(text)) | 61 if (IsFullName(text)) |
54 possible_types->insert(NAME_FULL); | 62 possible_types->insert(NAME_FULL); |
55 | |
56 if (email_ == text) | |
57 possible_types->insert(EMAIL_ADDRESS); | |
58 | |
59 if (company_name_ == text) | |
60 possible_types->insert(COMPANY_NAME); | |
61 } | 63 } |
62 | 64 |
63 void ContactInfo::GetAvailableFieldTypes(FieldTypeSet* available_types) const { | 65 void NameInfo::GetAvailableFieldTypes(FieldTypeSet* available_types) const { |
64 DCHECK(available_types); | 66 DCHECK(available_types); |
65 | 67 |
66 if (!first().empty()) | 68 if (!first().empty()) |
67 available_types->insert(NAME_FIRST); | 69 available_types->insert(NAME_FIRST); |
68 | 70 |
69 if (!middle().empty()) | 71 if (!middle().empty()) |
70 available_types->insert(NAME_MIDDLE); | 72 available_types->insert(NAME_MIDDLE); |
71 | 73 |
72 if (!last().empty()) | 74 if (!last().empty()) |
73 available_types->insert(NAME_LAST); | 75 available_types->insert(NAME_LAST); |
74 | 76 |
75 if (!MiddleInitial().empty()) | 77 if (!MiddleInitial().empty()) |
76 available_types->insert(NAME_MIDDLE_INITIAL); | 78 available_types->insert(NAME_MIDDLE_INITIAL); |
77 | 79 |
78 if (!FullName().empty()) | 80 if (!FullName().empty()) |
79 available_types->insert(NAME_FULL); | 81 available_types->insert(NAME_FULL); |
80 | |
81 if (!suffix().empty()) | |
82 available_types->insert(NAME_SUFFIX); | |
83 | |
84 if (!email().empty()) | |
85 available_types->insert(EMAIL_ADDRESS); | |
86 | |
87 if (!company_name().empty()) | |
88 available_types->insert(COMPANY_NAME); | |
89 } | 82 } |
90 | 83 |
91 void ContactInfo::FindInfoMatches(const AutofillType& type, | 84 void NameInfo::FindInfoMatches(const AutofillType& type, |
92 const string16& info, | 85 const string16& info, |
93 std::vector<string16>* matched_text) const { | 86 std::vector<string16>* matched_text) const { |
94 DCHECK(matched_text); | 87 DCHECK(matched_text); |
95 | 88 |
96 string16 match; | 89 string16 match; |
97 if (type.field_type() == UNKNOWN_TYPE) { | 90 if (type.field_type() == UNKNOWN_TYPE) { |
98 for (size_t i = 0; i < kAutoFillContactInfoLength; i++) { | 91 for (size_t i = 0; i < kAutoFillNameInfoLength; i++) { |
99 if (FindInfoMatchesHelper(kAutoFillContactInfoTypes[i], info, &match)) | 92 if (FindInfoMatchesHelper(kAutoFillNameInfoTypes[i], info, &match)) |
100 matched_text->push_back(match); | 93 matched_text->push_back(match); |
101 } | 94 } |
102 } else if (FindInfoMatchesHelper(type.field_type(), info, &match)) { | 95 } else if (FindInfoMatchesHelper(type.field_type(), info, &match)) { |
103 matched_text->push_back(match); | 96 matched_text->push_back(match); |
104 } | 97 } |
105 } | 98 } |
106 | 99 |
107 string16 ContactInfo::GetFieldText(const AutofillType& type) const { | 100 string16 NameInfo::GetFieldText(const AutofillType& type) const { |
108 AutofillFieldType field_type = type.field_type(); | 101 AutofillFieldType field_type = type.field_type(); |
109 if (field_type == NAME_FIRST) | 102 if (field_type == NAME_FIRST) |
110 return first(); | 103 return first(); |
111 | 104 |
112 if (field_type == NAME_MIDDLE) | 105 if (field_type == NAME_MIDDLE) |
113 return middle(); | 106 return middle(); |
114 | 107 |
115 if (field_type == NAME_LAST) | 108 if (field_type == NAME_LAST) |
116 return last(); | 109 return last(); |
117 | 110 |
118 if (field_type == NAME_MIDDLE_INITIAL) | 111 if (field_type == NAME_MIDDLE_INITIAL) |
119 return MiddleInitial(); | 112 return MiddleInitial(); |
120 | 113 |
121 if (field_type == NAME_FULL) | 114 if (field_type == NAME_FULL) |
122 return FullName(); | 115 return FullName(); |
123 | 116 |
124 if (field_type == NAME_SUFFIX) | |
125 return suffix(); | |
126 | |
127 if (field_type == EMAIL_ADDRESS) | |
128 return email(); | |
129 | |
130 if (field_type == COMPANY_NAME) | |
131 return company_name(); | |
132 | |
133 return string16(); | 117 return string16(); |
134 } | 118 } |
135 | 119 |
136 void ContactInfo::SetInfo(const AutofillType& type, const string16& value) { | 120 void NameInfo::SetInfo(const AutofillType& type, const string16& value) { |
137 AutofillFieldType field_type = type.field_type(); | 121 AutofillFieldType field_type = type.field_type(); |
138 DCHECK_EQ(AutofillType::CONTACT_INFO, type.group()); | 122 DCHECK_EQ(AutofillType::NAME, type.group()); |
139 if (field_type == NAME_FIRST) | 123 if (field_type == NAME_FIRST) |
140 SetFirst(value); | 124 SetFirst(value); |
141 else if (field_type == NAME_MIDDLE || field_type == NAME_MIDDLE_INITIAL) | 125 else if (field_type == NAME_MIDDLE || field_type == NAME_MIDDLE_INITIAL) |
142 SetMiddle(value); | 126 SetMiddle(value); |
143 else if (field_type == NAME_LAST) | 127 else if (field_type == NAME_LAST) |
144 SetLast(value); | 128 SetLast(value); |
145 else if (field_type == NAME_SUFFIX) | |
146 set_suffix(value); | |
147 else if (field_type == EMAIL_ADDRESS) | |
148 email_ = value; | |
149 else if (field_type == COMPANY_NAME) | |
150 company_name_ = value; | |
151 else if (field_type == NAME_FULL) | 129 else if (field_type == NAME_FULL) |
152 SetFullName(value); | 130 SetFullName(value); |
153 else | 131 else |
154 NOTREACHED(); | 132 NOTREACHED(); |
155 } | 133 } |
156 | 134 |
157 ContactInfo::ContactInfo(const ContactInfo& contact_info) | 135 bool NameInfo::FindInfoMatchesHelper(const AutofillFieldType& field_type, |
158 : FormGroup(), | |
159 first_tokens_(contact_info.first_tokens_), | |
160 middle_tokens_(contact_info.middle_tokens_), | |
161 last_tokens_(contact_info.last_tokens_), | |
162 first_(contact_info.first_), | |
163 middle_(contact_info.middle_), | |
164 last_(contact_info.last_), | |
165 suffix_(contact_info.suffix_), | |
166 email_(contact_info.email_), | |
167 company_name_(contact_info.company_name_) { | |
168 } | |
169 | |
170 string16 ContactInfo::FullName() const { | |
171 if (first_.empty()) | |
172 return string16(); | |
173 | |
174 std::vector<string16> full_name; | |
175 full_name.push_back(first_); | |
176 | |
177 if (!middle_.empty()) | |
178 full_name.push_back(middle_); | |
179 | |
180 if (!last_.empty()) | |
181 full_name.push_back(last_); | |
182 | |
183 if (!suffix_.empty()) | |
184 full_name.push_back(suffix_); | |
185 | |
186 return JoinString(full_name, ' '); | |
187 } | |
188 | |
189 string16 ContactInfo::MiddleInitial() const { | |
190 if (middle_.empty()) | |
191 return string16(); | |
192 | |
193 string16 middle_name(middle()); | |
194 string16 initial; | |
195 initial.push_back(middle_name[0]); | |
196 return initial; | |
197 } | |
198 | |
199 bool ContactInfo::FindInfoMatchesHelper(const AutofillFieldType& field_type, | |
200 const string16& info, | 136 const string16& info, |
201 string16* match) const { | 137 string16* match) const { |
202 if (match == NULL) { | 138 if (match == NULL) { |
203 DLOG(ERROR) << "NULL match string passed in"; | 139 DLOG(ERROR) << "NULL match string passed in"; |
204 return false; | 140 return false; |
205 } | 141 } |
206 | 142 |
207 match->clear(); | 143 match->clear(); |
208 if (field_type == NAME_FIRST && | 144 if (field_type == NAME_FIRST && |
209 StartsWith(first(), info, false)) { | 145 StartsWith(first(), info, false)) { |
210 *match = first(); | 146 *match = first(); |
211 } else if (field_type == NAME_MIDDLE && | 147 } else if (field_type == NAME_MIDDLE && |
212 StartsWith(middle(), info, false)) { | 148 StartsWith(middle(), info, false)) { |
213 *match = middle(); | 149 *match = middle(); |
214 } else if (field_type == NAME_LAST && | 150 } else if (field_type == NAME_LAST && |
215 StartsWith(last(), info, false)) { | 151 StartsWith(last(), info, false)) { |
216 *match = last(); | 152 *match = last(); |
217 } else if (field_type == NAME_SUFFIX && | |
218 StartsWith(suffix(), info, false)) { | |
219 *match = suffix(); | |
220 } else if (field_type == NAME_MIDDLE_INITIAL && IsMiddleInitial(info)) { | 153 } else if (field_type == NAME_MIDDLE_INITIAL && IsMiddleInitial(info)) { |
221 *match = MiddleInitial(); | 154 *match = MiddleInitial(); |
222 } else if (field_type == NAME_FULL && | 155 } else if (field_type == NAME_FULL && |
223 StartsWith(FullName(), info, false)) { | 156 StartsWith(FullName(), info, false)) { |
224 *match = FullName(); | 157 *match = FullName(); |
225 } else if (field_type == EMAIL_ADDRESS && | |
226 StartsWith(email(), info, false)) { | |
227 *match = email(); | |
228 } else if (field_type == COMPANY_NAME && | |
229 StartsWith(company_name(), info, false)) { | |
230 *match = company_name(); | |
231 } | 158 } |
232 | 159 |
233 return !match->empty(); | 160 return !match->empty(); |
234 } | 161 } |
235 | 162 |
163 string16 NameInfo::FullName() const { | |
164 if (first_.empty()) | |
165 return string16(); | |
166 | |
167 std::vector<string16> full_name; | |
168 full_name.push_back(first_); | |
169 | |
170 if (!middle_.empty()) | |
171 full_name.push_back(middle_); | |
172 | |
173 if (!last_.empty()) | |
174 full_name.push_back(last_); | |
175 | |
176 return JoinString(full_name, ' '); | |
177 } | |
178 | |
179 string16 NameInfo::MiddleInitial() const { | |
Ilya Sherman
2011/03/09 00:50:50
Is this method ever used? It seems like we should
dhollowa
2011/03/09 01:55:47
It is not. But NameField is set up to parse, so w
Ilya Sherman
2011/03/09 02:01:22
Why not just store a parsed initial as a middle na
| |
180 if (middle_.empty()) | |
181 return string16(); | |
182 | |
183 string16 middle_name(middle()); | |
184 string16 initial; | |
185 initial.push_back(middle_name[0]); | |
186 return initial; | |
187 } | |
188 | |
236 // If each of the 'words' contained in the text are also present in the first | 189 // If each of the 'words' contained in the text are also present in the first |
237 // name then we will consider the text to be of type kFirstName. This means | 190 // name then we will consider the text to be of type kFirstName. This means |
238 // that people with multiple first names will be able to enter any one of | 191 // that people with multiple first names will be able to enter any one of |
239 // their first names and have it correctly recognized. | 192 // their first names and have it correctly recognized. |
240 bool ContactInfo::IsFirstName(const string16& text) const { | 193 bool NameInfo::IsFirstName(const string16& text) const { |
241 return IsNameMatch(text, first_tokens_); | 194 return IsNameMatch(text, first_tokens_); |
242 } | 195 } |
243 | 196 |
244 // If each of the 'words' contained in the text are also present in the middle | 197 // If each of the 'words' contained in the text are also present in the middle |
245 // name then we will consider the text to be of type kMiddleName. | 198 // name then we will consider the text to be of type kMiddleName. |
246 bool ContactInfo::IsMiddleName(const string16& text) const { | 199 bool NameInfo::IsMiddleName(const string16& text) const { |
247 return IsNameMatch(text, middle_tokens_); | 200 return IsNameMatch(text, middle_tokens_); |
248 } | 201 } |
249 | 202 |
250 // If each of the 'words' contained in the text are also present in the last | 203 // If each of the 'words' contained in the text are also present in the last |
251 // name then we will consider the text to be of type kLastName. | 204 // name then we will consider the text to be of type kLastName. |
252 bool ContactInfo::IsLastName(const string16& text) const { | 205 bool NameInfo::IsLastName(const string16& text) const { |
253 return IsNameMatch(text, last_tokens_); | 206 return IsNameMatch(text, last_tokens_); |
254 } | 207 } |
255 | 208 |
256 bool ContactInfo::IsSuffix(const string16& text) const { | 209 bool NameInfo::IsMiddleInitial(const string16& text) const { |
257 string16 lower_suffix = StringToLowerASCII(suffix_); | |
258 return (lower_suffix == text); | |
259 } | |
260 | |
261 bool ContactInfo::IsMiddleInitial(const string16& text) const { | |
262 if (text.length() != 1) | 210 if (text.length() != 1) |
263 return false; | 211 return false; |
264 | 212 |
265 string16 lower_case = StringToLowerASCII(text); | 213 string16 lower_case = StringToLowerASCII(text); |
266 // If the text entered was a single character and it matches the first letter | 214 // If the text entered was a single character and it matches the first letter |
267 // of any of the given middle names then we consider it to be a middle | 215 // of any of the given middle names then we consider it to be a middle |
268 // initial field. | 216 // initial field. |
269 size_t middle_tokens_size = middle_tokens_.size(); | 217 size_t middle_tokens_size = middle_tokens_.size(); |
270 for (size_t i = 0; i < middle_tokens_size; ++i) { | 218 for (size_t i = 0; i < middle_tokens_size; ++i) { |
271 if (middle_tokens_[i][0] == lower_case[0]) | 219 if (middle_tokens_[i][0] == lower_case[0]) |
272 return true; | 220 return true; |
273 } | 221 } |
274 | 222 |
275 return false; | 223 return false; |
276 } | 224 } |
277 | 225 |
278 // A field will be considered to be of type NAME_FULL if: | 226 // A field will be considered to be of type NAME_FULL if: |
279 // 1) it contains at least one word from the first name. | 227 // 1) it contains at least one word from the first name. |
280 // 2) it contains at least one word from the last name. | 228 // 2) it contains at least one word from the last name. |
281 // 3) all of the words in the field match a word in either the first, | 229 // 3) all of the words in the field match a word in either the first, |
282 // middle, or last name. | 230 // middle, or last name. |
283 bool ContactInfo::IsFullName(const string16& text) const { | 231 bool NameInfo::IsFullName(const string16& text) const { |
284 size_t first_tokens_size = first_tokens_.size(); | 232 size_t first_tokens_size = first_tokens_.size(); |
285 if (first_tokens_size == 0) | 233 if (first_tokens_size == 0) |
286 return false; | 234 return false; |
287 | 235 |
288 size_t middle_tokens_size = middle_tokens_.size(); | 236 size_t middle_tokens_size = middle_tokens_.size(); |
289 | 237 |
290 size_t last_tokens_size = last_tokens_.size(); | 238 size_t last_tokens_size = last_tokens_.size(); |
291 if (last_tokens_size == 0) | 239 if (last_tokens_size == 0) |
292 return false; | 240 return false; |
293 | 241 |
(...skipping 26 matching lines...) Expand all Loading... | |
320 if (IsWordInName(*iter, middle_tokens_)) | 268 if (IsWordInName(*iter, middle_tokens_)) |
321 match = true; | 269 match = true; |
322 | 270 |
323 if (!match) | 271 if (!match) |
324 return false; | 272 return false; |
325 } | 273 } |
326 | 274 |
327 return (first_name_match && last_name_match); | 275 return (first_name_match && last_name_match); |
328 } | 276 } |
329 | 277 |
330 bool ContactInfo::IsNameMatch(const string16& text, | 278 bool NameInfo::IsNameMatch(const string16& text, |
331 const NameTokens& name_tokens) const { | 279 const NameTokens& name_tokens) const { |
332 size_t name_tokens_size = name_tokens.size(); | 280 size_t name_tokens_size = name_tokens.size(); |
333 if (name_tokens_size == 0) | 281 if (name_tokens_size == 0) |
334 return false; | 282 return false; |
335 | 283 |
336 NameTokens text_tokens; | 284 NameTokens text_tokens; |
337 Tokenize(text, kNameSplitChars, &text_tokens); | 285 Tokenize(text, kNameSplitChars, &text_tokens); |
338 size_t text_tokens_size = text_tokens.size(); | 286 size_t text_tokens_size = text_tokens.size(); |
339 if (text_tokens_size == 0) | 287 if (text_tokens_size == 0) |
340 return false; | 288 return false; |
341 | 289 |
342 if (text_tokens_size > name_tokens_size) | 290 if (text_tokens_size > name_tokens_size) |
343 return false; | 291 return false; |
344 | 292 |
345 // If each of the 'words' contained in the text are also present in the name, | 293 // If each of the 'words' contained in the text are also present in the name, |
346 // then we will consider the text to match the name. | 294 // then we will consider the text to match the name. |
347 NameTokens::iterator iter; | 295 NameTokens::iterator iter; |
348 for (iter = text_tokens.begin(); iter != text_tokens.end(); ++iter) { | 296 for (iter = text_tokens.begin(); iter != text_tokens.end(); ++iter) { |
349 if (!IsWordInName(*iter, name_tokens)) | 297 if (!IsWordInName(*iter, name_tokens)) |
350 return false; | 298 return false; |
351 } | 299 } |
352 | 300 |
353 return true; | 301 return true; |
354 } | 302 } |
355 | 303 |
356 bool ContactInfo::IsWordInName(const string16& word, | 304 bool NameInfo::IsWordInName(const string16& word, |
357 const NameTokens& name_tokens) const { | 305 const NameTokens& name_tokens) const { |
358 NameTokens::const_iterator iter; | 306 NameTokens::const_iterator iter; |
359 for (iter = name_tokens.begin(); iter != name_tokens.end(); ++iter) { | 307 for (iter = name_tokens.begin(); iter != name_tokens.end(); ++iter) { |
360 // |*iter| is already lower-cased. | 308 // |*iter| is already lower-cased. |
361 if (StringToLowerASCII(word) == *iter) | 309 if (StringToLowerASCII(word) == *iter) |
362 return true; | 310 return true; |
363 } | 311 } |
364 | 312 |
365 return false; | 313 return false; |
366 } | 314 } |
367 | 315 |
368 void ContactInfo::SetFirst(const string16& first) { | 316 void NameInfo::SetFirst(const string16& first) { |
369 first_ = first; | 317 first_ = first; |
370 first_tokens_.clear(); | 318 first_tokens_.clear(); |
371 Tokenize(first, kNameSplitChars, &first_tokens_); | 319 Tokenize(first, kNameSplitChars, &first_tokens_); |
372 NameTokens::iterator iter; | 320 NameTokens::iterator iter; |
373 for (iter = first_tokens_.begin(); iter != first_tokens_.end(); ++iter) | 321 for (iter = first_tokens_.begin(); iter != first_tokens_.end(); ++iter) |
374 *iter = StringToLowerASCII(*iter); | 322 *iter = StringToLowerASCII(*iter); |
375 } | 323 } |
376 | 324 |
377 void ContactInfo::SetMiddle(const string16& middle) { | 325 void NameInfo::SetMiddle(const string16& middle) { |
378 middle_ = middle; | 326 middle_ = middle; |
379 middle_tokens_.clear(); | 327 middle_tokens_.clear(); |
380 Tokenize(middle, kNameSplitChars, &middle_tokens_); | 328 Tokenize(middle, kNameSplitChars, &middle_tokens_); |
381 NameTokens::iterator iter; | 329 NameTokens::iterator iter; |
382 for (iter = middle_tokens_.begin(); iter != middle_tokens_.end(); ++iter) | 330 for (iter = middle_tokens_.begin(); iter != middle_tokens_.end(); ++iter) |
383 *iter = StringToLowerASCII(*iter); | 331 *iter = StringToLowerASCII(*iter); |
384 } | 332 } |
385 | 333 |
386 void ContactInfo::SetLast(const string16& last) { | 334 void NameInfo::SetLast(const string16& last) { |
387 last_ = last; | 335 last_ = last; |
388 last_tokens_.clear(); | 336 last_tokens_.clear(); |
389 Tokenize(last, kNameSplitChars, &last_tokens_); | 337 Tokenize(last, kNameSplitChars, &last_tokens_); |
390 NameTokens::iterator iter; | 338 NameTokens::iterator iter; |
391 for (iter = last_tokens_.begin(); iter != last_tokens_.end(); ++iter) | 339 for (iter = last_tokens_.begin(); iter != last_tokens_.end(); ++iter) |
392 *iter = StringToLowerASCII(*iter); | 340 *iter = StringToLowerASCII(*iter); |
393 } | 341 } |
394 | 342 |
395 void ContactInfo::SetFullName(const string16& full) { | 343 void NameInfo::SetFullName(const string16& full) { |
396 NameTokens full_name_tokens; | 344 NameTokens full_name_tokens; |
397 Tokenize(full, ASCIIToUTF16(" "), &full_name_tokens); | 345 Tokenize(full, ASCIIToUTF16(" "), &full_name_tokens); |
398 // Clear the names. | 346 // Clear the names. |
399 SetFirst(string16()); | 347 SetFirst(string16()); |
400 SetMiddle(string16()); | 348 SetMiddle(string16()); |
401 SetLast(string16()); | 349 SetLast(string16()); |
402 | 350 |
403 // There are four possibilities: empty; first name; first and last names; | 351 // There are four possibilities: empty; first name; first and last names; |
404 // first, middle (possibly multiple strings) and then the last name. | 352 // first, middle (possibly multiple strings) and then the last name. |
405 if (full_name_tokens.size() > 0) { | 353 if (full_name_tokens.size() > 0) { |
406 SetFirst(full_name_tokens[0]); | 354 SetFirst(full_name_tokens[0]); |
407 if (full_name_tokens.size() > 1) { | 355 if (full_name_tokens.size() > 1) { |
408 SetLast(full_name_tokens.back()); | 356 SetLast(full_name_tokens.back()); |
409 if (full_name_tokens.size() > 2) { | 357 if (full_name_tokens.size() > 2) { |
410 full_name_tokens.erase(full_name_tokens.begin()); | 358 full_name_tokens.erase(full_name_tokens.begin()); |
411 full_name_tokens.pop_back(); | 359 full_name_tokens.pop_back(); |
412 SetMiddle(JoinString(full_name_tokens, ' ')); | 360 SetMiddle(JoinString(full_name_tokens, ' ')); |
413 } | 361 } |
414 } | 362 } |
415 } | 363 } |
416 } | 364 } |
417 | 365 |
366 #pragma mark - | |
367 | |
368 EmailInfo::EmailInfo() {} | |
369 | |
370 EmailInfo::EmailInfo(const EmailInfo& info) : FormGroup() { | |
371 *this = info; | |
372 } | |
373 | |
374 EmailInfo::~EmailInfo() {} | |
375 | |
376 EmailInfo& EmailInfo::operator=(const EmailInfo& info) { | |
377 if (this == &info) | |
378 return *this; | |
379 | |
380 email_ = info.email_; | |
381 return *this; | |
382 } | |
383 | |
384 void EmailInfo::GetPossibleFieldTypes(const string16& text, | |
385 FieldTypeSet* possible_types) const { | |
386 DCHECK(possible_types); | |
387 if (email_ == text) | |
Ilya Sherman
2011/03/09 00:50:50
This check should probably be case-insensitive.
dhollowa
2011/03/09 01:55:47
I've added a TODO here to investigate.
On 2011/03
| |
388 possible_types->insert(EMAIL_ADDRESS); | |
389 } | |
390 | |
391 void EmailInfo::GetAvailableFieldTypes(FieldTypeSet* available_types) const { | |
392 DCHECK(available_types); | |
393 if (!email().empty()) | |
394 available_types->insert(EMAIL_ADDRESS); | |
395 } | |
396 | |
397 void EmailInfo::FindInfoMatches(const AutofillType& type, | |
398 const string16& info, | |
399 std::vector<string16>* matched_text) const { | |
400 DCHECK(matched_text); | |
401 | |
402 string16 match; | |
403 if (type.field_type() == UNKNOWN_TYPE) { | |
404 if (FindInfoMatchesHelper(EMAIL_ADDRESS, info, &match)) | |
Ilya Sherman
2011/03/09 00:50:50
I think it would be clearer just to inline the log
dhollowa
2011/03/09 01:55:47
Done.
| |
405 matched_text->push_back(match); | |
406 } else if (FindInfoMatchesHelper(type.field_type(), info, &match)) { | |
407 matched_text->push_back(match); | |
408 } | |
409 } | |
410 | |
411 string16 EmailInfo::GetFieldText(const AutofillType& type) const { | |
412 AutofillFieldType field_type = type.field_type(); | |
413 if (field_type == EMAIL_ADDRESS) | |
414 return email(); | |
415 | |
416 return string16(); | |
417 } | |
418 | |
419 void EmailInfo::SetInfo(const AutofillType& type, const string16& value) { | |
420 AutofillFieldType field_type = type.field_type(); | |
421 DCHECK_EQ(AutofillType::EMAIL, type.group()); | |
422 if (field_type == EMAIL_ADDRESS) | |
423 email_ = value; | |
424 else | |
425 NOTREACHED(); | |
Ilya Sherman
2011/03/09 00:50:50
nit: This seems redundant with the DCHECK above.
dhollowa
2011/03/09 01:55:47
Done.
| |
426 } | |
427 | |
428 bool EmailInfo::FindInfoMatchesHelper(const AutofillFieldType& field_type, | |
429 const string16& info, | |
430 string16* match) const { | |
431 if (match == NULL) { | |
432 DLOG(ERROR) << "NULL match string passed in"; | |
433 return false; | |
434 } | |
435 | |
436 match->clear(); | |
437 if (field_type == EMAIL_ADDRESS && | |
438 StartsWith(email(), info, false)) { | |
439 *match = email(); | |
440 } | |
441 | |
442 return !match->empty(); | |
443 } | |
444 | |
445 #pragma mark - | |
446 | |
447 CompanyInfo::CompanyInfo() {} | |
448 | |
449 CompanyInfo::CompanyInfo(const CompanyInfo& info) : FormGroup() { | |
450 *this = info; | |
451 } | |
452 | |
453 CompanyInfo::~CompanyInfo() {} | |
454 | |
455 CompanyInfo& CompanyInfo::operator=(const CompanyInfo& info) { | |
456 if (this == &info) | |
457 return *this; | |
458 | |
459 company_name_ = info.company_name_; | |
460 return *this; | |
461 } | |
462 | |
463 void CompanyInfo::GetPossibleFieldTypes(const string16& text, | |
464 FieldTypeSet* possible_types) const { | |
465 DCHECK(possible_types); | |
466 | |
467 if (company_name_ == text) | |
468 possible_types->insert(COMPANY_NAME); | |
469 } | |
470 | |
471 void CompanyInfo::GetAvailableFieldTypes(FieldTypeSet* available_types) const { | |
472 DCHECK(available_types); | |
473 | |
474 if (!company_name().empty()) | |
475 available_types->insert(COMPANY_NAME); | |
476 } | |
477 | |
478 void CompanyInfo::FindInfoMatches(const AutofillType& type, | |
479 const string16& info, | |
480 std::vector<string16>* matched_text) const { | |
481 DCHECK(matched_text); | |
482 | |
483 string16 match; | |
484 if (type.field_type() == UNKNOWN_TYPE) { | |
485 if (FindInfoMatchesHelper(COMPANY_NAME, info, &match)) | |
486 matched_text->push_back(match); | |
487 } else if (FindInfoMatchesHelper(type.field_type(), info, &match)) { | |
488 matched_text->push_back(match); | |
489 } | |
490 } | |
491 | |
492 string16 CompanyInfo::GetFieldText(const AutofillType& type) const { | |
493 AutofillFieldType field_type = type.field_type(); | |
494 | |
495 if (field_type == COMPANY_NAME) | |
496 return company_name(); | |
497 | |
498 return string16(); | |
499 } | |
500 | |
501 void CompanyInfo::SetInfo(const AutofillType& type, const string16& value) { | |
502 AutofillFieldType field_type = type.field_type(); | |
503 DCHECK_EQ(AutofillType::COMPANY, type.group()); | |
504 else if (field_type == COMPANY_NAME) | |
505 company_name_ = value; | |
506 else | |
507 NOTREACHED(); | |
508 } | |
509 | |
510 bool CompanyInfo::FindInfoMatchesHelper(const AutofillFieldType& field_type, | |
511 const string16& info, | |
512 string16* match) const { | |
513 if (match == NULL) { | |
514 DLOG(ERROR) << "NULL match string passed in"; | |
515 return false; | |
516 } | |
517 | |
518 match->clear(); | |
519 if (field_type == COMPANY_NAME && | |
520 StartsWith(company_name(), info, false)) { | |
521 *match = company_name(); | |
522 } | |
523 | |
524 return !match->empty(); | |
525 } | |
OLD | NEW |