| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 // https://rps.fidelity.com/ftgw/rps/RtlCust/CreatePIN/Init. | 128 // https://rps.fidelity.com/ftgw/rps/RtlCust/CreatePIN/Init. |
| 129 // Instead, we match only words beginning with "month". | 129 // Instead, we match only words beginning with "month". |
| 130 if (is_ecml) | 130 if (is_ecml) |
| 131 pattern = GetEcmlPattern(kEcmlCardExpireMonth); | 131 pattern = GetEcmlPattern(kEcmlCardExpireMonth); |
| 132 else | 132 else |
| 133 pattern = ASCIIToUTF16("expir|exp.*month|exp date|ccmonth"); | 133 pattern = ASCIIToUTF16("expir|exp.*month|exp date|ccmonth"); |
| 134 | 134 |
| 135 if ((!credit_card_field->expiration_month_ || | 135 if ((!credit_card_field->expiration_month_ || |
| 136 credit_card_field->expiration_month_->IsEmpty()) && | 136 credit_card_field->expiration_month_->IsEmpty()) && |
| 137 ParseText(&q, pattern, &credit_card_field->expiration_month_)) { | 137 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 | 138 |
| 143 if (!ParseText(&q, pattern, &credit_card_field->expiration_year_)) | 139 // If type="month", year is included into the exipration_month_. |
| 144 return NULL; | 140 // So we don't need another year input field. |
| 141 if (!LowerCaseEqualsASCII( |
| 142 credit_card_field->expiration_month_->form_control_type(), "month")) { |
| 143 if (is_ecml) |
| 144 pattern = GetEcmlPattern(kEcmlCardExpireYear); |
| 145 else |
| 146 pattern = ASCIIToUTF16("|exp|^/|ccyear|year"); |
| 145 | 147 |
| 148 if (!ParseText(&q, pattern, &credit_card_field->expiration_year_)) { |
| 149 return NULL; |
| 150 } |
| 151 } |
| 146 continue; | 152 continue; |
| 147 } | 153 } |
| 148 | 154 |
| 149 if (ParseText(&q, GetEcmlPattern(kEcmlCardExpireDay))) | 155 if (ParseText(&q, GetEcmlPattern(kEcmlCardExpireDay))) |
| 150 continue; | 156 continue; |
| 151 | 157 |
| 152 // Some pages (e.g. ExpediaBilling.html) have a "card description" | 158 // Some pages (e.g. ExpediaBilling.html) have a "card description" |
| 153 // field; we parse this field but ignore it. | 159 // field; we parse this field but ignore it. |
| 154 // We also ignore any other fields within a credit card block that | 160 // We also ignore any other fields within a credit card block that |
| 155 // start with "card", under the assumption that they are related to | 161 // start with "card", under the assumption that they are related to |
| (...skipping 14 matching lines...) Expand all Loading... |
| 170 | 176 |
| 171 // On some pages, the user selects a card type using radio buttons | 177 // 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, | 178 // (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. | 179 // so we treat the card type as optional for now. |
| 174 // The existence of a number or cvc in combination with expiration date is | 180 // 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 | 181 // 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 | 182 // 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. | 183 // the cvc and date were found independently they are returned. |
| 178 if ((credit_card_field->number_ || credit_card_field->verification_) && | 184 if ((credit_card_field->number_ || credit_card_field->verification_) && |
| 179 credit_card_field->expiration_month_ && | 185 credit_card_field->expiration_month_ && |
| 180 credit_card_field->expiration_year_) { | 186 (credit_card_field->expiration_year_ || |
| 187 (LowerCaseEqualsASCII( |
| 188 credit_card_field->expiration_month_->form_control_type(), "month")))) { |
| 181 *iter = q; | 189 *iter = q; |
| 182 return credit_card_field.release(); | 190 return credit_card_field.release(); |
| 183 } | 191 } |
| 184 | 192 |
| 185 return NULL; | 193 return NULL; |
| 186 } | 194 } |
| 187 | 195 |
| 188 CreditCardField::CreditCardField() | 196 CreditCardField::CreditCardField() |
| 189 : cardholder_(NULL), | 197 : cardholder_(NULL), |
| 190 cardholder_last_(NULL), | 198 cardholder_last_(NULL), |
| 191 type_(NULL), | 199 type_(NULL), |
| 192 number_(NULL), | 200 number_(NULL), |
| 193 verification_(NULL), | 201 verification_(NULL), |
| 194 expiration_month_(NULL), | 202 expiration_month_(NULL), |
| 195 expiration_year_(NULL) { | 203 expiration_year_(NULL) { |
| 196 } | 204 } |
| OLD | NEW |