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/case_conversion.h" | 10 #include "base/i18n/case_conversion.h" |
11 #include "base/i18n/string_search.h" | 11 #include "base/i18n/string_search.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/metrics/field_trial.h" | 13 #include "base/metrics/field_trial.h" |
14 #include "base/sha1.h" | 14 #include "base/sha1.h" |
vabr (Chromium)
2016/09/07 16:18:06
Is this #include still needed?
kolos1
2016/09/08 08:34:27
Done.
| |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
19 #include "components/autofill/core/browser/autofill_country.h" | 19 #include "components/autofill/core/browser/autofill_country.h" |
20 #include "components/autofill/core/browser/autofill_type.h" | 20 #include "components/autofill/core/browser/autofill_type.h" |
21 #include "components/autofill/core/browser/country_names.h" | 21 #include "components/autofill/core/browser/country_names.h" |
22 #include "components/autofill/core/browser/credit_card.h" | 22 #include "components/autofill/core/browser/credit_card.h" |
23 #include "components/autofill/core/browser/phone_number.h" | 23 #include "components/autofill/core/browser/phone_number.h" |
24 #include "components/autofill/core/browser/proto/server.pb.h" | 24 #include "components/autofill/core/browser/proto/server.pb.h" |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
520 } | 520 } |
521 break; | 521 break; |
522 default: | 522 default: |
523 // Includes the case where max_length is not specified (0). | 523 // Includes the case where max_length is not specified (0). |
524 field->value = month + kSeparator + year; | 524 field->value = month + kSeparator + year; |
525 } | 525 } |
526 | 526 |
527 return true; | 527 return true; |
528 } | 528 } |
529 | 529 |
530 std::string Hash32Bit(const std::string& str) { | |
531 std::string hash_bin = base::SHA1HashString(str); | |
532 DCHECK_EQ(base::kSHA1Length, hash_bin.length()); | |
533 | |
534 uint32_t hash32 = ((hash_bin[0] & 0xFF) << 24) | | |
535 ((hash_bin[1] & 0xFF) << 16) | ((hash_bin[2] & 0xFF) << 8) | | |
536 (hash_bin[3] & 0xFF); | |
537 | |
538 return base::UintToString(hash32); | |
539 } | |
540 | |
541 base::string16 RemoveWhitespace(const base::string16& value) { | 530 base::string16 RemoveWhitespace(const base::string16& value) { |
542 base::string16 stripped_value; | 531 base::string16 stripped_value; |
543 base::RemoveChars(value, base::kWhitespaceUTF16, &stripped_value); | 532 base::RemoveChars(value, base::kWhitespaceUTF16, &stripped_value); |
544 return stripped_value; | 533 return stripped_value; |
545 } | 534 } |
546 | 535 |
547 } // namespace | 536 } // namespace |
548 | 537 |
549 AutofillField::AutofillField() | 538 AutofillField::AutofillField() |
550 : server_type_(NO_SERVER_DATA), | 539 : server_type_(NO_SERVER_DATA), |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
636 return AutofillType(server_type_); | 625 return AutofillType(server_type_); |
637 } | 626 } |
638 | 627 |
639 return AutofillType(heuristic_type_); | 628 return AutofillType(heuristic_type_); |
640 } | 629 } |
641 | 630 |
642 bool AutofillField::IsEmpty() const { | 631 bool AutofillField::IsEmpty() const { |
643 return value.empty(); | 632 return value.empty(); |
644 } | 633 } |
645 | 634 |
646 std::string AutofillField::FieldSignature() const { | 635 FieldSignature AutofillField::FieldSignature() const { |
647 std::string field_name = base::UTF16ToUTF8(name); | 636 return CalculateFieldSignatureByNameAndType(name, form_control_type); |
648 std::string field_string = field_name + "&" + form_control_type; | 637 } |
649 return Hash32Bit(field_string); | 638 |
639 std::string AutofillField::FieldSignatureAsStr() const { | |
640 return base::UintToString(FieldSignature()); | |
650 } | 641 } |
651 | 642 |
652 bool AutofillField::IsFieldFillable() const { | 643 bool AutofillField::IsFieldFillable() const { |
653 return !Type().IsUnknown(); | 644 return !Type().IsUnknown(); |
654 } | 645 } |
655 | 646 |
656 // static | 647 // static |
657 bool AutofillField::FillFormField(const AutofillField& field, | 648 bool AutofillField::FillFormField(const AutofillField& field, |
658 const base::string16& value, | 649 const base::string16& value, |
659 const std::string& address_language_code, | 650 const std::string& address_language_code, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
771 } | 762 } |
772 return best_match; | 763 return best_match; |
773 } | 764 } |
774 | 765 |
775 bool AutofillField::IsCreditCardPrediction() const { | 766 bool AutofillField::IsCreditCardPrediction() const { |
776 return AutofillType(server_type_).group() == CREDIT_CARD || | 767 return AutofillType(server_type_).group() == CREDIT_CARD || |
777 AutofillType(heuristic_type_).group() == CREDIT_CARD; | 768 AutofillType(heuristic_type_).group() == CREDIT_CARD; |
778 } | 769 } |
779 | 770 |
780 } // namespace autofill | 771 } // namespace autofill |
OLD | NEW |