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

Side by Side Diff: components/autofill/content/renderer/form_autofill_util.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/content/renderer/form_autofill_util.h" 5 #include "components/autofill/content/renderer/form_autofill_util.h"
6 6
7 #include <map> 7 #include <map>
8 #include <memory>
8 #include <set> 9 #include <set>
10 #include <vector>
9 11
10 #include "base/command_line.h" 12 #include "base/command_line.h"
11 #include "base/logging.h" 13 #include "base/logging.h"
12 #include "base/memory/scoped_vector.h" 14 #include "base/memory/ptr_util.h"
13 #include "base/stl_util.h" 15 #include "base/stl_util.h"
14 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
17 #include "build/build_config.h" 19 #include "build/build_config.h"
18 #include "components/autofill/core/common/autofill_data_validation.h" 20 #include "components/autofill/core/common/autofill_data_validation.h"
19 #include "components/autofill/core/common/autofill_regexes.h" 21 #include "components/autofill/core/common/autofill_regexes.h"
20 #include "components/autofill/core/common/autofill_switches.h" 22 #include "components/autofill/core/common/autofill_switches.h"
21 #include "components/autofill/core/common/autofill_util.h" 23 #include "components/autofill/core/common/autofill_util.h"
22 #include "components/autofill/core/common/form_data.h" 24 #include "components/autofill/core/common/form_data.h"
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 // |form_fields|. The extracted fields are also placed in |element_map|. 958 // |form_fields|. The extracted fields are also placed in |element_map|.
957 // |form_fields| and |element_map| should start out empty. 959 // |form_fields| and |element_map| should start out empty.
958 // |fields_extracted| should have as many elements as |control_elements|, 960 // |fields_extracted| should have as many elements as |control_elements|,
959 // initialized to false. 961 // initialized to false.
960 // Returns true if the number of fields extracted is within 962 // Returns true if the number of fields extracted is within
961 // [1, kMaxParseableFields]. 963 // [1, kMaxParseableFields].
962 bool ExtractFieldsFromControlElements( 964 bool ExtractFieldsFromControlElements(
963 const WebVector<WebFormControlElement>& control_elements, 965 const WebVector<WebFormControlElement>& control_elements,
964 const FieldValueAndPropertiesMaskMap* field_value_and_properties_map, 966 const FieldValueAndPropertiesMaskMap* field_value_and_properties_map,
965 ExtractMask extract_mask, 967 ExtractMask extract_mask,
966 ScopedVector<FormFieldData>* form_fields, 968 std::vector<std::unique_ptr<FormFieldData>>* form_fields,
967 std::vector<bool>* fields_extracted, 969 std::vector<bool>* fields_extracted,
968 std::map<WebFormControlElement, FormFieldData*>* element_map) { 970 std::map<WebFormControlElement, FormFieldData*>* element_map) {
969 DCHECK(form_fields->empty()); 971 DCHECK(form_fields->empty());
970 DCHECK(element_map->empty()); 972 DCHECK(element_map->empty());
971 DCHECK_EQ(control_elements.size(), fields_extracted->size()); 973 DCHECK_EQ(control_elements.size(), fields_extracted->size());
972 974
973 for (size_t i = 0; i < control_elements.size(); ++i) { 975 for (size_t i = 0; i < control_elements.size(); ++i) {
974 const WebFormControlElement& control_element = control_elements[i]; 976 const WebFormControlElement& control_element = control_elements[i];
975 977
976 if (!IsAutofillableElement(control_element)) 978 if (!IsAutofillableElement(control_element))
977 continue; 979 continue;
978 980
979 // Create a new FormFieldData, fill it out and map it to the field's name. 981 // Create a new FormFieldData, fill it out and map it to the field's name.
980 FormFieldData* form_field = new FormFieldData; 982 FormFieldData* form_field = new FormFieldData;
981 WebFormControlElementToFormField(control_element, 983 WebFormControlElementToFormField(control_element,
982 field_value_and_properties_map, 984 field_value_and_properties_map,
983 extract_mask, form_field); 985 extract_mask, form_field);
984 form_fields->push_back(form_field); 986 form_fields->push_back(base::WrapUnique(form_field));
985 (*element_map)[control_element] = form_field; 987 (*element_map)[control_element] = form_field;
986 (*fields_extracted)[i] = true; 988 (*fields_extracted)[i] = true;
987 989
988 // To avoid overly expensive computation, we impose a maximum number of 990 // To avoid overly expensive computation, we impose a maximum number of
989 // allowable fields. 991 // allowable fields.
990 if (form_fields->size() > kMaxParseableFields) 992 if (form_fields->size() > kMaxParseableFields)
991 return false; 993 return false;
992 } 994 }
993 995
994 // Succeeded if fields were extracted. 996 // Succeeded if fields were extracted.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 if (form_element) 1078 if (form_element)
1077 DCHECK(fieldsets.empty()); 1079 DCHECK(fieldsets.empty());
1078 if (field) 1080 if (field)
1079 DCHECK(form_control_element); 1081 DCHECK(form_control_element);
1080 1082
1081 // A map from a FormFieldData's name to the FormFieldData itself. 1083 // A map from a FormFieldData's name to the FormFieldData itself.
1082 std::map<WebFormControlElement, FormFieldData*> element_map; 1084 std::map<WebFormControlElement, FormFieldData*> element_map;
1083 1085
1084 // The extracted FormFields. We use pointers so we can store them in 1086 // The extracted FormFields. We use pointers so we can store them in
1085 // |element_map|. 1087 // |element_map|.
1086 ScopedVector<FormFieldData> form_fields; 1088 std::vector<std::unique_ptr<FormFieldData>> form_fields;
1087 1089
1088 // A vector of bools that indicate whether each field in the form meets the 1090 // A vector of bools that indicate whether each field in the form meets the
1089 // requirements and thus will be in the resulting |form|. 1091 // requirements and thus will be in the resulting |form|.
1090 std::vector<bool> fields_extracted(control_elements.size(), false); 1092 std::vector<bool> fields_extracted(control_elements.size(), false);
1091 1093
1092 if (!ExtractFieldsFromControlElements( 1094 if (!ExtractFieldsFromControlElements(
1093 control_elements, field_value_and_properties_map, extract_mask, 1095 control_elements, field_value_and_properties_map, extract_mask,
1094 &form_fields, &fields_extracted, &element_map)) { 1096 &form_fields, &fields_extracted, &element_map)) {
1095 return false; 1097 return false;
1096 } 1098 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 } 1147 }
1146 TruncateString(&form_fields[field_idx]->label, kMaxDataLength); 1148 TruncateString(&form_fields[field_idx]->label, kMaxDataLength);
1147 1149
1148 if (field && *form_control_element == control_element) 1150 if (field && *form_control_element == control_element)
1149 *field = *form_fields[field_idx]; 1151 *field = *form_fields[field_idx];
1150 1152
1151 ++field_idx; 1153 ++field_idx;
1152 } 1154 }
1153 1155
1154 // Copy the created FormFields into the resulting FormData object. 1156 // Copy the created FormFields into the resulting FormData object.
1155 for (const auto* iter : form_fields) 1157 for (const auto& field : form_fields)
1156 form->fields.push_back(*iter); 1158 form->fields.push_back(*field);
1157 return true; 1159 return true;
1158 } 1160 }
1159 1161
1160 bool UnownedFormElementsAndFieldSetsToFormData( 1162 bool UnownedFormElementsAndFieldSetsToFormData(
1161 const std::vector<blink::WebElement>& fieldsets, 1163 const std::vector<blink::WebElement>& fieldsets,
1162 const std::vector<blink::WebFormControlElement>& control_elements, 1164 const std::vector<blink::WebFormControlElement>& control_elements,
1163 const blink::WebFormControlElement* element, 1165 const blink::WebFormControlElement* element,
1164 const blink::WebDocument& document, 1166 const blink::WebDocument& document,
1165 const FieldValueAndPropertiesMaskMap* field_value_and_properties_map, 1167 const FieldValueAndPropertiesMaskMap* field_value_and_properties_map,
1166 ExtractMask extract_mask, 1168 ExtractMask extract_mask,
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
1802 // Zero selection start is for password manager, which can show usernames 1804 // Zero selection start is for password manager, which can show usernames
1803 // that do not begin with the user input value. 1805 // that do not begin with the user input value.
1804 selection_start = (offset == base::string16::npos) ? 0 : offset; 1806 selection_start = (offset == base::string16::npos) ? 0 : offset;
1805 } 1807 }
1806 1808
1807 input_element->setSelectionRange(selection_start, suggestion.length()); 1809 input_element->setSelectionRange(selection_start, suggestion.length());
1808 } 1810 }
1809 1811
1810 } // namespace form_util 1812 } // namespace form_util
1811 } // namespace autofill 1813 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/autofill/form_structure_browsertest.cc ('k') | components/autofill/content/renderer/password_autofill_agent.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698