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/core/browser/credit_card_field.h" | 5 #include "components/autofill/core/browser/credit_card_field.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 case CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR: { | 65 case CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR: { |
| 66 static int kMinimum4YearCcExpLength = strlen("12/2014"); | 66 static int kMinimum4YearCcExpLength = strlen("12/2014"); |
| 67 return max_length >= kMinimum4YearCcExpLength; | 67 return max_length >= kMinimum4YearCcExpLength; |
| 68 } | 68 } |
| 69 default: | 69 default: |
| 70 NOTREACHED(); | 70 NOTREACHED(); |
| 71 return false; | 71 return false; |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 | 74 |
| 75 | |
| 76 } // namespace | 75 } // namespace |
| 77 | 76 |
| 78 // static | 77 // static |
| 79 scoped_ptr<FormField> CreditCardField::Parse(AutofillScanner* scanner) { | 78 scoped_ptr<FormField> CreditCardField::Parse(AutofillScanner* scanner) { |
| 80 if (scanner->IsEnd()) | 79 if (scanner->IsEnd()) |
| 81 return nullptr; | 80 return nullptr; |
| 82 | 81 |
| 83 scoped_ptr<CreditCardField> credit_card_field(new CreditCardField); | 82 scoped_ptr<CreditCardField> credit_card_field(new CreditCardField); |
| 84 size_t saved_cursor = scanner->SaveCursor(); | 83 size_t saved_cursor = scanner->SaveCursor(); |
| 85 | 84 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 134 // We look for a card security code before we look for a credit card number | 133 // We look for a card security code before we look for a credit card number |
| 135 // and match the general term "number". The security code has a plethora of | 134 // and match the general term "number". The security code has a plethora of |
| 136 // names; we've seen "verification #", "verification number", "card | 135 // names; we've seen "verification #", "verification number", "card |
| 137 // identification number", and others listed in the regex pattern used | 136 // identification number", and others listed in the regex pattern used |
| 138 // below. | 137 // below. |
| 139 // Note: Some sites use type="tel" or type="number" for numerical inputs. | 138 // Note: Some sites use type="tel" or type="number" for numerical inputs. |
| 140 const int kMatchNumAndTel = MATCH_DEFAULT | MATCH_NUMBER | MATCH_TELEPHONE; | 139 const int kMatchNumAndTel = MATCH_DEFAULT | MATCH_NUMBER | MATCH_TELEPHONE; |
| 141 if (!credit_card_field->verification_ && | 140 if (!credit_card_field->verification_ && |
| 142 ParseFieldSpecifics(scanner, | 141 ParseFieldSpecifics(scanner, |
| 143 base::UTF8ToUTF16(kCardCvcRe), | 142 base::UTF8ToUTF16(kCardCvcRe), |
| 144 kMatchNumAndTel | MATCH_PASSWORD, | 143 kMatchNumAndTel | MATCH_PASSWORD, |
|
Mathieu
2016/03/04 18:54:38
note: add MATCH_PASSWORD to the constant above.
Toyama
2016/03/04 19:29:40
I think that makes sense, but it might introduce d
sebsg
2016/03/09 16:38:35
Once I rebase the other will use password also, so
sebsg
2016/03/09 16:38:36
Done.
| |
| 145 &credit_card_field->verification_)) { | 144 &credit_card_field->verification_)) { |
| 145 // A couple of sites have multiple verification codes right after an | |
|
Toyama
2016/03/04 19:08:49
s/an another/another/
sebsg
2016/03/09 16:38:35
Done.
| |
| 146 // other. Allow the classification of these codes one by one. | |
| 147 AutofillField* cvv = credit_card_field->verification_; | |
|
Mathieu
2016/03/04 18:54:38
rename to |saved_cvv|?
Toyama
2016/03/04 19:08:50
const
sebsg
2016/03/09 16:38:35
Done.
sebsg
2016/03/09 16:38:35
Done.
| |
| 148 | |
| 149 // Make sure that only a verification code was found. | |
|
Mathieu
2016/03/04 18:54:38
Combine the previous comment with this:
// If the
Toyama
2016/03/04 19:08:49
s/a/one/
sebsg
2016/03/09 16:38:35
Done.
sebsg
2016/03/09 16:38:35
Done.
| |
| 150 if (credit_card_field->numbers_.empty() && | |
| 151 !credit_card_field->HasExpiration() && | |
| 152 !credit_card_field->cardholder_) { | |
| 153 // Check if the previous field was a verification code. | |
| 154 scanner->RewindTo(scanner->SaveCursor() - 2); | |
| 155 if (ParseFieldSpecifics(scanner, base::UTF8ToUTF16(kCardCvcRe), | |
| 156 kMatchNumAndTel | MATCH_PASSWORD, | |
| 157 &credit_card_field->verification_)) { | |
| 158 // Reset the current cvv (The verification parse overwrote it). | |
| 159 credit_card_field->verification_ = cvv; | |
| 160 // Put the scanner back to the field right after the current cvv. | |
| 161 scanner->Advance(); | |
| 162 return std::move(credit_card_field); | |
|
Mathieu
2016/03/04 18:54:38
wait, isn't |credit_card_field| mostly empty here?
sebsg
2016/03/09 16:38:35
At this point it contains only a CVV. The effect o
| |
| 163 } else { | |
| 164 // Put the scanner back to the field right after the current cvv. | |
| 165 scanner->Advance(); | |
| 166 scanner->Advance(); | |
| 167 } | |
| 168 } | |
| 169 | |
| 146 continue; | 170 continue; |
| 147 } | 171 } |
| 148 | 172 |
| 149 AutofillField* current_number_field; | 173 AutofillField* current_number_field; |
| 150 if (ParseFieldSpecifics(scanner, | 174 if (ParseFieldSpecifics(scanner, |
| 151 base::UTF8ToUTF16(kCardNumberRe), | 175 base::UTF8ToUTF16(kCardNumberRe), |
| 152 kMatchNumAndTel, | 176 kMatchNumAndTel, |
| 153 ¤t_number_field)) { | 177 ¤t_number_field)) { |
| 154 // Avoid autofilling any credit card number field having very low or high | 178 // Avoid autofilling any credit card number field having very low or high |
| 155 // |start_index| on the HTML form. | 179 // |start_index| on the HTML form. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 if (credit_card_field->cardholder_) | 217 if (credit_card_field->cardholder_) |
| 194 return std::move(credit_card_field); | 218 return std::move(credit_card_field); |
| 195 | 219 |
| 196 // On some pages, the user selects a card type using radio buttons | 220 // On some pages, the user selects a card type using radio buttons |
| 197 // (e.g. test page Apple Store Billing.html). We can't handle that yet, | 221 // (e.g. test page Apple Store Billing.html). We can't handle that yet, |
| 198 // so we treat the card type as optional for now. | 222 // so we treat the card type as optional for now. |
| 199 // The existence of a number or cvc in combination with expiration date is | 223 // The existence of a number or cvc in combination with expiration date is |
| 200 // a strong enough signal that this is a credit card. It is possible that | 224 // a strong enough signal that this is a credit card. It is possible that |
| 201 // the number and name were parsed in a separate part of the form. So if | 225 // the number and name were parsed in a separate part of the form. So if |
| 202 // the cvc and date were found independently they are returned. | 226 // the cvc and date were found independently they are returned. |
| 203 bool has_cc_number_or_verification = (credit_card_field->verification_ || | 227 bool has_cc_number_or_verification = (credit_card_field->verification_ || |
|
Toyama
2016/03/04 19:29:40
This is not your change, but this should be const.
sebsg
2016/03/09 16:38:35
Done.
| |
| 204 !credit_card_field->numbers_.empty()); | 228 !credit_card_field->numbers_.empty()); |
| 205 bool has_date_or_mm_yy = (credit_card_field->expiration_date_ || | 229 if (has_cc_number_or_verification && credit_card_field->HasExpiration()) |
| 206 (credit_card_field->expiration_month_ && | |
| 207 credit_card_field->expiration_year_)); | |
| 208 if (has_cc_number_or_verification && has_date_or_mm_yy) | |
| 209 return std::move(credit_card_field); | 230 return std::move(credit_card_field); |
| 210 | 231 |
| 211 scanner->RewindTo(saved_cursor); | 232 scanner->RewindTo(saved_cursor); |
| 212 return nullptr; | 233 return nullptr; |
| 213 } | 234 } |
| 214 | 235 |
| 215 // static | 236 // static |
| 216 bool CreditCardField::LikelyCardMonthSelectField(AutofillScanner* scanner) { | 237 bool CreditCardField::LikelyCardMonthSelectField(AutofillScanner* scanner) { |
| 217 if (scanner->IsEnd()) | 238 if (scanner->IsEnd()) |
| 218 return false; | 239 return false; |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 470 } | 491 } |
| 471 | 492 |
| 472 ServerFieldType CreditCardField::GetExpirationYearType() const { | 493 ServerFieldType CreditCardField::GetExpirationYearType() const { |
| 473 return (expiration_date_ | 494 return (expiration_date_ |
| 474 ? exp_year_type_ | 495 ? exp_year_type_ |
| 475 : ((expiration_year_ && expiration_year_->max_length == 2) | 496 : ((expiration_year_ && expiration_year_->max_length == 2) |
| 476 ? CREDIT_CARD_EXP_2_DIGIT_YEAR | 497 ? CREDIT_CARD_EXP_2_DIGIT_YEAR |
| 477 : CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 498 : CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
| 478 } | 499 } |
| 479 | 500 |
| 501 bool CreditCardField::HasExpiration() const { | |
| 502 return expiration_date_ || (expiration_month_ && expiration_year_); | |
| 503 } | |
| 504 | |
| 480 } // namespace autofill | 505 } // namespace autofill |
| OLD | NEW |