| 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::GetInfo(const std::string& app_locale, |
| 158 const AutofillType& type) { |
| 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::ASCIIToUTF16(GetPan()); |
| 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::ASCIIToUTF16(GetCvn()); |
| 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()); |
| 177 | 178 |
| 178 case CREDIT_CARD_EXP_2_DIGIT_YEAR: | 179 case CREDIT_CARD_EXP_2_DIGIT_YEAR: |
| 179 if (expiration_year() == 0) | 180 if (expiration_year() == 0) |
| 180 return base::string16(); | 181 return base::string16(); |
| 181 return base::IntToString16(expiration_year() % 100); | 182 return base::IntToString16(expiration_year() % 100); |
| 182 | 183 |
| 183 case CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR: | 184 case CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR: |
| 184 if (expiration_month() == 0 || expiration_year() == 0) | 185 if (expiration_month() == 0 || expiration_year() == 0) |
| 185 return base::string16(); | 186 return base::string16(); |
| 186 return base::IntToString16(expiration_month()) + base::ASCIIToUTF16("/") + | 187 return base::IntToString16(expiration_month()) + base::ASCIIToUTF16("/") + |
| 187 base::IntToString16(expiration_year() % 100); | 188 base::IntToString16(expiration_year() % 100); |
| 188 | 189 |
| 189 case CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR: | 190 case CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR: |
| 190 if (expiration_month() == 0 || expiration_year() == 0) | 191 if (expiration_month() == 0 || expiration_year() == 0) |
| 191 return base::string16(); | 192 return base::string16(); |
| 192 return base::IntToString16(expiration_month()) + base::ASCIIToUTF16("/") + | 193 return base::IntToString16(expiration_month()) + base::ASCIIToUTF16("/") + |
| 193 base::IntToString16(expiration_year()); | 194 base::IntToString16(expiration_year()); |
| 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::ASCIIToUTF16(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 switch (type.group()) { |
| 206 case NAME_BILLING: |
| 207 case PHONE_BILLING: |
| 208 case ADDRESS_BILLING: |
| 209 return billing_address_->GetInfo(type, app_locale); |
| 210 |
| 211 case CREDIT_CARD: |
| 212 NOTREACHED(); |
| 213 |
| 214 default: |
| 215 return shipping_address_->GetInfo(type, app_locale); |
| 216 } |
| 217 } |
| 205 } | 218 } |
| 206 | |
| 207 return base::string16(); | |
| 208 } | 219 } |
| 209 | 220 |
| 210 bool FullWallet::HasRequiredAction(RequiredAction action) const { | 221 bool FullWallet::HasRequiredAction(RequiredAction action) const { |
| 211 DCHECK(ActionAppliesToFullWallet(action)); | 222 DCHECK(ActionAppliesToFullWallet(action)); |
| 212 return std::find(required_actions_.begin(), | 223 return std::find(required_actions_.begin(), |
| 213 required_actions_.end(), | 224 required_actions_.end(), |
| 214 action) != required_actions_.end(); | 225 action) != required_actions_.end(); |
| 215 } | 226 } |
| 216 | 227 |
| 217 base::string16 FullWallet::TypeAndLastFourDigits() { | 228 base::string16 FullWallet::TypeAndLastFourDigits() { |
| 218 CreditCard card; | 229 CreditCard card; |
| 219 card.SetRawInfo(CREDIT_CARD_NUMBER, | 230 card.SetRawInfo(CREDIT_CARD_NUMBER, base::ASCIIToUTF16(GetPan())); |
| 220 GetInfo(AutofillType(CREDIT_CARD_NUMBER))); | |
| 221 return card.TypeAndLastFourDigits(); | 231 return card.TypeAndLastFourDigits(); |
| 222 } | 232 } |
| 223 | 233 |
| 234 const std::string& FullWallet::GetPan() { |
| 235 if (pan_.empty()) |
| 236 DecryptCardInfo(); |
| 237 return pan_; |
| 238 } |
| 239 |
| 224 bool FullWallet::operator==(const FullWallet& other) const { | 240 bool FullWallet::operator==(const FullWallet& other) const { |
| 225 if (expiration_month_ != other.expiration_month_) | 241 if (expiration_month_ != other.expiration_month_) |
| 226 return false; | 242 return false; |
| 227 | 243 |
| 228 if (expiration_year_ != other.expiration_year_) | 244 if (expiration_year_ != other.expiration_year_) |
| 229 return false; | 245 return false; |
| 230 | 246 |
| 231 if (iin_ != other.iin_) | 247 if (iin_ != other.iin_) |
| 232 return false; | 248 return false; |
| 233 | 249 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 // to be padded with 0's until it is. | 316 // to be padded with 0's until it is. |
| 301 if (card_info.size() != padded_length) | 317 if (card_info.size() != padded_length) |
| 302 card_info.insert(card_info.begin(), padded_length - card_info.size(), '0'); | 318 card_info.insert(card_info.begin(), padded_length - card_info.size(), '0'); |
| 303 | 319 |
| 304 // Separate out the PAN from the CVN. | 320 // Separate out the PAN from the CVN. |
| 305 size_t split = kPanSize - kBinSize; | 321 size_t split = kPanSize - kBinSize; |
| 306 cvn_ = card_info.substr(split); | 322 cvn_ = card_info.substr(split); |
| 307 pan_ = iin_ + card_info.substr(0, split); | 323 pan_ = iin_ + card_info.substr(0, split); |
| 308 } | 324 } |
| 309 | 325 |
| 310 const std::string& FullWallet::GetPan() { | |
| 311 if (pan_.empty()) | |
| 312 DecryptCardInfo(); | |
| 313 return pan_; | |
| 314 } | |
| 315 | |
| 316 const std::string& FullWallet::GetCvn() { | 326 const std::string& FullWallet::GetCvn() { |
| 317 if (cvn_.empty()) | 327 if (cvn_.empty()) |
| 318 DecryptCardInfo(); | 328 DecryptCardInfo(); |
| 319 return cvn_; | 329 return cvn_; |
| 320 } | 330 } |
| 321 | 331 |
| 322 } // namespace wallet | 332 } // namespace wallet |
| 323 } // namespace autofill | 333 } // namespace autofill |
| OLD | NEW |