Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(456)

Side by Side Diff: components/autofill/core/browser/autofill_field.cc

Issue 1639563002: [Autofill] Fill from the last digits when filling a phone number with a maximum length. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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.group() == PHONE_HOME) {
535 FillPhoneNumberField(field, value, field_data); 535 FillPhoneNumberField(field, value, field_data);
536 return true; 536 return true;
537 } else if (field_data->form_control_type == "select-one") { 537 } else if (field_data->form_control_type == "select-one") {
538 return FillSelectControl(type, value, app_locale, field_data); 538 return FillSelectControl(type, value, app_locale, field_data);
539 } else if (field_data->form_control_type == "month") { 539 } else if (field_data->form_control_type == "month") {
540 return FillMonthControl(value, field_data); 540 return FillMonthControl(value, field_data);
541 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) { 541 } else if (type.GetStorableType() == ADDRESS_HOME_STREET_ADDRESS) {
542 FillStreetAddress(value, address_language_code, field_data); 542 FillStreetAddress(value, address_language_code, field_data);
543 return true; 543 return true;
544 } else if (type.GetStorableType() == CREDIT_CARD_NUMBER) { 544 } else if (type.GetStorableType() == CREDIT_CARD_NUMBER) {
545 FillCreditCardNumberField(field, value, field_data); 545 FillCreditCardNumberField(field, value, field_data);
546 return true; 546 return true;
547 } 547 }
548 548
549 field_data->value = value; 549 field_data->value = value;
550 return true; 550 return true;
551 } 551 }
552 552
553 // TODO(crbug.com/581514): Add support for filling only the prefix/suffix for
554 // phone numbers with 10 or 11 digits.
553 base::string16 AutofillField::GetPhoneNumberValue( 555 base::string16 AutofillField::GetPhoneNumberValue(
554 const AutofillField& field, 556 const AutofillField& field,
555 const base::string16& number, 557 const base::string16& number,
556 const FormFieldData& field_data) { 558 const FormFieldData& field_data) {
557 // Check to see if the size field matches the "prefix" or "suffix" size. 559 // TODO(crbug.com/581485): Investigate the use of libphonenumber here.
558 // If so, return the appropriate substring. 560 // Check to see if the size field matches the "prefix" or "suffix" size or if
Mathieu 2016/01/27 14:30:49 size field -> |field| size
sebsg 2016/01/27 21:01:21 Done.
559 if (number.length() != 561 // the field was labeled as such. If so, return the appropriate substring.
560 PhoneNumber::kPrefixLength + PhoneNumber::kSuffixLength) { 562 if (number.length() ==
561 return number; 563 PhoneNumber::kPrefixLength + PhoneNumber::kSuffixLength) {
564 if (field.phone_part() == AutofillField::PHONE_PREFIX ||
565 field_data.max_length == PhoneNumber::kPrefixLength) {
566 return number.substr(PhoneNumber::kPrefixOffset,
567 PhoneNumber::kPrefixLength);
568 }
569
570 if (field.phone_part() == AutofillField::PHONE_SUFFIX ||
571 field_data.max_length == PhoneNumber::kSuffixLength) {
572 return number.substr(PhoneNumber::kSuffixOffset,
573 PhoneNumber::kSuffixLength);
574 }
562 } 575 }
563 576
564 if (field.phone_part() == AutofillField::PHONE_PREFIX || 577 // If no max length was specified, return the complete number.
565 field_data.max_length == PhoneNumber::kPrefixLength) { 578 if (field_data.max_length == 0)
566 return 579 return number;
567 number.substr(PhoneNumber::kPrefixOffset, PhoneNumber::kPrefixLength);
568 }
569 580
570 if (field.phone_part() == AutofillField::PHONE_SUFFIX || 581 // If |number| exceeds the maximum size of the field, cut the first part to
571 field_data.max_length == PhoneNumber::kSuffixLength) { 582 // provide a valid number for the field. For example, the number 15142365264
572 return 583 // with a field with a max length of 10 would return 5142365264, thus removing
573 number.substr(PhoneNumber::kSuffixOffset, PhoneNumber::kSuffixLength); 584 // the country code and remaining valid.
585 if (number.length() > field_data.max_length) {
586 return number.substr(number.length() - field_data.max_length,
587 field_data.max_length);
574 } 588 }
575 589
576 return number; 590 return number;
577 } 591 }
578 592
579 // static 593 // static
580 bool AutofillField::FindValueInSelectControl(const FormFieldData& field, 594 bool AutofillField::FindValueInSelectControl(const FormFieldData& field,
581 const base::string16& value, 595 const base::string16& value,
582 size_t* index) { 596 size_t* index) {
583 l10n::CaseInsensitiveCompare compare; 597 l10n::CaseInsensitiveCompare compare;
(...skipping 12 matching lines...) Expand all
596 if (compare.StringsEqual(value_stripped, option_contents)) { 610 if (compare.StringsEqual(value_stripped, option_contents)) {
597 if (index) 611 if (index)
598 *index = i; 612 *index = i;
599 return true; 613 return true;
600 } 614 }
601 } 615 }
602 return false; 616 return false;
603 } 617 }
604 618
605 } // namespace autofill 619 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698