| 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 "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" | 10 #include "chrome/browser/ui/autofill/autofill_dialog_models.h" |
| 11 #include "components/autofill/browser/autofill_data_model.h" | 11 #include "components/autofill/browser/autofill_data_model.h" |
| 12 #include "components/autofill/browser/autofill_profile.h" | 12 #include "components/autofill/browser/autofill_profile.h" |
| 13 #include "components/autofill/browser/autofill_type.h" | 13 #include "components/autofill/browser/autofill_type.h" |
| 14 #include "components/autofill/browser/credit_card.h" | 14 #include "components/autofill/browser/credit_card.h" |
| 15 #include "components/autofill/browser/form_structure.h" | 15 #include "components/autofill/browser/form_structure.h" |
| 16 #include "components/autofill/browser/validation.h" |
| 16 #include "components/autofill/browser/wallet/full_wallet.h" | 17 #include "components/autofill/browser/wallet/full_wallet.h" |
| 17 #include "components/autofill/browser/wallet/wallet_address.h" | 18 #include "components/autofill/browser/wallet/wallet_address.h" |
| 18 #include "components/autofill/browser/wallet/wallet_items.h" | 19 #include "components/autofill/browser/wallet/wallet_items.h" |
| 19 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
| 20 #include "ui/gfx/image/image.h" | 21 #include "ui/gfx/image/image.h" |
| 21 | 22 |
| 22 namespace autofill { | 23 namespace autofill { |
| 23 | 24 |
| 24 DataModelWrapper::~DataModelWrapper() {} | 25 DataModelWrapper::~DataModelWrapper() {} |
| 25 | 26 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 | 119 |
| 119 return AutofillDataModelWrapper::GetInfo(type); | 120 return AutofillDataModelWrapper::GetInfo(type); |
| 120 } | 121 } |
| 121 | 122 |
| 122 gfx::Image AutofillCreditCardWrapper::GetIcon() { | 123 gfx::Image AutofillCreditCardWrapper::GetIcon() { |
| 123 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 124 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 124 return rb.GetImageNamed(card_->IconResourceId()); | 125 return rb.GetImageNamed(card_->IconResourceId()); |
| 125 } | 126 } |
| 126 | 127 |
| 127 string16 AutofillCreditCardWrapper::GetDisplayText() { | 128 string16 AutofillCreditCardWrapper::GetDisplayText() { |
| 129 if (!autofill::IsValidCreditCardExpirationDate( |
| 130 card_->GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR), |
| 131 card_->GetRawInfo(CREDIT_CARD_EXP_MONTH), |
| 132 base::Time::Now())) { |
| 133 return string16(); |
| 134 } |
| 135 |
| 128 return card_->TypeAndLastFourDigits(); | 136 return card_->TypeAndLastFourDigits(); |
| 129 } | 137 } |
| 130 | 138 |
| 131 void AutofillCreditCardWrapper::FillFormField(AutofillField* field) { | 139 void AutofillCreditCardWrapper::FillFormField(AutofillField* field) { |
| 132 AutofillFieldType field_type = field->type(); | 140 AutofillFieldType field_type = field->type(); |
| 133 | 141 |
| 134 if (field_type == NAME_FULL) { | 142 if (field_type == NAME_FULL) { |
| 135 // Requests for the user's full name are filled from the credit card data, | 143 // Requests for the user's full name are filled from the credit card data, |
| 136 // but the CreditCard class only knows how to fill credit card fields. So, | 144 // but the CreditCard class only knows how to fill credit card fields. So, |
| 137 // temporarily set the type to the corresponding credit card type. | 145 // temporarily set the type to the corresponding credit card type. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 167 return MonthComboboxModel::FormatMonth(instrument_->expiration_month()); | 175 return MonthComboboxModel::FormatMonth(instrument_->expiration_month()); |
| 168 | 176 |
| 169 return instrument_->GetInfo(type, g_browser_process->GetApplicationLocale()); | 177 return instrument_->GetInfo(type, g_browser_process->GetApplicationLocale()); |
| 170 } | 178 } |
| 171 | 179 |
| 172 gfx::Image WalletInstrumentWrapper::GetIcon() { | 180 gfx::Image WalletInstrumentWrapper::GetIcon() { |
| 173 return instrument_->CardIcon(); | 181 return instrument_->CardIcon(); |
| 174 } | 182 } |
| 175 | 183 |
| 176 string16 WalletInstrumentWrapper::GetDisplayText() { | 184 string16 WalletInstrumentWrapper::GetDisplayText() { |
| 185 // TODO(dbeam): handle other instrument statuses? http://crbug.com/233048 |
| 186 if (instrument_->status() == wallet::WalletItems::MaskedInstrument::EXPIRED) |
| 187 return string16(); |
| 188 |
| 177 // TODO(estade): descriptive_name() is user-provided. Should we use it or | 189 // TODO(estade): descriptive_name() is user-provided. Should we use it or |
| 178 // just type + last 4 digits? | 190 // just type + last 4 digits? |
| 179 string16 line1 = instrument_->descriptive_name(); | 191 string16 line1 = instrument_->descriptive_name(); |
| 180 return line1 + ASCIIToUTF16("\n") + DataModelWrapper::GetDisplayText(); | 192 return line1 + ASCIIToUTF16("\n") + DataModelWrapper::GetDisplayText(); |
| 181 } | 193 } |
| 182 | 194 |
| 183 // FullWalletBillingWrapper | 195 // FullWalletBillingWrapper |
| 184 | 196 |
| 185 FullWalletBillingWrapper::FullWalletBillingWrapper( | 197 FullWalletBillingWrapper::FullWalletBillingWrapper( |
| 186 wallet::FullWallet* full_wallet) | 198 wallet::FullWallet* full_wallet) |
| 187 : full_wallet_(full_wallet) { | 199 : full_wallet_(full_wallet) { |
| 188 DCHECK(full_wallet_); | 200 DCHECK(full_wallet_); |
| 189 } | 201 } |
| 190 | 202 |
| 191 FullWalletBillingWrapper::~FullWalletBillingWrapper() {} | 203 FullWalletBillingWrapper::~FullWalletBillingWrapper() {} |
| 192 | 204 |
| 193 string16 FullWalletBillingWrapper::GetInfo(AutofillFieldType type) { | 205 string16 FullWalletBillingWrapper::GetInfo(AutofillFieldType type) { |
| 194 if (AutofillType(type).group() == AutofillType::CREDIT_CARD) | 206 if (AutofillType(type).group() == AutofillType::CREDIT_CARD) |
| 195 return full_wallet_->GetInfo(type); | 207 return full_wallet_->GetInfo(type); |
| 196 | 208 |
| 197 return full_wallet_->billing_address()->GetInfo( | 209 return full_wallet_->billing_address()->GetInfo( |
| 198 type, g_browser_process->GetApplicationLocale()); | 210 type, g_browser_process->GetApplicationLocale()); |
| 199 } | 211 } |
| 200 | 212 |
| 213 string16 FullWalletBillingWrapper::GetDisplayText() { |
| 214 // TODO(dbeam): handle other required actions? http://crbug.com/163508 |
| 215 if (full_wallet_->HasRequiredAction(wallet::UPDATE_EXPIRATION_DATE)) |
| 216 return string16(); |
| 217 |
| 218 return DataModelWrapper::GetDisplayText(); |
| 219 } |
| 220 |
| 201 // FullWalletShippingWrapper | 221 // FullWalletShippingWrapper |
| 202 | 222 |
| 203 FullWalletShippingWrapper::FullWalletShippingWrapper( | 223 FullWalletShippingWrapper::FullWalletShippingWrapper( |
| 204 wallet::FullWallet* full_wallet) | 224 wallet::FullWallet* full_wallet) |
| 205 : full_wallet_(full_wallet) { | 225 : full_wallet_(full_wallet) { |
| 206 DCHECK(full_wallet_); | 226 DCHECK(full_wallet_); |
| 207 } | 227 } |
| 208 | 228 |
| 209 FullWalletShippingWrapper::~FullWalletShippingWrapper() {} | 229 FullWalletShippingWrapper::~FullWalletShippingWrapper() {} |
| 210 | 230 |
| 211 string16 FullWalletShippingWrapper::GetInfo(AutofillFieldType type) { | 231 string16 FullWalletShippingWrapper::GetInfo(AutofillFieldType type) { |
| 212 return full_wallet_->shipping_address()->GetInfo( | 232 return full_wallet_->shipping_address()->GetInfo( |
| 213 type, g_browser_process->GetApplicationLocale()); | 233 type, g_browser_process->GetApplicationLocale()); |
| 214 } | 234 } |
| 215 | 235 |
| 216 } // namespace autofill | 236 } // namespace autofill |
| OLD | NEW |