| OLD | NEW |
| (Empty) |
| 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/macros.h" | |
| 12 #include "base/strings/string16.h" | |
| 13 #include "chrome/browser/ui/autofill/autofill_dialog_types.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" | |
| 17 | |
| 18 namespace gfx { | |
| 19 class Image; | |
| 20 } | |
| 21 | |
| 22 namespace i18n { | |
| 23 namespace addressinput { | |
| 24 struct AddressData; | |
| 25 } | |
| 26 } | |
| 27 | |
| 28 namespace autofill { | |
| 29 | |
| 30 class AutofillDataModel; | |
| 31 class AutofillProfile; | |
| 32 class AutofillType; | |
| 33 class CreditCard; | |
| 34 class FormStructure; | |
| 35 | |
| 36 // A glue class that allows uniform interactions with autocomplete data sources, | |
| 37 // regardless of their type. Implementations are intended to be lightweight and | |
| 38 // copyable, only holding weak references to their backing model. | |
| 39 class DataModelWrapper { | |
| 40 public: | |
| 41 virtual ~DataModelWrapper(); | |
| 42 | |
| 43 // Fills in |inputs| with the data that this model contains (|inputs| is an | |
| 44 // out-param). | |
| 45 void FillInputs(DetailInputs* inputs); | |
| 46 | |
| 47 // Returns the data for a specific autocomplete type in a format for filling | |
| 48 // into a web form. | |
| 49 virtual base::string16 GetInfo(const AutofillType& type) const = 0; | |
| 50 | |
| 51 // Returns the data for a specified type in a format optimized for displaying | |
| 52 // to the user. | |
| 53 virtual base::string16 GetInfoForDisplay(const AutofillType& type) const; | |
| 54 | |
| 55 // Returns the icon, if any, that represents this model. | |
| 56 virtual gfx::Image GetIcon(); | |
| 57 | |
| 58 // Gets text to display to the user to summarize this data source. The | |
| 59 // default implementation assumes this is an address. Both params are required | |
| 60 // to be non-NULL and will be filled in with text that is vertically compact | |
| 61 // (but may take up a lot of horizontal space) and horizontally compact (but | |
| 62 // may take up a lot of vertical space) respectively. The return value will | |
| 63 // be true and the outparams will be filled in only if the data represented is | |
| 64 // complete and valid. | |
| 65 virtual bool GetDisplayText(base::string16* vertically_compact, | |
| 66 base::string16* horizontally_compact); | |
| 67 | |
| 68 // Returns the BCP 47 language code that should be used for formatting the | |
| 69 // data for display. | |
| 70 virtual const std::string& GetLanguageCode() const = 0; | |
| 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. | |
| 89 class AutofillProfileWrapper : public DataModelWrapper { | |
| 90 public: | |
| 91 explicit AutofillProfileWrapper(const AutofillProfile* profile); | |
| 92 ~AutofillProfileWrapper() override; | |
| 93 | |
| 94 base::string16 GetInfo(const AutofillType& type) const override; | |
| 95 base::string16 GetInfoForDisplay(const AutofillType& type) const override; | |
| 96 const std::string& GetLanguageCode() const override; | |
| 97 | |
| 98 private: | |
| 99 const AutofillProfile* profile_; | |
| 100 | |
| 101 DISALLOW_COPY_AND_ASSIGN(AutofillProfileWrapper); | |
| 102 }; | |
| 103 | |
| 104 // A DataModelWrapper specifically for shipping address profiles. | |
| 105 class AutofillShippingAddressWrapper : public AutofillProfileWrapper { | |
| 106 public: | |
| 107 explicit AutofillShippingAddressWrapper(const AutofillProfile* profile); | |
| 108 ~AutofillShippingAddressWrapper() override; | |
| 109 | |
| 110 base::string16 GetInfo(const AutofillType& type) const override; | |
| 111 | |
| 112 private: | |
| 113 DISALLOW_COPY_AND_ASSIGN(AutofillShippingAddressWrapper); | |
| 114 }; | |
| 115 | |
| 116 // A DataModelWrapper specifically for Autofill CreditCard data. | |
| 117 class AutofillCreditCardWrapper : public DataModelWrapper { | |
| 118 public: | |
| 119 explicit AutofillCreditCardWrapper(const CreditCard* card); | |
| 120 ~AutofillCreditCardWrapper() override; | |
| 121 | |
| 122 base::string16 GetInfo(const AutofillType& type) const override; | |
| 123 gfx::Image GetIcon() override; | |
| 124 bool GetDisplayText(base::string16* vertically_compact, | |
| 125 base::string16* horizontally_compact) override; | |
| 126 const std::string& GetLanguageCode() const override; | |
| 127 | |
| 128 private: | |
| 129 const CreditCard* card_; | |
| 130 | |
| 131 DISALLOW_COPY_AND_ASSIGN(AutofillCreditCardWrapper); | |
| 132 }; | |
| 133 | |
| 134 // A DataModelWrapper for ::i18n::addressinput::AddressData objects. | |
| 135 class I18nAddressDataWrapper : public DataModelWrapper { | |
| 136 public: | |
| 137 explicit I18nAddressDataWrapper( | |
| 138 const ::i18n::addressinput::AddressData* address); | |
| 139 ~I18nAddressDataWrapper() override; | |
| 140 | |
| 141 base::string16 GetInfo(const AutofillType& type) const override; | |
| 142 const std::string& GetLanguageCode() const override; | |
| 143 | |
| 144 private: | |
| 145 const ::i18n::addressinput::AddressData* address_; | |
| 146 | |
| 147 DISALLOW_COPY_AND_ASSIGN(I18nAddressDataWrapper); | |
| 148 }; | |
| 149 | |
| 150 } // namespace autofill | |
| 151 | |
| 152 #endif // CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_ | |
| OLD | NEW |