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

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

Issue 12089035: add experiment support and add urlprefix for autocheckout. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
« no previous file with comments | « no previous file | chrome/browser/autofill/form_structure_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 22 matching lines...) Expand all
33 const char kFormMethodPost[] = "post"; 33 const char kFormMethodPost[] = "post";
34 34
35 // XML elements and attributes. 35 // XML elements and attributes.
36 const char kAttributeAcceptedFeatures[] = "accepts"; 36 const char kAttributeAcceptedFeatures[] = "accepts";
37 const char kAttributeAutofillUsed[] = "autofillused"; 37 const char kAttributeAutofillUsed[] = "autofillused";
38 const char kAttributeAutofillType[] = "autofilltype"; 38 const char kAttributeAutofillType[] = "autofilltype";
39 const char kAttributeClientVersion[] = "clientversion"; 39 const char kAttributeClientVersion[] = "clientversion";
40 const char kAttributeDataPresent[] = "datapresent"; 40 const char kAttributeDataPresent[] = "datapresent";
41 const char kAttributeFormSignature[] = "formsignature"; 41 const char kAttributeFormSignature[] = "formsignature";
42 const char kAttributeSignature[] = "signature"; 42 const char kAttributeSignature[] = "signature";
43 const char kAcceptedFeatures[] = "e"; // e=experiments 43 const char kAttributeUrlprefix[] = "urlprefix";
44 const char kAcceptedFeatureExperiment[] = "e"; // e=experiments
45 const char kAcceptedFeatureAutocheckout[] = "a"; // a=autocheckout
44 const char kClientVersion[] = "6.1.1715.1442/en (GGLL)"; 46 const char kClientVersion[] = "6.1.1715.1442/en (GGLL)";
45 const char kXMLDeclaration[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; 47 const char kXMLDeclaration[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
46 const char kXMLElementAutofillQuery[] = "autofillquery"; 48 const char kXMLElementAutofillQuery[] = "autofillquery";
47 const char kXMLElementAutofillUpload[] = "autofillupload"; 49 const char kXMLElementAutofillUpload[] = "autofillupload";
48 const char kXMLElementForm[] = "form"; 50 const char kXMLElementForm[] = "form";
49 const char kXMLElementField[] = "field"; 51 const char kXMLElementField[] = "field";
50 52
51 // The number of fillable fields necessary for a form to be fillable. 53 // The number of fillable fields necessary for a form to be fillable.
52 const size_t kRequiredFillableFields = 3; 54 const size_t kRequiredFillableFields = 3;
53 55
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 DCHECK(encoded_xml); 370 DCHECK(encoded_xml);
369 encoded_xml->clear(); 371 encoded_xml->clear();
370 encoded_signatures->clear(); 372 encoded_signatures->clear();
371 encoded_signatures->reserve(forms.size()); 373 encoded_signatures->reserve(forms.size());
372 374
373 // Set up the <autofillquery> element and attributes. 375 // Set up the <autofillquery> element and attributes.
374 buzz::XmlElement autofill_request_xml( 376 buzz::XmlElement autofill_request_xml(
375 (buzz::QName(kXMLElementAutofillQuery))); 377 (buzz::QName(kXMLElementAutofillQuery)));
376 autofill_request_xml.SetAttr(buzz::QName(kAttributeClientVersion), 378 autofill_request_xml.SetAttr(buzz::QName(kAttributeClientVersion),
377 kClientVersion); 379 kClientVersion);
378 autofill_request_xml.SetAttr(buzz::QName(kAttributeAcceptedFeatures),
379 kAcceptedFeatures);
380 380
381 std::string autocheckout_urlprefix;
381 // Some badly formatted web sites repeat forms - detect that and encode only 382 // Some badly formatted web sites repeat forms - detect that and encode only
382 // one form as returned data would be the same for all the repeated forms. 383 // one form as returned data would be the same for all the repeated forms.
383 std::set<std::string> processed_forms; 384 std::set<std::string> processed_forms;
384 for (ScopedVector<FormStructure>::const_iterator it = forms.begin(); 385 for (ScopedVector<FormStructure>::const_iterator it = forms.begin();
385 it != forms.end(); 386 it != forms.end();
386 ++it) { 387 ++it) {
387 std::string signature((*it)->FormSignature()); 388 std::string signature((*it)->FormSignature());
388 if (processed_forms.find(signature) != processed_forms.end()) 389 if (processed_forms.find(signature) != processed_forms.end())
389 continue; 390 continue;
390 processed_forms.insert(signature); 391 processed_forms.insert(signature);
391 scoped_ptr<buzz::XmlElement> encompassing_xml_element( 392 scoped_ptr<buzz::XmlElement> encompassing_xml_element(
392 new buzz::XmlElement(buzz::QName(kXMLElementForm))); 393 new buzz::XmlElement(buzz::QName(kXMLElementForm)));
393 encompassing_xml_element->SetAttr(buzz::QName(kAttributeSignature), 394 encompassing_xml_element->SetAttr(buzz::QName(kAttributeSignature),
394 signature); 395 signature);
395 396
396 if (!(*it)->EncodeFormRequest(FormStructure::QUERY, 397 if (!(*it)->EncodeFormRequest(FormStructure::QUERY,
397 encompassing_xml_element.get())) 398 encompassing_xml_element.get()))
398 continue; // Malformed form, skip it. 399 continue; // Malformed form, skip it.
399 400
401 if ((*it)->autocheckout_enabled_ && autocheckout_urlprefix.empty()) {
402 GURL::Replacements replacements;
403 replacements.ClearQuery();
404 autocheckout_urlprefix = (*it)->source_url()
405 .ReplaceComponents(replacements).spec();
406 }
407
400 autofill_request_xml.AddElement(encompassing_xml_element.release()); 408 autofill_request_xml.AddElement(encompassing_xml_element.release());
401 encoded_signatures->push_back(signature); 409 encoded_signatures->push_back(signature);
402 } 410 }
403 411
404 if (!encoded_signatures->size()) 412 if (!encoded_signatures->size())
405 return false; 413 return false;
406 414
415 if (autocheckout_urlprefix.empty()) {
416 autofill_request_xml.SetAttr(buzz::QName(kAttributeAcceptedFeatures),
417 kAcceptedFeatureExperiment);
418 } else {
419 autofill_request_xml.SetAttr(buzz::QName(kAttributeAcceptedFeatures),
420 kAcceptedFeatureAutocheckout);
421 autofill_request_xml.SetAttr(buzz::QName(kAttributeUrlprefix),
422 autocheckout_urlprefix);
423 }
424
407 // Obtain the XML structure as a string. 425 // Obtain the XML structure as a string.
408 *encoded_xml = kXMLDeclaration; 426 *encoded_xml = kXMLDeclaration;
409 *encoded_xml += autofill_request_xml.Str().c_str(); 427 *encoded_xml += autofill_request_xml.Str().c_str();
410 428
411 return true; 429 return true;
412 } 430 }
413 431
414 // static 432 // static
415 void FormStructure::ParseQueryResponse(const std::string& response_xml, 433 void FormStructure::ParseQueryResponse(const std::string& response_xml,
416 const std::vector<FormStructure*>& forms, 434 const std::vector<FormStructure*>& forms,
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 for (std::vector<AutofillField*>::iterator field = fields_.begin(); 1129 for (std::vector<AutofillField*>::iterator field = fields_.begin();
1112 field != fields_.end(); ++field) { 1130 field != fields_.end(); ++field) {
1113 AutofillType::FieldTypeGroup field_type_group = 1131 AutofillType::FieldTypeGroup field_type_group =
1114 AutofillType((*field)->type()).group(); 1132 AutofillType((*field)->type()).group();
1115 if (field_type_group == AutofillType::CREDIT_CARD) 1133 if (field_type_group == AutofillType::CREDIT_CARD)
1116 (*field)->set_section((*field)->section() + "-cc"); 1134 (*field)->set_section((*field)->section() + "-cc");
1117 else 1135 else
1118 (*field)->set_section((*field)->section() + "-default"); 1136 (*field)->set_section((*field)->section() + "-default");
1119 } 1137 }
1120 } 1138 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autofill/form_structure_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698