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

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: revert code change for manual testing/:wq. Created 7 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 | 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 : 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 upload_required_(USE_UPLOAD_RATES),
231 server_experiment_id_("no server response"),
232 current_page_number_(-1),
233 total_pages_(-1),
234 has_author_specified_types_(false),
235 autocheckout_enabled_(false) {
236 Init(form);
237 }
238
239 FormStructure::FormStructure(const FormData& form, bool autocheckout_enabled)
240 : form_name_(form.name),
241 source_url_(form.origin),
242 target_url_(form.action),
243 autofill_count_(0),
230 checkable_field_count_(0), 244 checkable_field_count_(0),
231 upload_required_(USE_UPLOAD_RATES), 245 upload_required_(USE_UPLOAD_RATES),
232 server_experiment_id_("no server response"), 246 server_experiment_id_("no server response"),
233 current_page_number_(-1), 247 current_page_number_(-1),
234 total_pages_(-1), 248 total_pages_(-1),
235 has_author_specified_types_(false), 249 has_author_specified_types_(false),
236 experimental_form_filling_enabled_( 250 autocheckout_enabled_(autocheckout_enabled) {
237 CommandLine::ForCurrentProcess()->HasSwitch( 251 Init(form);
238 switches::kEnableExperimentalFormFilling)) { 252 }
253
254 void FormStructure::Init(const FormData& form) {
239 // Copy the form fields. 255 // Copy the form fields.
240 std::map<string16, size_t> unique_names; 256 std::map<string16, size_t> unique_names;
241 for (std::vector<FormFieldData>::const_iterator field = 257 for (std::vector<FormFieldData>::const_iterator field =
242 form.fields.begin(); 258 form.fields.begin();
243 field != form.fields.end(); field++) { 259 field != form.fields.end(); field++) {
244 // Skipping checkable elements when flag is not set, else these fields will 260 // Skipping checkable elements when flag is not set, else these fields will
245 // interfere with existing field signatures with Autofill servers. 261 // interfere with existing field signatures with Autofill servers.
246 // TODO(ramankk): Add checkable elements only on whitelisted pages 262 if (!field->is_checkable || autocheckout_enabled_) {
247 if (!field->is_checkable || experimental_form_filling_enabled_) {
248 // Add all supported form fields (including with empty names) to the 263 // Add all supported form fields (including with empty names) to the
249 // signature. This is a requirement for Autofill servers. 264 // signature. This is a requirement for Autofill servers.
250 form_signature_field_names_.append("&"); 265 form_signature_field_names_.append("&");
251 form_signature_field_names_.append(UTF16ToUTF8(field->name)); 266 form_signature_field_names_.append(UTF16ToUTF8(field->name));
252 } 267 }
253 268
254 // Generate a unique name for this field by appending a counter to the name. 269 // 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 270 // Make sure to prepend the counter with a non-numeric digit so that we are
256 // guaranteed to avoid collisions. 271 // guaranteed to avoid collisions.
257 if (!unique_names.count(field->name)) 272 if (!unique_names.count(field->name))
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 *encoded_xml += autofill_request_xml.Str().c_str(); 426 *encoded_xml += autofill_request_xml.Str().c_str();
412 427
413 return true; 428 return true;
414 } 429 }
415 430
416 // static 431 // static
417 void FormStructure::ParseQueryResponse(const std::string& response_xml, 432 void FormStructure::ParseQueryResponse(const std::string& response_xml,
418 const std::vector<FormStructure*>& forms, 433 const std::vector<FormStructure*>& forms,
419 const AutofillMetrics& metric_logger) { 434 const AutofillMetrics& metric_logger) {
420 metric_logger.LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_RECEIVED); 435 metric_logger.LogServerQueryMetric(AutofillMetrics::QUERY_RESPONSE_RECEIVED);
421
Ilya Sherman 2013/01/24 22:01:55 nit: Please revert this diff.
benquan 2013/01/25 00:55:31 Done.
422 // Parse the field types from the server response to the query. 436 // Parse the field types from the server response to the query.
423 std::vector<AutofillServerFieldInfo> field_infos; 437 std::vector<AutofillServerFieldInfo> field_infos;
424 UploadRequired upload_required; 438 UploadRequired upload_required;
425 std::string experiment_id; 439 std::string experiment_id;
426 AutofillQueryXmlParser parse_handler(&field_infos, &upload_required, 440 AutofillQueryXmlParser parse_handler(&field_infos, &upload_required,
427 &experiment_id); 441 &experiment_id);
428 buzz::XmlParser parser(&parse_handler); 442 buzz::XmlParser parser(&parse_handler);
429 parser.Parse(response_xml.c_str(), response_xml.length(), true); 443 parser.Parse(response_xml.c_str(), response_xml.length(), true);
430 if (!parse_handler.succeeded()) 444 if (!parse_handler.succeeded())
431 return; 445 return;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 } 550 }
537 551
538 std::string form_string = scheme + "://" + host + "&" + 552 std::string form_string = scheme + "://" + host + "&" +
539 UTF16ToUTF8(form_name_) + 553 UTF16ToUTF8(form_name_) +
540 form_signature_field_names_; 554 form_signature_field_names_;
541 555
542 return Hash64Bit(form_string); 556 return Hash64Bit(form_string);
543 } 557 }
544 558
545 bool FormStructure::IsAutofillable(bool require_method_post) const { 559 bool FormStructure::IsAutofillable(bool require_method_post) const {
546 // TODO(ramankk): Remove this check once we have better way of identifying the 560 if (autocheckout_enabled_)
547 // cases to trigger experimental form filling.
548 if (experimental_form_filling_enabled_)
549 return true; 561 return true;
550 562
551 if (autofill_count() < kRequiredFillableFields) 563 if (autofill_count() < kRequiredFillableFields)
552 return false; 564 return false;
553 565
554 return ShouldBeParsed(require_method_post); 566 return ShouldBeParsed(require_method_post);
555 } 567 }
556 568
557 void FormStructure::UpdateAutofillCount() { 569 void FormStructure::UpdateAutofillCount() {
558 autofill_count_ = 0; 570 autofill_count_ = 0;
559 for (std::vector<AutofillField*>::const_iterator iter = begin(); 571 for (std::vector<AutofillField*>::const_iterator iter = begin();
560 iter != end(); ++iter) { 572 iter != end(); ++iter) {
561 AutofillField* field = *iter; 573 AutofillField* field = *iter;
562 if (field && field->IsFieldFillable()) 574 if (field && field->IsFieldFillable())
563 ++autofill_count_; 575 ++autofill_count_;
564 } 576 }
565 } 577 }
566 578
567 bool FormStructure::ShouldBeParsed(bool require_method_post) const { 579 bool FormStructure::ShouldBeParsed(bool require_method_post) const {
568 // TODO(ramankk): Remove this check once we have better way of identifying the 580 if (autocheckout_enabled_)
569 // cases to trigger experimental form filling.
570 if (experimental_form_filling_enabled_)
571 return true; 581 return true;
572 582
573 // Ignore counting checkable elements towards minimum number of elements 583 // Ignore counting checkable elements towards minimum number of elements
574 // required to parse. This avoids trying to crowdsource forms with few text 584 // required to parse. This avoids trying to crowdsource forms with few text
575 // or select elements. 585 // or select elements.
576 if ((field_count() - checkable_field_count()) < kRequiredFillableFields) 586 if ((field_count() - checkable_field_count()) < kRequiredFillableFields)
577 return false; 587 return false;
578 588
579 // Rule out http(s)://*/search?... 589 // Rule out http(s)://*/search?...
580 // e.g. http://www.google.com/search?q=... 590 // e.g. http://www.google.com/search?q=...
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 buzz::XmlElement *field_element = new buzz::XmlElement( 931 buzz::XmlElement *field_element = new buzz::XmlElement(
922 buzz::QName(kXMLElementField)); 932 buzz::QName(kXMLElementField));
923 933
924 field_element->SetAttr(buzz::QName(kAttributeSignature), 934 field_element->SetAttr(buzz::QName(kAttributeSignature),
925 field->FieldSignature()); 935 field->FieldSignature());
926 field_element->SetAttr(buzz::QName(kAttributeAutofillType), 936 field_element->SetAttr(buzz::QName(kAttributeAutofillType),
927 base::IntToString(*field_type)); 937 base::IntToString(*field_type));
928 encompassing_xml_element->AddElement(field_element); 938 encompassing_xml_element->AddElement(field_element);
929 } 939 }
930 } else { 940 } else {
931 // Skip putting checkable fields in the request if the flag is not set. 941 // Skip putting checkable fields in the request if autocheckout is not
932 if (field->is_checkable && !experimental_form_filling_enabled_) 942 // enabled.
943 if (field->is_checkable && !autocheckout_enabled_)
933 continue; 944 continue;
934 945
935 buzz::XmlElement *field_element = new buzz::XmlElement( 946 buzz::XmlElement *field_element = new buzz::XmlElement(
936 buzz::QName(kXMLElementField)); 947 buzz::QName(kXMLElementField));
937 field_element->SetAttr(buzz::QName(kAttributeSignature), 948 field_element->SetAttr(buzz::QName(kAttributeSignature),
938 field->FieldSignature()); 949 field->FieldSignature());
939 encompassing_xml_element->AddElement(field_element); 950 encompassing_xml_element->AddElement(field_element);
940 } 951 }
941 } 952 }
942 return true; 953 return true;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1113 for (std::vector<AutofillField*>::iterator field = fields_.begin(); 1124 for (std::vector<AutofillField*>::iterator field = fields_.begin();
1114 field != fields_.end(); ++field) { 1125 field != fields_.end(); ++field) {
1115 AutofillType::FieldTypeGroup field_type_group = 1126 AutofillType::FieldTypeGroup field_type_group =
1116 AutofillType((*field)->type()).group(); 1127 AutofillType((*field)->type()).group();
1117 if (field_type_group == AutofillType::CREDIT_CARD) 1128 if (field_type_group == AutofillType::CREDIT_CARD)
1118 (*field)->set_section((*field)->section() + "-cc"); 1129 (*field)->set_section((*field)->section() + "-cc");
1119 else 1130 else
1120 (*field)->set_section((*field)->section() + "-default"); 1131 (*field)->set_section((*field)->section() + "-default");
1121 } 1132 }
1122 } 1133 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698