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

Side by Side Diff: components/autofill/core/browser/form_field.cc

Issue 2609703002: Remove ScopedVector from autofill. (Closed)
Patch Set: drop the using Created 3 years, 11 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "components/autofill/core/browser/form_field.h" 5 #include "components/autofill/core/browser/form_field.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstddef> 8 #include <cstddef>
9 #include <iterator> 9 #include <iterator>
10 #include <memory> 10 #include <memory>
11 #include <string> 11 #include <string>
12 #include <utility> 12 #include <utility>
13 13
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
18 #include "components/autofill/core/browser/address_field.h" 18 #include "components/autofill/core/browser/address_field.h"
19 #include "components/autofill/core/browser/autofill_field.h" 19 #include "components/autofill/core/browser/autofill_field.h"
20 #include "components/autofill/core/browser/autofill_scanner.h" 20 #include "components/autofill/core/browser/autofill_scanner.h"
21 #include "components/autofill/core/browser/credit_card_field.h" 21 #include "components/autofill/core/browser/credit_card_field.h"
22 #include "components/autofill/core/browser/email_field.h" 22 #include "components/autofill/core/browser/email_field.h"
23 #include "components/autofill/core/browser/form_structure.h" 23 #include "components/autofill/core/browser/form_structure.h"
24 #include "components/autofill/core/browser/name_field.h" 24 #include "components/autofill/core/browser/name_field.h"
25 #include "components/autofill/core/browser/phone_field.h" 25 #include "components/autofill/core/browser/phone_field.h"
26 #include "components/autofill/core/common/autofill_regexes.h" 26 #include "components/autofill/core/common/autofill_regexes.h"
27 #include "components/autofill/core/common/autofill_util.h" 27 #include "components/autofill/core/common/autofill_util.h"
28 28
29 namespace autofill { 29 namespace autofill {
30 namespace {
31
32 bool ShouldBeProcessed(const AutofillField* field) {
33 // Ignore checkable fields as they interfere with parsers assuming context.
34 // Eg., while parsing address, "Is PO box" checkbox after ADDRESS_LINE1
35 // interferes with correctly understanding ADDRESS_LINE2.
36 // Ignore fields marked as presentational. See
37 // http://www.w3.org/TR/wai-aria/roles#presentation
38 return !(IsCheckable(field->check_status) ||
39 field->role == FormFieldData::ROLE_ATTRIBUTE_PRESENTATION);
40 }
41
42 } // namespace
43 30
44 // There's an implicit precedence determined by the values assigned here. Email 31 // There's an implicit precedence determined by the values assigned here. Email
45 // is currently the most important followed by Phone, Address, Credit Card and 32 // is currently the most important followed by Phone, Address, Credit Card and
46 // finally Name. 33 // finally Name.
47 const float FormField::kBaseEmailParserScore = 1.4f; 34 const float FormField::kBaseEmailParserScore = 1.4f;
48 const float FormField::kBasePhoneParserScore = 1.3f; 35 const float FormField::kBasePhoneParserScore = 1.3f;
49 const float FormField::kBaseAddressParserScore = 1.2f; 36 const float FormField::kBaseAddressParserScore = 1.2f;
50 const float FormField::kBaseCreditCardParserScore = 1.1f; 37 const float FormField::kBaseCreditCardParserScore = 1.1f;
51 const float FormField::kBaseNameParserScore = 1.0f; 38 const float FormField::kBaseNameParserScore = 1.0f;
52 39
53 // static 40 // static
54 FieldCandidatesMap FormField::ParseFormFields( 41 FieldCandidatesMap FormField::ParseFormFields(
55 const std::vector<AutofillField*>& fields, 42 const std::vector<std::unique_ptr<AutofillField>>& fields,
56 bool is_form_tag) { 43 bool is_form_tag) {
57 // Set up a working copy of the fields to be processed. 44 // Set up a working copy of the fields to be processed.
58 std::vector<AutofillField*> processed_fields; 45 std::vector<AutofillField*> processed_fields;
59 std::copy_if(fields.begin(), fields.end(), 46 for (const auto& field : fields) {
60 std::back_inserter(processed_fields), ShouldBeProcessed); 47 // Ignore checkable fields as they interfere with parsers assuming context.
48 // Eg., while parsing address, "Is PO box" checkbox after ADDRESS_LINE1
49 // interferes with correctly understanding ADDRESS_LINE2.
50 // Ignore fields marked as presentational. See
51 // http://www.w3.org/TR/wai-aria/roles#presentation
52 if (IsCheckable(field->check_status) ||
53 field->role == FormFieldData::ROLE_ATTRIBUTE_PRESENTATION) {
54 continue;
55 }
56 processed_fields.push_back(field.get());
57 }
61 58
62 FieldCandidatesMap field_candidates; 59 FieldCandidatesMap field_candidates;
63 60
64 // Email pass. 61 // Email pass.
65 ParseFormFieldsPass(EmailField::Parse, processed_fields, &field_candidates); 62 ParseFormFieldsPass(EmailField::Parse, processed_fields, &field_candidates);
66 const size_t email_count = field_candidates.size(); 63 const size_t email_count = field_candidates.size();
67 64
68 // Phone pass. 65 // Phone pass.
69 ParseFormFieldsPass(PhoneField::Parse, processed_fields, &field_candidates); 66 ParseFormFieldsPass(PhoneField::Parse, processed_fields, &field_candidates);
70 67
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 165
169 return false; 166 return false;
170 } 167 }
171 168
172 // static 169 // static
173 void FormField::ParseFormFieldsPass(ParseFunction parse, 170 void FormField::ParseFormFieldsPass(ParseFunction parse,
174 const std::vector<AutofillField*>& fields, 171 const std::vector<AutofillField*>& fields,
175 FieldCandidatesMap* field_candidates) { 172 FieldCandidatesMap* field_candidates) {
176 AutofillScanner scanner(fields); 173 AutofillScanner scanner(fields);
177 while (!scanner.IsEnd()) { 174 while (!scanner.IsEnd()) {
178 std::unique_ptr<FormField> form_field(parse(&scanner)); 175 std::unique_ptr<FormField> form_field = parse(&scanner);
179 if (form_field == nullptr) { 176 if (form_field == nullptr) {
180 scanner.Advance(); 177 scanner.Advance();
181 } else { 178 } else {
182 // Add entries into |field_candidates| for each field type found in 179 // Add entries into |field_candidates| for each field type found in
183 // |fields|. 180 // |fields|.
184 form_field->AddClassifications(field_candidates); 181 form_field->AddClassifications(field_candidates);
185 } 182 }
186 } 183 }
187 } 184 }
188 185
(...skipping 17 matching lines...) Expand all
206 if ((match_type & MATCH_PASSWORD) && type == "password") 203 if ((match_type & MATCH_PASSWORD) && type == "password")
207 return true; 204 return true;
208 205
209 if ((match_type & MATCH_NUMBER) && type == "number") 206 if ((match_type & MATCH_NUMBER) && type == "number")
210 return true; 207 return true;
211 208
212 return false; 209 return false;
213 } 210 }
214 211
215 } // namespace autofill 212 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/form_field.h ('k') | components/autofill/core/browser/form_field_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698