Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(384)

Side by Side Diff: chrome/browser/autofill/credit_card_field.cc

Issue 7014011: Change heuristic regex and order to match grabber-continental. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Use bit pattern version. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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_TEXT, &credit_card_field->number_))
113 continue; 119 continue;
114 120
115 if (LowerCaseEqualsASCII(scanner->Cursor()->form_control_type, "month")) { 121 if (LowerCaseEqualsASCII(scanner->Cursor()->form_control_type, "month")) {
116 credit_card_field->expiration_month_ = scanner->Cursor(); 122 credit_card_field->expiration_month_ = scanner->Cursor();
117 scanner->Advance(); 123 scanner->Advance();
118 } else { 124 } else {
119 // "Expiration date" is the most common label here, but some pages have 125 // "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 126 // "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 127 // for the field names ccmonth and ccyear, which appear on at least 4 of
122 // our test pages. 128 // our test pages.
123 // 129 //
124 // -> On at least one page (The China Shop2.html) we find only the labels 130 // -> 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 131 // "month" and "year". So for now we match these words directly; we'll
126 // see if this turns out to be too general. 132 // see if this turns out to be too general.
127 // 133 //
128 // Toolbar Bug 51451: indeed, simply matching "month" is too general for 134 // Toolbar Bug 51451: indeed, simply matching "month" is too general for
129 // https://rps.fidelity.com/ftgw/rps/RtlCust/CreatePIN/Init. 135 // https://rps.fidelity.com/ftgw/rps/RtlCust/CreatePIN/Init.
130 // Instead, we match only words beginning with "month". 136 // Instead, we match only words beginning with "month".
131 if (is_ecml) 137 if (is_ecml)
132 pattern = GetEcmlPattern(kEcmlCardExpireMonth); 138 pattern = GetEcmlPattern(kEcmlCardExpireMonth);
133 else 139 else
134 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_EXPIRATION_MONTH_RE); 140 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_EXPIRATION_MONTH_RE);
135 141
136 if ((!credit_card_field->expiration_month_ || 142 if ((!credit_card_field->expiration_month_ ||
137 credit_card_field->expiration_month_->IsEmpty()) && 143 credit_card_field->expiration_month_->IsEmpty()) &&
138 ParseText(scanner, pattern, &credit_card_field->expiration_month_)) { 144 ParseText(scanner, pattern, MATCH_TEXT | MATCH_SELECT,
145 &credit_card_field->expiration_month_)) {
139 if (is_ecml) 146 if (is_ecml)
140 pattern = GetEcmlPattern(kEcmlCardExpireYear); 147 pattern = GetEcmlPattern(kEcmlCardExpireYear);
141 else 148 else
142 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_EXPIRATION_DATE_RE); 149 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_EXPIRATION_DATE_RE);
143 150
144 if (!ParseText(scanner, pattern, 151 if (!ParseText(scanner, pattern, MATCH_TEXT | MATCH_SELECT,
145 &credit_card_field->expiration_year_)) { 152 &credit_card_field->expiration_year_)) {
146 scanner->Rewind(); 153 scanner->Rewind();
147 return NULL; 154 return NULL;
148 } 155 }
149 continue; 156 continue;
150 } 157 }
151 } 158 }
152 159
153 if (ParseText(scanner, GetEcmlPattern(kEcmlCardExpireDay))) 160 if (ParseText(scanner,
161 GetEcmlPattern(kEcmlCardExpireDay),
162 MATCH_NAME | MATCH_LABEL | MATCH_TEXT | MATCH_SELECT))
154 continue; 163 continue;
155 164
156 // Some pages (e.g. ExpediaBilling.html) have a "card description" 165 // Some pages (e.g. ExpediaBilling.html) have a "card description"
157 // field; we parse this field but ignore it. 166 // field; we parse this field but ignore it.
158 // We also ignore any other fields within a credit card block that 167 // We also ignore any other fields within a credit card block that
159 // start with "card", under the assumption that they are related to 168 // start with "card", under the assumption that they are related to
160 // the credit card section being processed but are uninteresting to us. 169 // the credit card section being processed but are uninteresting to us.
161 if (ParseText(scanner, 170 if (ParseText(scanner,
162 l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_IGNORED_RE))) 171 l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_IGNORED_RE),
172 MATCH_NAME | MATCH_LABEL | MATCH_TEXT))
163 continue; 173 continue;
164 174
165 break; 175 break;
166 } 176 }
167 177
168 // Some pages have a billing address field after the cardholder name field. 178 // 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 179 // For that case, allow only just the cardholder name field. The remaining
170 // CC fields will be picked up in a following CreditCardField. 180 // CC fields will be picked up in a following CreditCardField.
171 if (credit_card_field->cardholder_) 181 if (credit_card_field->cardholder_)
172 return credit_card_field.release(); 182 return credit_card_field.release();
(...skipping 20 matching lines...) Expand all
193 203
194 CreditCardField::CreditCardField() 204 CreditCardField::CreditCardField()
195 : cardholder_(NULL), 205 : cardholder_(NULL),
196 cardholder_last_(NULL), 206 cardholder_last_(NULL),
197 type_(NULL), 207 type_(NULL),
198 number_(NULL), 208 number_(NULL),
199 verification_(NULL), 209 verification_(NULL),
200 expiration_month_(NULL), 210 expiration_month_(NULL),
201 expiration_year_(NULL) { 211 expiration_year_(NULL) {
202 } 212 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698