diff options
| author | Ben Murdoch <benm@google.com> | 2010-11-18 18:32:45 +0000 |
|---|---|---|
| committer | Ben Murdoch <benm@google.com> | 2010-11-18 18:38:07 +0000 |
| commit | 513209b27ff55e2841eac0e4120199c23acce758 (patch) | |
| tree | aeba30bb08c5f47c57003544e378a377c297eee6 /chrome/browser/autofill/form_structure.cc | |
| parent | 164f7496de0fbee436b385a79ead9e3cb81a50c1 (diff) | |
| download | external_chromium-513209b27ff55e2841eac0e4120199c23acce758.zip external_chromium-513209b27ff55e2841eac0e4120199c23acce758.tar.gz external_chromium-513209b27ff55e2841eac0e4120199c23acce758.tar.bz2 | |
Merge Chromium at r65505: Initial merge by git.
Change-Id: I31d8f1d8cd33caaf7f47ffa7350aef42d5fbdb45
Diffstat (limited to 'chrome/browser/autofill/form_structure.cc')
| -rw-r--r-- | chrome/browser/autofill/form_structure.cc | 46 |
1 files changed, 38 insertions, 8 deletions
diff --git a/chrome/browser/autofill/form_structure.cc b/chrome/browser/autofill/form_structure.cc index 299c58b..d9ff45b 100644 --- a/chrome/browser/autofill/form_structure.cc +++ b/chrome/browser/autofill/form_structure.cc @@ -115,6 +115,8 @@ FormStructure::~FormStructure() {} bool FormStructure::EncodeUploadRequest(bool auto_fill_used, std::string* encoded_xml) const { + DCHECK(encoded_xml); + encoded_xml->clear(); bool auto_fillable = IsAutoFillable(); DCHECK(auto_fillable); // Caller should've checked for search pages. if (!auto_fillable) @@ -139,7 +141,8 @@ bool FormStructure::EncodeUploadRequest(bool auto_fill_used, // personaldata_manager_->GetDataPresent(); autofil_request_xml.SetAttr(buzz::QName(kAttributeDataPresent), ""); - EncodeFormRequest(FormStructure::UPLOAD, &autofil_request_xml); + if (!EncodeFormRequest(FormStructure::UPLOAD, &autofil_request_xml)) + return false; // Malformed form, skip it. // Obtain the XML structure as a string. *encoded_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; @@ -150,7 +153,13 @@ bool FormStructure::EncodeUploadRequest(bool auto_fill_used, // static bool FormStructure::EncodeQueryRequest(const ScopedVector<FormStructure>& forms, - std::string* encoded_xml) { + std::vector<std::string>* encoded_signatures, + std::string* encoded_xml) { + DCHECK(encoded_signatures); + DCHECK(encoded_xml); + encoded_xml->clear(); + encoded_signatures->clear(); + encoded_signatures->reserve(forms.size()); buzz::XmlElement autofil_request_xml(buzz::QName("autofillquery")); // Attributes for the <autofillquery> element. // @@ -158,19 +167,32 @@ bool FormStructure::EncodeQueryRequest(const ScopedVector<FormStructure>& forms, // For now these values are hacked from the toolbar code. autofil_request_xml.SetAttr(buzz::QName(kAttributeClientVersion), "6.1.1715.1442/en (GGLL)"); + // Some badly formatted web sites repeat forms - detect that and encode only + // one form as returned data would be the same for all the repeated forms. + std::set<std::string> processed_forms; for (ScopedVector<FormStructure>::const_iterator it = forms.begin(); it != forms.end(); ++it) { - buzz::XmlElement* encompassing_xml_element = - new buzz::XmlElement(buzz::QName("form")); + std::string signature((*it)->FormSignature()); + if (processed_forms.find(signature) != processed_forms.end()) + continue; + processed_forms.insert(signature); + scoped_ptr<buzz::XmlElement> encompassing_xml_element( + new buzz::XmlElement(buzz::QName("form"))); encompassing_xml_element->SetAttr(buzz::QName(kAttributeSignature), - (*it)->FormSignature()); + signature); - (*it)->EncodeFormRequest(FormStructure::QUERY, encompassing_xml_element); + if (!(*it)->EncodeFormRequest(FormStructure::QUERY, + encompassing_xml_element.get())) + continue; // Malformed form, skip it. - autofil_request_xml.AddElement(encompassing_xml_element); + autofil_request_xml.AddElement(encompassing_xml_element.release()); + encoded_signatures->push_back(signature); } + if (!encoded_signatures->size()) + return false; + // Obtain the XML structure as a string. *encoded_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; *encoded_xml += autofil_request_xml.Str().c_str(); @@ -402,8 +424,16 @@ bool FormStructure::EncodeFormRequest( buzz::XmlElement* encompassing_xml_element) const { if (!field_count()) // Nothing to add. return false; + // Some badly formatted web sites repeat fields - limit number of fields to + // 48, which is far larger than any valid form and XML still fits into 2K. + const size_t kMaxFieldsOnTheForm = 48; + if (field_count() > kMaxFieldsOnTheForm) { + // This is not a valid form, most certainly. Do not send request for the + // wrongly formatted forms. + return false; + } // Add the child nodes for the form fields. - for (size_t index = 0; index < field_count(); index++) { + for (size_t index = 0; index < field_count(); ++index) { const AutoFillField* field = fields_[index]; if (request_type == FormStructure::UPLOAD) { FieldTypeSet types = field->possible_types(); |
