data_model_wrapper.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
1// Copyright (c) 2012 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_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_
6#define CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_
7
8#include "base/compiler_specific.h"
9#include "base/strings/string16.h"
10#include "chrome/browser/ui/autofill/autofill_dialog_types.h"
11#include "components/autofill/content/browser/wallet/wallet_items.h"
12#include "components/autofill/core/browser/field_types.h"
13
14namespace gfx {
15class Image;
16}
17
18namespace autofill {
19
20class AutofillDataModel;
21class AutofillProfile;
22class CreditCard;
23class FormStructure;
24
25namespace wallet {
26class Address;
27class FullWallet;
28}
29
30// A glue class that allows uniform interactions with autocomplete data sources,
31// regardless of their type. Implementations are intended to be lightweight and
32// copyable, only holding weak references to their backing model.
33class DataModelWrapper {
34 public:
35  virtual ~DataModelWrapper();
36
37  // Returns the data for a specific autocomplete type.
38  virtual string16 GetInfo(AutofillFieldType type) const = 0;
39
40  // Returns the icon, if any, that represents this model.
41  virtual gfx::Image GetIcon();
42
43  // Fills in |inputs| with the data that this model contains (|inputs| is an
44  // out-param).
45  virtual void FillInputs(DetailInputs* inputs);
46
47  // Returns text to display to the user to summarize this data source. The
48  // default implementation assumes this is an address.
49  virtual string16 GetDisplayText();
50
51  // Fills in |form_structure| with the data that this model contains. |inputs|
52  // and |comparator| are used to determine whether each field in the
53  // FormStructure should be filled in or left alone. Returns whether any fields
54  // in |form_structure| were found to be matching.
55  bool FillFormStructure(
56      const DetailInputs& inputs,
57      const InputFieldComparator& compare,
58      FormStructure* form_structure) const;
59
60 protected:
61  DataModelWrapper();
62
63  // Fills in |field| with data from the model.
64  virtual void FillFormField(AutofillField* field) const;
65
66 private:
67  DISALLOW_COPY_AND_ASSIGN(DataModelWrapper);
68};
69
70// A DataModelWrapper that does not hold data and does nothing when told to
71// fill in a form.
72class EmptyDataModelWrapper : public DataModelWrapper {
73 public:
74  EmptyDataModelWrapper();
75  virtual ~EmptyDataModelWrapper();
76
77  virtual string16 GetInfo(AutofillFieldType type) const OVERRIDE;
78
79 protected:
80  virtual void FillFormField(AutofillField* field) const OVERRIDE;
81
82  DISALLOW_COPY_AND_ASSIGN(EmptyDataModelWrapper);
83};
84
85// A DataModelWrapper for Autofill data.
86class AutofillDataModelWrapper : public DataModelWrapper {
87 public:
88  AutofillDataModelWrapper(const AutofillDataModel* data_model, size_t variant);
89  virtual ~AutofillDataModelWrapper();
90
91  virtual string16 GetInfo(AutofillFieldType type) const OVERRIDE;
92
93 protected:
94  virtual void FillFormField(AutofillField* field) const OVERRIDE;
95
96  size_t variant() const { return variant_; }
97
98 private:
99  const AutofillDataModel* data_model_;
100  const size_t variant_;
101
102  DISALLOW_COPY_AND_ASSIGN(AutofillDataModelWrapper);
103};
104
105// A DataModelWrapper for Autofill profiles.
106class AutofillProfileWrapper : public AutofillDataModelWrapper {
107 public:
108  AutofillProfileWrapper(const AutofillProfile* profile, size_t variant);
109  virtual ~AutofillProfileWrapper();
110
111  virtual void FillInputs(DetailInputs* inputs) OVERRIDE;
112
113 private:
114  const AutofillProfile* profile_;
115
116  DISALLOW_COPY_AND_ASSIGN(AutofillProfileWrapper);
117};
118
119// A DataModelWrapper specifically for Autofill CreditCard data.
120class AutofillCreditCardWrapper : public AutofillDataModelWrapper {
121 public:
122  explicit AutofillCreditCardWrapper(const CreditCard* card);
123  virtual ~AutofillCreditCardWrapper();
124
125  virtual string16 GetInfo(AutofillFieldType type) const OVERRIDE;
126  virtual gfx::Image GetIcon() OVERRIDE;
127  virtual string16 GetDisplayText() OVERRIDE;
128
129 protected:
130  virtual void FillFormField(AutofillField* field) const OVERRIDE;
131
132 private:
133  const CreditCard* card_;
134
135  DISALLOW_COPY_AND_ASSIGN(AutofillCreditCardWrapper);
136};
137
138// A DataModelWrapper for Wallet addresses.
139class WalletAddressWrapper : public DataModelWrapper {
140 public:
141  explicit WalletAddressWrapper(const wallet::Address* address);
142  virtual ~WalletAddressWrapper();
143
144  virtual string16 GetInfo(AutofillFieldType type) const OVERRIDE;
145  virtual string16 GetDisplayText() OVERRIDE;
146
147 private:
148  const wallet::Address* address_;
149
150  DISALLOW_COPY_AND_ASSIGN(WalletAddressWrapper);
151};
152
153// A DataModelWrapper for Wallet instruments.
154class WalletInstrumentWrapper : public DataModelWrapper {
155 public:
156  explicit WalletInstrumentWrapper(
157      const wallet::WalletItems::MaskedInstrument* instrument);
158  virtual ~WalletInstrumentWrapper();
159
160  virtual string16 GetInfo(AutofillFieldType type) const OVERRIDE;
161  virtual gfx::Image GetIcon() OVERRIDE;
162  virtual string16 GetDisplayText() OVERRIDE;
163
164 private:
165  const wallet::WalletItems::MaskedInstrument* instrument_;
166
167  DISALLOW_COPY_AND_ASSIGN(WalletInstrumentWrapper);
168};
169
170// A DataModelWrapper for FullWallet billing data.
171class FullWalletBillingWrapper : public DataModelWrapper {
172 public:
173  explicit FullWalletBillingWrapper(wallet::FullWallet* full_wallet);
174  virtual ~FullWalletBillingWrapper();
175
176  virtual string16 GetInfo(AutofillFieldType type) const OVERRIDE;
177  virtual string16 GetDisplayText() OVERRIDE;
178
179 private:
180  wallet::FullWallet* full_wallet_;
181
182  DISALLOW_COPY_AND_ASSIGN(FullWalletBillingWrapper);
183};
184
185// A DataModelWrapper for FullWallet shipping data.
186class FullWalletShippingWrapper : public DataModelWrapper {
187 public:
188  explicit FullWalletShippingWrapper(wallet::FullWallet* full_wallet);
189  virtual ~FullWalletShippingWrapper();
190
191  virtual string16 GetInfo(AutofillFieldType type) const OVERRIDE;
192
193 private:
194  wallet::FullWallet* full_wallet_;
195
196  DISALLOW_COPY_AND_ASSIGN(FullWalletShippingWrapper);
197};
198
199// A DataModelWrapper to copy the output of one section to the input of another.
200class DetailOutputWrapper : public DataModelWrapper {
201 public:
202  explicit DetailOutputWrapper(const DetailOutputMap& outputs);
203  virtual ~DetailOutputWrapper();
204
205  virtual base::string16 GetInfo(AutofillFieldType type) const OVERRIDE;
206
207 private:
208  const DetailOutputMap& outputs_;
209
210  DISALLOW_COPY_AND_ASSIGN(DetailOutputWrapper);
211};
212
213}  // namespace autofill
214
215#endif  // CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_
216