Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 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 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 8 | #include <string> |
| 9 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 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: |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 18 | explicit AutofillType(ServerFieldType field_type); |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 19 | AutofillType(HtmlFieldType field_type, HtmlFieldMode mode); |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 20 | AutofillType(const AutofillType& autofill_type); |
| 21 | AutofillType& operator=(const AutofillType& autofill_type); |
| 22 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 23 | FieldTypeGroup group() const; |
| 24 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 25 | // Returns true if both the |server_type_| and the |html_type_| are set to |
| 26 | // their respective enum's unknown value. |
| 27 | bool IsUnknown() const; |
| 28 | |
| 29 | // Maps |this| type to a field type that can be directly stored in an Autofill |
| 30 | // data model (in the sense that it makes sense to call |
| 31 | // |AutofillDataModel::SetRawInfo()| with the returned field type as the first |
| 32 | // parameter). |
| 33 | ServerFieldType GetStorableType() const; |
| 34 | |
| 35 | // Serializes |this| type to a string. |
| 36 | std::string ToString() const; |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 37 | |
| 38 | // Maps |field_type| to a field type from ADDRESS_BILLING FieldTypeGroup if |
| 39 | // field type is an Address type. |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 40 | // TODO(isherman): This method is only used by the |
| 41 | // AutofillDialogControllerImpl class. Consider moving it to a more focused |
| 42 | // location. |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 43 | static ServerFieldType GetEquivalentBillingFieldType( |
| 44 | ServerFieldType field_type); |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 45 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 46 | // TODO(isherman): This method is only used be a single test class. Move the |
| 47 | // logic into there or something, eh? |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 48 | static ServerFieldType StringToFieldType(const std::string& str); |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 49 | |
| 50 | private: |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 51 | // The server-native field type, or UNKNOWN_TYPE if unset. |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 52 | ServerFieldType server_type_; |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 53 | |
| 54 | // The HTML autocomplete field type and mode hints, or HTML_TYPE_UNKNOWN and |
| 55 | // HTML_MODE_NONE if unset. |
| 56 | HtmlFieldType html_type_; |
| 57 | HtmlFieldMode html_mode_; |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 58 | }; |
| 59 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 60 | } // namespace autofill |
| 61 | |
| 62 | #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_TYPE_H_ |