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_
10 #include "base/compiler_specific.h"
11 #include "base/strings/string16.h"
12 #include "chrome/browser/ui/autofill/autofill_dialog_types.h"
13 #include "components/autofill/content/browser/wallet/wallet_items.h"
14 #include "components/autofill/core/browser/field_types.h"
15 #include "components/autofill/core/browser/form_structure.h"
22 namespace addressinput {
29 class AutofillDataModel;
30 class AutofillProfile;
40 // A glue class that allows uniform interactions with autocomplete data sources,
41 // regardless of their type. Implementations are intended to be lightweight and
42 // copyable, only holding weak references to their backing model.
43 class DataModelWrapper {
45 virtual ~DataModelWrapper();
47 // Fills in |inputs| with the data that this model contains (|inputs| is an
49 void FillInputs(DetailInputs* inputs);
51 // Returns the data for a specific autocomplete type in a format for filling
53 virtual base::string16 GetInfo(const AutofillType& type) const = 0;
55 // Returns the data for a specified type in a format optimized for displaying
57 virtual base::string16 GetInfoForDisplay(const AutofillType& type) const;
59 // Returns the icon, if any, that represents this model.
60 virtual gfx::Image GetIcon();
62 // Gets text to display to the user to summarize this data source. The
63 // default implementation assumes this is an address. Both params are required
64 // to be non-NULL and will be filled in with text that is vertically compact
65 // (but may take up a lot of horizontal space) and horizontally compact (but
66 // may take up a lot of vertical space) respectively. The return value will
67 // be true and the outparams will be filled in only if the data represented is
68 // complete and valid.
69 virtual bool GetDisplayText(base::string16* vertically_compact,
70 base::string16* horizontally_compact);
72 // Returns the BCP 47 language code that should be used for formatting the
74 virtual const std::string& GetLanguageCode() const = 0;
76 // Fills in |form_structure| with the data that this model contains. |inputs|
77 // and |comparator| are used to determine whether each field in the
78 // FormStructure should be filled in or left alone. Returns whether any fields
79 // in |form_structure| were found to be matching.
80 bool FillFormStructure(
81 const std::vector<ServerFieldType>& types,
82 const FormStructure::InputFieldComparator& compare,
83 FormStructure* form_structure) const;
89 DISALLOW_COPY_AND_ASSIGN(DataModelWrapper);
92 // A DataModelWrapper for Autofill profiles.
93 class AutofillProfileWrapper : public DataModelWrapper {
95 explicit AutofillProfileWrapper(const AutofillProfile* profile);
96 AutofillProfileWrapper(const AutofillProfile* profile,
97 const AutofillType& variant_type,
99 virtual ~AutofillProfileWrapper();
101 virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
102 virtual base::string16 GetInfoForDisplay(const AutofillType& type) const
104 virtual const std::string& GetLanguageCode() const OVERRIDE;
107 // Returns the variant that should be used when dealing with an element that
108 // has the given |type|.
109 size_t GetVariantForType(const AutofillType& type) const;
112 const AutofillProfile* profile_;
114 // The profile variant. |variant_| describes which variant of |variant_group_|
115 // to use in the profile.
116 FieldTypeGroup variant_group_;
119 DISALLOW_COPY_AND_ASSIGN(AutofillProfileWrapper);
122 // A DataModelWrapper specifically for shipping address profiles.
123 class AutofillShippingAddressWrapper : public AutofillProfileWrapper {
125 explicit AutofillShippingAddressWrapper(const AutofillProfile* profile);
126 virtual ~AutofillShippingAddressWrapper();
128 virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
131 DISALLOW_COPY_AND_ASSIGN(AutofillShippingAddressWrapper);
134 // A DataModelWrapper specifically for Autofill CreditCard data.
135 class AutofillCreditCardWrapper : public DataModelWrapper {
137 explicit AutofillCreditCardWrapper(const CreditCard* card);
138 virtual ~AutofillCreditCardWrapper();
140 virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
141 virtual gfx::Image GetIcon() OVERRIDE;
142 virtual bool GetDisplayText(base::string16* vertically_compact,
143 base::string16* horizontally_compact) OVERRIDE;
144 virtual const std::string& GetLanguageCode() const OVERRIDE;
147 const CreditCard* card_;
149 DISALLOW_COPY_AND_ASSIGN(AutofillCreditCardWrapper);
152 // A DataModelWrapper for Wallet addresses.
153 class WalletAddressWrapper : public DataModelWrapper {
155 explicit WalletAddressWrapper(const wallet::Address* address);
156 virtual ~WalletAddressWrapper();
158 virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
159 virtual base::string16 GetInfoForDisplay(const AutofillType& type) const
161 virtual bool GetDisplayText(base::string16* vertically_compact,
162 base::string16* horizontally_compact) OVERRIDE;
163 virtual const std::string& GetLanguageCode() const OVERRIDE;
166 const wallet::Address* address_;
168 DISALLOW_COPY_AND_ASSIGN(WalletAddressWrapper);
171 // A DataModelWrapper for Wallet instruments.
172 class WalletInstrumentWrapper : public DataModelWrapper {
174 explicit WalletInstrumentWrapper(
175 const wallet::WalletItems::MaskedInstrument* instrument);
176 virtual ~WalletInstrumentWrapper();
178 virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
179 virtual base::string16 GetInfoForDisplay(const AutofillType& type) const
181 virtual gfx::Image GetIcon() OVERRIDE;
182 virtual bool GetDisplayText(base::string16* vertically_compact,
183 base::string16* horizontally_compact) OVERRIDE;
184 virtual const std::string& GetLanguageCode() const OVERRIDE;
187 const wallet::WalletItems::MaskedInstrument* instrument_;
189 DISALLOW_COPY_AND_ASSIGN(WalletInstrumentWrapper);
192 // A DataModelWrapper for FullWallet billing data.
193 class FullWalletBillingWrapper : public DataModelWrapper {
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;
201 virtual const std::string& GetLanguageCode() const OVERRIDE;
204 wallet::FullWallet* full_wallet_;
206 DISALLOW_COPY_AND_ASSIGN(FullWalletBillingWrapper);
209 // A DataModelWrapper for FullWallet shipping data.
210 class FullWalletShippingWrapper : public DataModelWrapper {
212 explicit FullWalletShippingWrapper(wallet::FullWallet* full_wallet);
213 virtual ~FullWalletShippingWrapper();
215 virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
216 virtual const std::string& GetLanguageCode() const OVERRIDE;
219 wallet::FullWallet* full_wallet_;
221 DISALLOW_COPY_AND_ASSIGN(FullWalletShippingWrapper);
224 // A DataModelWrapper for ::i18n::addressinput::AddressData objects.
225 class I18nAddressDataWrapper : public DataModelWrapper {
227 explicit I18nAddressDataWrapper(
228 const ::i18n::addressinput::AddressData* address);
229 virtual ~I18nAddressDataWrapper();
231 virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE;
232 virtual const std::string& GetLanguageCode() const OVERRIDE;
235 const ::i18n::addressinput::AddressData* address_;
237 DISALLOW_COPY_AND_ASSIGN(I18nAddressDataWrapper);
240 } // namespace autofill
242 #endif // CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_