Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / autofill / data_model_wrapper.h
blobeae86d30b2595125ec44c6cb715d82a032a122f0
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.
5 #ifndef CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_
6 #define CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_
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"
14 namespace gfx {
15 class Image;
18 namespace autofill {
20 class AutofillDataModel;
21 class AutofillProfile;
22 class AutofillType;
23 class CreditCard;
24 class FormStructure;
26 namespace wallet {
27 class Address;
28 class FullWallet;
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();
38 // Fills in |inputs| with the data that this model contains (|inputs| is an
39 // out-param).
40 void FillInputs(DetailInputs* inputs);
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;
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;
50 // Returns the icon, if any, that represents this model.
51 virtual gfx::Image GetIcon();
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);
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;
72 protected:
73 DataModelWrapper();
75 private:
76 // Formats address data into a single string using |separator| between
77 // fields.
78 base::string16 GetAddressDisplayText(const base::string16& separator);
80 DISALLOW_COPY_AND_ASSIGN(DataModelWrapper);
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();
90 virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
92 protected:
93 DISALLOW_COPY_AND_ASSIGN(EmptyDataModelWrapper);
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();
105 virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
106 virtual base::string16 GetInfoForDisplay(const AutofillType& type) const
107 OVERRIDE;
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;
114 private:
115 const AutofillProfile* profile_;
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_;
122 DISALLOW_COPY_AND_ASSIGN(AutofillProfileWrapper);
125 // A DataModelWrapper specifically for shipping address profiles.
126 class AutofillShippingAddressWrapper : public AutofillProfileWrapper {
127 public:
128 explicit AutofillShippingAddressWrapper(const AutofillProfile* profile);
129 virtual ~AutofillShippingAddressWrapper();
131 virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
133 private:
134 DISALLOW_COPY_AND_ASSIGN(AutofillShippingAddressWrapper);
137 // A DataModelWrapper specifically for Autofill CreditCard data.
138 class AutofillCreditCardWrapper : public DataModelWrapper {
139 public:
140 explicit AutofillCreditCardWrapper(const CreditCard* card);
141 virtual ~AutofillCreditCardWrapper();
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;
148 private:
149 const CreditCard* card_;
151 DISALLOW_COPY_AND_ASSIGN(AutofillCreditCardWrapper);
154 // A DataModelWrapper for Wallet addresses.
155 class WalletAddressWrapper : public DataModelWrapper {
156 public:
157 explicit WalletAddressWrapper(const wallet::Address* address);
158 virtual ~WalletAddressWrapper();
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;
166 private:
167 const wallet::Address* address_;
169 DISALLOW_COPY_AND_ASSIGN(WalletAddressWrapper);
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();
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;
186 private:
187 const wallet::WalletItems::MaskedInstrument* instrument_;
189 DISALLOW_COPY_AND_ASSIGN(WalletInstrumentWrapper);
192 // A DataModelWrapper for FullWallet billing data.
193 class FullWalletBillingWrapper : public DataModelWrapper {
194 public:
195 explicit FullWalletBillingWrapper(wallet::FullWallet* full_wallet);
196 virtual ~FullWalletBillingWrapper();
198 virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
199 virtual bool GetDisplayText(base::string16* vertically_compact,
200 base::string16* horizontally_compact) OVERRIDE;
202 private:
203 wallet::FullWallet* full_wallet_;
205 DISALLOW_COPY_AND_ASSIGN(FullWalletBillingWrapper);
208 // A DataModelWrapper for FullWallet shipping data.
209 class FullWalletShippingWrapper : public DataModelWrapper {
210 public:
211 explicit FullWalletShippingWrapper(wallet::FullWallet* full_wallet);
212 virtual ~FullWalletShippingWrapper();
214 virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
216 private:
217 wallet::FullWallet* full_wallet_;
219 DISALLOW_COPY_AND_ASSIGN(FullWalletShippingWrapper);
222 // A DataModelWrapper to copy the output of one section to the input of another.
223 class FieldMapWrapper : public DataModelWrapper {
224 public:
225 explicit FieldMapWrapper(const FieldValueMap& field_map);
226 virtual ~FieldMapWrapper();
228 virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
230 private:
231 const FieldValueMap& field_map_;
233 DISALLOW_COPY_AND_ASSIGN(FieldMapWrapper);
236 } // namespace autofill
238 #endif // CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_