OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/autofill/data_model_wrapper.h" | 5 #include "chrome/browser/ui/autofill/data_model_wrapper.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "components/autofill/browser/autofill_country.h" | 9 #include "components/autofill/browser/autofill_country.h" |
10 #include "components/autofill/browser/autofill_profile.h" | 10 #include "components/autofill/browser/autofill_profile.h" |
11 #include "components/autofill/browser/autofill_type.h" | |
11 #include "components/autofill/browser/credit_card.h" | 12 #include "components/autofill/browser/credit_card.h" |
12 #include "components/autofill/browser/form_group.h" | 13 #include "components/autofill/browser/form_group.h" |
13 #include "components/autofill/browser/form_structure.h" | 14 #include "components/autofill/browser/form_structure.h" |
14 #include "components/autofill/browser/wallet/wallet_address.h" | 15 #include "components/autofill/browser/wallet/full_wallet.h" |
15 #include "components/autofill/browser/wallet/wallet_address.h" | 16 #include "components/autofill/browser/wallet/wallet_address.h" |
16 #include "components/autofill/browser/wallet/wallet_items.h" | 17 #include "components/autofill/browser/wallet/wallet_items.h" |
17 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
18 #include "ui/gfx/image/image.h" | 19 #include "ui/gfx/image/image.h" |
19 | 20 |
20 namespace autofill { | 21 namespace autofill { |
21 | 22 |
22 DataModelWrapper::~DataModelWrapper() {} | 23 DataModelWrapper::~DataModelWrapper() {} |
23 | 24 |
24 string16 DataModelWrapper::GetDisplayText() { | 25 string16 DataModelWrapper::GetDisplayText() { |
(...skipping 17 matching lines...) Expand all Loading... | |
42 AutofillField* field = form_structure->field(i); | 43 AutofillField* field = form_structure->field(i); |
43 for (size_t j = 0; j < inputs.size(); ++j) { | 44 for (size_t j = 0; j < inputs.size(); ++j) { |
44 if (compare.Run(inputs[j], *field)) { | 45 if (compare.Run(inputs[j], *field)) { |
45 FillFormField(field); | 46 FillFormField(field); |
46 break; | 47 break; |
47 } | 48 } |
48 } | 49 } |
49 } | 50 } |
50 } | 51 } |
51 | 52 |
53 void DataModelWrapper::FillInputs(DetailInputs* inputs) { | |
54 for (size_t i = 0; i < inputs->size(); ++i) { | |
55 (*inputs)[i].autofilled_value = GetInfo((*inputs)[i].type); | |
56 } | |
57 } | |
58 | |
59 void DataModelWrapper::FillFormField(AutofillField* field) { | |
60 field->value = GetInfo(field->type()); | |
61 } | |
62 | |
63 gfx::Image DataModelWrapper::GetIcon() { | |
64 return gfx::Image(); | |
65 } | |
66 | |
52 // AutofillFormGroupWrapper | 67 // AutofillFormGroupWrapper |
53 | 68 |
54 AutofillFormGroupWrapper::AutofillFormGroupWrapper(const FormGroup* form_group, | 69 AutofillFormGroupWrapper::AutofillFormGroupWrapper(const FormGroup* form_group, |
55 size_t variant) | 70 size_t variant) |
56 : form_group_(form_group), | 71 : form_group_(form_group), |
57 variant_(variant) {} | 72 variant_(variant) {} |
58 | 73 |
59 AutofillFormGroupWrapper::~AutofillFormGroupWrapper() {} | 74 AutofillFormGroupWrapper::~AutofillFormGroupWrapper() {} |
60 | 75 |
61 string16 AutofillFormGroupWrapper::GetInfo(AutofillFieldType type) { | 76 string16 AutofillFormGroupWrapper::GetInfo(AutofillFieldType type) { |
62 return form_group_->GetInfo(type, AutofillCountry::ApplicationLocale()); | 77 return form_group_->GetInfo(type, AutofillCountry::ApplicationLocale()); |
63 } | 78 } |
64 | 79 |
65 gfx::Image AutofillFormGroupWrapper::GetIcon() { | |
66 return gfx::Image(); | |
67 } | |
68 | |
69 void AutofillFormGroupWrapper::FillFormField(AutofillField* field) { | 80 void AutofillFormGroupWrapper::FillFormField(AutofillField* field) { |
70 form_group_->FillFormField(*field, variant_, field); | 81 form_group_->FillFormField(*field, variant_, field); |
71 } | 82 } |
72 | 83 |
73 // AutofillProfileWrapper | 84 // AutofillProfileWrapper |
74 | 85 |
75 AutofillProfileWrapper::AutofillProfileWrapper( | 86 AutofillProfileWrapper::AutofillProfileWrapper( |
76 const AutofillProfile* profile, size_t variant) | 87 const AutofillProfile* profile, size_t variant) |
77 : AutofillFormGroupWrapper(profile, variant), | 88 : AutofillFormGroupWrapper(profile, variant), |
78 profile_(profile) {} | 89 profile_(profile) {} |
(...skipping 15 matching lines...) Expand all Loading... | |
94 : AutofillFormGroupWrapper(card, 0), | 105 : AutofillFormGroupWrapper(card, 0), |
95 card_(card) {} | 106 card_(card) {} |
96 | 107 |
97 AutofillCreditCardWrapper::~AutofillCreditCardWrapper() {} | 108 AutofillCreditCardWrapper::~AutofillCreditCardWrapper() {} |
98 | 109 |
99 gfx::Image AutofillCreditCardWrapper::GetIcon() { | 110 gfx::Image AutofillCreditCardWrapper::GetIcon() { |
100 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 111 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
101 return rb.GetImageNamed(card_->IconResourceId()); | 112 return rb.GetImageNamed(card_->IconResourceId()); |
102 } | 113 } |
103 | 114 |
104 void AutofillCreditCardWrapper::FillInputs(DetailInputs* inputs) { | |
105 const std::string app_locale = AutofillCountry::ApplicationLocale(); | |
106 for (size_t j = 0; j < inputs->size(); ++j) { | |
107 (*inputs)[j].autofilled_value = | |
108 card_->GetInfo((*inputs)[j].type, app_locale); | |
109 } | |
110 } | |
111 | |
112 string16 AutofillCreditCardWrapper::GetDisplayText() { | 115 string16 AutofillCreditCardWrapper::GetDisplayText() { |
113 return card_->TypeAndLastFourDigits(); | 116 return card_->TypeAndLastFourDigits(); |
114 } | 117 } |
115 | 118 |
116 void AutofillCreditCardWrapper::FillFormField(AutofillField* field) { | 119 void AutofillCreditCardWrapper::FillFormField(AutofillField* field) { |
117 AutofillFieldType field_type = field->type(); | 120 AutofillFieldType field_type = field->type(); |
118 | 121 |
119 if (field_type == NAME_FULL) { | 122 if (field_type == NAME_FULL) { |
120 // Requests for the user's full name are filled from the credit card data, | 123 // Requests for the user's full name are filled from the credit card data, |
121 // but the CreditCard class only knows how to fill credit card fields. So, | 124 // but the CreditCard class only knows how to fill credit card fields. So, |
(...skipping 10 matching lines...) Expand all Loading... | |
132 | 135 |
133 WalletAddressWrapper::WalletAddressWrapper( | 136 WalletAddressWrapper::WalletAddressWrapper( |
134 const wallet::Address* address) : address_(address) {} | 137 const wallet::Address* address) : address_(address) {} |
135 | 138 |
136 WalletAddressWrapper::~WalletAddressWrapper() {} | 139 WalletAddressWrapper::~WalletAddressWrapper() {} |
137 | 140 |
138 string16 WalletAddressWrapper::GetInfo(AutofillFieldType type) { | 141 string16 WalletAddressWrapper::GetInfo(AutofillFieldType type) { |
139 return address_->GetInfo(type); | 142 return address_->GetInfo(type); |
140 } | 143 } |
141 | 144 |
142 gfx::Image WalletAddressWrapper::GetIcon() { | |
143 return gfx::Image(); | |
144 } | |
145 | |
146 void WalletAddressWrapper::FillInputs(DetailInputs* inputs) { | |
147 for (size_t j = 0; j < inputs->size(); ++j) { | |
148 (*inputs)[j].autofilled_value = address_->GetInfo((*inputs)[j].type); | |
149 } | |
150 } | |
151 | |
152 void WalletAddressWrapper::FillFormField(AutofillField* field) { | |
153 field->value = GetInfo(field->type()); | |
154 } | |
155 | |
156 // WalletInstrumentWrapper | 145 // WalletInstrumentWrapper |
157 | 146 |
158 WalletInstrumentWrapper::WalletInstrumentWrapper( | 147 WalletInstrumentWrapper::WalletInstrumentWrapper( |
159 const wallet::WalletItems::MaskedInstrument* instrument) | 148 const wallet::WalletItems::MaskedInstrument* instrument) |
160 : instrument_(instrument) {} | 149 : instrument_(instrument) {} |
161 | 150 |
162 WalletInstrumentWrapper::~WalletInstrumentWrapper() {} | 151 WalletInstrumentWrapper::~WalletInstrumentWrapper() {} |
163 | 152 |
164 string16 WalletInstrumentWrapper::GetInfo(AutofillFieldType type) { | 153 string16 WalletInstrumentWrapper::GetInfo(AutofillFieldType type) { |
165 return instrument_->address().GetInfo(type); | 154 return instrument_->address().GetInfo(type); |
166 } | 155 } |
167 | 156 |
168 gfx::Image WalletInstrumentWrapper::GetIcon() { | 157 gfx::Image WalletInstrumentWrapper::GetIcon() { |
169 return instrument_->CardIcon(); | 158 return instrument_->CardIcon(); |
170 } | 159 } |
171 | 160 |
172 void WalletInstrumentWrapper::FillInputs(DetailInputs* inputs) { | 161 void WalletInstrumentWrapper::FillInputs(DetailInputs* inputs) { |
173 // TODO(estade): implement. | 162 // TODO(estade): implement. |
174 } | 163 } |
175 | 164 |
176 string16 WalletInstrumentWrapper::GetDisplayText() { | 165 string16 WalletInstrumentWrapper::GetDisplayText() { |
177 // TODO(estade): descriptive_name() is user-provided. Should we use it or | 166 // TODO(estade): descriptive_name() is user-provided. Should we use it or |
178 // just type + last 4 digits? | 167 // just type + last 4 digits? |
179 string16 line1 = instrument_->descriptive_name(); | 168 string16 line1 = instrument_->descriptive_name(); |
180 return line1 + ASCIIToUTF16("\n") + DataModelWrapper::GetDisplayText(); | 169 return line1 + ASCIIToUTF16("\n") + DataModelWrapper::GetDisplayText(); |
181 } | 170 } |
182 | 171 |
183 void WalletInstrumentWrapper::FillFormField(AutofillField* field) { | 172 // FullWalletBillingWrapper |
184 field->value = GetInfo(field->type()); | 173 |
174 FullWalletBillingWrapper::FullWalletBillingWrapper( | |
175 wallet::FullWallet* full_wallet) : full_wallet_(full_wallet) { | |
Evan Stade
2013/03/14 18:15:47
initializer list on new line
Dan Beam
2013/03/14 18:36:43
Done.
| |
176 DCHECK(full_wallet_); | |
177 } | |
178 | |
179 FullWalletBillingWrapper::~FullWalletBillingWrapper() {} | |
180 | |
181 string16 FullWalletBillingWrapper::GetInfo(AutofillFieldType type) { | |
182 if (AutofillType(type).group() == AutofillType::CREDIT_CARD) | |
183 return full_wallet_->GetInfo(type); | |
184 | |
185 return full_wallet_->billing_address()->GetInfo(type); | |
186 } | |
187 | |
188 // FullWalletShippingWrapper | |
189 | |
190 FullWalletShippingWrapper::FullWalletShippingWrapper( | |
191 wallet::FullWallet* full_wallet) : full_wallet_(full_wallet) { | |
Evan Stade
2013/03/14 18:15:47
initializer list on new line
Dan Beam
2013/03/14 18:36:43
Done.
| |
192 DCHECK(full_wallet_); | |
193 } | |
194 | |
195 FullWalletShippingWrapper::~FullWalletShippingWrapper() {} | |
196 | |
197 string16 FullWalletShippingWrapper::GetInfo(AutofillFieldType type) { | |
198 return full_wallet_->shipping_address()->GetInfo(type); | |
185 } | 199 } |
186 | 200 |
187 } // namespace autofill | 201 } // namespace autofill |
OLD | NEW |