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