| 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/form_field.h" | 5 #include "chrome/browser/autofill/form_field.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/command_line.h" | |
| 12 #include "base/logging.h" | 11 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 15 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 16 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/autofill/address_field.h" | 16 #include "chrome/browser/autofill/address_field.h" |
| 18 #include "chrome/browser/autofill/autofill_field.h" | 17 #include "chrome/browser/autofill/autofill_field.h" |
| 19 #include "chrome/browser/autofill/autofill_regexes.h" | 18 #include "chrome/browser/autofill/autofill_regexes.h" |
| 20 #include "chrome/browser/autofill/autofill_scanner.h" | 19 #include "chrome/browser/autofill/autofill_scanner.h" |
| 21 #include "chrome/browser/autofill/credit_card_field.h" | 20 #include "chrome/browser/autofill/credit_card_field.h" |
| 22 #include "chrome/browser/autofill/email_field.h" | 21 #include "chrome/browser/autofill/email_field.h" |
| 23 #include "chrome/browser/autofill/field_types.h" | 22 #include "chrome/browser/autofill/field_types.h" |
| 24 #include "chrome/browser/autofill/form_structure.h" | 23 #include "chrome/browser/autofill/form_structure.h" |
| 25 #include "chrome/browser/autofill/name_field.h" | 24 #include "chrome/browser/autofill/name_field.h" |
| 26 #include "chrome/browser/autofill/phone_field.h" | 25 #include "chrome/browser/autofill/phone_field.h" |
| 27 #include "chrome/common/chrome_switches.h" | |
| 28 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 29 | 27 |
| 30 namespace { | 28 namespace { |
| 31 | 29 |
| 32 bool IsTextField(const std::string& type) { | 30 bool IsTextField(const std::string& type) { |
| 33 return type == "text"; | 31 return type == "text"; |
| 34 } | 32 } |
| 35 | 33 |
| 36 bool IsEmailField(const std::string& type) { | 34 bool IsEmailField(const std::string& type) { |
| 37 return type == "email"; | 35 return type == "email"; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 59 std::copy(fields.begin(), fields.end(), remaining_fields.begin()); | 57 std::copy(fields.begin(), fields.end(), remaining_fields.begin()); |
| 60 | 58 |
| 61 // Ignore checkable fields as they interfere with parsers assuming context. | 59 // Ignore checkable fields as they interfere with parsers assuming context. |
| 62 // Eg., while parsing address, "Is PO box" checkbox after ADDRESS_LINE1 | 60 // Eg., while parsing address, "Is PO box" checkbox after ADDRESS_LINE1 |
| 63 // interferes with correctly understanding ADDRESS_LINE2. | 61 // interferes with correctly understanding ADDRESS_LINE2. |
| 64 remaining_fields.erase( | 62 remaining_fields.erase( |
| 65 std::remove_if(remaining_fields.begin(), remaining_fields.end(), | 63 std::remove_if(remaining_fields.begin(), remaining_fields.end(), |
| 66 IsCheckable), | 64 IsCheckable), |
| 67 remaining_fields.end()); | 65 remaining_fields.end()); |
| 68 | 66 |
| 69 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
| 70 bool parse_new_field_types = | |
| 71 command_line.HasSwitch(switches::kEnableNewAutofillHeuristics); | |
| 72 | |
| 73 // Email pass. | 67 // Email pass. |
| 74 ParseFormFieldsPass(EmailField::Parse, parse_new_field_types, | 68 ParseFormFieldsPass(EmailField::Parse, &remaining_fields, map); |
| 75 &remaining_fields, map); | |
| 76 | 69 |
| 77 // Phone pass. | 70 // Phone pass. |
| 78 ParseFormFieldsPass(PhoneField::Parse, parse_new_field_types, | 71 ParseFormFieldsPass(PhoneField::Parse, &remaining_fields, map); |
| 79 &remaining_fields, map); | |
| 80 | 72 |
| 81 // Address pass. | 73 // Address pass. |
| 82 ParseFormFieldsPass(AddressField::Parse, parse_new_field_types, | 74 ParseFormFieldsPass(AddressField::Parse, &remaining_fields, map); |
| 83 &remaining_fields, map); | |
| 84 | 75 |
| 85 // Credit card pass. | 76 // Credit card pass. |
| 86 ParseFormFieldsPass(CreditCardField::Parse, parse_new_field_types, | 77 ParseFormFieldsPass(CreditCardField::Parse, &remaining_fields, map); |
| 87 &remaining_fields, map); | |
| 88 | 78 |
| 89 // Name pass. | 79 // Name pass. |
| 90 ParseFormFieldsPass(NameField::Parse, parse_new_field_types, | 80 ParseFormFieldsPass(NameField::Parse, &remaining_fields, map); |
| 91 &remaining_fields, map); | |
| 92 } | 81 } |
| 93 | 82 |
| 94 // static | 83 // static |
| 95 bool FormField::ParseField(AutofillScanner* scanner, | 84 bool FormField::ParseField(AutofillScanner* scanner, |
| 96 const string16& pattern, | 85 const string16& pattern, |
| 97 const AutofillField** match) { | 86 const AutofillField** match) { |
| 98 return ParseFieldSpecifics(scanner, pattern, MATCH_DEFAULT, match); | 87 return ParseFieldSpecifics(scanner, pattern, MATCH_DEFAULT, match); |
| 99 } | 88 } |
| 100 | 89 |
| 101 // static | 90 // static |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 if ((match_type & FormField::MATCH_VALUE) && | 167 if ((match_type & FormField::MATCH_VALUE) && |
| 179 autofill::MatchesPattern(field->value, pattern)) { | 168 autofill::MatchesPattern(field->value, pattern)) { |
| 180 return true; | 169 return true; |
| 181 } | 170 } |
| 182 | 171 |
| 183 return false; | 172 return false; |
| 184 } | 173 } |
| 185 | 174 |
| 186 // static | 175 // static |
| 187 void FormField::ParseFormFieldsPass(ParseFunction parse, | 176 void FormField::ParseFormFieldsPass(ParseFunction parse, |
| 188 bool parse_new_field_types, | |
| 189 std::vector<const AutofillField*>* fields, | 177 std::vector<const AutofillField*>* fields, |
| 190 FieldTypeMap* map) { | 178 FieldTypeMap* map) { |
| 191 // Store unmatched fields for further processing by the caller. | 179 // Store unmatched fields for further processing by the caller. |
| 192 std::vector<const AutofillField*> remaining_fields; | 180 std::vector<const AutofillField*> remaining_fields; |
| 193 | 181 |
| 194 AutofillScanner scanner(*fields); | 182 AutofillScanner scanner(*fields); |
| 195 while (!scanner.IsEnd()) { | 183 while (!scanner.IsEnd()) { |
| 196 scoped_ptr<FormField> form_field(parse(&scanner, parse_new_field_types)); | 184 scoped_ptr<FormField> form_field(parse(&scanner)); |
| 197 if (!form_field.get()) { | 185 if (!form_field.get()) { |
| 198 remaining_fields.push_back(scanner.Cursor()); | 186 remaining_fields.push_back(scanner.Cursor()); |
| 199 scanner.Advance(); | 187 scanner.Advance(); |
| 200 continue; | 188 continue; |
| 201 } | 189 } |
| 202 | 190 |
| 203 // Add entries into the map for each field type found in |form_field|. | 191 // Add entries into the map for each field type found in |form_field|. |
| 204 bool ok = form_field->ClassifyField(map); | 192 bool ok = form_field->ClassifyField(map); |
| 205 DCHECK(ok); | 193 DCHECK(ok); |
| 206 } | 194 } |
| 207 | 195 |
| 208 std::swap(*fields, remaining_fields); | 196 std::swap(*fields, remaining_fields); |
| 209 } | 197 } |
| OLD | NEW |