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

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

Issue 2611453002: Remove ScopedVector from autofill::FormStructure (Closed)
Patch Set: Fix ios build 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 processed_fields.push_back(field.get());
55 }
56 }
61 57
62 FieldCandidatesMap field_candidates; 58 FieldCandidatesMap field_candidates;
63 59
64 // Email pass. 60 // Email pass.
65 ParseFormFieldsPass(EmailField::Parse, processed_fields, &field_candidates); 61 ParseFormFieldsPass(EmailField::Parse, processed_fields, &field_candidates);
66 const size_t email_count = field_candidates.size(); 62 const size_t email_count = field_candidates.size();
67 63
68 // Phone pass. 64 // Phone pass.
69 ParseFormFieldsPass(PhoneField::Parse, processed_fields, &field_candidates); 65 ParseFormFieldsPass(PhoneField::Parse, processed_fields, &field_candidates);
70 66
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 if ((match_type & MATCH_PASSWORD) && type == "password") 202 if ((match_type & MATCH_PASSWORD) && type == "password")
207 return true; 203 return true;
208 204
209 if ((match_type & MATCH_NUMBER) && type == "number") 205 if ((match_type & MATCH_NUMBER) && type == "number")
210 return true; 206 return true;
211 207
212 return false; 208 return false;
213 } 209 }
214 210
215 } // namespace autofill 211 } // 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