- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / autofill / data_model_wrapper.h
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
14 namespace gfx {
15 class Image;
16 }
17
18 namespace autofill {
19
20 class AutofillDataModel;
21 class AutofillProfile;
22 class AutofillType;
23 class CreditCard;
24 class FormStructure;
25
26 namespace wallet {
27 class Address;
28 class FullWallet;
29 }
30
31 // A glue class that allows uniform interactions with autocomplete data sources,
32 // regardless of their type. Implementations are intended to be lightweight and
33 // copyable, only holding weak references to their backing model.
34 class DataModelWrapper {
35  public:
36   virtual ~DataModelWrapper();
37
38   // Fills in |inputs| with the data that this model contains (|inputs| is an
39   // out-param).
40   void FillInputs(DetailInputs* inputs);
41
42   // Returns the data for a specific autocomplete type in a format for filling
43   // into a web form.
44   virtual base::string16 GetInfo(const AutofillType& type) const = 0;
45
46   // Returns the data for a specified type in a format optimized for displaying
47   // to the user.
48   virtual base::string16 GetInfoForDisplay(const AutofillType& type) const;
49
50   // Returns the icon, if any, that represents this model.
51   virtual gfx::Image GetIcon();
52
53   // Gets text to display to the user to summarize this data source. The
54   // default implementation assumes this is an address. Both params are required
55   // to be non-NULL and will be filled in with text that is vertically compact
56   // (but may take up a lot of horizontal space) and horizontally compact (but
57   // may take up a lot of vertical space) respectively. The return value will
58   // be true and the outparams will be filled in only if the data represented is
59   // complete and valid.
60   virtual bool GetDisplayText(base::string16* vertically_compact,
61                               base::string16* horizontally_compact);
62
63   // Fills in |form_structure| with the data that this model contains. |inputs|
64   // and |comparator| are used to determine whether each field in the
65   // FormStructure should be filled in or left alone. Returns whether any fields
66   // in |form_structure| were found to be matching.
67   bool FillFormStructure(
68       const DetailInputs& inputs,
69       const InputFieldComparator& compare,
70       FormStructure* form_structure) const;
71
72  protected:
73   DataModelWrapper();
74
75  private:
76   // Formats address data into a single string using |separator| between
77   // fields.
78   base::string16 GetAddressDisplayText(const base::string16& separator);
79
80   DISALLOW_COPY_AND_ASSIGN(DataModelWrapper);
81 };
82
83 // A DataModelWrapper that does not hold data and does nothing when told to
84 // fill in a form.
85 class EmptyDataModelWrapper : public DataModelWrapper {
86  public:
87   EmptyDataModelWrapper();
88   virtual ~EmptyDataModelWrapper();
89
90   virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
91
92  protected:
93   DISALLOW_COPY_AND_ASSIGN(EmptyDataModelWrapper);
94 };
95
96 // A DataModelWrapper for Autofill profiles.
97 class AutofillProfileWrapper : public DataModelWrapper {
98  public:
99   explicit AutofillProfileWrapper(const AutofillProfile* profile);
100   AutofillProfileWrapper(const AutofillProfile* profile,
101                          const AutofillType& variant_type,
102                          size_t variant);
103   virtual ~AutofillProfileWrapper();
104
105   virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
106   virtual base::string16 GetInfoForDisplay(const AutofillType& type) const
107       OVERRIDE;
108
109  protected:
110   // Returns the variant that should be used when dealing with an element that
111   // has the given |type|.
112   size_t GetVariantForType(const AutofillType& type) const;
113
114  private:
115   const AutofillProfile* profile_;
116
117   // The profile variant. |variant_| describes which variant of |variant_group_|
118   // to use in the profile.
119   FieldTypeGroup variant_group_;
120   size_t variant_;
121
122   DISALLOW_COPY_AND_ASSIGN(AutofillProfileWrapper);
123 };
124
125 // A DataModelWrapper specifically for shipping address profiles.
126 class AutofillShippingAddressWrapper : public AutofillProfileWrapper {
127  public:
128   explicit AutofillShippingAddressWrapper(const AutofillProfile* profile);
129   virtual ~AutofillShippingAddressWrapper();
130
131   virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
132
133  private:
134   DISALLOW_COPY_AND_ASSIGN(AutofillShippingAddressWrapper);
135 };
136
137 // A DataModelWrapper specifically for Autofill CreditCard data.
138 class AutofillCreditCardWrapper : public DataModelWrapper {
139  public:
140   explicit AutofillCreditCardWrapper(const CreditCard* card);
141   virtual ~AutofillCreditCardWrapper();
142
143   virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
144   virtual gfx::Image GetIcon() OVERRIDE;
145   virtual bool GetDisplayText(base::string16* vertically_compact,
146                               base::string16* horizontally_compact) OVERRIDE;
147
148  private:
149   const CreditCard* card_;
150
151   DISALLOW_COPY_AND_ASSIGN(AutofillCreditCardWrapper);
152 };
153
154 // A DataModelWrapper for Wallet addresses.
155 class WalletAddressWrapper : public DataModelWrapper {
156  public:
157   explicit WalletAddressWrapper(const wallet::Address* address);
158   virtual ~WalletAddressWrapper();
159
160   virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
161   virtual base::string16 GetInfoForDisplay(const AutofillType& type) const
162       OVERRIDE;
163   virtual bool GetDisplayText(base::string16* vertically_compact,
164                               base::string16* horizontally_compact) OVERRIDE;
165
166  private:
167   const wallet::Address* address_;
168
169   DISALLOW_COPY_AND_ASSIGN(WalletAddressWrapper);
170 };
171
172 // A DataModelWrapper for Wallet instruments.
173 class WalletInstrumentWrapper : public DataModelWrapper {
174  public:
175   explicit WalletInstrumentWrapper(
176       const wallet::WalletItems::MaskedInstrument* instrument);
177   virtual ~WalletInstrumentWrapper();
178
179   virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
180   virtual base::string16 GetInfoForDisplay(const AutofillType& type) const
181       OVERRIDE;
182   virtual gfx::Image GetIcon() OVERRIDE;
183   virtual bool GetDisplayText(base::string16* vertically_compact,
184                               base::string16* horizontally_compact) OVERRIDE;
185
186  private:
187   const wallet::WalletItems::MaskedInstrument* instrument_;
188
189   DISALLOW_COPY_AND_ASSIGN(WalletInstrumentWrapper);
190 };
191
192 // A DataModelWrapper for FullWallet billing data.
193 class FullWalletBillingWrapper : public DataModelWrapper {
194  public:
195   explicit FullWalletBillingWrapper(wallet::FullWallet* full_wallet);
196   virtual ~FullWalletBillingWrapper();
197
198   virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
199   virtual bool GetDisplayText(base::string16* vertically_compact,
200                               base::string16* horizontally_compact) OVERRIDE;
201
202  private:
203   wallet::FullWallet* full_wallet_;
204
205   DISALLOW_COPY_AND_ASSIGN(FullWalletBillingWrapper);
206 };
207
208 // A DataModelWrapper for FullWallet shipping data.
209 class FullWalletShippingWrapper : public DataModelWrapper {
210  public:
211   explicit FullWalletShippingWrapper(wallet::FullWallet* full_wallet);
212   virtual ~FullWalletShippingWrapper();
213
214   virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
215
216  private:
217   wallet::FullWallet* full_wallet_;
218
219   DISALLOW_COPY_AND_ASSIGN(FullWalletShippingWrapper);
220 };
221
222 // A DataModelWrapper to copy the output of one section to the input of another.
223 class DetailOutputWrapper : public DataModelWrapper {
224  public:
225   explicit DetailOutputWrapper(const DetailOutputMap& outputs);
226   virtual ~DetailOutputWrapper();
227
228   virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
229
230  private:
231   const DetailOutputMap& outputs_;
232
233   DISALLOW_COPY_AND_ASSIGN(DetailOutputWrapper);
234 };
235
236 }  // namespace autofill
237
238 #endif  // CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_