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 "components/autofill/browser/form_structure.h" | 5 #include "components/autofill/browser/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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 } | 226 } |
227 | 227 |
228 } // namespace | 228 } // namespace |
229 | 229 |
230 FormStructure::FormStructure(const FormData& form, | 230 FormStructure::FormStructure(const FormData& form, |
231 const std::string& autocheckout_url_prefix) | 231 const std::string& autocheckout_url_prefix) |
232 : form_name_(form.name), | 232 : form_name_(form.name), |
233 source_url_(form.origin), | 233 source_url_(form.origin), |
234 target_url_(form.action), | 234 target_url_(form.action), |
235 autofill_count_(0), | 235 autofill_count_(0), |
236 checkable_field_count_(0), | 236 active_field_count_(0), |
237 upload_required_(USE_UPLOAD_RATES), | 237 upload_required_(USE_UPLOAD_RATES), |
238 server_experiment_id_("no server response"), | 238 server_experiment_id_("no server response"), |
239 has_author_specified_types_(false), | 239 has_author_specified_types_(false), |
240 autocheckout_url_prefix_(autocheckout_url_prefix) { | 240 autocheckout_url_prefix_(autocheckout_url_prefix) { |
241 // Copy the form fields. | 241 // Copy the form fields. |
242 std::map<string16, size_t> unique_names; | 242 std::map<string16, size_t> unique_names; |
243 for (std::vector<FormFieldData>::const_iterator field = | 243 for (std::vector<FormFieldData>::const_iterator field = |
244 form.fields.begin(); | 244 form.fields.begin(); |
245 field != form.fields.end(); field++) { | 245 field != form.fields.end(); field++) { |
246 | 246 |
247 // Skipping checkable elements when Autocheckout is not enabled, else | 247 // Skip checkable and password elements when Autocheckout is not enabled, |
248 // these fields will interfere with existing field signatures with Autofill | 248 // else these fields will interfere with existing field signatures with |
249 // servers. | 249 // Autofill servers. |
250 if (!field->is_checkable || IsAutocheckoutEnabled()) { | 250 if ((!field->is_checkable && field->form_control_type != "password") || |
| 251 IsAutocheckoutEnabled()) { |
251 // Add all supported form fields (including with empty names) to the | 252 // Add all supported form fields (including with empty names) to the |
252 // signature. This is a requirement for Autofill servers. | 253 // signature. This is a requirement for Autofill servers. |
253 form_signature_field_names_.append("&"); | 254 form_signature_field_names_.append("&"); |
254 form_signature_field_names_.append(UTF16ToUTF8(field->name)); | 255 form_signature_field_names_.append(UTF16ToUTF8(field->name)); |
| 256 |
| 257 ++active_field_count_; |
255 } | 258 } |
256 | 259 |
257 // Generate a unique name for this field by appending a counter to the name. | 260 // Generate a unique name for this field by appending a counter to the name. |
258 // Make sure to prepend the counter with a non-numeric digit so that we are | 261 // Make sure to prepend the counter with a non-numeric digit so that we are |
259 // guaranteed to avoid collisions. | 262 // guaranteed to avoid collisions. |
260 if (!unique_names.count(field->name)) | 263 if (!unique_names.count(field->name)) |
261 unique_names[field->name] = 1; | 264 unique_names[field->name] = 1; |
262 else | 265 else |
263 ++unique_names[field->name]; | 266 ++unique_names[field->name]; |
264 string16 unique_name = field->name + ASCIIToUTF16("_") + | 267 string16 unique_name = field->name + ASCIIToUTF16("_") + |
265 base::IntToString16(unique_names[field->name]); | 268 base::IntToString16(unique_names[field->name]); |
266 fields_.push_back(new AutofillField(*field, unique_name)); | 269 fields_.push_back(new AutofillField(*field, unique_name)); |
267 | |
268 if (field->is_checkable) | |
269 ++checkable_field_count_; | |
270 } | 270 } |
271 | 271 |
272 std::string method = UTF16ToUTF8(form.method); | 272 std::string method = UTF16ToUTF8(form.method); |
273 if (StringToLowerASCII(method) == kFormMethodPost) { | 273 if (StringToLowerASCII(method) == kFormMethodPost) { |
274 method_ = POST; | 274 method_ = POST; |
275 } else { | 275 } else { |
276 // Either the method is 'get', or we don't know. In this case we default | 276 // Either the method is 'get', or we don't know. In this case we default |
277 // to GET. | 277 // to GET. |
278 method_ = GET; | 278 method_ = GET; |
279 } | 279 } |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
602 autofill_count_ = 0; | 602 autofill_count_ = 0; |
603 for (std::vector<AutofillField*>::const_iterator iter = begin(); | 603 for (std::vector<AutofillField*>::const_iterator iter = begin(); |
604 iter != end(); ++iter) { | 604 iter != end(); ++iter) { |
605 AutofillField* field = *iter; | 605 AutofillField* field = *iter; |
606 if (field && field->IsFieldFillable()) | 606 if (field && field->IsFieldFillable()) |
607 ++autofill_count_; | 607 ++autofill_count_; |
608 } | 608 } |
609 } | 609 } |
610 | 610 |
611 bool FormStructure::ShouldBeParsed(bool require_method_post) const { | 611 bool FormStructure::ShouldBeParsed(bool require_method_post) const { |
612 // Ignore counting checkable elements towards minimum number of elements | 612 if (active_field_count() < RequiredFillableFields()) |
613 // required to parse. This avoids trying to crowdsource forms with few text | |
614 // or select elements. | |
615 if ((field_count() - checkable_field_count()) < RequiredFillableFields()) | |
616 return false; | 613 return false; |
617 | 614 |
618 // Rule out http(s)://*/search?... | 615 // Rule out http(s)://*/search?... |
619 // e.g. http://www.google.com/search?q=... | 616 // e.g. http://www.google.com/search?q=... |
620 // http://search.yahoo.com/search?p=... | 617 // http://search.yahoo.com/search?p=... |
621 if (target_url_.path() == "/search") | 618 if (target_url_.path() == "/search") |
622 return false; | 619 return false; |
623 | 620 |
624 if (!IsAutocheckoutEnabled()) { | 621 if (!IsAutocheckoutEnabled()) { |
625 // Make sure there is at least one text field when Autocheckout is | 622 // Make sure there is at least one text field when Autocheckout is |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 | 867 |
871 AutofillField* FormStructure::field(size_t index) { | 868 AutofillField* FormStructure::field(size_t index) { |
872 return const_cast<AutofillField*>( | 869 return const_cast<AutofillField*>( |
873 static_cast<const FormStructure*>(this)->field(index)); | 870 static_cast<const FormStructure*>(this)->field(index)); |
874 } | 871 } |
875 | 872 |
876 size_t FormStructure::field_count() const { | 873 size_t FormStructure::field_count() const { |
877 return fields_.size(); | 874 return fields_.size(); |
878 } | 875 } |
879 | 876 |
880 size_t FormStructure::checkable_field_count() const { | 877 size_t FormStructure::active_field_count() const { |
881 return checkable_field_count_; | 878 return active_field_count_; |
882 } | 879 } |
883 | 880 |
884 std::string FormStructure::server_experiment_id() const { | 881 std::string FormStructure::server_experiment_id() const { |
885 return server_experiment_id_; | 882 return server_experiment_id_; |
886 } | 883 } |
887 | 884 |
888 FormData FormStructure::ToFormData() const { | 885 FormData FormStructure::ToFormData() const { |
889 // |data.user_submitted| will always be false. | 886 // |data.user_submitted| will always be false. |
890 FormData data; | 887 FormData data; |
891 data.name = form_name_; | 888 data.name = form_name_; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 buzz::XmlElement *field_element = new buzz::XmlElement( | 960 buzz::XmlElement *field_element = new buzz::XmlElement( |
964 buzz::QName(kXMLElementField)); | 961 buzz::QName(kXMLElementField)); |
965 | 962 |
966 field_element->SetAttr(buzz::QName(kAttributeSignature), | 963 field_element->SetAttr(buzz::QName(kAttributeSignature), |
967 field->FieldSignature()); | 964 field->FieldSignature()); |
968 field_element->SetAttr(buzz::QName(kAttributeAutofillType), | 965 field_element->SetAttr(buzz::QName(kAttributeAutofillType), |
969 base::IntToString(*field_type)); | 966 base::IntToString(*field_type)); |
970 encompassing_xml_element->AddElement(field_element); | 967 encompassing_xml_element->AddElement(field_element); |
971 } | 968 } |
972 } else { | 969 } else { |
973 // Skip putting checkable fields in the request if Autocheckout is not | 970 // Skip putting checkable and password fields in the request if |
974 // enabled. | 971 // Autocheckout is not enabled. |
975 if (field->is_checkable && !IsAutocheckoutEnabled()) | 972 if ((field->is_checkable || field->form_control_type == "password") && |
| 973 !IsAutocheckoutEnabled()) |
976 continue; | 974 continue; |
977 | 975 |
978 buzz::XmlElement *field_element = new buzz::XmlElement( | 976 buzz::XmlElement *field_element = new buzz::XmlElement( |
979 buzz::QName(kXMLElementField)); | 977 buzz::QName(kXMLElementField)); |
980 field_element->SetAttr(buzz::QName(kAttributeSignature), | 978 field_element->SetAttr(buzz::QName(kAttributeSignature), |
981 field->FieldSignature()); | 979 field->FieldSignature()); |
982 encompassing_xml_element->AddElement(field_element); | 980 encompassing_xml_element->AddElement(field_element); |
983 } | 981 } |
984 } | 982 } |
985 return true; | 983 return true; |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1148 for (std::vector<AutofillField*>::iterator field = fields_.begin(); | 1146 for (std::vector<AutofillField*>::iterator field = fields_.begin(); |
1149 field != fields_.end(); ++field) { | 1147 field != fields_.end(); ++field) { |
1150 AutofillType::FieldTypeGroup field_type_group = | 1148 AutofillType::FieldTypeGroup field_type_group = |
1151 AutofillType((*field)->type()).group(); | 1149 AutofillType((*field)->type()).group(); |
1152 if (field_type_group == AutofillType::CREDIT_CARD) | 1150 if (field_type_group == AutofillType::CREDIT_CARD) |
1153 (*field)->set_section((*field)->section() + "-cc"); | 1151 (*field)->set_section((*field)->section() + "-cc"); |
1154 else | 1152 else |
1155 (*field)->set_section((*field)->section() + "-default"); | 1153 (*field)->set_section((*field)->section() + "-default"); |
1156 } | 1154 } |
1157 } | 1155 } |
OLD | NEW |