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 22 matching lines...) Expand all Loading... | |
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 kAttributeUrlprefixSignature[] = "urlprefixsignature"; |
44 const char kAcceptedFeaturesExperiment[] = "e"; // e=experiments | |
45 const char kAcceptedFeaturesAutocheckoutExperiment[] = "a,e"; // 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 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 DCHECK(encoded_xml); | 371 DCHECK(encoded_xml); |
370 encoded_xml->clear(); | 372 encoded_xml->clear(); |
371 encoded_signatures->clear(); | 373 encoded_signatures->clear(); |
372 encoded_signatures->reserve(forms.size()); | 374 encoded_signatures->reserve(forms.size()); |
373 | 375 |
374 // Set up the <autofillquery> element and attributes. | 376 // Set up the <autofillquery> element and attributes. |
375 buzz::XmlElement autofill_request_xml( | 377 buzz::XmlElement autofill_request_xml( |
376 (buzz::QName(kXMLElementAutofillQuery))); | 378 (buzz::QName(kXMLElementAutofillQuery))); |
377 autofill_request_xml.SetAttr(buzz::QName(kAttributeClientVersion), | 379 autofill_request_xml.SetAttr(buzz::QName(kAttributeClientVersion), |
378 kClientVersion); | 380 kClientVersion); |
379 autofill_request_xml.SetAttr(buzz::QName(kAttributeAcceptedFeatures), | 381 |
380 kAcceptedFeatures); | 382 // autocheckout_url_prefix tells autofillserver where the forms in the request |
Ilya Sherman
2013/01/31 05:03:28
nit: "tells autofillserver" -> "tells the Autofill
benquan
2013/02/01 02:55:04
Done.
| |
383 // came from, and the autofillserver checks internal status and decide to | |
384 // enable autocheckout or not and may return autocheckout related data in the | |
385 // response accordingly. | |
386 // There is no page/frame level object associated with FormStructure that | |
387 // we could extract URL prefix from. But, all the forms should come from the | |
388 // same frame, so they should have the same autocheckout URL prefix. Thus we | |
389 // use URL prefix from the first form with autocheckout enabled. | |
390 std::string autocheckout_url_prefix; | |
391 | |
392 // Strip the query string from the URL as it may contain PII info. | |
393 GURL::Replacements replacements; | |
394 replacements.ClearQuery(); | |
Ilya Sherman
2013/01/31 05:03:28
nit: Remove these; they don't seem to be used.
benquan
2013/02/01 02:55:04
Done.
| |
381 | 395 |
382 // Some badly formatted web sites repeat forms - detect that and encode only | 396 // Some badly formatted web sites repeat forms - detect that and encode only |
383 // one form as returned data would be the same for all the repeated forms. | 397 // one form as returned data would be the same for all the repeated forms. |
384 std::set<std::string> processed_forms; | 398 std::set<std::string> processed_forms; |
385 for (ScopedVector<FormStructure>::const_iterator it = forms.begin(); | 399 for (ScopedVector<FormStructure>::const_iterator it = forms.begin(); |
386 it != forms.end(); | 400 it != forms.end(); |
387 ++it) { | 401 ++it) { |
388 std::string signature((*it)->FormSignature()); | 402 std::string signature((*it)->FormSignature()); |
389 if (processed_forms.find(signature) != processed_forms.end()) | 403 if (processed_forms.find(signature) != processed_forms.end()) |
390 continue; | 404 continue; |
391 processed_forms.insert(signature); | 405 processed_forms.insert(signature); |
392 scoped_ptr<buzz::XmlElement> encompassing_xml_element( | 406 scoped_ptr<buzz::XmlElement> encompassing_xml_element( |
393 new buzz::XmlElement(buzz::QName(kXMLElementForm))); | 407 new buzz::XmlElement(buzz::QName(kXMLElementForm))); |
394 encompassing_xml_element->SetAttr(buzz::QName(kAttributeSignature), | 408 encompassing_xml_element->SetAttr(buzz::QName(kAttributeSignature), |
395 signature); | 409 signature); |
396 | 410 |
397 if (!(*it)->EncodeFormRequest(FormStructure::QUERY, | 411 if (!(*it)->EncodeFormRequest(FormStructure::QUERY, |
398 encompassing_xml_element.get())) | 412 encompassing_xml_element.get())) |
399 continue; // Malformed form, skip it. | 413 continue; // Malformed form, skip it. |
400 | 414 |
415 if ((*it)->IsAutocheckoutEnabled()) { | |
416 if (autocheckout_url_prefix.empty()) { | |
417 autocheckout_url_prefix = (*it)->autocheckout_url_prefix_; | |
418 } else { | |
419 // Making sure all the forms in the request has the same url_prefix. | |
420 DCHECK_EQ(autocheckout_url_prefix, (*it)->autocheckout_url_prefix_); | |
421 } | |
422 } | |
423 | |
401 autofill_request_xml.AddElement(encompassing_xml_element.release()); | 424 autofill_request_xml.AddElement(encompassing_xml_element.release()); |
402 encoded_signatures->push_back(signature); | 425 encoded_signatures->push_back(signature); |
403 } | 426 } |
404 | 427 |
405 if (!encoded_signatures->size()) | 428 if (!encoded_signatures->size()) |
406 return false; | 429 return false; |
407 | 430 |
431 if (autocheckout_url_prefix.empty()) { | |
432 autofill_request_xml.SetAttr(buzz::QName(kAttributeAcceptedFeatures), | |
433 kAcceptedFeaturesExperiment); | |
434 } else { | |
435 autofill_request_xml.SetAttr(buzz::QName(kAttributeAcceptedFeatures), | |
436 kAcceptedFeaturesAutocheckoutExperiment); | |
437 autofill_request_xml.SetAttr(buzz::QName(kAttributeUrlprefixSignature), | |
438 Hash64Bit(autocheckout_url_prefix)); | |
439 } | |
440 | |
408 // Obtain the XML structure as a string. | 441 // Obtain the XML structure as a string. |
409 *encoded_xml = kXMLDeclaration; | 442 *encoded_xml = kXMLDeclaration; |
410 *encoded_xml += autofill_request_xml.Str().c_str(); | 443 *encoded_xml += autofill_request_xml.Str().c_str(); |
411 | 444 |
412 return true; | 445 return true; |
413 } | 446 } |
414 | 447 |
415 // static | 448 // static |
416 void FormStructure::ParseQueryResponse(const std::string& response_xml, | 449 void FormStructure::ParseQueryResponse(const std::string& response_xml, |
417 const std::vector<FormStructure*>& forms, | 450 const std::vector<FormStructure*>& forms, |
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1116 for (std::vector<AutofillField*>::iterator field = fields_.begin(); | 1149 for (std::vector<AutofillField*>::iterator field = fields_.begin(); |
1117 field != fields_.end(); ++field) { | 1150 field != fields_.end(); ++field) { |
1118 AutofillType::FieldTypeGroup field_type_group = | 1151 AutofillType::FieldTypeGroup field_type_group = |
1119 AutofillType((*field)->type()).group(); | 1152 AutofillType((*field)->type()).group(); |
1120 if (field_type_group == AutofillType::CREDIT_CARD) | 1153 if (field_type_group == AutofillType::CREDIT_CARD) |
1121 (*field)->set_section((*field)->section() + "-cc"); | 1154 (*field)->set_section((*field)->section() + "-cc"); |
1122 else | 1155 else |
1123 (*field)->set_section((*field)->section() + "-default"); | 1156 (*field)->set_section((*field)->section() + "-default"); |
1124 } | 1157 } |
1125 } | 1158 } |
OLD | NEW |