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