Only grant permissions to new extensions from sync if they have the expected version
[chromium-blink-merge.git] / components / autofill / core / browser / autofill_field.h
blob0c1c81db7407279d6f4ec95fa2ac582a8f7373fb
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_
8 #include <string>
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"
15 namespace autofill {
17 class AutofillType;
19 class AutofillField : public FormFieldData {
20 public:
21 enum PhonePart {
22 IGNORED = 0,
23 PHONE_PREFIX = 1,
24 PHONE_SUFFIX = 2,
27 AutofillField();
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_; }
40 bool previously_autofilled() const { return previously_autofilled_; }
42 // Setters for the detected type and section for this field.
43 void set_section(const std::string& section) { section_ = section; }
44 void set_heuristic_type(ServerFieldType type);
45 void set_server_type(ServerFieldType type);
46 void set_possible_types(const ServerFieldTypeSet& possible_types) {
47 possible_types_ = possible_types;
49 void SetHtmlType(HtmlFieldType type, HtmlFieldMode mode);
50 void set_previously_autofilled(bool previously_autofilled) {
51 previously_autofilled_ = previously_autofilled;
54 // This function automatically chooses between server and heuristic autofill
55 // type, depending on the data available.
56 AutofillType Type() const;
58 // Returns true if the value of this field is empty.
59 bool IsEmpty() const;
61 // The unique signature of this field, composed of the field name and the html
62 // input type in a 32-bit hash.
63 std::string FieldSignature() const;
65 // Returns true if the field type has been determined (without the text in the
66 // field).
67 bool IsFieldFillable() const;
69 void set_default_value(const std::string& value) { default_value_ = value; }
70 const std::string& default_value() const { return default_value_; }
72 void set_credit_card_number_offset(size_t position) {
73 credit_card_number_offset_ = position;
75 size_t credit_card_number_offset() const {
76 return credit_card_number_offset_;
79 // Set |field_data|'s value to |value|. Uses |field|, |address_language_code|,
80 // and |app_locale| as hints when filling exceptional cases like phone number
81 // values and <select> fields. Returns |true| if the field has been filled,
82 // |false| otherwise.
83 static bool FillFormField(const AutofillField& field,
84 const base::string16& value,
85 const std::string& address_language_code,
86 const std::string& app_locale,
87 FormFieldData* field_data);
89 // Returns the phone number value for the given |field|. The returned value
90 // might be |number|, or could possibly be a prefix or suffix of |number|
91 // if that's appropriate for the field.
92 static base::string16 GetPhoneNumberValue(const AutofillField& field,
93 const base::string16& number,
94 const FormFieldData& field_data);
96 // Returns true if the select |field| contains an option that matches |value|.
97 // If the return value is true and |index| is non-NULL, write the index of the
98 // matching option into |index|.
99 static bool FindValueInSelectControl(const FormFieldData& field,
100 const base::string16& value,
101 size_t* index);
103 private:
104 // The unique name of this field, generated by Autofill.
105 base::string16 unique_name_;
107 // The unique identifier for the section (e.g. billing vs. shipping address)
108 // that this field belongs to.
109 std::string section_;
111 // The type of the field, as determined by the Autofill server.
112 ServerFieldType server_type_;
114 // The type of the field, as determined by the local heuristics.
115 ServerFieldType heuristic_type_;
117 // The type of the field, as specified by the site author in HTML.
118 HtmlFieldType html_type_;
120 // The "mode" of the field, as specified by the site author in HTML.
121 // Currently this is used to distinguish between billing and shipping fields.
122 HtmlFieldMode html_mode_;
124 // The set of possible types for this field.
125 ServerFieldTypeSet possible_types_;
127 // Used to track whether this field is a phone prefix or suffix.
128 PhonePart phone_part_;
130 // The default value returned by the Autofill server.
131 std::string default_value_;
133 // Used to hold the position of the first digit to be copied as a substring
134 // from credit card number.
135 size_t credit_card_number_offset_;
137 // Whether the field was autofilled then later edited.
138 bool previously_autofilled_;
140 DISALLOW_COPY_AND_ASSIGN(AutofillField);
143 } // namespace autofill
145 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_FIELD_H_