Chromium Code Reviews| 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 | |
| 52 // AutofillFormGroupWrapper | 59 // AutofillFormGroupWrapper |
| 53 | 60 |
| 54 AutofillFormGroupWrapper::AutofillFormGroupWrapper(const FormGroup* form_group, | 61 AutofillFormGroupWrapper::AutofillFormGroupWrapper(const FormGroup* form_group, |
| 55 size_t variant) | 62 size_t variant) |
| 56 : form_group_(form_group), | 63 : form_group_(form_group), |
| 57 variant_(variant) {} | 64 variant_(variant) {} |
| 58 | 65 |
| 59 AutofillFormGroupWrapper::~AutofillFormGroupWrapper() {} | 66 AutofillFormGroupWrapper::~AutofillFormGroupWrapper() {} |
| 60 | 67 |
| 61 string16 AutofillFormGroupWrapper::GetInfo(AutofillFieldType type) { | 68 string16 AutofillFormGroupWrapper::GetInfo(AutofillFieldType type) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 WalletAddressWrapper::~WalletAddressWrapper() {} | 143 WalletAddressWrapper::~WalletAddressWrapper() {} |
| 137 | 144 |
| 138 string16 WalletAddressWrapper::GetInfo(AutofillFieldType type) { | 145 string16 WalletAddressWrapper::GetInfo(AutofillFieldType type) { |
| 139 return address_->GetInfo(type); | 146 return address_->GetInfo(type); |
| 140 } | 147 } |
| 141 | 148 |
| 142 gfx::Image WalletAddressWrapper::GetIcon() { | 149 gfx::Image WalletAddressWrapper::GetIcon() { |
| 143 return gfx::Image(); | 150 return gfx::Image(); |
| 144 } | 151 } |
| 145 | 152 |
| 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 void WalletAddressWrapper::FillFormField(AutofillField* field) { |
| 153 field->value = GetInfo(field->type()); | 154 field->value = GetInfo(field->type()); |
| 154 } | 155 } |
| 155 | 156 |
| 156 // WalletInstrumentWrapper | 157 // WalletInstrumentWrapper |
| 157 | 158 |
| 158 WalletInstrumentWrapper::WalletInstrumentWrapper( | 159 WalletInstrumentWrapper::WalletInstrumentWrapper( |
| 159 const wallet::WalletItems::MaskedInstrument* instrument) | 160 const wallet::WalletItems::MaskedInstrument* instrument) |
| 160 : instrument_(instrument) {} | 161 : instrument_(instrument) {} |
| 161 | 162 |
| 162 WalletInstrumentWrapper::~WalletInstrumentWrapper() {} | 163 WalletInstrumentWrapper::~WalletInstrumentWrapper() {} |
| 163 | 164 |
| 164 string16 WalletInstrumentWrapper::GetInfo(AutofillFieldType type) { | 165 string16 WalletInstrumentWrapper::GetInfo(AutofillFieldType type) { |
| 165 return instrument_->address().GetInfo(type); | 166 return instrument_->address().GetInfo(type); |
| 166 } | 167 } |
| 167 | 168 |
| 168 gfx::Image WalletInstrumentWrapper::GetIcon() { | 169 gfx::Image WalletInstrumentWrapper::GetIcon() { |
| 169 return instrument_->CardIcon(); | 170 return instrument_->CardIcon(); |
| 170 } | 171 } |
| 171 | 172 |
| 172 void WalletInstrumentWrapper::FillInputs(DetailInputs* inputs) { | |
| 173 // TODO(estade): implement. | |
| 174 } | |
| 175 | |
| 176 string16 WalletInstrumentWrapper::GetDisplayText() { | 173 string16 WalletInstrumentWrapper::GetDisplayText() { |
| 177 // TODO(estade): descriptive_name() is user-provided. Should we use it or | 174 // TODO(estade): descriptive_name() is user-provided. Should we use it or |
| 178 // just type + last 4 digits? | 175 // just type + last 4 digits? |
| 179 string16 line1 = instrument_->descriptive_name(); | 176 string16 line1 = instrument_->descriptive_name(); |
| 180 return line1 + ASCIIToUTF16("\n") + DataModelWrapper::GetDisplayText(); | 177 return line1 + ASCIIToUTF16("\n") + DataModelWrapper::GetDisplayText(); |
| 181 } | 178 } |
| 182 | 179 |
| 183 void WalletInstrumentWrapper::FillFormField(AutofillField* field) { | 180 void WalletInstrumentWrapper::FillFormField(AutofillField* field) { |
| 184 field->value = GetInfo(field->type()); | 181 field->value = GetInfo(field->type()); |
| 185 } | 182 } |
| 186 | 183 |
| 184 // FullWalletWrapper | |
| 185 | |
| 186 FullWalletWrapper::FullWalletWrapper(wallet::FullWallet* full_wallet) | |
| 187 : full_wallet_(full_wallet) { | |
| 188 DCHECK(full_wallet_); | |
| 189 } | |
| 190 | |
| 191 FullWalletWrapper::~FullWalletWrapper() {} | |
| 192 | |
| 193 string16 FullWalletWrapper::GetInfo(AutofillFieldType type) { | |
|
Evan Stade
2013/03/14 02:39:38
FullWalletWrapper needn't exist. Implement GetInfo
Dan Beam
2013/03/14 04:31:51
Done.
| |
| 194 return full_wallet_->GetInfo(type, IsBillingWrapper()); | |
| 195 } | |
| 196 | |
| 197 gfx::Image FullWalletWrapper::GetIcon() { | |
| 198 // TODO(dbeam): this could be implemented if necessary, I just don't see where | |
|
Evan Stade
2013/03/14 02:39:38
comment too verbose. Remove.
Dan Beam
2013/03/14 04:31:51
Done.
| |
| 199 // we'd ever need it -- this wrapper is only used to fill values into | |
| 200 // |AutofillDialogControllerImlp::form_structure_| at the moment. | |
| 201 return gfx::Image(); | |
| 202 } | |
| 203 | |
| 204 void FullWalletWrapper::FillFormField(AutofillField* field) { | |
| 205 field->value = GetInfo(field->type()); | |
| 206 } | |
| 207 | |
| 208 // FullWalletBillingWrapper | |
| 209 | |
| 210 FullWalletBillingWrapper::FullWalletBillingWrapper( | |
| 211 wallet::FullWallet* full_wallet) | |
| 212 : FullWalletWrapper(full_wallet) {} | |
| 213 | |
| 214 FullWalletBillingWrapper::~FullWalletBillingWrapper() {} | |
| 215 | |
| 216 bool FullWalletBillingWrapper::IsBillingWrapper() const { | |
| 217 return true; | |
| 218 } | |
| 219 | |
| 220 // FullWalletShippingWrapper | |
| 221 | |
| 222 FullWalletShippingWrapper::FullWalletShippingWrapper( | |
| 223 wallet::FullWallet* full_wallet) | |
| 224 : FullWalletWrapper(full_wallet) {} | |
| 225 | |
| 226 FullWalletShippingWrapper::~FullWalletShippingWrapper() {} | |
| 227 | |
| 228 bool FullWalletShippingWrapper::IsBillingWrapper() const { | |
| 229 return false; | |
| 230 } | |
| 231 | |
| 187 } // namespace autofill | 232 } // namespace autofill |
| OLD | NEW |