autofill_field.h revision 5f1c94371a64b3196d4be9466099bb892df9b88e
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. 4 5#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_FIELD_H_ 6#define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_FIELD_H_ 7 8#include <string> 9 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" 14 15namespace autofill { 16 17class AutofillType; 18 19class AutofillField : public FormFieldData { 20 public: 21 enum PhonePart { 22 IGNORED = 0, 23 PHONE_PREFIX = 1, 24 PHONE_SUFFIX = 2, 25 }; 26 27 AutofillField(); 28 AutofillField(const FormFieldData& field, const base::string16& unique_name); 29 virtual ~AutofillField(); 30 31 const base::string16& unique_name() const { return unique_name_; } 32 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 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; 47 } 48 void SetHtmlType(HtmlFieldType type, HtmlFieldMode mode); 49 50 // This function automatically chooses between server and heuristic autofill 51 // type, depending on the data available. 52 AutofillType Type() const; 53 54 // Returns true if the value of this field is empty. 55 bool IsEmpty() const; 56 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; 60 61 // Returns true if the field type has been determined (without the text in the 62 // field). 63 bool IsFieldFillable() const; 64 65 void set_default_value(const std::string& value) { default_value_ = value; } 66 const std::string& default_value() const { return default_value_; } 67 68 // Set |field_data|'s value to |value|. Uses |field|, |address_language_code|, 69 // and |app_locale| as hints when filling exceptional cases like phone number 70 // values and <select> fields. Returns |true| if the field has been filled, 71 // |false| otherwise. 72 static bool FillFormField(const AutofillField& field, 73 const base::string16& value, 74 const std::string& address_language_code, 75 const std::string& app_locale, 76 FormFieldData* field_data); 77 78 private: 79 // The unique name of this field, generated by Autofill. 80 base::string16 unique_name_; 81 82 // The unique identifier for the section (e.g. billing vs. shipping address) 83 // that this field belongs to. 84 std::string section_; 85 86 // The type of the field, as determined by the Autofill server. 87 ServerFieldType server_type_; 88 89 // The type of the field, as determined by the local heuristics. 90 ServerFieldType heuristic_type_; 91 92 // The type of the field, as specified by the site author in HTML. 93 HtmlFieldType html_type_; 94 95 // The "mode" of the field, as specified by the site author in HTML. 96 // Currently this is used to distinguish between billing and shipping fields. 97 HtmlFieldMode html_mode_; 98 99 // The set of possible types for this field. 100 ServerFieldTypeSet possible_types_; 101 102 // Used to track whether this field is a phone prefix or suffix. 103 PhonePart phone_part_; 104 105 // The default value returned by the Autofill server. 106 std::string default_value_; 107 108 DISALLOW_COPY_AND_ASSIGN(AutofillField); 109}; 110 111} // namespace autofill 112 113#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_FIELD_H_ 114