OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/scoped_ptr.h" | 8 #include "base/scoped_ptr.h" |
9 #include "base/string16.h" | 9 #include "base/string16.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 | 111 |
112 if (is_ecml) | 112 if (is_ecml) |
113 pattern = GetEcmlPattern(kEcmlCardNumber); | 113 pattern = GetEcmlPattern(kEcmlCardNumber); |
114 else | 114 else |
115 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_NUMBER_RE); | 115 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_NUMBER_RE); |
116 | 116 |
117 if (credit_card_field->number_ == NULL && ParseText(&q, pattern, | 117 if (credit_card_field->number_ == NULL && ParseText(&q, pattern, |
118 &credit_card_field->number_)) | 118 &credit_card_field->number_)) |
119 continue; | 119 continue; |
120 | 120 |
121 // "Expiration date" is the most common label here, but some pages have | 121 if ((*q) && LowerCaseEqualsASCII((*q)->form_control_type(), "month")) { |
122 // "Expires", "exp. date" or "exp. month" and "exp. year". We also look for | 122 credit_card_field->expiration_month_ = *q++; |
honten.org
2011/01/07 05:33:49
I cannot reproduce your bug.
I made form as follo
dhollowa
2011/01/07 19:29:46
I tried again with this latest patch and things se
| |
123 // the field names ccmonth and ccyear, which appear on at least 4 of our | 123 } else { |
124 // test pages. | 124 // "Expiration date" is the most common label here, but some pages have |
125 // | 125 // "Expires", "exp. date" or "exp. month" and "exp. year". We also look |
126 // -> On at least one page (The China Shop2.html) we find only the labels | 126 // for the field names ccmonth and ccyear, which appear on at least 4 of |
127 // "month" and "year". So for now we match these words directly; we'll | 127 // our test pages. |
128 // see if this turns out to be too general. | 128 // |
129 // | 129 // -> On at least one page (The China Shop2.html) we find only the labels |
130 // Toolbar Bug 51451: indeed, simply matching "month" is too general for | 130 // "month" and "year". So for now we match these words directly; we'll |
131 // https://rps.fidelity.com/ftgw/rps/RtlCust/CreatePIN/Init. | 131 // see if this turns out to be too general. |
132 // Instead, we match only words beginning with "month". | 132 // |
133 if (is_ecml) | 133 // Toolbar Bug 51451: indeed, simply matching "month" is too general for |
134 pattern = GetEcmlPattern(kEcmlCardExpireMonth); | 134 // https://rps.fidelity.com/ftgw/rps/RtlCust/CreatePIN/Init. |
135 else | 135 // Instead, we match only words beginning with "month". |
136 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_EXPIRATION_MONTH_RE); | 136 if (is_ecml) |
137 pattern = GetEcmlPattern(kEcmlCardExpireMonth); | |
138 else | |
139 pattern = ASCIIToUTF16("expir|exp.*month|exp date|ccmonth"); | |
dhollowa
2011/01/07 18:50:26
These regexes should be pulled from resources. It
| |
137 | 140 |
138 if ((!credit_card_field->expiration_month_ || | 141 if ((!credit_card_field->expiration_month_ || |
139 credit_card_field->expiration_month_->IsEmpty()) && | 142 credit_card_field->expiration_month_->IsEmpty()) && |
140 ParseText(&q, pattern, &credit_card_field->expiration_month_)) { | 143 ParseText(&q, pattern, &credit_card_field->expiration_month_)) { |
141 if (is_ecml) | |
142 pattern = GetEcmlPattern(kEcmlCardExpireYear); | |
143 else | |
144 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_EXPIRATION_DATE_RE); | |
145 | 144 |
146 if (!ParseText(&q, pattern, &credit_card_field->expiration_year_)) | 145 if (is_ecml) |
147 return NULL; | 146 pattern = GetEcmlPattern(kEcmlCardExpireYear); |
147 else | |
148 pattern = ASCIIToUTF16("|exp|^/|ccyear|year"); | |
148 | 149 |
149 continue; | 150 if (!ParseText(&q, pattern, &credit_card_field->expiration_year_)) { |
151 return NULL; | |
152 } | |
153 continue; | |
154 } | |
150 } | 155 } |
151 | 156 |
152 if (ParseText(&q, GetEcmlPattern(kEcmlCardExpireDay))) | 157 if (ParseText(&q, GetEcmlPattern(kEcmlCardExpireDay))) |
153 continue; | 158 continue; |
154 | 159 |
155 // Some pages (e.g. ExpediaBilling.html) have a "card description" | 160 // Some pages (e.g. ExpediaBilling.html) have a "card description" |
156 // field; we parse this field but ignore it. | 161 // field; we parse this field but ignore it. |
157 // We also ignore any other fields within a credit card block that | 162 // We also ignore any other fields within a credit card block that |
158 // start with "card", under the assumption that they are related to | 163 // start with "card", under the assumption that they are related to |
159 // the credit card section being processed but are uninteresting to us. | 164 // the credit card section being processed but are uninteresting to us. |
(...skipping 13 matching lines...) Expand all Loading... | |
173 | 178 |
174 // On some pages, the user selects a card type using radio buttons | 179 // On some pages, the user selects a card type using radio buttons |
175 // (e.g. test page Apple Store Billing.html). We can't handle that yet, | 180 // (e.g. test page Apple Store Billing.html). We can't handle that yet, |
176 // so we treat the card type as optional for now. | 181 // so we treat the card type as optional for now. |
177 // The existence of a number or cvc in combination with expiration date is | 182 // The existence of a number or cvc in combination with expiration date is |
178 // a strong enough signal that this is a credit card. It is possible that | 183 // a strong enough signal that this is a credit card. It is possible that |
179 // the number and name were parsed in a separate part of the form. So if | 184 // the number and name were parsed in a separate part of the form. So if |
180 // the cvc and date were found independently they are returned. | 185 // the cvc and date were found independently they are returned. |
181 if ((credit_card_field->number_ || credit_card_field->verification_) && | 186 if ((credit_card_field->number_ || credit_card_field->verification_) && |
182 credit_card_field->expiration_month_ && | 187 credit_card_field->expiration_month_ && |
183 credit_card_field->expiration_year_) { | 188 (credit_card_field->expiration_year_ || |
189 (LowerCaseEqualsASCII( | |
190 credit_card_field->expiration_month_->form_control_type(), | |
191 "month")))) { | |
184 *iter = q; | 192 *iter = q; |
185 return credit_card_field.release(); | 193 return credit_card_field.release(); |
186 } | 194 } |
187 | 195 |
188 return NULL; | 196 return NULL; |
189 } | 197 } |
190 | 198 |
191 CreditCardField::CreditCardField() | 199 CreditCardField::CreditCardField() |
192 : cardholder_(NULL), | 200 : cardholder_(NULL), |
193 cardholder_last_(NULL), | 201 cardholder_last_(NULL), |
194 type_(NULL), | 202 type_(NULL), |
195 number_(NULL), | 203 number_(NULL), |
196 verification_(NULL), | 204 verification_(NULL), |
197 expiration_month_(NULL), | 205 expiration_month_(NULL), |
198 expiration_year_(NULL) { | 206 expiration_year_(NULL) { |
199 } | 207 } |
OLD | NEW |