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 "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
8 #include "base/string16.h" | 8 #include "base/string16.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/autofill/autofill_field.h" | 10 #include "chrome/browser/autofill/autofill_field.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 | 108 |
109 if (is_ecml) | 109 if (is_ecml) |
110 pattern = GetEcmlPattern(kEcmlCardNumber); | 110 pattern = GetEcmlPattern(kEcmlCardNumber); |
111 else | 111 else |
112 pattern = ASCIIToUTF16("number|card #|card no.|card_number|card number"); | 112 pattern = ASCIIToUTF16("number|card #|card no.|card_number|card number"); |
113 | 113 |
114 if (credit_card_field->number_ == NULL && ParseText(&q, pattern, | 114 if (credit_card_field->number_ == NULL && ParseText(&q, pattern, |
115 &credit_card_field->number_)) | 115 &credit_card_field->number_)) |
116 continue; | 116 continue; |
117 | 117 |
118 // "Expiration date" is the most common label here, but some pages have | 118 if ((*q) && LowerCaseEqualsASCII((*q)->form_control_type(), "month")) { |
dhollowa
2011/01/07 03:47:15
This is looking good.
However, I tried it against
honten.org
2011/01/07 04:05:59
I can't see your full example. Did you put your ex
| |
119 // "Expires", "exp. date" or "exp. month" and "exp. year". We also look for | 119 credit_card_field->expiration_month_ = *q++; |
120 // the field names ccmonth and ccyear, which appear on at least 4 of our | 120 } else { |
121 // test pages. | 121 // "Expiration date" is the most common label here, but some pages have |
122 // | 122 // "Expires", "exp. date" or "exp. month" and "exp. year". We also look |
123 // -> On at least one page (The China Shop2.html) we find only the labels | 123 // for the field names ccmonth and ccyear, which appear on at least 4 of |
124 // "month" and "year". So for now we match these words directly; we'll | 124 // our test pages. |
125 // see if this turns out to be too general. | 125 // |
126 // | 126 // -> On at least one page (The China Shop2.html) we find only the labels |
127 // Toolbar Bug 51451: indeed, simply matching "month" is too general for | 127 // "month" and "year". So for now we match these words directly; we'll |
128 // https://rps.fidelity.com/ftgw/rps/RtlCust/CreatePIN/Init. | 128 // see if this turns out to be too general. |
129 // Instead, we match only words beginning with "month". | 129 // |
130 if (is_ecml) | 130 // Toolbar Bug 51451: indeed, simply matching "month" is too general for |
131 pattern = GetEcmlPattern(kEcmlCardExpireMonth); | 131 // https://rps.fidelity.com/ftgw/rps/RtlCust/CreatePIN/Init. |
132 else | 132 // Instead, we match only words beginning with "month". |
133 pattern = ASCIIToUTF16("expir|exp.*month|exp date|ccmonth"); | 133 if (is_ecml) |
134 pattern = GetEcmlPattern(kEcmlCardExpireMonth); | |
135 else | |
136 pattern = ASCIIToUTF16("expir|exp.*month|exp date|ccmonth"); | |
134 | 137 |
135 if ((!credit_card_field->expiration_month_ || | 138 if ((!credit_card_field->expiration_month_ || |
136 credit_card_field->expiration_month_->IsEmpty()) && | 139 credit_card_field->expiration_month_->IsEmpty()) && |
137 ParseText(&q, pattern, &credit_card_field->expiration_month_)) { | 140 ParseText(&q, pattern, &credit_card_field->expiration_month_)) { |
138 if (is_ecml) | |
139 pattern = GetEcmlPattern(kEcmlCardExpireYear); | |
140 else | |
141 pattern = ASCIIToUTF16("|exp|^/|ccyear|year"); | |
142 | 141 |
143 if (!ParseText(&q, pattern, &credit_card_field->expiration_year_)) | 142 // If type="month", year is included into the expiration_month_. |
dhollowa
2011/01/07 03:47:15
This comment can be removed now.
| |
144 return NULL; | 143 // So we don't need another year input field. |
144 if (is_ecml) | |
145 pattern = GetEcmlPattern(kEcmlCardExpireYear); | |
146 else | |
147 pattern = ASCIIToUTF16("|exp|^/|ccyear|year"); | |
145 | 148 |
146 continue; | 149 if (!ParseText(&q, pattern, &credit_card_field->expiration_year_)) { |
150 return NULL; | |
151 } | |
Ilya Sherman
2011/01/07 07:28:28
nit: This is a one-line if-stmt, so no need for br
| |
152 continue; | |
153 } | |
147 } | 154 } |
148 | 155 |
149 if (ParseText(&q, GetEcmlPattern(kEcmlCardExpireDay))) | 156 if (ParseText(&q, GetEcmlPattern(kEcmlCardExpireDay))) |
150 continue; | 157 continue; |
151 | 158 |
152 // Some pages (e.g. ExpediaBilling.html) have a "card description" | 159 // Some pages (e.g. ExpediaBilling.html) have a "card description" |
153 // field; we parse this field but ignore it. | 160 // field; we parse this field but ignore it. |
154 // We also ignore any other fields within a credit card block that | 161 // We also ignore any other fields within a credit card block that |
155 // start with "card", under the assumption that they are related to | 162 // start with "card", under the assumption that they are related to |
156 // the credit card section being processed but are uninteresting to us. | 163 // the credit card section being processed but are uninteresting to us. |
(...skipping 13 matching lines...) Expand all Loading... | |
170 | 177 |
171 // On some pages, the user selects a card type using radio buttons | 178 // On some pages, the user selects a card type using radio buttons |
172 // (e.g. test page Apple Store Billing.html). We can't handle that yet, | 179 // (e.g. test page Apple Store Billing.html). We can't handle that yet, |
173 // so we treat the card type as optional for now. | 180 // so we treat the card type as optional for now. |
174 // The existence of a number or cvc in combination with expiration date is | 181 // The existence of a number or cvc in combination with expiration date is |
175 // a strong enough signal that this is a credit card. It is possible that | 182 // a strong enough signal that this is a credit card. It is possible that |
176 // the number and name were parsed in a separate part of the form. So if | 183 // the number and name were parsed in a separate part of the form. So if |
177 // the cvc and date were found independently they are returned. | 184 // the cvc and date were found independently they are returned. |
178 if ((credit_card_field->number_ || credit_card_field->verification_) && | 185 if ((credit_card_field->number_ || credit_card_field->verification_) && |
179 credit_card_field->expiration_month_ && | 186 credit_card_field->expiration_month_ && |
180 credit_card_field->expiration_year_) { | 187 (credit_card_field->expiration_year_ || |
188 (LowerCaseEqualsASCII( | |
189 credit_card_field->expiration_month_->form_control_type(), | |
190 "month")))) { | |
181 *iter = q; | 191 *iter = q; |
182 return credit_card_field.release(); | 192 return credit_card_field.release(); |
183 } | 193 } |
184 | 194 |
185 return NULL; | 195 return NULL; |
186 } | 196 } |
187 | 197 |
188 CreditCardField::CreditCardField() | 198 CreditCardField::CreditCardField() |
189 : cardholder_(NULL), | 199 : cardholder_(NULL), |
190 cardholder_last_(NULL), | 200 cardholder_last_(NULL), |
191 type_(NULL), | 201 type_(NULL), |
192 number_(NULL), | 202 number_(NULL), |
193 verification_(NULL), | 203 verification_(NULL), |
194 expiration_month_(NULL), | 204 expiration_month_(NULL), |
195 expiration_year_(NULL) { | 205 expiration_year_(NULL) { |
196 } | 206 } |
OLD | NEW |