summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/autofill/data_model_wrapper.h
blob: fc90d12513b012c2a0cd17d1a971aac55de7b75a (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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
// Copyright (c) 2012 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_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_
#define CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_

#include "base/compiler_specific.h"
#include "base/strings/string16.h"
#include "chrome/browser/ui/autofill/autofill_dialog_types.h"
#include "components/autofill/content/browser/wallet/wallet_items.h"
#include "components/autofill/core/browser/field_types.h"

namespace gfx {
class Image;
}

namespace autofill {

class AutofillDataModel;
class AutofillProfile;
class AutofillType;
class CreditCard;
class FormStructure;

namespace wallet {
class Address;
class FullWallet;
}

// A glue class that allows uniform interactions with autocomplete data sources,
// regardless of their type. Implementations are intended to be lightweight and
// copyable, only holding weak references to their backing model.
class DataModelWrapper {
 public:
  virtual ~DataModelWrapper();

  // Fills in |inputs| with the data that this model contains (|inputs| is an
  // out-param).
  void FillInputs(DetailInputs* inputs);

  // Returns the data for a specific autocomplete type in a format for filling
  // into a web form.
  virtual base::string16 GetInfo(const AutofillType& type) const = 0;

  // Returns the data for a specified type in a format optimized for displaying
  // to the user.
  virtual base::string16 GetInfoForDisplay(const AutofillType& type) const;

  // Returns the icon, if any, that represents this model.
  virtual gfx::Image GetIcon();

#if !defined(OS_ANDROID)
  // Gets text to display to the user to summarize this data source. The
  // default implementation assumes this is an address. Both params are required
  // to be non-NULL and will be filled in with text that is vertically compact
  // (but may take up a lot of horizontal space) and horizontally compact (but
  // may take up a lot of vertical space) respectively. The return value will
  // be true and the outparams will be filled in only if the data represented is
  // complete and valid.
  virtual bool GetDisplayText(base::string16* vertically_compact,
                              base::string16* horizontally_compact);
#endif

  // Fills in |form_structure| with the data that this model contains. |inputs|
  // and |comparator| are used to determine whether each field in the
  // FormStructure should be filled in or left alone. Returns whether any fields
  // in |form_structure| were found to be matching.
  bool FillFormStructure(
      const DetailInputs& inputs,
      const InputFieldComparator& compare,
      FormStructure* form_structure) const;

 protected:
  DataModelWrapper();

 private:
  DISALLOW_COPY_AND_ASSIGN(DataModelWrapper);
};

// A DataModelWrapper that does not hold data and does nothing when told to
// fill in a form.
class EmptyDataModelWrapper : public DataModelWrapper {
 public:
  EmptyDataModelWrapper();
  virtual ~EmptyDataModelWrapper();

  virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;

 protected:
  DISALLOW_COPY_AND_ASSIGN(EmptyDataModelWrapper);
};

// A DataModelWrapper for Autofill profiles.
class AutofillProfileWrapper : public DataModelWrapper {
 public:
  explicit AutofillProfileWrapper(const AutofillProfile* profile);
  AutofillProfileWrapper(const AutofillProfile* profile,
                         const AutofillType& variant_type,
                         size_t variant);
  virtual ~AutofillProfileWrapper();

  virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
  virtual base::string16 GetInfoForDisplay(const AutofillType& type) const
      OVERRIDE;

 protected:
  // Returns the variant that should be used when dealing with an element that
  // has the given |type|.
  size_t GetVariantForType(const AutofillType& type) const;

 private:
  const AutofillProfile* profile_;

  // The profile variant. |variant_| describes which variant of |variant_group_|
  // to use in the profile.
  FieldTypeGroup variant_group_;
  size_t variant_;

  DISALLOW_COPY_AND_ASSIGN(AutofillProfileWrapper);
};

// A DataModelWrapper specifically for shipping address profiles.
class AutofillShippingAddressWrapper : public AutofillProfileWrapper {
 public:
  explicit AutofillShippingAddressWrapper(const AutofillProfile* profile);
  virtual ~AutofillShippingAddressWrapper();

  virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;

 private:
  DISALLOW_COPY_AND_ASSIGN(AutofillShippingAddressWrapper);
};

// A DataModelWrapper specifically for Autofill CreditCard data.
class AutofillCreditCardWrapper : public DataModelWrapper {
 public:
  explicit AutofillCreditCardWrapper(const CreditCard* card);
  virtual ~AutofillCreditCardWrapper();

  virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
  virtual gfx::Image GetIcon() OVERRIDE;
#if !defined(OS_ANDROID)
  virtual bool GetDisplayText(base::string16* vertically_compact,
                              base::string16* horizontally_compact) OVERRIDE;
#endif

 private:
  const CreditCard* card_;

  DISALLOW_COPY_AND_ASSIGN(AutofillCreditCardWrapper);
};

// A DataModelWrapper for Wallet addresses.
class WalletAddressWrapper : public DataModelWrapper {
 public:
  explicit WalletAddressWrapper(const wallet::Address* address);
  virtual ~WalletAddressWrapper();

  virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
  virtual base::string16 GetInfoForDisplay(const AutofillType& type) const
      OVERRIDE;
#if !defined(OS_ANDROID)
  virtual bool GetDisplayText(base::string16* vertically_compact,
                              base::string16* horizontally_compact) OVERRIDE;
#endif

 private:
  const wallet::Address* address_;

  DISALLOW_COPY_AND_ASSIGN(WalletAddressWrapper);
};

// A DataModelWrapper for Wallet instruments.
class WalletInstrumentWrapper : public DataModelWrapper {
 public:
  explicit WalletInstrumentWrapper(
      const wallet::WalletItems::MaskedInstrument* instrument);
  virtual ~WalletInstrumentWrapper();

  virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
  virtual base::string16 GetInfoForDisplay(const AutofillType& type) const
      OVERRIDE;
  virtual gfx::Image GetIcon() OVERRIDE;
#if !defined(OS_ANDROID)
  virtual bool GetDisplayText(base::string16* vertically_compact,
                              base::string16* horizontally_compact) OVERRIDE;
#endif

 private:
  const wallet::WalletItems::MaskedInstrument* instrument_;

  DISALLOW_COPY_AND_ASSIGN(WalletInstrumentWrapper);
};

// A DataModelWrapper for FullWallet billing data.
class FullWalletBillingWrapper : public DataModelWrapper {
 public:
  explicit FullWalletBillingWrapper(wallet::FullWallet* full_wallet);
  virtual ~FullWalletBillingWrapper();

  virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
#if !defined(OS_ANDROID)
  virtual bool GetDisplayText(base::string16* vertically_compact,
                              base::string16* horizontally_compact) OVERRIDE;
#endif

 private:
  wallet::FullWallet* full_wallet_;

  DISALLOW_COPY_AND_ASSIGN(FullWalletBillingWrapper);
};

// A DataModelWrapper for FullWallet shipping data.
class FullWalletShippingWrapper : public DataModelWrapper {
 public:
  explicit FullWalletShippingWrapper(wallet::FullWallet* full_wallet);
  virtual ~FullWalletShippingWrapper();

  virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;

 private:
  wallet::FullWallet* full_wallet_;

  DISALLOW_COPY_AND_ASSIGN(FullWalletShippingWrapper);
};

// A DataModelWrapper to copy the output of one section to the input of another.
class FieldMapWrapper : public DataModelWrapper {
 public:
  explicit FieldMapWrapper(const FieldValueMap& field_map);
  virtual ~FieldMapWrapper();

  virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;

 private:
  const FieldValueMap& field_map_;

  DISALLOW_COPY_AND_ASSIGN(FieldMapWrapper);
};

}  // namespace autofill

#endif  // CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_