| 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 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 FormFieldData* field_data) { | 537 FormFieldData* field_data) { |
| 538 AutofillType type = field.Type(); | 538 AutofillType type = field.Type(); |
| 539 | 539 |
| 540 // Don't fill if autocomplete=off is set on |field| on desktop for non credit | 540 // Don't fill if autocomplete=off is set on |field| on desktop for non credit |
| 541 // card related fields. | 541 // card related fields. |
| 542 if (!field.should_autocomplete && IsDesktopPlatform() && | 542 if (!field.should_autocomplete && IsDesktopPlatform() && |
| 543 (type.group() != CREDIT_CARD)) { | 543 (type.group() != CREDIT_CARD)) { |
| 544 return false; | 544 return false; |
| 545 } | 545 } |
| 546 | 546 |
| 547 if (type.GetStorableType() == PHONE_HOME_NUMBER) { | 547 if (type.group() == PHONE_HOME) { |
| 548 FillPhoneNumberField(field, value, field_data); | 548 FillPhoneNumberField(field, value, field_data); |
| 549 return true; | 549 return true; |
| 550 } else if (field_data->form_control_type == "select-one") { | 550 } else if (field_data->form_control_type == "select-one") { |
| 551 return FillSelectControl(type, value, app_locale, field_data); | 551 return FillSelectControl(type, value, app_locale, field_data); |
| 552 } else if (field_data->form_control_type == "month") { | 552 } else if (field_data->form_control_type == "month") { |
| 553 return FillMonthControl(value, field_data); | 553 return FillMonthControl(value, field_data); |
| 554 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) { | 554 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) { |
| 555 FillStreetAddress(value, address_language_code, field_data); | 555 FillStreetAddress(value, address_language_code, field_data); |
| 556 return true; | 556 return true; |
| 557 } else if (type.GetStorableType() == CREDIT_CARD_NUMBER) { | 557 } else if (type.GetStorableType() == CREDIT_CARD_NUMBER) { |
| 558 FillCreditCardNumberField(field, value, field_data); | 558 FillCreditCardNumberField(field, value, field_data); |
| 559 return true; | 559 return true; |
| 560 } | 560 } |
| 561 | 561 |
| 562 field_data->value = value; | 562 field_data->value = value; |
| 563 return true; | 563 return true; |
| 564 } | 564 } |
| 565 | 565 |
| 566 // TODO(crbug.com/581514): Add support for filling only the prefix/suffix for |
| 567 // phone numbers with 10 or 11 digits. |
| 566 base::string16 AutofillField::GetPhoneNumberValue( | 568 base::string16 AutofillField::GetPhoneNumberValue( |
| 567 const AutofillField& field, | 569 const AutofillField& field, |
| 568 const base::string16& number, | 570 const base::string16& number, |
| 569 const FormFieldData& field_data) { | 571 const FormFieldData& field_data) { |
| 570 // Check to see if the size field matches the "prefix" or "suffix" size. | 572 // TODO(crbug.com/581485): Investigate the use of libphonenumber here. |
| 571 // If so, return the appropriate substring. | 573 // Check to see if the |field| size matches the "prefix" or "suffix" size or |
| 572 if (number.length() != | 574 // if |
| 573 PhoneNumber::kPrefixLength + PhoneNumber::kSuffixLength) { | 575 // the field was labeled as such. If so, return the appropriate substring. |
| 574 return number; | 576 if (number.length() == |
| 577 PhoneNumber::kPrefixLength + PhoneNumber::kSuffixLength) { |
| 578 if (field.phone_part() == AutofillField::PHONE_PREFIX || |
| 579 field_data.max_length == PhoneNumber::kPrefixLength) { |
| 580 return number.substr(PhoneNumber::kPrefixOffset, |
| 581 PhoneNumber::kPrefixLength); |
| 582 } |
| 583 |
| 584 if (field.phone_part() == AutofillField::PHONE_SUFFIX || |
| 585 field_data.max_length == PhoneNumber::kSuffixLength) { |
| 586 return number.substr(PhoneNumber::kSuffixOffset, |
| 587 PhoneNumber::kSuffixLength); |
| 588 } |
| 575 } | 589 } |
| 576 | 590 |
| 577 if (field.phone_part() == AutofillField::PHONE_PREFIX || | 591 // If no max length was specified, return the complete number. |
| 578 field_data.max_length == PhoneNumber::kPrefixLength) { | 592 if (field_data.max_length == 0) |
| 579 return | 593 return number; |
| 580 number.substr(PhoneNumber::kPrefixOffset, PhoneNumber::kPrefixLength); | |
| 581 } | |
| 582 | 594 |
| 583 if (field.phone_part() == AutofillField::PHONE_SUFFIX || | 595 // If |number| exceeds the maximum size of the field, cut the first part to |
| 584 field_data.max_length == PhoneNumber::kSuffixLength) { | 596 // provide a valid number for the field. For example, the number 15142365264 |
| 585 return | 597 // with a field with a max length of 10 would return 5142365264, thus removing |
| 586 number.substr(PhoneNumber::kSuffixOffset, PhoneNumber::kSuffixLength); | 598 // the country code and remaining valid. |
| 599 if (number.length() > field_data.max_length) { |
| 600 return number.substr(number.length() - field_data.max_length, |
| 601 field_data.max_length); |
| 587 } | 602 } |
| 588 | 603 |
| 589 return number; | 604 return number; |
| 590 } | 605 } |
| 591 | 606 |
| 592 // static | 607 // static |
| 593 bool AutofillField::FindValueInSelectControl(const FormFieldData& field, | 608 bool AutofillField::FindValueInSelectControl(const FormFieldData& field, |
| 594 const base::string16& value, | 609 const base::string16& value, |
| 595 size_t* index) { | 610 size_t* index) { |
| 596 l10n::CaseInsensitiveCompare compare; | 611 l10n::CaseInsensitiveCompare compare; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 609 if (compare.StringsEqual(value_stripped, option_contents)) { | 624 if (compare.StringsEqual(value_stripped, option_contents)) { |
| 610 if (index) | 625 if (index) |
| 611 *index = i; | 626 *index = i; |
| 612 return true; | 627 return true; |
| 613 } | 628 } |
| 614 } | 629 } |
| 615 return false; | 630 return false; |
| 616 } | 631 } |
| 617 | 632 |
| 618 } // namespace autofill | 633 } // namespace autofill |
| OLD | NEW |