form_group.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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_FORM_GROUP_H_ 6#define COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_GROUP_H_ 7 8#include <string> 9 10#include "base/strings/string16.h" 11#include "components/autofill/core/browser/field_types.h" 12 13namespace autofill { 14 15// This class is an interface for collections of form fields, grouped by type. 16class FormGroup { 17 public: 18 virtual ~FormGroup() {} 19 20 // Used to determine the type of a field based on the text that a user enters 21 // into the field, interpreted in the given |app_locale| if appropriate. The 22 // field types can then be reported back to the server. This method is 23 // additive on |matching_types|. 24 virtual void GetMatchingTypes(const base::string16& text, 25 const std::string& app_locale, 26 FieldTypeSet* matching_types) const; 27 28 // Returns a set of AutofillFieldTypes for which this FormGroup has non-empty 29 // data. This method is additive on |non_empty_types|. 30 virtual void GetNonEmptyTypes(const std::string& app_locale, 31 FieldTypeSet* non_empty_types) const; 32 33 // Returns the string associated with |type|, without canonicalizing the 34 // returned value. For user-visible strings, use GetInfo() instead. 35 virtual base::string16 GetRawInfo(AutofillFieldType type) const = 0; 36 37 // Sets this FormGroup object's data for |type| to |value|, without 38 // canonicalizing the |value|. For data that has not already been 39 // canonicalized, use SetInfo() instead. 40 virtual void SetRawInfo(AutofillFieldType type, 41 const base::string16& value) = 0; 42 43 // Returns the string that should be auto-filled into a text field given the 44 // type of that field, localized to the given |app_locale| if appropriate. 45 virtual base::string16 GetInfo(AutofillFieldType type, 46 const std::string& app_locale) const; 47 48 // Used to populate this FormGroup object with data. Canonicalizes the data 49 // according to the specified |app_locale| prior to storing, if appropriate. 50 virtual bool SetInfo(AutofillFieldType type, 51 const base::string16& value, 52 const std::string& app_locale); 53 54 protected: 55 // AutofillProfile needs to call into GetSupportedTypes() for objects of 56 // non-AutofillProfile type, for which mere inheritance is insufficient. 57 friend class AutofillProfile; 58 59 // Returns a set of AutofillFieldTypes for which this FormGroup can store 60 // data. This method is additive on |supported_types|. 61 virtual void GetSupportedTypes(FieldTypeSet* supported_types) const = 0; 62}; 63 64} // namespace autofill 65 66#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_GROUP_H_ 67