autofill_field.h revision 3240926e260ce088908e02ac07a6cf7b0c0cbf44
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 const ServerFieldTypeSet& possible_types() const { return possible_types_; } 37 PhonePart phone_part() const { return phone_part_; } 38 39 // Sets the heuristic type of this field, validating the input. 40 void set_section(const std::string& section) { section_ = section; } 41 void set_heuristic_type(ServerFieldType type); 42 void set_server_type(ServerFieldType type); 43 void set_possible_types(const ServerFieldTypeSet& possible_types) { 44 possible_types_ = possible_types; 45 } 46 void set_phone_part(PhonePart part) { phone_part_ = part; } 47 48 // This function automatically chooses between server and heuristic autofill 49 // type, depending on the data available. 50 AutofillType Type() const; 51 52 // Returns true if the value of this field is empty. 53 bool IsEmpty() const; 54 55 // The unique signature of this field, composed of the field name and the html 56 // input type in a 32-bit hash. 57 std::string FieldSignature() const; 58 59 // Returns true if the field type has been determined (without the text in the 60 // field). 61 bool IsFieldFillable() const; 62 63 void set_default_value(const std::string& value) { default_value_ = value; } 64 const std::string& default_value() const { return default_value_; } 65 66 private: 67 // The unique name of this field, generated by Autofill. 68 base::string16 unique_name_; 69 70 // The unique identifier for the section (e.g. billing vs. shipping address) 71 // that this field belongs to. 72 std::string section_; 73 74 // The type of the field, as determined by the Autofill server. 75 ServerFieldType server_type_; 76 77 // The type of the field, as determined by the local heuristics. 78 ServerFieldType heuristic_type_; 79 80 // The set of possible types for this field. 81 ServerFieldTypeSet possible_types_; 82 83 // Used to track whether this field is a phone prefix or suffix. 84 PhonePart phone_part_; 85 86 // The default value returned by the Autofill server. 87 std::string default_value_; 88 89 DISALLOW_COPY_AND_ASSIGN(AutofillField); 90}; 91 92} // namespace autofill 93 94#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_FIELD_H_ 95