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/core/browser/detail_input.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
;
35 // A glue class that allows uniform interactions with autocomplete data sources,
36 // regardless of their type. Implementations are intended to be lightweight and
37 // copyable, only holding weak references to their backing model.
38 class DataModelWrapper
{
40 virtual ~DataModelWrapper();
42 // Fills in |inputs| with the data that this model contains (|inputs| is an
44 void FillInputs(DetailInputs
* inputs
);
46 // Returns the data for a specific autocomplete type in a format for filling
48 virtual base::string16
GetInfo(const AutofillType
& type
) const = 0;
50 // Returns the data for a specified type in a format optimized for displaying
52 virtual base::string16
GetInfoForDisplay(const AutofillType
& type
) const;
54 // Returns the icon, if any, that represents this model.
55 virtual gfx::Image
GetIcon();
57 // Gets text to display to the user to summarize this data source. The
58 // default implementation assumes this is an address. Both params are required
59 // to be non-NULL and will be filled in with text that is vertically compact
60 // (but may take up a lot of horizontal space) and horizontally compact (but
61 // may take up a lot of vertical space) respectively. The return value will
62 // be true and the outparams will be filled in only if the data represented is
63 // complete and valid.
64 virtual bool GetDisplayText(base::string16
* vertically_compact
,
65 base::string16
* horizontally_compact
);
67 // Returns the BCP 47 language code that should be used for formatting the
69 virtual const std::string
& GetLanguageCode() const = 0;
71 // Fills in |form_structure| with the data that this model contains. |inputs|
72 // and |comparator| are used to determine whether each field in the
73 // FormStructure should be filled in or left alone. Returns whether any fields
74 // in |form_structure| were found to be matching.
75 bool FillFormStructure(
76 const std::vector
<ServerFieldType
>& types
,
77 const FormStructure::InputFieldComparator
& compare
,
78 FormStructure
* form_structure
) const;
84 DISALLOW_COPY_AND_ASSIGN(DataModelWrapper
);
87 // A DataModelWrapper for Autofill profiles.
88 class AutofillProfileWrapper
: public DataModelWrapper
{
90 explicit AutofillProfileWrapper(const AutofillProfile
* profile
);
91 ~AutofillProfileWrapper() override
;
93 base::string16
GetInfo(const AutofillType
& type
) const override
;
94 base::string16
GetInfoForDisplay(const AutofillType
& type
) const override
;
95 const std::string
& GetLanguageCode() const override
;
98 const AutofillProfile
* profile_
;
100 DISALLOW_COPY_AND_ASSIGN(AutofillProfileWrapper
);
103 // A DataModelWrapper specifically for shipping address profiles.
104 class AutofillShippingAddressWrapper
: public AutofillProfileWrapper
{
106 explicit AutofillShippingAddressWrapper(const AutofillProfile
* profile
);
107 ~AutofillShippingAddressWrapper() override
;
109 base::string16
GetInfo(const AutofillType
& type
) const override
;
112 DISALLOW_COPY_AND_ASSIGN(AutofillShippingAddressWrapper
);
115 // A DataModelWrapper specifically for Autofill CreditCard data.
116 class AutofillCreditCardWrapper
: public DataModelWrapper
{
118 explicit AutofillCreditCardWrapper(const CreditCard
* card
);
119 ~AutofillCreditCardWrapper() override
;
121 base::string16
GetInfo(const AutofillType
& type
) const override
;
122 gfx::Image
GetIcon() override
;
123 bool GetDisplayText(base::string16
* vertically_compact
,
124 base::string16
* horizontally_compact
) override
;
125 const std::string
& GetLanguageCode() const override
;
128 const CreditCard
* card_
;
130 DISALLOW_COPY_AND_ASSIGN(AutofillCreditCardWrapper
);
133 // A DataModelWrapper for ::i18n::addressinput::AddressData objects.
134 class I18nAddressDataWrapper
: public DataModelWrapper
{
136 explicit I18nAddressDataWrapper(
137 const ::i18n::addressinput::AddressData
* address
);
138 ~I18nAddressDataWrapper() override
;
140 base::string16
GetInfo(const AutofillType
& type
) const override
;
141 const std::string
& GetLanguageCode() const override
;
144 const ::i18n::addressinput::AddressData
* address_
;
146 DISALLOW_COPY_AND_ASSIGN(I18nAddressDataWrapper
);
149 } // namespace autofill
151 #endif // CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_