| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/sha1.h" | 8 #include "base/sha1.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "components/autofill/core/browser/autofill_type.h" |
| 11 | 12 |
| 12 namespace { | 13 namespace { |
| 13 | 14 |
| 14 static std::string Hash32Bit(const std::string& str) { | 15 static std::string Hash32Bit(const std::string& str) { |
| 15 std::string hash_bin = base::SHA1HashString(str); | 16 std::string hash_bin = base::SHA1HashString(str); |
| 16 DCHECK_EQ(20U, hash_bin.length()); | 17 DCHECK_EQ(20U, hash_bin.length()); |
| 17 | 18 |
| 18 uint32 hash32 = ((hash_bin[0] & 0xFF) << 24) | | 19 uint32 hash32 = ((hash_bin[0] & 0xFF) << 24) | |
| 19 ((hash_bin[1] & 0xFF) << 16) | | 20 ((hash_bin[1] & 0xFF) << 16) | |
| 20 ((hash_bin[2] & 0xFF) << 8) | | 21 ((hash_bin[2] & 0xFF) << 8) | |
| (...skipping 16 matching lines...) Expand all Loading... |
| 37 const base::string16& unique_name) | 38 const base::string16& unique_name) |
| 38 : FormFieldData(field), | 39 : FormFieldData(field), |
| 39 unique_name_(unique_name), | 40 unique_name_(unique_name), |
| 40 server_type_(NO_SERVER_DATA), | 41 server_type_(NO_SERVER_DATA), |
| 41 heuristic_type_(UNKNOWN_TYPE), | 42 heuristic_type_(UNKNOWN_TYPE), |
| 42 phone_part_(IGNORED) { | 43 phone_part_(IGNORED) { |
| 43 } | 44 } |
| 44 | 45 |
| 45 AutofillField::~AutofillField() {} | 46 AutofillField::~AutofillField() {} |
| 46 | 47 |
| 47 void AutofillField::set_heuristic_type(AutofillFieldType type) { | 48 void AutofillField::set_heuristic_type(ServerFieldType type) { |
| 48 if (type >= 0 && type < MAX_VALID_FIELD_TYPE && | 49 if (type >= 0 && type < MAX_VALID_FIELD_TYPE && |
| 49 type != FIELD_WITH_DEFAULT_VALUE) { | 50 type != FIELD_WITH_DEFAULT_VALUE) { |
| 50 heuristic_type_ = type; | 51 heuristic_type_ = type; |
| 51 } else { | 52 } else { |
| 52 NOTREACHED(); | 53 NOTREACHED(); |
| 53 // This case should not be reachable; but since this has potential | 54 // This case should not be reachable; but since this has potential |
| 54 // implications on data uploaded to the server, better safe than sorry. | 55 // implications on data uploaded to the server, better safe than sorry. |
| 55 heuristic_type_ = UNKNOWN_TYPE; | 56 heuristic_type_ = UNKNOWN_TYPE; |
| 56 } | 57 } |
| 57 } | 58 } |
| 58 | 59 |
| 59 void AutofillField::set_server_type(AutofillFieldType type) { | 60 void AutofillField::set_server_type(ServerFieldType type) { |
| 60 // Chrome no longer supports fax numbers, but the server still does. | 61 // Chrome no longer supports fax numbers, but the server still does. |
| 61 if (type >= PHONE_FAX_NUMBER && type <= PHONE_FAX_WHOLE_NUMBER) | 62 if (type >= PHONE_FAX_NUMBER && type <= PHONE_FAX_WHOLE_NUMBER) |
| 62 return; | 63 return; |
| 63 | 64 |
| 64 server_type_ = type; | 65 server_type_ = type; |
| 65 } | 66 } |
| 66 | 67 |
| 67 AutofillFieldType AutofillField::type() const { | 68 AutofillType AutofillField::Type() const { |
| 68 if (server_type_ != NO_SERVER_DATA) | 69 if (server_type_ != NO_SERVER_DATA) |
| 69 return server_type_; | 70 return AutofillType(server_type_); |
| 70 | 71 |
| 71 return heuristic_type_; | 72 return AutofillType(heuristic_type_); |
| 72 } | 73 } |
| 73 | 74 |
| 74 bool AutofillField::IsEmpty() const { | 75 bool AutofillField::IsEmpty() const { |
| 75 return value.empty(); | 76 return value.empty(); |
| 76 } | 77 } |
| 77 | 78 |
| 78 std::string AutofillField::FieldSignature() const { | 79 std::string AutofillField::FieldSignature() const { |
| 79 std::string field_name = UTF16ToUTF8(name); | 80 std::string field_name = UTF16ToUTF8(name); |
| 80 std::string field_string = field_name + "&" + form_control_type; | 81 std::string field_string = field_name + "&" + form_control_type; |
| 81 return Hash32Bit(field_string); | 82 return Hash32Bit(field_string); |
| 82 } | 83 } |
| 83 | 84 |
| 84 bool AutofillField::IsFieldFillable() const { | 85 bool AutofillField::IsFieldFillable() const { |
| 85 return type() != UNKNOWN_TYPE; | 86 return Type().server_type() != UNKNOWN_TYPE; |
| 86 } | 87 } |
| 87 | 88 |
| 88 } // namespace autofill | 89 } // namespace autofill |
| OLD | NEW |