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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 return PHONE_HOME_NUMBER; | 215 return PHONE_HOME_NUMBER; |
216 | 216 |
217 if (autocomplete_type == "email") | 217 if (autocomplete_type == "email") |
218 return EMAIL_ADDRESS; | 218 return EMAIL_ADDRESS; |
219 | 219 |
220 return UNKNOWN_TYPE; | 220 return UNKNOWN_TYPE; |
221 } | 221 } |
222 | 222 |
223 } // namespace | 223 } // namespace |
224 | 224 |
225 FormStructure::FormStructure(const FormData& form) | 225 FormStructure::FormStructure(const FormData& form, bool autocheckout_enabled) |
226 : form_name_(form.name), | 226 : form_name_(form.name), |
227 source_url_(form.origin), | 227 source_url_(form.origin), |
228 target_url_(form.action), | 228 target_url_(form.action), |
229 autofill_count_(0), | 229 autofill_count_(0), |
230 checkable_field_count_(0), | 230 checkable_field_count_(0), |
231 upload_required_(USE_UPLOAD_RATES), | 231 upload_required_(USE_UPLOAD_RATES), |
232 server_experiment_id_("no server response"), | 232 server_experiment_id_("no server response"), |
233 current_page_number_(-1), | 233 current_page_number_(-1), |
234 total_pages_(-1), | 234 total_pages_(-1), |
235 has_author_specified_types_(false), | 235 has_author_specified_types_(false), |
236 experimental_form_filling_enabled_( | 236 autocheckout_enabled_(autocheckout_enabled) { |
237 CommandLine::ForCurrentProcess()->HasSwitch( | |
238 switches::kEnableExperimentalFormFilling)) { | |
239 // Copy the form fields. | 237 // Copy the form fields. |
240 std::map<string16, size_t> unique_names; | 238 std::map<string16, size_t> unique_names; |
241 for (std::vector<FormFieldData>::const_iterator field = | 239 for (std::vector<FormFieldData>::const_iterator field = |
242 form.fields.begin(); | 240 form.fields.begin(); |
243 field != form.fields.end(); field++) { | 241 field != form.fields.end(); field++) { |
244 // Skipping checkable elements when flag is not set, else these fields will | 242 // Skipping checkable elements when autocheckout is not enabled, else |
245 // interfere with existing field signatures with Autofill servers. | 243 // these fields will interfere with existing field signatures with Autofill |
246 // TODO(ramankk): Add checkable elements only on whitelisted pages | 244 // servers. |
247 if (!field->is_checkable || experimental_form_filling_enabled_) { | 245 if (!field->is_checkable || autocheckout_enabled_) { |
248 // Add all supported form fields (including with empty names) to the | 246 // Add all supported form fields (including with empty names) to the |
249 // signature. This is a requirement for Autofill servers. | 247 // signature. This is a requirement for Autofill servers. |
250 form_signature_field_names_.append("&"); | 248 form_signature_field_names_.append("&"); |
251 form_signature_field_names_.append(UTF16ToUTF8(field->name)); | 249 form_signature_field_names_.append(UTF16ToUTF8(field->name)); |
252 } | 250 } |
253 | 251 |
254 // Generate a unique name for this field by appending a counter to the name. | 252 // Generate a unique name for this field by appending a counter to the name. |
255 // Make sure to prepend the counter with a non-numeric digit so that we are | 253 // Make sure to prepend the counter with a non-numeric digit so that we are |
256 // guaranteed to avoid collisions. | 254 // guaranteed to avoid collisions. |
257 if (!unique_names.count(field->name)) | 255 if (!unique_names.count(field->name)) |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 host = source_url_.host(); | 538 host = source_url_.host(); |
541 } | 539 } |
542 | 540 |
543 std::string form_string = scheme + "://" + host + "&" + | 541 std::string form_string = scheme + "://" + host + "&" + |
544 UTF16ToUTF8(form_name_) + | 542 UTF16ToUTF8(form_name_) + |
545 form_signature_field_names_; | 543 form_signature_field_names_; |
546 | 544 |
547 return Hash64Bit(form_string); | 545 return Hash64Bit(form_string); |
548 } | 546 } |
549 | 547 |
| 548 size_t FormStructure::RequiredFillableFields() const { |
| 549 return autocheckout_enabled_? 0 : kRequiredFillableFields; |
| 550 } |
| 551 |
550 bool FormStructure::IsAutofillable(bool require_method_post) const { | 552 bool FormStructure::IsAutofillable(bool require_method_post) const { |
551 // TODO(ramankk): Remove this check once we have better way of identifying the | 553 if (autofill_count() < RequiredFillableFields()) |
552 // cases to trigger experimental form filling. | |
553 if (experimental_form_filling_enabled_) | |
554 return true; | |
555 | |
556 if (autofill_count() < kRequiredFillableFields) | |
557 return false; | 554 return false; |
558 | 555 |
559 return ShouldBeParsed(require_method_post); | 556 return ShouldBeParsed(require_method_post); |
560 } | 557 } |
561 | 558 |
562 void FormStructure::UpdateAutofillCount() { | 559 void FormStructure::UpdateAutofillCount() { |
563 autofill_count_ = 0; | 560 autofill_count_ = 0; |
564 for (std::vector<AutofillField*>::const_iterator iter = begin(); | 561 for (std::vector<AutofillField*>::const_iterator iter = begin(); |
565 iter != end(); ++iter) { | 562 iter != end(); ++iter) { |
566 AutofillField* field = *iter; | 563 AutofillField* field = *iter; |
567 if (field && field->IsFieldFillable()) | 564 if (field && field->IsFieldFillable()) |
568 ++autofill_count_; | 565 ++autofill_count_; |
569 } | 566 } |
570 } | 567 } |
571 | 568 |
572 bool FormStructure::ShouldBeParsed(bool require_method_post) const { | 569 bool FormStructure::ShouldBeParsed(bool require_method_post) const { |
573 // TODO(ramankk): Remove this check once we have better way of identifying the | |
574 // cases to trigger experimental form filling. | |
575 if (experimental_form_filling_enabled_) | |
576 return true; | |
577 | |
578 // Ignore counting checkable elements towards minimum number of elements | 570 // Ignore counting checkable elements towards minimum number of elements |
579 // required to parse. This avoids trying to crowdsource forms with few text | 571 // required to parse. This avoids trying to crowdsource forms with few text |
580 // or select elements. | 572 // or select elements. |
581 if ((field_count() - checkable_field_count()) < kRequiredFillableFields) | 573 if ((field_count() - checkable_field_count()) < RequiredFillableFields()) |
582 return false; | 574 return false; |
583 | 575 |
584 // Rule out http(s)://*/search?... | 576 // Rule out http(s)://*/search?... |
585 // e.g. http://www.google.com/search?q=... | 577 // e.g. http://www.google.com/search?q=... |
586 // http://search.yahoo.com/search?p=... | 578 // http://search.yahoo.com/search?p=... |
587 if (target_url_.path() == "/search") | 579 if (target_url_.path() == "/search") |
588 return false; | 580 return false; |
589 | 581 |
590 // Make sure there as at least one text field. | 582 // Make sure there as at least one text field. |
591 bool has_text_field = false; | 583 bool has_text_field = false; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 AutofillMetrics::NOT_AUTOFILLED_SERVER_TYPE_MATCH, | 761 AutofillMetrics::NOT_AUTOFILLED_SERVER_TYPE_MATCH, |
770 experiment_id); | 762 experiment_id); |
771 } else { | 763 } else { |
772 metric_logger.LogQualityMetric( | 764 metric_logger.LogQualityMetric( |
773 AutofillMetrics::NOT_AUTOFILLED_SERVER_TYPE_MISMATCH, | 765 AutofillMetrics::NOT_AUTOFILLED_SERVER_TYPE_MISMATCH, |
774 experiment_id); | 766 experiment_id); |
775 } | 767 } |
776 } | 768 } |
777 } | 769 } |
778 | 770 |
779 if (num_detected_field_types < kRequiredFillableFields) { | 771 if (num_detected_field_types < RequiredFillableFields()) { |
780 metric_logger.LogUserHappinessMetric( | 772 metric_logger.LogUserHappinessMetric( |
781 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM); | 773 AutofillMetrics::SUBMITTED_NON_FILLABLE_FORM); |
782 } else { | 774 } else { |
783 if (did_autofill_all_possible_fields) { | 775 if (did_autofill_all_possible_fields) { |
784 metric_logger.LogUserHappinessMetric( | 776 metric_logger.LogUserHappinessMetric( |
785 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_ALL); | 777 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_ALL); |
786 } else if (did_autofill_some_possible_fields) { | 778 } else if (did_autofill_some_possible_fields) { |
787 metric_logger.LogUserHappinessMetric( | 779 metric_logger.LogUserHappinessMetric( |
788 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME); | 780 AutofillMetrics::SUBMITTED_FILLABLE_FORM_AUTOFILLED_SOME); |
789 } else { | 781 } else { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 buzz::XmlElement *field_element = new buzz::XmlElement( | 918 buzz::XmlElement *field_element = new buzz::XmlElement( |
927 buzz::QName(kXMLElementField)); | 919 buzz::QName(kXMLElementField)); |
928 | 920 |
929 field_element->SetAttr(buzz::QName(kAttributeSignature), | 921 field_element->SetAttr(buzz::QName(kAttributeSignature), |
930 field->FieldSignature()); | 922 field->FieldSignature()); |
931 field_element->SetAttr(buzz::QName(kAttributeAutofillType), | 923 field_element->SetAttr(buzz::QName(kAttributeAutofillType), |
932 base::IntToString(*field_type)); | 924 base::IntToString(*field_type)); |
933 encompassing_xml_element->AddElement(field_element); | 925 encompassing_xml_element->AddElement(field_element); |
934 } | 926 } |
935 } else { | 927 } else { |
936 // Skip putting checkable fields in the request if the flag is not set. | 928 // Skip putting checkable fields in the request if autocheckout is not |
937 if (field->is_checkable && !experimental_form_filling_enabled_) | 929 // enabled. |
| 930 if (field->is_checkable && !autocheckout_enabled_) |
938 continue; | 931 continue; |
939 | 932 |
940 buzz::XmlElement *field_element = new buzz::XmlElement( | 933 buzz::XmlElement *field_element = new buzz::XmlElement( |
941 buzz::QName(kXMLElementField)); | 934 buzz::QName(kXMLElementField)); |
942 field_element->SetAttr(buzz::QName(kAttributeSignature), | 935 field_element->SetAttr(buzz::QName(kAttributeSignature), |
943 field->FieldSignature()); | 936 field->FieldSignature()); |
944 encompassing_xml_element->AddElement(field_element); | 937 encompassing_xml_element->AddElement(field_element); |
945 } | 938 } |
946 } | 939 } |
947 return true; | 940 return true; |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 for (std::vector<AutofillField*>::iterator field = fields_.begin(); | 1111 for (std::vector<AutofillField*>::iterator field = fields_.begin(); |
1119 field != fields_.end(); ++field) { | 1112 field != fields_.end(); ++field) { |
1120 AutofillType::FieldTypeGroup field_type_group = | 1113 AutofillType::FieldTypeGroup field_type_group = |
1121 AutofillType((*field)->type()).group(); | 1114 AutofillType((*field)->type()).group(); |
1122 if (field_type_group == AutofillType::CREDIT_CARD) | 1115 if (field_type_group == AutofillType::CREDIT_CARD) |
1123 (*field)->set_section((*field)->section() + "-cc"); | 1116 (*field)->set_section((*field)->section() + "-cc"); |
1124 else | 1117 else |
1125 (*field)->set_section((*field)->section() + "-default"); | 1118 (*field)->set_section((*field)->section() + "-default"); |
1126 } | 1119 } |
1127 } | 1120 } |
OLD | NEW |