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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/i18n/string_search.h" | 10 #include "base/i18n/string_search.h" |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
524 FormFieldData* field_data) { | 524 FormFieldData* field_data) { |
525 AutofillType type = field.Type(); | 525 AutofillType type = field.Type(); |
526 | 526 |
527 // Don't fill if autocomplete=off is set on |field| on desktop for non credit | 527 // Don't fill if autocomplete=off is set on |field| on desktop for non credit |
528 // card related fields. | 528 // card related fields. |
529 if (!field.should_autocomplete && IsDesktopPlatform() && | 529 if (!field.should_autocomplete && IsDesktopPlatform() && |
530 (type.group() != CREDIT_CARD)) { | 530 (type.group() != CREDIT_CARD)) { |
531 return false; | 531 return false; |
532 } | 532 } |
533 | 533 |
534 if (type.GetStorableType() == PHONE_HOME_NUMBER) { | 534 if (type.GetStorableType() == PHONE_HOME_NUMBER || |
535 type.GetStorableType() == PHONE_HOME_WHOLE_NUMBER) { | |
535 FillPhoneNumberField(field, value, field_data); | 536 FillPhoneNumberField(field, value, field_data); |
536 return true; | 537 return true; |
537 } else if (field_data->form_control_type == "select-one") { | 538 } else if (field_data->form_control_type == "select-one") { |
538 return FillSelectControl(type, value, app_locale, field_data); | 539 return FillSelectControl(type, value, app_locale, field_data); |
539 } else if (field_data->form_control_type == "month") { | 540 } else if (field_data->form_control_type == "month") { |
540 return FillMonthControl(value, field_data); | 541 return FillMonthControl(value, field_data); |
541 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) { | 542 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) { |
542 FillStreetAddress(value, address_language_code, field_data); | 543 FillStreetAddress(value, address_language_code, field_data); |
543 return true; | 544 return true; |
544 } else if (type.GetStorableType() == CREDIT_CARD_NUMBER) { | 545 } else if (type.GetStorableType() == CREDIT_CARD_NUMBER) { |
545 FillCreditCardNumberField(field, value, field_data); | 546 FillCreditCardNumberField(field, value, field_data); |
546 return true; | 547 return true; |
547 } | 548 } |
548 | 549 |
549 field_data->value = value; | 550 field_data->value = value; |
550 return true; | 551 return true; |
551 } | 552 } |
552 | 553 |
553 base::string16 AutofillField::GetPhoneNumberValue( | 554 base::string16 AutofillField::GetPhoneNumberValue( |
554 const AutofillField& field, | 555 const AutofillField& field, |
555 const base::string16& number, | 556 const base::string16& number, |
556 const FormFieldData& field_data) { | 557 const FormFieldData& field_data) { |
557 // Check to see if the size field matches the "prefix" or "suffix" size. | 558 // Check to see if the size field matches the "prefix" or "suffix" size. |
558 // If so, return the appropriate substring. | 559 // If so, return the appropriate substring. |
559 if (number.length() != | 560 if (number.length() == |
Mathieu
2016/01/26 14:43:01
In which cases will the phone number size be 7? I'
sebsg
2016/01/26 23:56:26
Done.
| |
560 PhoneNumber::kPrefixLength + PhoneNumber::kSuffixLength) { | 561 PhoneNumber::kPrefixLength + PhoneNumber::kSuffixLength) { |
561 return number; | 562 if (field.phone_part() == AutofillField::PHONE_PREFIX || |
563 field_data.max_length == PhoneNumber::kPrefixLength) { | |
564 return number.substr(PhoneNumber::kPrefixOffset, | |
565 PhoneNumber::kPrefixLength); | |
566 } | |
567 | |
568 if (field.phone_part() == AutofillField::PHONE_SUFFIX || | |
569 field_data.max_length == PhoneNumber::kSuffixLength) { | |
570 return number.substr(PhoneNumber::kSuffixOffset, | |
571 PhoneNumber::kSuffixLength); | |
572 } | |
562 } | 573 } |
563 | 574 |
564 if (field.phone_part() == AutofillField::PHONE_PREFIX || | 575 // Check to see if the max length of the field matches the "city and number" |
565 field_data.max_length == PhoneNumber::kPrefixLength) { | 576 // size. If |number| exceeds that size, cut the first part to provide a valid |
566 return | 577 // number for the field. |
567 number.substr(PhoneNumber::kPrefixOffset, PhoneNumber::kPrefixLength); | 578 if (field_data.max_length == PhoneNumber::kCityAndNumberLength && |
Mathieu
2016/01/26 14:43:02
Why should we check for max_length == 10? It feels
sebsg
2016/01/26 23:56:26
I thought it was safer that way, to only cut the f
| |
568 } | 579 number.length() > field_data.max_length) { |
569 | 580 return number.substr(number.length() - field_data.max_length, |
570 if (field.phone_part() == AutofillField::PHONE_SUFFIX || | 581 field_data.max_length); |
571 field_data.max_length == PhoneNumber::kSuffixLength) { | |
572 return | |
573 number.substr(PhoneNumber::kSuffixOffset, PhoneNumber::kSuffixLength); | |
574 } | 582 } |
575 | 583 |
576 return number; | 584 return number; |
577 } | 585 } |
578 | 586 |
579 // static | 587 // static |
580 bool AutofillField::FindValueInSelectControl(const FormFieldData& field, | 588 bool AutofillField::FindValueInSelectControl(const FormFieldData& field, |
581 const base::string16& value, | 589 const base::string16& value, |
582 size_t* index) { | 590 size_t* index) { |
583 l10n::CaseInsensitiveCompare compare; | 591 l10n::CaseInsensitiveCompare compare; |
(...skipping 12 matching lines...) Expand all Loading... | |
596 if (compare.StringsEqual(value_stripped, option_contents)) { | 604 if (compare.StringsEqual(value_stripped, option_contents)) { |
597 if (index) | 605 if (index) |
598 *index = i; | 606 *index = i; |
599 return true; | 607 return true; |
600 } | 608 } |
601 } | 609 } |
602 return false; | 610 return false; |
603 } | 611 } |
604 | 612 |
605 } // namespace autofill | 613 } // namespace autofill |
OLD | NEW |