OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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 CHROME_BROWSER_AUTOFILL_FORM_GROUP_H_ | |
6 #define CHROME_BROWSER_AUTOFILL_FORM_GROUP_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/string16.h" | |
12 #include "base/string_util.h" | |
13 #include "chrome/browser/autofill/field_types.h" | |
14 | |
15 class AutofillField; | |
16 struct FormFieldData; | |
17 | |
18 // This class is an interface for collections of form fields, grouped by type. | |
19 // The information in objects of this class is managed by the | |
20 // PersonalDataManager. | |
21 class FormGroup { | |
22 public: | |
23 virtual ~FormGroup() {} | |
24 | |
25 // Returns a globally unique ID for this object. It is an error to call the | |
26 // default implementation. | |
27 virtual std::string GetGUID() const; | |
28 | |
29 // Used to determine the type of a field based on the text that a user enters | |
30 // into the field, interpreted in the given |app_locale| if appropriate. The | |
31 // field types can then be reported back to the server. This method is | |
32 // additive on |matching_types|. | |
33 virtual void GetMatchingTypes(const string16& text, | |
34 const std::string& app_locale, | |
35 FieldTypeSet* matching_types) const; | |
36 | |
37 // Returns a set of AutofillFieldTypes for which this FormGroup has non-empty | |
38 // data. This method is additive on |non_empty_types|. | |
39 virtual void GetNonEmptyTypes(const std::string& app_locale, | |
40 FieldTypeSet* non_empty_types) const; | |
41 | |
42 // Returns the string associated with |type|, without canonicalizing the | |
43 // returned value. For user-visible strings, use GetInfo() instead. | |
44 virtual string16 GetRawInfo(AutofillFieldType type) const = 0; | |
45 | |
46 // Sets this FormGroup object's data for |type| to |value|, without | |
47 // canonicalizing the |value|. For data that has not already been | |
48 // canonicalized, use SetInfo() instead. | |
49 virtual void SetRawInfo(AutofillFieldType type, const string16& value) = 0; | |
50 | |
51 // Returns the string that should be auto-filled into a text field given the | |
52 // type of that field, localized to the given |app_locale| if appropriate. | |
53 virtual string16 GetInfo(AutofillFieldType type, | |
54 const std::string& app_locale) const; | |
55 | |
56 // Used to populate this FormGroup object with data. Canonicalizes the data | |
57 // according to the specified |app_locale| prior to storing, if appropriate. | |
58 virtual bool SetInfo(AutofillFieldType type, | |
59 const string16& value, | |
60 const std::string& app_locale); | |
61 | |
62 // Set |field_data|'s value based on |field| and contents of |this| (using | |
63 // data variant |variant|). It is an error to call the default implementation. | |
64 virtual void FillFormField(const AutofillField& field, | |
65 size_t variant, | |
66 FormFieldData* field_data) const; | |
67 | |
68 // Fills in select control with data matching |type| from |this|. | |
69 // Public for testing purposes. | |
70 void FillSelectControl(AutofillFieldType type, | |
71 FormFieldData* field_data) const; | |
72 | |
73 // Returns true if |value| is a valid US state name or abbreviation. It is | |
74 // case insensitive. Valid for US states only. | |
75 // TODO(estade): this is a crappy place for this function. | |
76 static bool IsValidState(const string16& value); | |
77 | |
78 protected: | |
79 // AutofillProfile needs to call into GetSupportedTypes() for objects of | |
80 // non-AutofillProfile type, for which mere inheritance is insufficient. | |
81 friend class AutofillProfile; | |
82 | |
83 // Returns a set of AutofillFieldTypes for which this FormGroup can store | |
84 // data. This method is additive on |supported_types|. | |
85 virtual void GetSupportedTypes(FieldTypeSet* supported_types) const = 0; | |
86 | |
87 // Fills in a select control for a country from data in |this|. Returns true | |
88 // for success. | |
89 virtual bool FillCountrySelectControl(FormFieldData* field_data) const; | |
90 }; | |
91 | |
92 #endif // CHROME_BROWSER_AUTOFILL_FORM_GROUP_H_ | |
OLD | NEW |