Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/content/browser/wallet/full_wallet.h" | 5 #include "components/autofill/content/browser/wallet/full_wallet.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 std::string(), // no iin -- clear text pan/cvn are set below. | 147 std::string(), // no iin -- clear text pan/cvn are set below. |
| 148 std::string(), // no encrypted_rest -- clear text pan/cvn are set below. | 148 std::string(), // no encrypted_rest -- clear text pan/cvn are set below. |
| 149 billing_address.Pass(), | 149 billing_address.Pass(), |
| 150 shipping_address.Pass(), | 150 shipping_address.Pass(), |
| 151 std::vector<RequiredAction>())); // no required actions in clear text. | 151 std::vector<RequiredAction>())); // no required actions in clear text. |
| 152 wallet->pan_ = pan; | 152 wallet->pan_ = pan; |
| 153 wallet->cvn_ = cvn; | 153 wallet->cvn_ = cvn; |
| 154 return wallet.Pass(); | 154 return wallet.Pass(); |
| 155 } | 155 } |
| 156 | 156 |
| 157 base::string16 FullWallet::GetInfo(const AutofillType& type) { | 157 base::string16 FullWallet::GetBillingInfo(const std::string& app_locale, |
| 158 const AutofillType& type) { | |
|
Dan Beam
2014/01/27 19:37:50
nit: reverse the order of |app_locale| and |type|
Evan Stade
2014/01/27 19:45:41
can't, this is needed for the bind() to work
| |
| 158 switch (type.GetStorableType()) { | 159 switch (type.GetStorableType()) { |
| 159 case CREDIT_CARD_NUMBER: | 160 case CREDIT_CARD_NUMBER: |
| 160 return base::UTF8ToUTF16(GetPan()); | 161 return base::UTF8ToUTF16(GetPan()); |
|
Dan Beam
2014/01/27 19:37:50
nit: base::ASCIIToUTF16() if you assume CVN/PAN ca
Evan Stade
2014/01/27 19:45:41
Done.
| |
| 161 | 162 |
| 162 case CREDIT_CARD_NAME: | 163 case CREDIT_CARD_NAME: |
| 163 return billing_address()->recipient_name(); | 164 return billing_address()->recipient_name(); |
| 164 | 165 |
| 165 case CREDIT_CARD_VERIFICATION_CODE: | 166 case CREDIT_CARD_VERIFICATION_CODE: |
| 166 return base::UTF8ToUTF16(GetCvn()); | 167 return base::UTF8ToUTF16(GetCvn()); |
|
Dan Beam
2014/01/27 19:37:50
same nit: re base::ASCIIToUTF16()
Evan Stade
2014/01/27 19:45:41
Done.
| |
| 167 | 168 |
| 168 case CREDIT_CARD_EXP_MONTH: | 169 case CREDIT_CARD_EXP_MONTH: |
| 169 if (expiration_month() == 0) | 170 if (expiration_month() == 0) |
| 170 return base::string16(); | 171 return base::string16(); |
| 171 return base::IntToString16(expiration_month()); | 172 return base::IntToString16(expiration_month()); |
| 172 | 173 |
| 173 case CREDIT_CARD_EXP_4_DIGIT_YEAR: | 174 case CREDIT_CARD_EXP_4_DIGIT_YEAR: |
| 174 if (expiration_year() == 0) | 175 if (expiration_year() == 0) |
| 175 return base::string16(); | 176 return base::string16(); |
| 176 return base::IntToString16(expiration_year()); | 177 return base::IntToString16(expiration_year()); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 194 | 195 |
| 195 case CREDIT_CARD_TYPE: { | 196 case CREDIT_CARD_TYPE: { |
| 196 std::string internal_type = | 197 std::string internal_type = |
| 197 CreditCard::GetCreditCardType(base::UTF8ToUTF16(GetPan())); | 198 CreditCard::GetCreditCardType(base::UTF8ToUTF16(GetPan())); |
| 198 if (internal_type == kGenericCard) | 199 if (internal_type == kGenericCard) |
| 199 return base::string16(); | 200 return base::string16(); |
| 200 return CreditCard::TypeForDisplay(internal_type); | 201 return CreditCard::TypeForDisplay(internal_type); |
| 201 } | 202 } |
| 202 | 203 |
| 203 default: | 204 default: |
| 204 NOTREACHED(); | 205 DCHECK_NE(CREDIT_CARD, type.group()); |
| 206 return billing_address_->GetInfo(type, app_locale); | |
| 205 } | 207 } |
| 208 } | |
| 206 | 209 |
| 207 return base::string16(); | 210 base::string16 FullWallet::GetShippingInfo(const std::string& app_locale, |
| 211 const AutofillType& type) { | |
| 212 return shipping_address_->GetInfo(type, app_locale); | |
| 208 } | 213 } |
| 209 | 214 |
| 210 bool FullWallet::HasRequiredAction(RequiredAction action) const { | 215 bool FullWallet::HasRequiredAction(RequiredAction action) const { |
| 211 DCHECK(ActionAppliesToFullWallet(action)); | 216 DCHECK(ActionAppliesToFullWallet(action)); |
| 212 return std::find(required_actions_.begin(), | 217 return std::find(required_actions_.begin(), |
| 213 required_actions_.end(), | 218 required_actions_.end(), |
| 214 action) != required_actions_.end(); | 219 action) != required_actions_.end(); |
| 215 } | 220 } |
| 216 | 221 |
| 217 base::string16 FullWallet::TypeAndLastFourDigits() { | 222 base::string16 FullWallet::TypeAndLastFourDigits() { |
| 218 CreditCard card; | 223 CreditCard card; |
| 219 card.SetRawInfo(CREDIT_CARD_NUMBER, | 224 card.SetRawInfo(CREDIT_CARD_NUMBER, base::ASCIIToUTF16(GetPan())); |
| 220 GetInfo(AutofillType(CREDIT_CARD_NUMBER))); | |
| 221 return card.TypeAndLastFourDigits(); | 225 return card.TypeAndLastFourDigits(); |
| 222 } | 226 } |
| 223 | 227 |
| 228 const std::string& FullWallet::GetPan() { | |
| 229 if (pan_.empty()) | |
| 230 DecryptCardInfo(); | |
| 231 return pan_; | |
| 232 } | |
| 233 | |
| 224 bool FullWallet::operator==(const FullWallet& other) const { | 234 bool FullWallet::operator==(const FullWallet& other) const { |
| 225 if (expiration_month_ != other.expiration_month_) | 235 if (expiration_month_ != other.expiration_month_) |
| 226 return false; | 236 return false; |
| 227 | 237 |
| 228 if (expiration_year_ != other.expiration_year_) | 238 if (expiration_year_ != other.expiration_year_) |
| 229 return false; | 239 return false; |
| 230 | 240 |
| 231 if (iin_ != other.iin_) | 241 if (iin_ != other.iin_) |
| 232 return false; | 242 return false; |
| 233 | 243 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 // to be padded with 0's until it is. | 310 // to be padded with 0's until it is. |
| 301 if (card_info.size() != padded_length) | 311 if (card_info.size() != padded_length) |
| 302 card_info.insert(card_info.begin(), padded_length - card_info.size(), '0'); | 312 card_info.insert(card_info.begin(), padded_length - card_info.size(), '0'); |
| 303 | 313 |
| 304 // Separate out the PAN from the CVN. | 314 // Separate out the PAN from the CVN. |
| 305 size_t split = kPanSize - kBinSize; | 315 size_t split = kPanSize - kBinSize; |
| 306 cvn_ = card_info.substr(split); | 316 cvn_ = card_info.substr(split); |
| 307 pan_ = iin_ + card_info.substr(0, split); | 317 pan_ = iin_ + card_info.substr(0, split); |
| 308 } | 318 } |
| 309 | 319 |
| 310 const std::string& FullWallet::GetPan() { | |
| 311 if (pan_.empty()) | |
| 312 DecryptCardInfo(); | |
| 313 return pan_; | |
| 314 } | |
| 315 | |
| 316 const std::string& FullWallet::GetCvn() { | 320 const std::string& FullWallet::GetCvn() { |
| 317 if (cvn_.empty()) | 321 if (cvn_.empty()) |
| 318 DecryptCardInfo(); | 322 DecryptCardInfo(); |
| 319 return cvn_; | 323 return cvn_; |
| 320 } | 324 } |
| 321 | 325 |
| 322 } // namespace wallet | 326 } // namespace wallet |
| 323 } // namespace autofill | 327 } // namespace autofill |
| OLD | NEW |