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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_FIELD_H_
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_FIELD_H_
10 #include "base/basictypes.h"
11 #include "base/strings/string16.h"
12 #include "components/autofill/core/browser/field_types.h"
13 #include "components/autofill/core/common/form_field_data.h"
19 class AutofillField
: public FormFieldData
{
28 AutofillField(const FormFieldData
& field
, const base::string16
& unique_name
);
29 virtual ~AutofillField();
31 const base::string16
& unique_name() const { return unique_name_
; }
33 const std::string
& section() const { return section_
; }
34 ServerFieldType
heuristic_type() const { return heuristic_type_
; }
35 ServerFieldType
server_type() const { return server_type_
; }
36 HtmlFieldType
html_type() const { return html_type_
; }
37 HtmlFieldMode
html_mode() const { return html_mode_
; }
38 const ServerFieldTypeSet
& possible_types() const { return possible_types_
; }
39 PhonePart
phone_part() const { return phone_part_
; }
41 // Setters for the detected type and section for this field.
42 void set_section(const std::string
& section
) { section_
= section
; }
43 void set_heuristic_type(ServerFieldType type
);
44 void set_server_type(ServerFieldType type
);
45 void set_possible_types(const ServerFieldTypeSet
& possible_types
) {
46 possible_types_
= possible_types
;
48 void SetHtmlType(HtmlFieldType type
, HtmlFieldMode mode
);
50 // This function automatically chooses between server and heuristic autofill
51 // type, depending on the data available.
52 AutofillType
Type() const;
54 // Returns true if the value of this field is empty.
57 // The unique signature of this field, composed of the field name and the html
58 // input type in a 32-bit hash.
59 std::string
FieldSignature() const;
61 // Returns true if the field type has been determined (without the text in the
63 bool IsFieldFillable() const;
65 void set_default_value(const std::string
& value
) { default_value_
= value
; }
66 const std::string
& default_value() const { return default_value_
; }
68 void set_credit_card_number_offset(size_t position
) {
69 credit_card_number_offset_
= position
;
71 size_t credit_card_number_offset() const {
72 return credit_card_number_offset_
;
75 // Set |field_data|'s value to |value|. Uses |field|, |address_language_code|,
76 // and |app_locale| as hints when filling exceptional cases like phone number
77 // values and <select> fields. Returns |true| if the field has been filled,
79 static bool FillFormField(const AutofillField
& field
,
80 const base::string16
& value
,
81 const std::string
& address_language_code
,
82 const std::string
& app_locale
,
83 FormFieldData
* field_data
);
85 // Returns the phone number value for the given |field|. The returned value
86 // might be |number|, or could possibly be a prefix or suffix of |number|
87 // if that's appropriate for the field.
88 static base::string16
GetPhoneNumberValue(const AutofillField
& field
,
89 const base::string16
& number
,
90 const FormFieldData
& field_data
);
92 // Returns true if the select |field| contains an option that matches |value|.
93 // If the return value is true and |index| is non-NULL, write the index of the
94 // matching option into |index|.
95 static bool FindValueInSelectControl(const FormFieldData
& field
,
96 const base::string16
& value
,
100 // The unique name of this field, generated by Autofill.
101 base::string16 unique_name_
;
103 // The unique identifier for the section (e.g. billing vs. shipping address)
104 // that this field belongs to.
105 std::string section_
;
107 // The type of the field, as determined by the Autofill server.
108 ServerFieldType server_type_
;
110 // The type of the field, as determined by the local heuristics.
111 ServerFieldType heuristic_type_
;
113 // The type of the field, as specified by the site author in HTML.
114 HtmlFieldType html_type_
;
116 // The "mode" of the field, as specified by the site author in HTML.
117 // Currently this is used to distinguish between billing and shipping fields.
118 HtmlFieldMode html_mode_
;
120 // The set of possible types for this field.
121 ServerFieldTypeSet possible_types_
;
123 // Used to track whether this field is a phone prefix or suffix.
124 PhonePart phone_part_
;
126 // The default value returned by the Autofill server.
127 std::string default_value_
;
129 // Used to hold the position of the first digit to be copied as a substring
130 // from credit card number.
131 size_t credit_card_number_offset_
;
133 DISALLOW_COPY_AND_ASSIGN(AutofillField
);
136 } // namespace autofill
138 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_FIELD_H_