| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 98 |
| 98 void AutofillProfileWrapper::FillInputs(DetailInputs* inputs) { | 99 void AutofillProfileWrapper::FillInputs(DetailInputs* inputs) { |
| 99 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 100 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
| 100 for (size_t j = 0; j < inputs->size(); ++j) { | 101 for (size_t j = 0; j < inputs->size(); ++j) { |
| 101 std::vector<string16> values; | 102 std::vector<string16> values; |
| 102 profile_->GetMultiInfo((*inputs)[j].type, app_locale, &values); | 103 profile_->GetMultiInfo((*inputs)[j].type, app_locale, &values); |
| 103 (*inputs)[j].initial_value = values[variant()]; | 104 (*inputs)[j].initial_value = values[variant()]; |
| 104 } | 105 } |
| 105 } | 106 } |
| 106 | 107 |
| 108 bool AutofillProfileWrapper::IsValid() const { |
| 109 return true; |
| 110 } |
| 111 |
| 107 // AutofillCreditCardWrapper | 112 // AutofillCreditCardWrapper |
| 108 | 113 |
| 109 AutofillCreditCardWrapper::AutofillCreditCardWrapper(const CreditCard* card) | 114 AutofillCreditCardWrapper::AutofillCreditCardWrapper(const CreditCard* card) |
| 110 : AutofillDataModelWrapper(card, 0), | 115 : AutofillDataModelWrapper(card, 0), |
| 111 card_(card) {} | 116 card_(card) {} |
| 112 | 117 |
| 113 AutofillCreditCardWrapper::~AutofillCreditCardWrapper() {} | 118 AutofillCreditCardWrapper::~AutofillCreditCardWrapper() {} |
| 114 | 119 |
| 115 string16 AutofillCreditCardWrapper::GetInfo(AutofillFieldType type) { | 120 string16 AutofillCreditCardWrapper::GetInfo(AutofillFieldType type) { |
| 116 if (type == CREDIT_CARD_EXP_MONTH) | 121 if (type == CREDIT_CARD_EXP_MONTH) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 136 // but the CreditCard class only knows how to fill credit card fields. So, | 141 // but the CreditCard class only knows how to fill credit card fields. So, |
| 137 // temporarily set the type to the corresponding credit card type. | 142 // temporarily set the type to the corresponding credit card type. |
| 138 field->set_heuristic_type(CREDIT_CARD_NAME); | 143 field->set_heuristic_type(CREDIT_CARD_NAME); |
| 139 } | 144 } |
| 140 | 145 |
| 141 AutofillDataModelWrapper::FillFormField(field); | 146 AutofillDataModelWrapper::FillFormField(field); |
| 142 | 147 |
| 143 field->set_heuristic_type(field_type); | 148 field->set_heuristic_type(field_type); |
| 144 } | 149 } |
| 145 | 150 |
| 151 bool AutofillCreditCardWrapper::IsValid() const { |
| 152 return autofill::IsValidCreditCardExpirationDate( |
| 153 card_->GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR), |
| 154 card_->GetRawInfo(CREDIT_CARD_EXP_MONTH), |
| 155 base::Time::Now()); |
| 156 } |
| 157 |
| 146 // WalletAddressWrapper | 158 // WalletAddressWrapper |
| 147 | 159 |
| 148 WalletAddressWrapper::WalletAddressWrapper( | 160 WalletAddressWrapper::WalletAddressWrapper( |
| 149 const wallet::Address* address) : address_(address) {} | 161 const wallet::Address* address) : address_(address) {} |
| 150 | 162 |
| 151 WalletAddressWrapper::~WalletAddressWrapper() {} | 163 WalletAddressWrapper::~WalletAddressWrapper() {} |
| 152 | 164 |
| 153 string16 WalletAddressWrapper::GetInfo(AutofillFieldType type) { | 165 string16 WalletAddressWrapper::GetInfo(AutofillFieldType type) { |
| 154 return address_->GetInfo(type, g_browser_process->GetApplicationLocale()); | 166 return address_->GetInfo(type, g_browser_process->GetApplicationLocale()); |
| 155 } | 167 } |
| 156 | 168 |
| 169 bool WalletAddressWrapper::IsValid() const { |
| 170 return true; |
| 171 } |
| 172 |
| 157 // WalletInstrumentWrapper | 173 // WalletInstrumentWrapper |
| 158 | 174 |
| 159 WalletInstrumentWrapper::WalletInstrumentWrapper( | 175 WalletInstrumentWrapper::WalletInstrumentWrapper( |
| 160 const wallet::WalletItems::MaskedInstrument* instrument) | 176 const wallet::WalletItems::MaskedInstrument* instrument) |
| 161 : instrument_(instrument) {} | 177 : instrument_(instrument) {} |
| 162 | 178 |
| 163 WalletInstrumentWrapper::~WalletInstrumentWrapper() {} | 179 WalletInstrumentWrapper::~WalletInstrumentWrapper() {} |
| 164 | 180 |
| 165 string16 WalletInstrumentWrapper::GetInfo(AutofillFieldType type) { | 181 string16 WalletInstrumentWrapper::GetInfo(AutofillFieldType type) { |
| 166 if (type == CREDIT_CARD_EXP_MONTH) | 182 if (type == CREDIT_CARD_EXP_MONTH) |
| 167 return MonthComboboxModel::FormatMonth(instrument_->expiration_month()); | 183 return MonthComboboxModel::FormatMonth(instrument_->expiration_month()); |
| 168 | 184 |
| 169 return instrument_->GetInfo(type, g_browser_process->GetApplicationLocale()); | 185 return instrument_->GetInfo(type, g_browser_process->GetApplicationLocale()); |
| 170 } | 186 } |
| 171 | 187 |
| 172 gfx::Image WalletInstrumentWrapper::GetIcon() { | 188 gfx::Image WalletInstrumentWrapper::GetIcon() { |
| 173 return instrument_->CardIcon(); | 189 return instrument_->CardIcon(); |
| 174 } | 190 } |
| 175 | 191 |
| 176 string16 WalletInstrumentWrapper::GetDisplayText() { | 192 string16 WalletInstrumentWrapper::GetDisplayText() { |
| 177 // TODO(estade): descriptive_name() is user-provided. Should we use it or | 193 // TODO(estade): descriptive_name() is user-provided. Should we use it or |
| 178 // just type + last 4 digits? | 194 // just type + last 4 digits? |
| 179 string16 line1 = instrument_->descriptive_name(); | 195 string16 line1 = instrument_->descriptive_name(); |
| 180 return line1 + ASCIIToUTF16("\n") + DataModelWrapper::GetDisplayText(); | 196 return line1 + ASCIIToUTF16("\n") + DataModelWrapper::GetDisplayText(); |
| 181 } | 197 } |
| 182 | 198 |
| 199 bool WalletInstrumentWrapper::IsValid() const { |
| 200 // TODO(dbeam): handle other instrument statuses? http://crbug.com/233048 |
| 201 return instrument_->status() != |
| 202 wallet::WalletItems::MaskedInstrument::EXPIRED; |
| 203 } |
| 204 |
| 183 // FullWalletBillingWrapper | 205 // FullWalletBillingWrapper |
| 184 | 206 |
| 185 FullWalletBillingWrapper::FullWalletBillingWrapper( | 207 FullWalletBillingWrapper::FullWalletBillingWrapper( |
| 186 wallet::FullWallet* full_wallet) | 208 wallet::FullWallet* full_wallet) |
| 187 : full_wallet_(full_wallet) { | 209 : full_wallet_(full_wallet) { |
| 188 DCHECK(full_wallet_); | 210 DCHECK(full_wallet_); |
| 189 } | 211 } |
| 190 | 212 |
| 191 FullWalletBillingWrapper::~FullWalletBillingWrapper() {} | 213 FullWalletBillingWrapper::~FullWalletBillingWrapper() {} |
| 192 | 214 |
| 193 string16 FullWalletBillingWrapper::GetInfo(AutofillFieldType type) { | 215 string16 FullWalletBillingWrapper::GetInfo(AutofillFieldType type) { |
| 194 if (AutofillType(type).group() == AutofillType::CREDIT_CARD) | 216 if (AutofillType(type).group() == AutofillType::CREDIT_CARD) |
| 195 return full_wallet_->GetInfo(type); | 217 return full_wallet_->GetInfo(type); |
| 196 | 218 |
| 197 return full_wallet_->billing_address()->GetInfo( | 219 return full_wallet_->billing_address()->GetInfo( |
| 198 type, g_browser_process->GetApplicationLocale()); | 220 type, g_browser_process->GetApplicationLocale()); |
| 199 } | 221 } |
| 200 | 222 |
| 223 bool FullWalletBillingWrapper::IsValid() const { |
| 224 // TODO(dbeam): handle other required actions? http://crbug.com/163508 |
| 225 return !full_wallet_->HasRequiredAction(wallet::UPDATE_EXPIRATION_DATE); |
| 226 } |
| 227 |
| 201 // FullWalletShippingWrapper | 228 // FullWalletShippingWrapper |
| 202 | 229 |
| 203 FullWalletShippingWrapper::FullWalletShippingWrapper( | 230 FullWalletShippingWrapper::FullWalletShippingWrapper( |
| 204 wallet::FullWallet* full_wallet) | 231 wallet::FullWallet* full_wallet) |
| 205 : full_wallet_(full_wallet) { | 232 : full_wallet_(full_wallet) { |
| 206 DCHECK(full_wallet_); | 233 DCHECK(full_wallet_); |
| 207 } | 234 } |
| 208 | 235 |
| 209 FullWalletShippingWrapper::~FullWalletShippingWrapper() {} | 236 FullWalletShippingWrapper::~FullWalletShippingWrapper() {} |
| 210 | 237 |
| 211 string16 FullWalletShippingWrapper::GetInfo(AutofillFieldType type) { | 238 string16 FullWalletShippingWrapper::GetInfo(AutofillFieldType type) { |
| 212 return full_wallet_->shipping_address()->GetInfo( | 239 return full_wallet_->shipping_address()->GetInfo( |
| 213 type, g_browser_process->GetApplicationLocale()); | 240 type, g_browser_process->GetApplicationLocale()); |
| 214 } | 241 } |
| 215 | 242 |
| 243 bool FullWalletShippingWrapper::IsValid() const { |
| 244 return true; |
| 245 } |
| 246 |
| 216 } // namespace autofill | 247 } // namespace autofill |
| OLD | NEW |