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

Side by Side Diff: chrome/browser/autofill/form_structure.cc

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

Powered by Google App Engine
This is Rietveld 408576698