summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill/form_group.h
blob: d9406826b2a71dac8e6cde3e6e87add704aada57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_AUTOFILL_FORM_GROUP_H_
#define CHROME_BROWSER_AUTOFILL_FORM_GROUP_H_
#pragma once

#include <vector>

#include "base/string16.h"
#include "base/string_util.h"
#include "chrome/browser/autofill/field_types.h"

// This class is an interface for collections of form fields, grouped by type.
// The information in objects of this class is managed by the
// PersonalDataManager.
class FormGroup {
 public:
  virtual ~FormGroup() {}

  // Used to determine the type of a field based on the text that a user enters
  // into the field. The field types can then be reported back to the server.
  // This method is additive on |matching_types|.
  virtual void GetMatchingTypes(const string16& text,
                                FieldTypeSet* matching_types) const;

  // Returns a set of AutofillFieldTypes for which this FormGroup has non-empty
  // data.  This method is additive on |non_empty_types|.
  virtual void GetNonEmptyTypes(FieldTypeSet* non_empty_types) const;

  // Returns the literal string associated with |type|.
  virtual string16 GetInfo(AutofillFieldType type) const = 0;

  // Used to populate this FormGroup object with data.
  virtual void SetInfo(AutofillFieldType type, const string16& value) = 0;

  // Returns the string that should be auto-filled into a text field given the
  // type of that field.
  virtual string16 GetCanonicalizedInfo(AutofillFieldType type) const;

  // Used to populate this FormGroup object with data.  Canonicalizes the data
  // prior to storing, if appropriate.
  virtual bool SetCanonicalizedInfo(AutofillFieldType type,
                                    const string16& value);

  // Returns the label for this FormGroup item. This should be overridden for
  // form group items that implement a label.
  virtual const string16 Label() const;

  // Returns true if the field data in |form_group| does not match the field
  // data in this FormGroup.
  virtual bool operator!=(const FormGroup& form_group) const;

  // Returns true if the data in this FormGroup is a subset of the data in
  // |form_group|.
  bool IsSubsetOf(const FormGroup& form_group) const;

  // Returns true if the values of the intersection of the available field types
  // are equal.  If the intersection is empty, the method returns false.
  bool IntersectionOfTypesHasEqualValues(const FormGroup& form_group) const;

  // Merges the field data in |form_group| with this FormGroup.
  void MergeWith(const FormGroup& form_group);

  // Overwrites the field data in |form_group| with this FormGroup.
  void OverwriteWith(const FormGroup& form_group);

 protected:
  // AutofillProfile needs to call into GetSupportedTypes() for objects of
  // non-AutofillProfile type, for which mere inheritance is insufficient.
  friend class AutofillProfile;

  // Returns a set of AutofillFieldTypes for which this FormGroup can store
  // data.  This method is additive on |supported_types|.
  virtual void GetSupportedTypes(FieldTypeSet* supported_types) const = 0;
};

#endif  // CHROME_BROWSER_AUTOFILL_FORM_GROUP_H_