| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/autofill/credit_card_field.h" | 5 #include "chrome/browser/autofill/credit_card_field.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 if (scanner->IsEnd()) | 22 if (scanner->IsEnd()) |
| 23 return NULL; | 23 return NULL; |
| 24 | 24 |
| 25 scoped_ptr<CreditCardField> credit_card_field(new CreditCardField); | 25 scoped_ptr<CreditCardField> credit_card_field(new CreditCardField); |
| 26 size_t saved_cursor = scanner->SaveCursor(); | 26 size_t saved_cursor = scanner->SaveCursor(); |
| 27 | 27 |
| 28 // Credit card fields can appear in many different orders. | 28 // Credit card fields can appear in many different orders. |
| 29 // We loop until no more credit card related fields are found, see |break| at | 29 // We loop until no more credit card related fields are found, see |break| at |
| 30 // bottom of the loop. | 30 // bottom of the loop. |
| 31 for (int fields = 0; !scanner->IsEnd(); ++fields) { | 31 for (int fields = 0; !scanner->IsEnd(); ++fields) { |
| 32 // Ignore gift card fields. |
| 33 if (ParseField(scanner, UTF8ToUTF16(autofill::kGiftCardRe), NULL)) |
| 34 break; |
| 35 |
| 32 // Sometimes the cardholder field is just labeled "name". Unfortunately this | 36 // Sometimes the cardholder field is just labeled "name". Unfortunately this |
| 33 // is a dangerously generic word to search for, since it will often match a | 37 // is a dangerously generic word to search for, since it will often match a |
| 34 // name (not cardholder name) field before or after credit card fields. So | 38 // name (not cardholder name) field before or after credit card fields. So |
| 35 // we search for "name" only when we've already parsed at least one other | 39 // we search for "name" only when we've already parsed at least one other |
| 36 // credit card field and haven't yet parsed the expiration date (which | 40 // credit card field and haven't yet parsed the expiration date (which |
| 37 // usually appears at the end). | 41 // usually appears at the end). |
| 38 if (credit_card_field->cardholder_ == NULL) { | 42 if (credit_card_field->cardholder_ == NULL) { |
| 39 string16 name_pattern; | 43 string16 name_pattern; |
| 40 if (fields == 0 || credit_card_field->expiration_month_) { | 44 if (fields == 0 || credit_card_field->expiration_month_) { |
| 41 // at beginning or end | 45 // at beginning or end |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 scanner->RewindTo(saved_cursor); | 128 scanner->RewindTo(saved_cursor); |
| 125 return NULL; | 129 return NULL; |
| 126 } | 130 } |
| 127 } | 131 } |
| 128 | 132 |
| 129 // Some pages (e.g. ExpediaBilling.html) have a "card description" | 133 // Some pages (e.g. ExpediaBilling.html) have a "card description" |
| 130 // field; we parse this field but ignore it. | 134 // field; we parse this field but ignore it. |
| 131 // We also ignore any other fields within a credit card block that | 135 // We also ignore any other fields within a credit card block that |
| 132 // start with "card", under the assumption that they are related to | 136 // start with "card", under the assumption that they are related to |
| 133 // the credit card section being processed but are uninteresting to us. | 137 // the credit card section being processed but are uninteresting to us. |
| 134 if (ParseField(scanner, UTF8ToUTF16(autofill::kCardIgnoredRe), NULL)) { | 138 if (ParseField(scanner, UTF8ToUTF16(autofill::kCardIgnoredRe), NULL)) |
| 135 continue; | 139 continue; |
| 136 } | |
| 137 | 140 |
| 138 break; | 141 break; |
| 139 } | 142 } |
| 140 | 143 |
| 141 // Some pages have a billing address field after the cardholder name field. | 144 // Some pages have a billing address field after the cardholder name field. |
| 142 // For that case, allow only just the cardholder name field. The remaining | 145 // For that case, allow only just the cardholder name field. The remaining |
| 143 // CC fields will be picked up in a following CreditCardField. | 146 // CC fields will be picked up in a following CreditCardField. |
| 144 if (credit_card_field->cardholder_) | 147 if (credit_card_field->cardholder_) |
| 145 return credit_card_field.release(); | 148 return credit_card_field.release(); |
| 146 | 149 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 map); | 207 map); |
| 205 } else { | 208 } else { |
| 206 ok = ok && AddClassification(expiration_year_, | 209 ok = ok && AddClassification(expiration_year_, |
| 207 CREDIT_CARD_EXP_4_DIGIT_YEAR, | 210 CREDIT_CARD_EXP_4_DIGIT_YEAR, |
| 208 map); | 211 map); |
| 209 } | 212 } |
| 210 } | 213 } |
| 211 | 214 |
| 212 return ok; | 215 return ok; |
| 213 } | 216 } |
| OLD | NEW |