data_model_wrapper.h revision effb81e5f8246d0db0270817048dc992db66e9fb
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 <vector> 9 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" 16 17namespace gfx { 18class Image; 19} 20 21namespace i18n { 22namespace addressinput { 23struct AddressData; 24} 25} 26 27namespace autofill { 28 29class AutofillDataModel; 30class AutofillProfile; 31class AutofillType; 32class CreditCard; 33class FormStructure; 34 35namespace wallet { 36class Address; 37class FullWallet; 38} 39 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. 43class DataModelWrapper { 44 public: 45 virtual ~DataModelWrapper(); 46 47 // Fills in |inputs| with the data that this model contains (|inputs| is an 48 // out-param). 49 void FillInputs(DetailInputs* inputs); 50 51 // Returns the data for a specific autocomplete type in a format for filling 52 // into a web form. 53 virtual base::string16 GetInfo(const AutofillType& type) const = 0; 54 55 // Returns the data for a specified type in a format optimized for displaying 56 // to the user. 57 virtual base::string16 GetInfoForDisplay(const AutofillType& type) const; 58 59 // Returns the icon, if any, that represents this model. 60 virtual gfx::Image GetIcon(); 61 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); 71 72 // Fills in |form_structure| with the data that this model contains. |inputs| 73 // and |comparator| are used to determine whether each field in the 74 // FormStructure should be filled in or left alone. Returns whether any fields 75 // in |form_structure| were found to be matching. 76 bool FillFormStructure( 77 const std::vector<ServerFieldType>& types, 78 const FormStructure::InputFieldComparator& compare, 79 FormStructure* form_structure) const; 80 81 protected: 82 DataModelWrapper(); 83 84 private: 85 DISALLOW_COPY_AND_ASSIGN(DataModelWrapper); 86}; 87 88// A DataModelWrapper for Autofill profiles. 89class AutofillProfileWrapper : public DataModelWrapper { 90 public: 91 explicit AutofillProfileWrapper(const AutofillProfile* profile); 92 AutofillProfileWrapper(const AutofillProfile* profile, 93 const AutofillType& variant_type, 94 size_t variant); 95 virtual ~AutofillProfileWrapper(); 96 97 virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE; 98 virtual base::string16 GetInfoForDisplay(const AutofillType& type) const 99 OVERRIDE; 100 101 protected: 102 // Returns the variant that should be used when dealing with an element that 103 // has the given |type|. 104 size_t GetVariantForType(const AutofillType& type) const; 105 106 private: 107 const AutofillProfile* profile_; 108 109 // The profile variant. |variant_| describes which variant of |variant_group_| 110 // to use in the profile. 111 FieldTypeGroup variant_group_; 112 size_t variant_; 113 114 DISALLOW_COPY_AND_ASSIGN(AutofillProfileWrapper); 115}; 116 117// A DataModelWrapper specifically for shipping address profiles. 118class AutofillShippingAddressWrapper : public AutofillProfileWrapper { 119 public: 120 explicit AutofillShippingAddressWrapper(const AutofillProfile* profile); 121 virtual ~AutofillShippingAddressWrapper(); 122 123 virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE; 124 125 private: 126 DISALLOW_COPY_AND_ASSIGN(AutofillShippingAddressWrapper); 127}; 128 129// A DataModelWrapper specifically for Autofill CreditCard data. 130class AutofillCreditCardWrapper : public DataModelWrapper { 131 public: 132 explicit AutofillCreditCardWrapper(const CreditCard* card); 133 virtual ~AutofillCreditCardWrapper(); 134 135 virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE; 136 virtual gfx::Image GetIcon() OVERRIDE; 137 virtual bool GetDisplayText(base::string16* vertically_compact, 138 base::string16* horizontally_compact) OVERRIDE; 139 140 private: 141 const CreditCard* card_; 142 143 DISALLOW_COPY_AND_ASSIGN(AutofillCreditCardWrapper); 144}; 145 146// A DataModelWrapper for Wallet addresses. 147class WalletAddressWrapper : public DataModelWrapper { 148 public: 149 explicit WalletAddressWrapper(const wallet::Address* address); 150 virtual ~WalletAddressWrapper(); 151 152 virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE; 153 virtual base::string16 GetInfoForDisplay(const AutofillType& type) const 154 OVERRIDE; 155 virtual bool GetDisplayText(base::string16* vertically_compact, 156 base::string16* horizontally_compact) OVERRIDE; 157 158 private: 159 const wallet::Address* address_; 160 161 DISALLOW_COPY_AND_ASSIGN(WalletAddressWrapper); 162}; 163 164// A DataModelWrapper for Wallet instruments. 165class WalletInstrumentWrapper : public DataModelWrapper { 166 public: 167 explicit WalletInstrumentWrapper( 168 const wallet::WalletItems::MaskedInstrument* instrument); 169 virtual ~WalletInstrumentWrapper(); 170 171 virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE; 172 virtual base::string16 GetInfoForDisplay(const AutofillType& type) const 173 OVERRIDE; 174 virtual gfx::Image GetIcon() OVERRIDE; 175 virtual bool GetDisplayText(base::string16* vertically_compact, 176 base::string16* horizontally_compact) OVERRIDE; 177 178 private: 179 const wallet::WalletItems::MaskedInstrument* instrument_; 180 181 DISALLOW_COPY_AND_ASSIGN(WalletInstrumentWrapper); 182}; 183 184// A DataModelWrapper for FullWallet billing data. 185class FullWalletBillingWrapper : public DataModelWrapper { 186 public: 187 explicit FullWalletBillingWrapper(wallet::FullWallet* full_wallet); 188 virtual ~FullWalletBillingWrapper(); 189 190 virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE; 191 virtual bool GetDisplayText(base::string16* vertically_compact, 192 base::string16* horizontally_compact) OVERRIDE; 193 194 private: 195 wallet::FullWallet* full_wallet_; 196 197 DISALLOW_COPY_AND_ASSIGN(FullWalletBillingWrapper); 198}; 199 200// A DataModelWrapper for FullWallet shipping data. 201class FullWalletShippingWrapper : public DataModelWrapper { 202 public: 203 explicit FullWalletShippingWrapper(wallet::FullWallet* full_wallet); 204 virtual ~FullWalletShippingWrapper(); 205 206 virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE; 207 208 private: 209 wallet::FullWallet* full_wallet_; 210 211 DISALLOW_COPY_AND_ASSIGN(FullWalletShippingWrapper); 212}; 213 214// A DataModelWrapper for ::i18n::addressinput::AddressData objects. 215class I18nAddressDataWrapper : public DataModelWrapper { 216 public: 217 explicit I18nAddressDataWrapper( 218 const ::i18n::addressinput::AddressData* address); 219 virtual ~I18nAddressDataWrapper(); 220 221 virtual base::string16 GetInfo(const AutofillType& type) const OVERRIDE; 222 223 private: 224 const ::i18n::addressinput::AddressData* address_; 225 226 DISALLOW_COPY_AND_ASSIGN(I18nAddressDataWrapper); 227}; 228 229} // namespace autofill 230 231#endif // CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_ 232