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/detail_input.h"
15 #include "components/autofill/core/browser/field_types.h"
16 #include "components/autofill/core/browser/form_structure.h"
23 namespace addressinput
{
30 class AutofillDataModel
;
31 class AutofillProfile
;
41 // A glue class that allows uniform interactions with autocomplete data sources,
42 // regardless of their type. Implementations are intended to be lightweight and
43 // copyable, only holding weak references to their backing model.
44 class DataModelWrapper
{
46 virtual ~DataModelWrapper();
48 // Fills in |inputs| with the data that this model contains (|inputs| is an
50 void FillInputs(DetailInputs
* inputs
);
52 // Returns the data for a specific autocomplete type in a format for filling
54 virtual base::string16
GetInfo(const AutofillType
& type
) const = 0;
56 // Returns the data for a specified type in a format optimized for displaying
58 virtual base::string16
GetInfoForDisplay(const AutofillType
& type
) const;
60 // Returns the icon, if any, that represents this model.
61 virtual gfx::Image
GetIcon();
63 // Gets text to display to the user to summarize this data source. The
64 // default implementation assumes this is an address. Both params are required
65 // to be non-NULL and will be filled in with text that is vertically compact
66 // (but may take up a lot of horizontal space) and horizontally compact (but
67 // may take up a lot of vertical space) respectively. The return value will
68 // be true and the outparams will be filled in only if the data represented is
69 // complete and valid.
70 virtual bool GetDisplayText(base::string16
* vertically_compact
,
71 base::string16
* horizontally_compact
);
73 // Returns the BCP 47 language code that should be used for formatting the
75 virtual const std::string
& GetLanguageCode() const = 0;
77 // Fills in |form_structure| with the data that this model contains. |inputs|
78 // and |comparator| are used to determine whether each field in the
79 // FormStructure should be filled in or left alone. Returns whether any fields
80 // in |form_structure| were found to be matching.
81 bool FillFormStructure(
82 const std::vector
<ServerFieldType
>& types
,
83 const FormStructure::InputFieldComparator
& compare
,
84 FormStructure
* form_structure
) const;
90 DISALLOW_COPY_AND_ASSIGN(DataModelWrapper
);
93 // A DataModelWrapper for Autofill profiles.
94 class AutofillProfileWrapper
: public DataModelWrapper
{
96 explicit AutofillProfileWrapper(const AutofillProfile
* profile
);
97 AutofillProfileWrapper(const AutofillProfile
* profile
,
98 const AutofillType
& variant_type
,
100 ~AutofillProfileWrapper() override
;
102 base::string16
GetInfo(const AutofillType
& type
) const override
;
103 base::string16
GetInfoForDisplay(const AutofillType
& type
) const override
;
104 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 ~AutofillShippingAddressWrapper() override
;
128 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 ~AutofillCreditCardWrapper() override
;
140 base::string16
GetInfo(const AutofillType
& type
) const override
;
141 gfx::Image
GetIcon() override
;
142 bool GetDisplayText(base::string16
* vertically_compact
,
143 base::string16
* horizontally_compact
) override
;
144 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 ~WalletAddressWrapper() override
;
158 base::string16
GetInfo(const AutofillType
& type
) const override
;
159 base::string16
GetInfoForDisplay(const AutofillType
& type
) const override
;
160 bool GetDisplayText(base::string16
* vertically_compact
,
161 base::string16
* horizontally_compact
) override
;
162 const std::string
& GetLanguageCode() const override
;
165 const wallet::Address
* address_
;
167 DISALLOW_COPY_AND_ASSIGN(WalletAddressWrapper
);
170 // A DataModelWrapper for Wallet instruments.
171 class WalletInstrumentWrapper
: public DataModelWrapper
{
173 explicit WalletInstrumentWrapper(
174 const wallet::WalletItems::MaskedInstrument
* instrument
);
175 ~WalletInstrumentWrapper() override
;
177 base::string16
GetInfo(const AutofillType
& type
) const override
;
178 base::string16
GetInfoForDisplay(const AutofillType
& type
) const override
;
179 gfx::Image
GetIcon() override
;
180 bool GetDisplayText(base::string16
* vertically_compact
,
181 base::string16
* horizontally_compact
) override
;
182 const std::string
& GetLanguageCode() const override
;
185 const wallet::WalletItems::MaskedInstrument
* instrument_
;
187 DISALLOW_COPY_AND_ASSIGN(WalletInstrumentWrapper
);
190 // A DataModelWrapper for FullWallet billing data.
191 class FullWalletBillingWrapper
: public DataModelWrapper
{
193 explicit FullWalletBillingWrapper(wallet::FullWallet
* full_wallet
);
194 ~FullWalletBillingWrapper() override
;
196 base::string16
GetInfo(const AutofillType
& type
) const override
;
197 bool GetDisplayText(base::string16
* vertically_compact
,
198 base::string16
* horizontally_compact
) override
;
199 const std::string
& GetLanguageCode() const override
;
202 wallet::FullWallet
* full_wallet_
;
204 DISALLOW_COPY_AND_ASSIGN(FullWalletBillingWrapper
);
207 // A DataModelWrapper for FullWallet shipping data.
208 class FullWalletShippingWrapper
: public DataModelWrapper
{
210 explicit FullWalletShippingWrapper(wallet::FullWallet
* full_wallet
);
211 ~FullWalletShippingWrapper() override
;
213 base::string16
GetInfo(const AutofillType
& type
) const override
;
214 const std::string
& GetLanguageCode() const override
;
217 wallet::FullWallet
* full_wallet_
;
219 DISALLOW_COPY_AND_ASSIGN(FullWalletShippingWrapper
);
222 // A DataModelWrapper for ::i18n::addressinput::AddressData objects.
223 class I18nAddressDataWrapper
: public DataModelWrapper
{
225 explicit I18nAddressDataWrapper(
226 const ::i18n::addressinput::AddressData
* address
);
227 ~I18nAddressDataWrapper() override
;
229 base::string16
GetInfo(const AutofillType
& type
) const override
;
230 const std::string
& GetLanguageCode() const override
;
233 const ::i18n::addressinput::AddressData
* address_
;
235 DISALLOW_COPY_AND_ASSIGN(I18nAddressDataWrapper
);
238 } // namespace autofill
240 #endif // CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_