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" |
(...skipping 13 matching lines...) Expand all Loading... |
24 return base::UintToString(hash32); | 24 return base::UintToString(hash32); |
25 } | 25 } |
26 | 26 |
27 } // namespace | 27 } // namespace |
28 | 28 |
29 namespace autofill { | 29 namespace autofill { |
30 | 30 |
31 AutofillField::AutofillField() | 31 AutofillField::AutofillField() |
32 : server_type_(NO_SERVER_DATA), | 32 : server_type_(NO_SERVER_DATA), |
33 heuristic_type_(UNKNOWN_TYPE), | 33 heuristic_type_(UNKNOWN_TYPE), |
| 34 html_type_(HTML_TYPE_UNKNOWN), |
| 35 html_mode_(HTML_MODE_NONE), |
34 phone_part_(IGNORED) { | 36 phone_part_(IGNORED) { |
35 } | 37 } |
36 | 38 |
37 AutofillField::AutofillField(const FormFieldData& field, | 39 AutofillField::AutofillField(const FormFieldData& field, |
38 const base::string16& unique_name) | 40 const base::string16& unique_name) |
39 : FormFieldData(field), | 41 : FormFieldData(field), |
40 unique_name_(unique_name), | 42 unique_name_(unique_name), |
41 server_type_(NO_SERVER_DATA), | 43 server_type_(NO_SERVER_DATA), |
42 heuristic_type_(UNKNOWN_TYPE), | 44 heuristic_type_(UNKNOWN_TYPE), |
| 45 html_type_(HTML_TYPE_UNKNOWN), |
| 46 html_mode_(HTML_MODE_NONE), |
43 phone_part_(IGNORED) { | 47 phone_part_(IGNORED) { |
44 } | 48 } |
45 | 49 |
46 AutofillField::~AutofillField() {} | 50 AutofillField::~AutofillField() {} |
47 | 51 |
48 void AutofillField::set_heuristic_type(ServerFieldType type) { | 52 void AutofillField::set_heuristic_type(ServerFieldType type) { |
49 if (type >= 0 && type < MAX_VALID_FIELD_TYPE && | 53 if (type >= 0 && type < MAX_VALID_FIELD_TYPE && |
50 type != FIELD_WITH_DEFAULT_VALUE) { | 54 type != FIELD_WITH_DEFAULT_VALUE) { |
51 heuristic_type_ = type; | 55 heuristic_type_ = type; |
52 } else { | 56 } else { |
53 NOTREACHED(); | 57 NOTREACHED(); |
54 // This case should not be reachable; but since this has potential | 58 // This case should not be reachable; but since this has potential |
55 // implications on data uploaded to the server, better safe than sorry. | 59 // implications on data uploaded to the server, better safe than sorry. |
56 heuristic_type_ = UNKNOWN_TYPE; | 60 heuristic_type_ = UNKNOWN_TYPE; |
57 } | 61 } |
58 } | 62 } |
59 | 63 |
60 void AutofillField::set_server_type(ServerFieldType type) { | 64 void AutofillField::set_server_type(ServerFieldType type) { |
61 // Chrome no longer supports fax numbers, but the server still does. | 65 // Chrome no longer supports fax numbers, but the server still does. |
62 if (type >= PHONE_FAX_NUMBER && type <= PHONE_FAX_WHOLE_NUMBER) | 66 if (type >= PHONE_FAX_NUMBER && type <= PHONE_FAX_WHOLE_NUMBER) |
63 return; | 67 return; |
64 | 68 |
65 server_type_ = type; | 69 server_type_ = type; |
66 } | 70 } |
67 | 71 |
| 72 void AutofillField::SetHtmlType(HtmlFieldType type, HtmlFieldMode mode) { |
| 73 html_type_ = type; |
| 74 html_mode_ = mode; |
| 75 |
| 76 if (type == HTML_TYPE_TEL_LOCAL_PREFIX) |
| 77 phone_part_ = AutofillField::PHONE_PREFIX; |
| 78 else if (type == HTML_TYPE_TEL_LOCAL_SUFFIX) |
| 79 phone_part_ = AutofillField::PHONE_SUFFIX; |
| 80 } |
| 81 |
68 AutofillType AutofillField::Type() const { | 82 AutofillType AutofillField::Type() const { |
| 83 if (html_type_ != HTML_TYPE_UNKNOWN) |
| 84 return AutofillType(html_type_, html_mode_); |
| 85 |
69 if (server_type_ != NO_SERVER_DATA) | 86 if (server_type_ != NO_SERVER_DATA) |
70 return AutofillType(server_type_); | 87 return AutofillType(server_type_); |
71 | 88 |
72 return AutofillType(heuristic_type_); | 89 return AutofillType(heuristic_type_); |
73 } | 90 } |
74 | 91 |
75 bool AutofillField::IsEmpty() const { | 92 bool AutofillField::IsEmpty() const { |
76 return value.empty(); | 93 return value.empty(); |
77 } | 94 } |
78 | 95 |
79 std::string AutofillField::FieldSignature() const { | 96 std::string AutofillField::FieldSignature() const { |
80 std::string field_name = UTF16ToUTF8(name); | 97 std::string field_name = UTF16ToUTF8(name); |
81 std::string field_string = field_name + "&" + form_control_type; | 98 std::string field_string = field_name + "&" + form_control_type; |
82 return Hash32Bit(field_string); | 99 return Hash32Bit(field_string); |
83 } | 100 } |
84 | 101 |
85 bool AutofillField::IsFieldFillable() const { | 102 bool AutofillField::IsFieldFillable() const { |
86 return Type().server_type() != UNKNOWN_TYPE; | 103 return !Type().IsUnknown(); |
87 } | 104 } |
88 | 105 |
89 } // namespace autofill | 106 } // namespace autofill |
OLD | NEW |