| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/form_structure.h" | 5 #include "components/autofill/browser/form_structure.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 source_url_(form.origin), | 292 source_url_(form.origin), |
| 293 target_url_(form.action), | 293 target_url_(form.action), |
| 294 autofill_count_(0), | 294 autofill_count_(0), |
| 295 active_field_count_(0), | 295 active_field_count_(0), |
| 296 upload_required_(USE_UPLOAD_RATES), | 296 upload_required_(USE_UPLOAD_RATES), |
| 297 server_experiment_id_("no server response"), | 297 server_experiment_id_("no server response"), |
| 298 has_author_specified_types_(false), | 298 has_author_specified_types_(false), |
| 299 autocheckout_url_prefix_(autocheckout_url_prefix), | 299 autocheckout_url_prefix_(autocheckout_url_prefix), |
| 300 filled_by_autocheckout_(false) { | 300 filled_by_autocheckout_(false) { |
| 301 // Copy the form fields. | 301 // Copy the form fields. |
| 302 std::map<string16, size_t> unique_names; | 302 std::map<base::string16, size_t> unique_names; |
| 303 for (std::vector<FormFieldData>::const_iterator field = | 303 for (std::vector<FormFieldData>::const_iterator field = |
| 304 form.fields.begin(); | 304 form.fields.begin(); |
| 305 field != form.fields.end(); field++) { | 305 field != form.fields.end(); field++) { |
| 306 | 306 |
| 307 // Skip checkable and password elements when Autocheckout is not enabled, | 307 // Skip checkable and password elements when Autocheckout is not enabled, |
| 308 // else these fields will interfere with existing field signatures with | 308 // else these fields will interfere with existing field signatures with |
| 309 // Autofill servers. | 309 // Autofill servers. |
| 310 if ((!field->is_checkable && field->form_control_type != "password") || | 310 if ((!field->is_checkable && field->form_control_type != "password") || |
| 311 IsAutocheckoutEnabled()) { | 311 IsAutocheckoutEnabled()) { |
| 312 // Add all supported form fields (including with empty names) to the | 312 // Add all supported form fields (including with empty names) to the |
| 313 // signature. This is a requirement for Autofill servers. | 313 // signature. This is a requirement for Autofill servers. |
| 314 form_signature_field_names_.append("&"); | 314 form_signature_field_names_.append("&"); |
| 315 form_signature_field_names_.append(UTF16ToUTF8(field->name)); | 315 form_signature_field_names_.append(UTF16ToUTF8(field->name)); |
| 316 | 316 |
| 317 ++active_field_count_; | 317 ++active_field_count_; |
| 318 } | 318 } |
| 319 | 319 |
| 320 // Generate a unique name for this field by appending a counter to the name. | 320 // Generate a unique name for this field by appending a counter to the name. |
| 321 // Make sure to prepend the counter with a non-numeric digit so that we are | 321 // Make sure to prepend the counter with a non-numeric digit so that we are |
| 322 // guaranteed to avoid collisions. | 322 // guaranteed to avoid collisions. |
| 323 if (!unique_names.count(field->name)) | 323 if (!unique_names.count(field->name)) |
| 324 unique_names[field->name] = 1; | 324 unique_names[field->name] = 1; |
| 325 else | 325 else |
| 326 ++unique_names[field->name]; | 326 ++unique_names[field->name]; |
| 327 string16 unique_name = field->name + ASCIIToUTF16("_") + | 327 base::string16 unique_name = field->name + ASCIIToUTF16("_") + |
| 328 base::IntToString16(unique_names[field->name]); | 328 base::IntToString16(unique_names[field->name]); |
| 329 fields_.push_back(new AutofillField(*field, unique_name)); | 329 fields_.push_back(new AutofillField(*field, unique_name)); |
| 330 } | 330 } |
| 331 | 331 |
| 332 std::string method = UTF16ToUTF8(form.method); | 332 std::string method = UTF16ToUTF8(form.method); |
| 333 if (StringToLowerASCII(method) == kFormMethodPost) { | 333 if (StringToLowerASCII(method) == kFormMethodPost) { |
| 334 method_ = POST; | 334 method_ = POST; |
| 335 } else { | 335 } else { |
| 336 // Either the method is 'get', or we don't know. In this case we default | 336 // Either the method is 'get', or we don't know. In this case we default |
| 337 // to GET. | 337 // to GET. |
| (...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 iter != end(); ++iter) { | 729 iter != end(); ++iter) { |
| 730 AutofillField* field = *iter; | 730 AutofillField* field = *iter; |
| 731 | 731 |
| 732 std::map<std::string, const AutofillField*>::const_iterator | 732 std::map<std::string, const AutofillField*>::const_iterator |
| 733 cached_field = cached_fields.find(field->FieldSignature()); | 733 cached_field = cached_fields.find(field->FieldSignature()); |
| 734 if (cached_field != cached_fields.end()) { | 734 if (cached_field != cached_fields.end()) { |
| 735 if (field->form_control_type != "select-one" && | 735 if (field->form_control_type != "select-one" && |
| 736 field->value == cached_field->second->value) { | 736 field->value == cached_field->second->value) { |
| 737 // From the perspective of learning user data, text fields containing | 737 // From the perspective of learning user data, text fields containing |
| 738 // default values are equivalent to empty fields. | 738 // default values are equivalent to empty fields. |
| 739 field->value = string16(); | 739 field->value = base::string16(); |
| 740 } | 740 } |
| 741 | 741 |
| 742 field->set_heuristic_type(cached_field->second->heuristic_type()); | 742 field->set_heuristic_type(cached_field->second->heuristic_type()); |
| 743 field->set_server_type(cached_field->second->server_type()); | 743 field->set_server_type(cached_field->second->server_type()); |
| 744 } | 744 } |
| 745 } | 745 } |
| 746 | 746 |
| 747 UpdateAutofillCount(); | 747 UpdateAutofillCount(); |
| 748 | 748 |
| 749 filled_by_autocheckout_ = cached_form.filled_by_autocheckout(); | 749 filled_by_autocheckout_ = cached_form.filled_by_autocheckout(); |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1156 field->set_phone_part(AutofillField::PHONE_SUFFIX); | 1156 field->set_phone_part(AutofillField::PHONE_SUFFIX); |
| 1157 } | 1157 } |
| 1158 } | 1158 } |
| 1159 | 1159 |
| 1160 void FormStructure::IdentifySections(bool has_author_specified_sections) { | 1160 void FormStructure::IdentifySections(bool has_author_specified_sections) { |
| 1161 if (fields_.empty()) | 1161 if (fields_.empty()) |
| 1162 return; | 1162 return; |
| 1163 | 1163 |
| 1164 if (!has_author_specified_sections) { | 1164 if (!has_author_specified_sections) { |
| 1165 // Name sections after the first field in the section. | 1165 // Name sections after the first field in the section. |
| 1166 string16 current_section = fields_.front()->unique_name(); | 1166 base::string16 current_section = fields_.front()->unique_name(); |
| 1167 | 1167 |
| 1168 // Keep track of the types we've seen in this section. | 1168 // Keep track of the types we've seen in this section. |
| 1169 std::set<AutofillFieldType> seen_types; | 1169 std::set<AutofillFieldType> seen_types; |
| 1170 AutofillFieldType previous_type = UNKNOWN_TYPE; | 1170 AutofillFieldType previous_type = UNKNOWN_TYPE; |
| 1171 | 1171 |
| 1172 for (std::vector<AutofillField*>::iterator field = fields_.begin(); | 1172 for (std::vector<AutofillField*>::iterator field = fields_.begin(); |
| 1173 field != fields_.end(); ++field) { | 1173 field != fields_.end(); ++field) { |
| 1174 const AutofillFieldType current_type = | 1174 const AutofillFieldType current_type = |
| 1175 AutofillType::GetEquivalentFieldType((*field)->type()); | 1175 AutofillType::GetEquivalentFieldType((*field)->type()); |
| 1176 | 1176 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1212 for (std::vector<AutofillField*>::iterator field = fields_.begin(); | 1212 for (std::vector<AutofillField*>::iterator field = fields_.begin(); |
| 1213 field != fields_.end(); ++field) { | 1213 field != fields_.end(); ++field) { |
| 1214 AutofillType::FieldTypeGroup field_type_group = | 1214 AutofillType::FieldTypeGroup field_type_group = |
| 1215 AutofillType((*field)->type()).group(); | 1215 AutofillType((*field)->type()).group(); |
| 1216 if (field_type_group == AutofillType::CREDIT_CARD) | 1216 if (field_type_group == AutofillType::CREDIT_CARD) |
| 1217 (*field)->set_section((*field)->section() + "-cc"); | 1217 (*field)->set_section((*field)->section() + "-cc"); |
| 1218 else | 1218 else |
| 1219 (*field)->set_section((*field)->section() + "-default"); | 1219 (*field)->set_section((*field)->section() + "-default"); |
| 1220 } | 1220 } |
| 1221 } | 1221 } |
| OLD | NEW |