Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: components/autofill/core/browser/form_structure.cc

Issue 2411333004: Make HasAutocompleteAttributeValue handle multi-valued strings (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 879 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 // To prevent potential section name collisions, add a default suffix for 890 // To prevent potential section name collisions, add a default suffix for
891 // other fields. Without this, 'autocomplete' attribute values 891 // other fields. Without this, 'autocomplete' attribute values
892 // "section--shipping street-address" and "shipping street-address" would be 892 // "section--shipping street-address" and "shipping street-address" would be
893 // parsed identically, given the section handling code below. We do this 893 // parsed identically, given the section handling code below. We do this
894 // before any validation so that fields with invalid attributes still end up 894 // before any validation so that fields with invalid attributes still end up
895 // in the default section. These default section names will be overridden 895 // in the default section. These default section names will be overridden
896 // by subsequent heuristic parsing steps if there are no author-specified 896 // by subsequent heuristic parsing steps if there are no author-specified
897 // section names. 897 // section names.
898 field->set_section(kDefaultSection); 898 field->set_section(kDefaultSection);
899 899
900 // Canonicalize the attribute value by trimming whitespace, collapsing 900 // Lowercase and tokenize the attribute value. Per the spec, the tokens are
vabr (Chromium) 2016/10/13 12:49:31 nit: The comment about the reverse order is relate
vabr (Chromium) 2016/10/13 12:49:31 nit: The first sentence of the comment can probabl
jdoerrie 2016/10/13 13:45:07 Done.
jdoerrie 2016/10/13 13:45:07 Done.
901 // non-space characters (e.g. tab) to spaces, and converting to lowercase. 901 // parsed in reverse order.
902 std::string autocomplete_attribute = 902 std::vector<std::string> tokens =
903 base::CollapseWhitespaceASCII(field->autocomplete_attribute, false); 903 LowercaseAndTokenizeAttributeString(field->autocomplete_attribute);
904 autocomplete_attribute = base::ToLowerASCII(autocomplete_attribute);
905 904
906 // The autocomplete attribute is overloaded: it can specify either a field 905 // The autocomplete attribute is overloaded: it can specify either a field
907 // type hint or whether autocomplete should be enabled at all. Ignore the 906 // type hint or whether autocomplete should be enabled at all. Ignore the
908 // latter type of attribute value. 907 // latter type of attribute value.
909 if (autocomplete_attribute.empty() || autocomplete_attribute == "on" || 908 if (tokens.empty() ||
910 autocomplete_attribute == "off") { 909 (tokens.size() == 1 && (tokens[0] == "on" || tokens[0] == "off"))) {
911 continue; 910 continue;
912 } 911 }
913 912
914 // Any other value, even it is invalid, is considered to be a type hint. 913 // Any other value, even it is invalid, is considered to be a type hint.
915 // This allows a website's author to specify an attribute like 914 // This allows a website's author to specify an attribute like
916 // autocomplete="other" on a field to disable all Autofill heuristics for 915 // autocomplete="other" on a field to disable all Autofill heuristics for
917 // the form. 916 // the form.
918 has_author_specified_types_ = true; 917 has_author_specified_types_ = true;
919 918
920 // Tokenize the attribute value. Per the spec, the tokens are parsed in
921 // reverse order.
922 std::vector<std::string> tokens =
923 base::SplitString(autocomplete_attribute, " ", base::KEEP_WHITESPACE,
924 base::SPLIT_WANT_NONEMPTY);
925
926 // The final token must be the field type. 919 // The final token must be the field type.
927 // If it is not one of the known types, abort. 920 // If it is not one of the known types, abort.
928 DCHECK(!tokens.empty()); 921 DCHECK(!tokens.empty());
929 std::string field_type_token = tokens.back(); 922 std::string field_type_token = tokens.back();
930 tokens.pop_back(); 923 tokens.pop_back();
931 HtmlFieldType field_type = 924 HtmlFieldType field_type =
932 FieldTypeFromAutocompleteAttributeValue(field_type_token, *field); 925 FieldTypeFromAutocompleteAttributeValue(field_type_token, *field);
933 if (field_type == HTML_TYPE_UNSPECIFIED) 926 if (field_type == HTML_TYPE_UNSPECIFIED)
934 continue; 927 continue;
935 928
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
1322 filtered_strings[0].at(prefix_len)) { 1315 filtered_strings[0].at(prefix_len)) {
1323 // Mismatch found. 1316 // Mismatch found.
1324 return filtered_strings[i].substr(0, prefix_len); 1317 return filtered_strings[i].substr(0, prefix_len);
1325 } 1318 }
1326 } 1319 }
1327 } 1320 }
1328 return filtered_strings[0]; 1321 return filtered_strings[0];
1329 } 1322 }
1330 1323
1331 } // namespace autofill 1324 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698