OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/core/browser/form_structure.h" | 5 #include "components/autofill/core/browser/form_structure.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <map> | 10 #include <map> |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 261 |
262 if (autocomplete_attribute_value == "tel-local-suffix") | 262 if (autocomplete_attribute_value == "tel-local-suffix") |
263 return HTML_TYPE_TEL_LOCAL_SUFFIX; | 263 return HTML_TYPE_TEL_LOCAL_SUFFIX; |
264 | 264 |
265 if (autocomplete_attribute_value == "tel-extension") | 265 if (autocomplete_attribute_value == "tel-extension") |
266 return HTML_TYPE_TEL_EXTENSION; | 266 return HTML_TYPE_TEL_EXTENSION; |
267 | 267 |
268 if (autocomplete_attribute_value == "email") | 268 if (autocomplete_attribute_value == "email") |
269 return HTML_TYPE_EMAIL; | 269 return HTML_TYPE_EMAIL; |
270 | 270 |
| 271 if (autocomplete_attribute_value == "upi-vpa") |
| 272 return HTML_TYPE_UPI_VPA; |
| 273 |
271 return HTML_TYPE_UNRECOGNIZED; | 274 return HTML_TYPE_UNRECOGNIZED; |
272 } | 275 } |
273 | 276 |
274 std::ostream& operator<<( | 277 std::ostream& operator<<( |
275 std::ostream& out, | 278 std::ostream& out, |
276 const autofill::AutofillQueryResponseContents& response) { | 279 const autofill::AutofillQueryResponseContents& response) { |
277 out << "upload_required: " << response.upload_required(); | 280 out << "upload_required: " << response.upload_required(); |
278 for (const auto& field : response.field()) { | 281 for (const auto& field : response.field()) { |
279 out << "\nautofill_type: " << field.autofill_type(); | 282 out << "\nautofill_type: " << field.autofill_type(); |
280 } | 283 } |
(...skipping 12 matching lines...) Expand all Loading... |
293 | 296 |
294 FormStructure::FormStructure(const FormData& form) | 297 FormStructure::FormStructure(const FormData& form) |
295 : form_name_(form.name), | 298 : form_name_(form.name), |
296 source_url_(form.origin), | 299 source_url_(form.origin), |
297 target_url_(form.action), | 300 target_url_(form.action), |
298 autofill_count_(0), | 301 autofill_count_(0), |
299 active_field_count_(0), | 302 active_field_count_(0), |
300 upload_required_(USE_UPLOAD_RATES), | 303 upload_required_(USE_UPLOAD_RATES), |
301 has_author_specified_types_(false), | 304 has_author_specified_types_(false), |
302 has_author_specified_sections_(false), | 305 has_author_specified_sections_(false), |
| 306 has_author_specified_upi_vpa_hint_(false), |
303 was_parsed_for_autocomplete_attributes_(false), | 307 was_parsed_for_autocomplete_attributes_(false), |
304 has_password_field_(false), | 308 has_password_field_(false), |
305 is_form_tag_(form.is_form_tag), | 309 is_form_tag_(form.is_form_tag), |
306 is_formless_checkout_(form.is_formless_checkout), | 310 is_formless_checkout_(form.is_formless_checkout), |
307 all_fields_are_passwords_(true) { | 311 all_fields_are_passwords_(true) { |
308 // Copy the form fields. | 312 // Copy the form fields. |
309 std::map<base::string16, size_t> unique_names; | 313 std::map<base::string16, size_t> unique_names; |
310 for (const FormFieldData& field : form.fields) { | 314 for (const FormFieldData& field : form.fields) { |
311 if (!ShouldSkipField(field)) | 315 if (!ShouldSkipField(field)) |
312 ++active_field_count_; | 316 ++active_field_count_; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 | 363 |
360 if (IsAutofillable()) { | 364 if (IsAutofillable()) { |
361 AutofillMetrics::LogDeveloperEngagementMetric( | 365 AutofillMetrics::LogDeveloperEngagementMetric( |
362 AutofillMetrics::FILLABLE_FORM_PARSED); | 366 AutofillMetrics::FILLABLE_FORM_PARSED); |
363 if (has_author_specified_types_) { | 367 if (has_author_specified_types_) { |
364 AutofillMetrics::LogDeveloperEngagementMetric( | 368 AutofillMetrics::LogDeveloperEngagementMetric( |
365 AutofillMetrics::FILLABLE_FORM_CONTAINS_TYPE_HINTS); | 369 AutofillMetrics::FILLABLE_FORM_CONTAINS_TYPE_HINTS); |
366 } | 370 } |
367 } | 371 } |
368 | 372 |
| 373 if (has_author_specified_upi_vpa_hint_) { |
| 374 AutofillMetrics::LogDeveloperEngagementMetric( |
| 375 AutofillMetrics::FORM_CONTAINS_UPI_VPA_HINT); |
| 376 } |
| 377 |
369 AutofillMetrics::LogDetermineHeuristicTypesTiming( | 378 AutofillMetrics::LogDetermineHeuristicTypesTiming( |
370 base::TimeTicks::Now() - determine_heuristic_types_start_time); | 379 base::TimeTicks::Now() - determine_heuristic_types_start_time); |
371 } | 380 } |
372 | 381 |
373 bool FormStructure::EncodeUploadRequest( | 382 bool FormStructure::EncodeUploadRequest( |
374 const ServerFieldTypeSet& available_field_types, | 383 const ServerFieldTypeSet& available_field_types, |
375 bool form_was_autofilled, | 384 bool form_was_autofilled, |
376 const std::string& login_form_signature, | 385 const std::string& login_form_signature, |
377 bool observed_submission, | 386 bool observed_submission, |
378 AutofillUploadContents* upload) const { | 387 AutofillUploadContents* upload) const { |
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 } | 889 } |
881 } | 890 } |
882 } | 891 } |
883 } | 892 } |
884 | 893 |
885 void FormStructure::ParseFieldTypesFromAutocompleteAttributes() { | 894 void FormStructure::ParseFieldTypesFromAutocompleteAttributes() { |
886 const std::string kDefaultSection = "-default"; | 895 const std::string kDefaultSection = "-default"; |
887 | 896 |
888 has_author_specified_types_ = false; | 897 has_author_specified_types_ = false; |
889 has_author_specified_sections_ = false; | 898 has_author_specified_sections_ = false; |
| 899 has_author_specified_upi_vpa_hint_ = false; |
890 for (const auto& field : fields_) { | 900 for (const auto& field : fields_) { |
891 // To prevent potential section name collisions, add a default suffix for | 901 // To prevent potential section name collisions, add a default suffix for |
892 // other fields. Without this, 'autocomplete' attribute values | 902 // other fields. Without this, 'autocomplete' attribute values |
893 // "section--shipping street-address" and "shipping street-address" would be | 903 // "section--shipping street-address" and "shipping street-address" would be |
894 // parsed identically, given the section handling code below. We do this | 904 // parsed identically, given the section handling code below. We do this |
895 // before any validation so that fields with invalid attributes still end up | 905 // before any validation so that fields with invalid attributes still end up |
896 // in the default section. These default section names will be overridden | 906 // in the default section. These default section names will be overridden |
897 // by subsequent heuristic parsing steps if there are no author-specified | 907 // by subsequent heuristic parsing steps if there are no author-specified |
898 // section names. | 908 // section names. |
899 field->set_section(kDefaultSection); | 909 field->set_section(kDefaultSection); |
(...skipping 17 matching lines...) Expand all Loading... |
917 | 927 |
918 // The final token must be the field type. | 928 // The final token must be the field type. |
919 // If it is not one of the known types, abort. | 929 // If it is not one of the known types, abort. |
920 DCHECK(!tokens.empty()); | 930 DCHECK(!tokens.empty()); |
921 | 931 |
922 // Per the spec, the tokens are parsed in reverse order. | 932 // Per the spec, the tokens are parsed in reverse order. |
923 std::string field_type_token = tokens.back(); | 933 std::string field_type_token = tokens.back(); |
924 tokens.pop_back(); | 934 tokens.pop_back(); |
925 HtmlFieldType field_type = | 935 HtmlFieldType field_type = |
926 FieldTypeFromAutocompleteAttributeValue(field_type_token, *field); | 936 FieldTypeFromAutocompleteAttributeValue(field_type_token, *field); |
| 937 if (field_type == HTML_TYPE_UPI_VPA) { |
| 938 has_author_specified_upi_vpa_hint_ = true; |
| 939 // TODO(crbug/702223): Flesh out support for UPI-VPA. |
| 940 field_type = HTML_TYPE_UNRECOGNIZED; |
| 941 } |
927 if (field_type == HTML_TYPE_UNSPECIFIED) | 942 if (field_type == HTML_TYPE_UNSPECIFIED) |
928 continue; | 943 continue; |
929 | 944 |
930 // The preceding token, if any, may be a type hint. | 945 // The preceding token, if any, may be a type hint. |
931 if (!tokens.empty() && IsContactTypeHint(tokens.back())) { | 946 if (!tokens.empty() && IsContactTypeHint(tokens.back())) { |
932 // If it is, it must match the field type; otherwise, abort. | 947 // If it is, it must match the field type; otherwise, abort. |
933 // Note that an invalid token invalidates the entire attribute value, even | 948 // Note that an invalid token invalidates the entire attribute value, even |
934 // if the other tokens are valid. | 949 // if the other tokens are valid. |
935 if (!ContactTypeHintMatchesFieldType(tokens.back(), field_type)) | 950 if (!ContactTypeHintMatchesFieldType(tokens.back(), field_type)) |
936 continue; | 951 continue; |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1319 filtered_strings[0].at(prefix_len)) { | 1334 filtered_strings[0].at(prefix_len)) { |
1320 // Mismatch found. | 1335 // Mismatch found. |
1321 return filtered_strings[i].substr(0, prefix_len); | 1336 return filtered_strings[i].substr(0, prefix_len); |
1322 } | 1337 } |
1323 } | 1338 } |
1324 } | 1339 } |
1325 return filtered_strings[0]; | 1340 return filtered_strings[0]; |
1326 } | 1341 } |
1327 | 1342 |
1328 } // namespace autofill | 1343 } // namespace autofill |
OLD | NEW |