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 "chrome/browser/autofill/form_structure.h" | 5 #include "chrome/browser/autofill/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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 target_url_(form.action), | 225 target_url_(form.action), |
226 autofill_count_(0), | 226 autofill_count_(0), |
227 upload_required_(USE_UPLOAD_RATES), | 227 upload_required_(USE_UPLOAD_RATES), |
228 server_experiment_id_("no server response"), | 228 server_experiment_id_("no server response"), |
229 has_author_specified_types_(false) { | 229 has_author_specified_types_(false) { |
230 // Copy the form fields. | 230 // Copy the form fields. |
231 std::map<string16, size_t> unique_names; | 231 std::map<string16, size_t> unique_names; |
232 for (std::vector<FormFieldData>::const_iterator field = | 232 for (std::vector<FormFieldData>::const_iterator field = |
233 form.fields.begin(); | 233 form.fields.begin(); |
234 field != form.fields.end(); field++) { | 234 field != form.fields.end(); field++) { |
235 // Add all supported form fields (including with empty names) to the | 235 // Skipping checkable elements when flag is not set, else these fields will |
236 // signature. This is a requirement for Autofill servers. | 236 // interfere with existing field signatures with autofill servers. |
Ilya Sherman
2012/12/01 00:54:12
nit: "autofill" -> "Autofill"
Raman Kakilate
2012/12/06 01:54:05
Done.
| |
237 form_signature_field_names_.append("&"); | 237 // TODO(ramankk): Add checkable elements only on whitelisted pages |
238 form_signature_field_names_.append(UTF16ToUTF8(field->name)); | 238 if (!field->is_checkable || |
239 CommandLine::ForCurrentProcess()->HasSwitch( | |
240 switches::kEnableExperimentalFormFilling)) { | |
241 // Add all supported form fields (including with empty names) to the | |
242 // signature. This is a requirement for Autofill servers. | |
243 form_signature_field_names_.append("&"); | |
244 form_signature_field_names_.append(UTF16ToUTF8(field->name)); | |
245 } | |
239 | 246 |
240 // Generate a unique name for this field by appending a counter to the name. | 247 // Generate a unique name for this field by appending a counter to the name. |
241 // Make sure to prepend the counter with a non-numeric digit so that we are | 248 // Make sure to prepend the counter with a non-numeric digit so that we are |
242 // guaranteed to avoid collisions. | 249 // guaranteed to avoid collisions. |
243 if (!unique_names.count(field->name)) | 250 if (!unique_names.count(field->name)) |
244 unique_names[field->name] = 1; | 251 unique_names[field->name] = 1; |
245 else | 252 else |
246 ++unique_names[field->name]; | 253 ++unique_names[field->name]; |
247 string16 unique_name = field->name + ASCIIToUTF16("_") + | 254 string16 unique_name = field->name + ASCIIToUTF16("_") + |
248 base::IntToString16(unique_names[field->name]); | 255 base::IntToString16(unique_names[field->name]); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
396 return true; | 403 return true; |
397 } | 404 } |
398 | 405 |
399 // static | 406 // static |
400 void FormStructure::ParseQueryResponse(const std::string& response_xml, | 407 void FormStructure::ParseQueryResponse(const std::string& response_xml, |
401 const std::vector<FormStructure*>& forms, | 408 const std::vector<FormStructure*>& forms, |
402 const AutofillMetrics& metric_logger) { | 409 const AutofillMetrics& metric_logger) { |
403 metric_logger.LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_RECEIVED); | 410 metric_logger.LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_RECEIVED); |
404 | 411 |
405 // Parse the field types from the server response to the query. | 412 // Parse the field types from the server response to the query. |
406 std::vector<AutofillFieldType> field_types; | 413 std::vector<AutofillFieldInfo> field_infos; |
407 UploadRequired upload_required; | 414 UploadRequired upload_required; |
408 std::string experiment_id; | 415 std::string experiment_id; |
409 AutofillQueryXmlParser parse_handler(&field_types, &upload_required, | 416 AutofillQueryXmlParser parse_handler(&field_infos, &upload_required, |
410 &experiment_id); | 417 &experiment_id); |
411 buzz::XmlParser parser(&parse_handler); | 418 buzz::XmlParser parser(&parse_handler); |
412 parser.Parse(response_xml.c_str(), response_xml.length(), true); | 419 parser.Parse(response_xml.c_str(), response_xml.length(), true); |
413 if (!parse_handler.succeeded()) | 420 if (!parse_handler.succeeded()) |
414 return; | 421 return; |
415 | 422 |
416 metric_logger.LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_PARSED); | 423 metric_logger.LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_PARSED); |
417 metric_logger.LogServerExperimentIdForQuery(experiment_id); | 424 metric_logger.LogServerExperimentIdForQuery(experiment_id); |
418 | 425 |
419 bool heuristics_detected_fillable_field = false; | 426 bool heuristics_detected_fillable_field = false; |
420 bool query_response_overrode_heuristics = false; | 427 bool query_response_overrode_heuristics = false; |
421 | 428 |
422 // Copy the field types into the actual form. | 429 // Copy the field types into the actual form. |
423 std::vector<AutofillFieldType>::iterator current_type = field_types.begin(); | 430 std::vector<AutofillFieldInfo>::iterator current_info = field_infos.begin(); |
424 for (std::vector<FormStructure*>::const_iterator iter = forms.begin(); | 431 for (std::vector<FormStructure*>::const_iterator iter = forms.begin(); |
425 iter != forms.end(); ++iter) { | 432 iter != forms.end(); ++iter) { |
426 FormStructure* form = *iter; | 433 FormStructure* form = *iter; |
427 form->upload_required_ = upload_required; | 434 form->upload_required_ = upload_required; |
428 form->server_experiment_id_ = experiment_id; | 435 form->server_experiment_id_ = experiment_id; |
429 | 436 |
430 for (std::vector<AutofillField*>::iterator field = form->fields_.begin(); | 437 for (std::vector<AutofillField*>::iterator field = form->fields_.begin(); |
431 field != form->fields_.end(); ++field, ++current_type) { | 438 field != form->fields_.end(); ++field, ++current_info) { |
432 // In some cases *successful* response does not return all the fields. | 439 // In some cases *successful* response does not return all the fields. |
433 // Quit the update of the types then. | 440 // Quit the update of the types then. |
434 if (current_type == field_types.end()) | 441 if (current_info == field_infos.end()) |
435 break; | 442 break; |
436 | 443 |
437 // UNKNOWN_TYPE is reserved for use by the client. | 444 // UNKNOWN_TYPE is reserved for use by the client. |
438 DCHECK_NE(*current_type, UNKNOWN_TYPE); | 445 DCHECK_NE(current_info->first, UNKNOWN_TYPE); |
439 | 446 |
440 AutofillFieldType heuristic_type = (*field)->type(); | 447 AutofillFieldType heuristic_type = (*field)->type(); |
441 if (heuristic_type != UNKNOWN_TYPE) | 448 if (heuristic_type != UNKNOWN_TYPE) |
442 heuristics_detected_fillable_field = true; | 449 heuristics_detected_fillable_field = true; |
443 | 450 |
444 (*field)->set_server_type(*current_type); | 451 (*field)->set_server_type(current_info->first); |
445 if (heuristic_type != (*field)->type()) | 452 if (heuristic_type != (*field)->type()) |
446 query_response_overrode_heuristics = true; | 453 query_response_overrode_heuristics = true; |
454 | |
455 // Copy default value into the field if available. | |
456 if (!current_info->second.empty()) | |
457 (*field)->set_default_value(current_info->second); | |
447 } | 458 } |
448 | |
449 form->UpdateAutofillCount(); | 459 form->UpdateAutofillCount(); |
450 form->IdentifySections(false); | 460 form->IdentifySections(false); |
451 } | 461 } |
452 | 462 |
453 AutofillMetrics::ServerQueryMetric metric; | 463 AutofillMetrics::ServerQueryMetric metric; |
454 if (query_response_overrode_heuristics) { | 464 if (query_response_overrode_heuristics) { |
455 if (heuristics_detected_fillable_field) { | 465 if (heuristics_detected_fillable_field) { |
456 metric = AutofillMetrics::QUERY_RESPONSE_OVERRODE_LOCAL_HEURISTICS; | 466 metric = AutofillMetrics::QUERY_RESPONSE_OVERRODE_LOCAL_HEURISTICS; |
457 } else { | 467 } else { |
458 metric = AutofillMetrics::QUERY_RESPONSE_WITH_NO_LOCAL_HEURISTICS; | 468 metric = AutofillMetrics::QUERY_RESPONSE_WITH_NO_LOCAL_HEURISTICS; |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
873 buzz::XmlElement *field_element = new buzz::XmlElement( | 883 buzz::XmlElement *field_element = new buzz::XmlElement( |
874 buzz::QName(kXMLElementField)); | 884 buzz::QName(kXMLElementField)); |
875 | 885 |
876 field_element->SetAttr(buzz::QName(kAttributeSignature), | 886 field_element->SetAttr(buzz::QName(kAttributeSignature), |
877 field->FieldSignature()); | 887 field->FieldSignature()); |
878 field_element->SetAttr(buzz::QName(kAttributeAutofillType), | 888 field_element->SetAttr(buzz::QName(kAttributeAutofillType), |
879 base::IntToString(*field_type)); | 889 base::IntToString(*field_type)); |
880 encompassing_xml_element->AddElement(field_element); | 890 encompassing_xml_element->AddElement(field_element); |
881 } | 891 } |
882 } else { | 892 } else { |
893 // Skip putting checkable fields in the request flag is not set. | |
Ilya Sherman
2012/12/01 00:54:12
nit: "in the request flag is not set" -> "in the r
Raman Kakilate
2012/12/06 01:54:05
Done.
| |
894 if (field->is_checkable && | |
895 !CommandLine::ForCurrentProcess()->HasSwitch( | |
896 switches::kEnableExperimentalFormFilling)) | |
897 continue; | |
883 buzz::XmlElement *field_element = new buzz::XmlElement( | 898 buzz::XmlElement *field_element = new buzz::XmlElement( |
884 buzz::QName(kXMLElementField)); | 899 buzz::QName(kXMLElementField)); |
885 field_element->SetAttr(buzz::QName(kAttributeSignature), | 900 field_element->SetAttr(buzz::QName(kAttributeSignature), |
886 field->FieldSignature()); | 901 field->FieldSignature()); |
887 encompassing_xml_element->AddElement(field_element); | 902 encompassing_xml_element->AddElement(field_element); |
888 } | 903 } |
889 } | 904 } |
890 return true; | 905 return true; |
891 } | 906 } |
892 | 907 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1053 for (std::vector<AutofillField*>::iterator field = fields_.begin(); | 1068 for (std::vector<AutofillField*>::iterator field = fields_.begin(); |
1054 field != fields_.end(); ++field) { | 1069 field != fields_.end(); ++field) { |
1055 AutofillType::FieldTypeGroup field_type_group = | 1070 AutofillType::FieldTypeGroup field_type_group = |
1056 AutofillType((*field)->type()).group(); | 1071 AutofillType((*field)->type()).group(); |
1057 if (field_type_group == AutofillType::CREDIT_CARD) | 1072 if (field_type_group == AutofillType::CREDIT_CARD) |
1058 (*field)->set_section((*field)->section() + "-cc"); | 1073 (*field)->set_section((*field)->section() + "-cc"); |
1059 else | 1074 else |
1060 (*field)->set_section((*field)->section() + "-default"); | 1075 (*field)->set_section((*field)->section() + "-default"); |
1061 } | 1076 } |
1062 } | 1077 } |
OLD | NEW |