| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 if (fields == 0 || credit_card_field->expiration_month_) { | 61 if (fields == 0 || credit_card_field->expiration_month_) { |
| 62 // at beginning or end | 62 // at beginning or end |
| 63 name_pattern = l10n_util::GetStringUTF16( | 63 name_pattern = l10n_util::GetStringUTF16( |
| 64 IDS_AUTOFILL_NAME_ON_CARD_RE); | 64 IDS_AUTOFILL_NAME_ON_CARD_RE); |
| 65 } else { | 65 } else { |
| 66 name_pattern = l10n_util::GetStringUTF16( | 66 name_pattern = l10n_util::GetStringUTF16( |
| 67 IDS_AUTOFILL_NAME_ON_CARD_CONTEXTUAL_RE); | 67 IDS_AUTOFILL_NAME_ON_CARD_CONTEXTUAL_RE); |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 if (ParseText(scanner, name_pattern, &credit_card_field->cardholder_)) | 71 if (ParseText(scanner, name_pattern, |
| 72 MATCH_NAME | MATCH_LABEL | MATCH_TEXT, |
| 73 &credit_card_field->cardholder_)) |
| 72 continue; | 74 continue; |
| 73 | 75 |
| 74 // As a hard-coded hack for Expedia's billing pages (expedia_checkout.html | 76 // As a hard-coded hack for Expedia's billing pages (expedia_checkout.html |
| 75 // and ExpediaBilling.html in our test suite), recognize separate fields | 77 // and ExpediaBilling.html in our test suite), recognize separate fields |
| 76 // for the cardholder's first and last name if they have the labels "cfnm" | 78 // for the cardholder's first and last name if they have the labels "cfnm" |
| 77 // and "clnm". | 79 // and "clnm". |
| 78 scanner->SaveCursor(); | 80 scanner->SaveCursor(); |
| 79 const AutofillField* first; | 81 const AutofillField* first; |
| 80 if (!is_ecml && ParseText(scanner, ASCIIToUTF16("^cfnm"), &first) && | 82 if (!is_ecml && ParseText(scanner, ASCIIToUTF16("^cfnm"), |
| 83 MATCH_NAME | MATCH_LABEL | MATCH_TEXT, |
| 84 &first) && |
| 81 ParseText(scanner, ASCIIToUTF16("^clnm"), | 85 ParseText(scanner, ASCIIToUTF16("^clnm"), |
| 86 MATCH_NAME | MATCH_LABEL | MATCH_TEXT, |
| 82 &credit_card_field->cardholder_last_)) { | 87 &credit_card_field->cardholder_last_)) { |
| 83 credit_card_field->cardholder_ = first; | 88 credit_card_field->cardholder_ = first; |
| 84 continue; | 89 continue; |
| 85 } | 90 } |
| 86 scanner->Rewind(); | 91 scanner->Rewind(); |
| 87 } | 92 } |
| 88 | 93 |
| 89 // We look for a card security code before we look for a credit | 94 // We look for a card security code before we look for a credit |
| 90 // card number and match the general term "number". The security code | 95 // card number and match the general term "number". The security code |
| 91 // has a plethora of names; we've seen "verification #", | 96 // has a plethora of names; we've seen "verification #", |
| 92 // "verification number", "card identification number" and others listed | 97 // "verification number", "card identification number" and others listed |
| 93 // in the |pattern| below. | 98 // in the |pattern| below. |
| 94 string16 pattern; | 99 string16 pattern; |
| 95 if (is_ecml) | 100 if (is_ecml) |
| 96 pattern = GetEcmlPattern(kEcmlCardVerification); | 101 pattern = GetEcmlPattern(kEcmlCardVerification); |
| 97 else | 102 else |
| 98 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_CVC_RE); | 103 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_CVC_RE); |
| 99 | 104 |
| 100 if (!credit_card_field->verification_ && | 105 if (!credit_card_field->verification_ && |
| 101 ParseText(scanner, pattern, &credit_card_field->verification_)) | 106 ParseText(scanner, pattern, MATCH_NAME | MATCH_LABEL | MATCH_TEXT, |
| 107 &credit_card_field->verification_)) |
| 102 continue; | 108 continue; |
| 103 | 109 |
| 104 // TODO(jhawkins): Parse the type select control. | 110 // TODO(jhawkins): Parse the type select control. |
| 105 | 111 |
| 106 if (is_ecml) | 112 if (is_ecml) |
| 107 pattern = GetEcmlPattern(kEcmlCardNumber); | 113 pattern = GetEcmlPattern(kEcmlCardNumber); |
| 108 else | 114 else |
| 109 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_NUMBER_RE); | 115 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_NUMBER_RE); |
| 110 | 116 |
| 111 if (!credit_card_field->number_ && | 117 if (!credit_card_field->number_ && |
| 112 ParseText(scanner, pattern, &credit_card_field->number_)) | 118 ParseText(scanner, pattern, MATCH_NAME | MATCH_LABEL | MATCH_TEXT, |
| 119 &credit_card_field->number_)) |
| 113 continue; | 120 continue; |
| 114 | 121 |
| 115 if (LowerCaseEqualsASCII(scanner->Cursor()->form_control_type, "month")) { | 122 if (LowerCaseEqualsASCII(scanner->Cursor()->form_control_type, "month")) { |
| 116 credit_card_field->expiration_month_ = scanner->Cursor(); | 123 credit_card_field->expiration_month_ = scanner->Cursor(); |
| 117 scanner->Advance(); | 124 scanner->Advance(); |
| 118 } else { | 125 } else { |
| 119 // "Expiration date" is the most common label here, but some pages have | 126 // "Expiration date" is the most common label here, but some pages have |
| 120 // "Expires", "exp. date" or "exp. month" and "exp. year". We also look | 127 // "Expires", "exp. date" or "exp. month" and "exp. year". We also look |
| 121 // for the field names ccmonth and ccyear, which appear on at least 4 of | 128 // for the field names ccmonth and ccyear, which appear on at least 4 of |
| 122 // our test pages. | 129 // our test pages. |
| 123 // | 130 // |
| 124 // -> On at least one page (The China Shop2.html) we find only the labels | 131 // -> On at least one page (The China Shop2.html) we find only the labels |
| 125 // "month" and "year". So for now we match these words directly; we'll | 132 // "month" and "year". So for now we match these words directly; we'll |
| 126 // see if this turns out to be too general. | 133 // see if this turns out to be too general. |
| 127 // | 134 // |
| 128 // Toolbar Bug 51451: indeed, simply matching "month" is too general for | 135 // Toolbar Bug 51451: indeed, simply matching "month" is too general for |
| 129 // https://rps.fidelity.com/ftgw/rps/RtlCust/CreatePIN/Init. | 136 // https://rps.fidelity.com/ftgw/rps/RtlCust/CreatePIN/Init. |
| 130 // Instead, we match only words beginning with "month". | 137 // Instead, we match only words beginning with "month". |
| 131 if (is_ecml) | 138 if (is_ecml) |
| 132 pattern = GetEcmlPattern(kEcmlCardExpireMonth); | 139 pattern = GetEcmlPattern(kEcmlCardExpireMonth); |
| 133 else | 140 else |
| 134 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_EXPIRATION_MONTH_RE); | 141 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_EXPIRATION_MONTH_RE); |
| 135 | 142 |
| 136 if ((!credit_card_field->expiration_month_ || | 143 if ((!credit_card_field->expiration_month_ || |
| 137 credit_card_field->expiration_month_->IsEmpty()) && | 144 credit_card_field->expiration_month_->IsEmpty()) && |
| 138 ParseText(scanner, pattern, &credit_card_field->expiration_month_)) { | 145 ParseText(scanner, pattern, |
| 146 MATCH_NAME | MATCH_LABEL | MATCH_TEXT | MATCH_SELECT, |
| 147 &credit_card_field->expiration_month_)) { |
| 139 if (is_ecml) | 148 if (is_ecml) |
| 140 pattern = GetEcmlPattern(kEcmlCardExpireYear); | 149 pattern = GetEcmlPattern(kEcmlCardExpireYear); |
| 141 else | 150 else |
| 142 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_EXPIRATION_DATE_RE); | 151 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_EXPIRATION_DATE_RE); |
| 143 | 152 |
| 144 if (!ParseText(scanner, pattern, | 153 if (!ParseText(scanner, pattern, |
| 154 MATCH_NAME | MATCH_LABEL | MATCH_TEXT | MATCH_SELECT, |
| 145 &credit_card_field->expiration_year_)) { | 155 &credit_card_field->expiration_year_)) { |
| 146 scanner->Rewind(); | 156 scanner->Rewind(); |
| 147 return NULL; | 157 return NULL; |
| 148 } | 158 } |
| 149 continue; | 159 continue; |
| 150 } | 160 } |
| 151 } | 161 } |
| 152 | 162 |
| 153 if (ParseText(scanner, GetEcmlPattern(kEcmlCardExpireDay))) | 163 if (ParseText(scanner, |
| 164 GetEcmlPattern(kEcmlCardExpireDay), |
| 165 MATCH_NAME | MATCH_LABEL | MATCH_TEXT | MATCH_SELECT)) |
| 154 continue; | 166 continue; |
| 155 | 167 |
| 156 // Some pages (e.g. ExpediaBilling.html) have a "card description" | 168 // Some pages (e.g. ExpediaBilling.html) have a "card description" |
| 157 // field; we parse this field but ignore it. | 169 // field; we parse this field but ignore it. |
| 158 // We also ignore any other fields within a credit card block that | 170 // We also ignore any other fields within a credit card block that |
| 159 // start with "card", under the assumption that they are related to | 171 // start with "card", under the assumption that they are related to |
| 160 // the credit card section being processed but are uninteresting to us. | 172 // the credit card section being processed but are uninteresting to us. |
| 161 if (ParseText(scanner, | 173 if (ParseText(scanner, |
| 162 l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_IGNORED_RE))) | 174 l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_IGNORED_RE), |
| 175 MATCH_NAME | MATCH_LABEL | MATCH_TEXT)) |
| 163 continue; | 176 continue; |
| 164 | 177 |
| 165 break; | 178 break; |
| 166 } | 179 } |
| 167 | 180 |
| 168 // Some pages have a billing address field after the cardholder name field. | 181 // Some pages have a billing address field after the cardholder name field. |
| 169 // For that case, allow only just the cardholder name field. The remaining | 182 // For that case, allow only just the cardholder name field. The remaining |
| 170 // CC fields will be picked up in a following CreditCardField. | 183 // CC fields will be picked up in a following CreditCardField. |
| 171 if (credit_card_field->cardholder_) | 184 if (credit_card_field->cardholder_) |
| 172 return credit_card_field.release(); | 185 return credit_card_field.release(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 193 | 206 |
| 194 CreditCardField::CreditCardField() | 207 CreditCardField::CreditCardField() |
| 195 : cardholder_(NULL), | 208 : cardholder_(NULL), |
| 196 cardholder_last_(NULL), | 209 cardholder_last_(NULL), |
| 197 type_(NULL), | 210 type_(NULL), |
| 198 number_(NULL), | 211 number_(NULL), |
| 199 verification_(NULL), | 212 verification_(NULL), |
| 200 expiration_month_(NULL), | 213 expiration_month_(NULL), |
| 201 expiration_year_(NULL) { | 214 expiration_year_(NULL) { |
| 202 } | 215 } |
| OLD | NEW |