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/autofill_field.h" | 5 #include "components/autofill/core/browser/autofill_field.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/sha1.h" | 8 #include "base/sha1.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 | 273 |
274 return false; | 274 return false; |
275 } | 275 } |
276 | 276 |
277 // Set |field_data|'s value to |number|, or possibly an appropriate substring of | 277 // Set |field_data|'s value to |number|, or possibly an appropriate substring of |
278 // |number|. The |field| specifies the type of the phone and whether this is a | 278 // |number|. The |field| specifies the type of the phone and whether this is a |
279 // phone prefix or suffix. | 279 // phone prefix or suffix. |
280 void FillPhoneNumberField(const AutofillField& field, | 280 void FillPhoneNumberField(const AutofillField& field, |
281 const base::string16& number, | 281 const base::string16& number, |
282 FormFieldData* field_data) { | 282 FormFieldData* field_data) { |
283 // Check to see if the size field matches the "prefix" or "suffix" sizes and | 283 field_data->value = |
284 // fill accordingly. | 284 AutofillField::GetPhoneNumberValue(field, number, *field_data); |
285 base::string16 value = number; | |
286 if (number.length() == | |
287 PhoneNumber::kPrefixLength + PhoneNumber::kSuffixLength) { | |
288 if (field.phone_part() == AutofillField::PHONE_PREFIX || | |
289 field_data->max_length == PhoneNumber::kPrefixLength) { | |
290 value = number.substr(PhoneNumber::kPrefixOffset, | |
291 PhoneNumber::kPrefixLength); | |
292 } else if (field.phone_part() == AutofillField::PHONE_SUFFIX || | |
293 field_data->max_length == PhoneNumber::kSuffixLength) { | |
294 value = number.substr(PhoneNumber::kSuffixOffset, | |
295 PhoneNumber::kSuffixLength); | |
296 } | |
297 } | |
298 | |
299 field_data->value = value; | |
300 } | 285 } |
301 | 286 |
302 // Fills in the select control |field| with |value|. If an exact match is not | 287 // Fills in the select control |field| with |value|. If an exact match is not |
303 // found, falls back to alternate filling strategies based on the |type|. | 288 // found, falls back to alternate filling strategies based on the |type|. |
304 bool FillSelectControl(const AutofillType& type, | 289 bool FillSelectControl(const AutofillType& type, |
305 const base::string16& value, | 290 const base::string16& value, |
306 const std::string& app_locale, | 291 const std::string& app_locale, |
307 FormFieldData* field) { | 292 FormFieldData* field) { |
308 DCHECK_EQ("select-one", field->form_control_type); | 293 DCHECK_EQ("select-one", field->form_control_type); |
309 | 294 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
486 return FillMonthControl(value, field_data); | 471 return FillMonthControl(value, field_data); |
487 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) { | 472 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) { |
488 FillStreetAddress(value, address_language_code, field_data); | 473 FillStreetAddress(value, address_language_code, field_data); |
489 return true; | 474 return true; |
490 } | 475 } |
491 | 476 |
492 field_data->value = value; | 477 field_data->value = value; |
493 return true; | 478 return true; |
494 } | 479 } |
495 | 480 |
481 // Returns the phone number value for the given |field|. The returned value | |
482 // might be |number|, or could possibly be a prefix or suffix of |number| | |
483 // if that's appropriate for the field. | |
Ilya Sherman
2014/09/22 21:24:02
nit: No need to duplicate the comment from the hea
| |
484 base::string16 AutofillField::GetPhoneNumberValue( | |
485 const AutofillField& field, | |
486 const base::string16& number, | |
487 const FormFieldData& field_data) { | |
488 // Check to see if the size field matches the "prefix" or "suffix" size. | |
489 // If so, return the appropriate substring. | |
490 if (number.length() != | |
491 PhoneNumber::kPrefixLength + PhoneNumber::kSuffixLength) { | |
492 return number; | |
493 } | |
494 | |
495 if (field.phone_part() == AutofillField::PHONE_PREFIX || | |
496 field_data.max_length == PhoneNumber::kPrefixLength) { | |
497 return | |
498 number.substr(PhoneNumber::kPrefixOffset, PhoneNumber::kPrefixLength); | |
499 } | |
500 | |
501 if (field.phone_part() == AutofillField::PHONE_SUFFIX || | |
502 field_data.max_length == PhoneNumber::kSuffixLength) { | |
503 return | |
504 number.substr(PhoneNumber::kSuffixOffset, PhoneNumber::kSuffixLength); | |
505 } | |
506 | |
507 return number; | |
508 } | |
509 | |
496 } // namespace autofill | 510 } // namespace autofill |
OLD | NEW |