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_TYPE_H_ 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_TYPE_H_ 7 8 #include <string> 9 10 #include "components/autofill/core/browser/field_types.h" 11 12 namespace autofill { 13 14 // The high-level description of Autofill types, used to categorize form fields 15 // and for associating form fields with form values in the Web Database. 16 class AutofillType { 17 public: 18 explicit AutofillType(ServerFieldType field_type); 19 AutofillType(HtmlFieldType field_type, HtmlFieldMode mode); 20 AutofillType(const AutofillType& autofill_type); 21 AutofillType& operator=(const AutofillType& autofill_type); 22 23 HtmlFieldType html_type() const { return html_type_; } 24 25 FieldTypeGroup group() const; 26 27 // Returns true if both the |server_type_| and the |html_type_| are set to 28 // their respective enum's unknown value. 29 bool IsUnknown() const; 30 31 // Maps |this| type to a field type that can be directly stored in an Autofill 32 // data model (in the sense that it makes sense to call 33 // |AutofillDataModel::SetRawInfo()| with the returned field type as the first 34 // parameter). Note that the returned type might not be exactly equivalent to 35 // |this| type. For example, the HTML types 'country' and 'country-name' both 36 // map to ADDRESS_HOME_COUNTRY. 37 ServerFieldType GetStorableType() const; 38 39 // Serializes |this| type to a string. 40 std::string ToString() const; 41 42 // Maps |field_type| to the corresponding billing field type if the field type 43 // is an address, name, or phone number type. 44 static ServerFieldType GetEquivalentBillingFieldType( 45 ServerFieldType field_type); 46 47 private: 48 // The server-native field type, or UNKNOWN_TYPE if unset. 49 ServerFieldType server_type_; 50 51 // The HTML autocomplete field type and mode hints, or HTML_TYPE_UNKNOWN and 52 // HTML_MODE_NONE if unset. 53 HtmlFieldType html_type_; 54 HtmlFieldMode html_mode_; 55 }; 56 57 } // namespace autofill 58 59 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_TYPE_H_ 60