| 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 23 matching lines...) Expand all Loading... |
| 34 const char kFormMethodPost[] = "post"; | 34 const char kFormMethodPost[] = "post"; |
| 35 | 35 |
| 36 // XML elements and attributes. | 36 // XML elements and attributes. |
| 37 const char kAttributeAcceptedFeatures[] = "accepts"; | 37 const char kAttributeAcceptedFeatures[] = "accepts"; |
| 38 const char kAttributeAutofillUsed[] = "autofillused"; | 38 const char kAttributeAutofillUsed[] = "autofillused"; |
| 39 const char kAttributeAutofillType[] = "autofilltype"; | 39 const char kAttributeAutofillType[] = "autofilltype"; |
| 40 const char kAttributeClientVersion[] = "clientversion"; | 40 const char kAttributeClientVersion[] = "clientversion"; |
| 41 const char kAttributeDataPresent[] = "datapresent"; | 41 const char kAttributeDataPresent[] = "datapresent"; |
| 42 const char kAttributeFormSignature[] = "formsignature"; | 42 const char kAttributeFormSignature[] = "formsignature"; |
| 43 const char kAttributeSignature[] = "signature"; | 43 const char kAttributeSignature[] = "signature"; |
| 44 const char kAcceptedFeatures[] = "e"; // e=experiments | 44 const char kAttributeUrlprefixSignature[] = "urlprefixsignature"; |
| 45 const char kAcceptedFeaturesExperiment[] = "e"; // e=experiments |
| 46 const char kAcceptedFeaturesAutocheckoutExperiment[] = "a,e"; // a=autocheckout |
| 45 const char kClientVersion[] = "6.1.1715.1442/en (GGLL)"; | 47 const char kClientVersion[] = "6.1.1715.1442/en (GGLL)"; |
| 46 const char kXMLDeclaration[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; | 48 const char kXMLDeclaration[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; |
| 47 const char kXMLElementAutofillQuery[] = "autofillquery"; | 49 const char kXMLElementAutofillQuery[] = "autofillquery"; |
| 48 const char kXMLElementAutofillUpload[] = "autofillupload"; | 50 const char kXMLElementAutofillUpload[] = "autofillupload"; |
| 49 const char kXMLElementForm[] = "form"; | 51 const char kXMLElementForm[] = "form"; |
| 50 const char kXMLElementField[] = "field"; | 52 const char kXMLElementField[] = "field"; |
| 51 | 53 |
| 52 // The number of fillable fields necessary for a form to be fillable. | 54 // The number of fillable fields necessary for a form to be fillable. |
| 53 const size_t kRequiredFillableFields = 3; | 55 const size_t kRequiredFillableFields = 3; |
| 54 | 56 |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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), | 380 |
| 379 kAcceptedFeatures); | 381 // autocheckout_url_prefix tells the Autofill server where the forms in the |
| 382 // request came from, and the the Autofill server checks internal status and |
| 383 // decide to enable autocheckout or not and may return autocheckout related |
| 384 // data in the response accordingly. |
| 385 // There is no page/frame level object associated with FormStructure that |
| 386 // we could extract URL prefix from. But, all the forms should come from the |
| 387 // same frame, so they should have the same autocheckout URL prefix. Thus we |
| 388 // use URL prefix from the first form with autocheckout enabled. |
| 389 std::string autocheckout_url_prefix; |
| 380 | 390 |
| 381 // Some badly formatted web sites repeat forms - detect that and encode only | 391 // 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. | 392 // one form as returned data would be the same for all the repeated forms. |
| 383 std::set<std::string> processed_forms; | 393 std::set<std::string> processed_forms; |
| 384 for (ScopedVector<FormStructure>::const_iterator it = forms.begin(); | 394 for (ScopedVector<FormStructure>::const_iterator it = forms.begin(); |
| 385 it != forms.end(); | 395 it != forms.end(); |
| 386 ++it) { | 396 ++it) { |
| 387 std::string signature((*it)->FormSignature()); | 397 std::string signature((*it)->FormSignature()); |
| 388 if (processed_forms.find(signature) != processed_forms.end()) | 398 if (processed_forms.find(signature) != processed_forms.end()) |
| 389 continue; | 399 continue; |
| 390 processed_forms.insert(signature); | 400 processed_forms.insert(signature); |
| 391 scoped_ptr<buzz::XmlElement> encompassing_xml_element( | 401 scoped_ptr<buzz::XmlElement> encompassing_xml_element( |
| 392 new buzz::XmlElement(buzz::QName(kXMLElementForm))); | 402 new buzz::XmlElement(buzz::QName(kXMLElementForm))); |
| 393 encompassing_xml_element->SetAttr(buzz::QName(kAttributeSignature), | 403 encompassing_xml_element->SetAttr(buzz::QName(kAttributeSignature), |
| 394 signature); | 404 signature); |
| 395 | 405 |
| 396 if (!(*it)->EncodeFormRequest(FormStructure::QUERY, | 406 if (!(*it)->EncodeFormRequest(FormStructure::QUERY, |
| 397 encompassing_xml_element.get())) | 407 encompassing_xml_element.get())) |
| 398 continue; // Malformed form, skip it. | 408 continue; // Malformed form, skip it. |
| 399 | 409 |
| 410 if ((*it)->IsAutocheckoutEnabled()) { |
| 411 if (autocheckout_url_prefix.empty()) { |
| 412 autocheckout_url_prefix = (*it)->autocheckout_url_prefix_; |
| 413 } else { |
| 414 // Making sure all the forms in the request has the same url_prefix. |
| 415 DCHECK_EQ(autocheckout_url_prefix, (*it)->autocheckout_url_prefix_); |
| 416 } |
| 417 } |
| 418 |
| 400 autofill_request_xml.AddElement(encompassing_xml_element.release()); | 419 autofill_request_xml.AddElement(encompassing_xml_element.release()); |
| 401 encoded_signatures->push_back(signature); | 420 encoded_signatures->push_back(signature); |
| 402 } | 421 } |
| 403 | 422 |
| 404 if (!encoded_signatures->size()) | 423 if (!encoded_signatures->size()) |
| 405 return false; | 424 return false; |
| 406 | 425 |
| 426 if (autocheckout_url_prefix.empty()) { |
| 427 autofill_request_xml.SetAttr(buzz::QName(kAttributeAcceptedFeatures), |
| 428 kAcceptedFeaturesExperiment); |
| 429 } else { |
| 430 autofill_request_xml.SetAttr(buzz::QName(kAttributeAcceptedFeatures), |
| 431 kAcceptedFeaturesAutocheckoutExperiment); |
| 432 autofill_request_xml.SetAttr(buzz::QName(kAttributeUrlprefixSignature), |
| 433 Hash64Bit(autocheckout_url_prefix)); |
| 434 } |
| 435 |
| 407 // Obtain the XML structure as a string. | 436 // Obtain the XML structure as a string. |
| 408 *encoded_xml = kXMLDeclaration; | 437 *encoded_xml = kXMLDeclaration; |
| 409 *encoded_xml += autofill_request_xml.Str().c_str(); | 438 *encoded_xml += autofill_request_xml.Str().c_str(); |
| 410 | 439 |
| 411 return true; | 440 return true; |
| 412 } | 441 } |
| 413 | 442 |
| 414 // static | 443 // static |
| 415 void FormStructure::ParseQueryResponse( | 444 void FormStructure::ParseQueryResponse( |
| 416 const std::string& response_xml, | 445 const std::string& response_xml, |
| (...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1112 for (std::vector<AutofillField*>::iterator field = fields_.begin(); | 1141 for (std::vector<AutofillField*>::iterator field = fields_.begin(); |
| 1113 field != fields_.end(); ++field) { | 1142 field != fields_.end(); ++field) { |
| 1114 AutofillType::FieldTypeGroup field_type_group = | 1143 AutofillType::FieldTypeGroup field_type_group = |
| 1115 AutofillType((*field)->type()).group(); | 1144 AutofillType((*field)->type()).group(); |
| 1116 if (field_type_group == AutofillType::CREDIT_CARD) | 1145 if (field_type_group == AutofillType::CREDIT_CARD) |
| 1117 (*field)->set_section((*field)->section() + "-cc"); | 1146 (*field)->set_section((*field)->section() + "-cc"); |
| 1118 else | 1147 else |
| 1119 (*field)->set_section((*field)->section() + "-default"); | 1148 (*field)->set_section((*field)->section() + "-default"); |
| 1120 } | 1149 } |
| 1121 } | 1150 } |
| OLD | NEW |