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/content/renderer/form_autofill_util.h" | 5 #include "components/autofill/content/renderer/form_autofill_util.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 TrimPositions prefix_trailing_whitespace = | 118 TrimPositions prefix_trailing_whitespace = |
119 TrimWhitespace(prefix, TRIM_TRAILING, &prefix_trimmed); | 119 TrimWhitespace(prefix, TRIM_TRAILING, &prefix_trimmed); |
120 | 120 |
121 // Recursively compute the children's text. | 121 // Recursively compute the children's text. |
122 base::string16 suffix_trimmed; | 122 base::string16 suffix_trimmed; |
123 TrimPositions suffix_leading_whitespace = | 123 TrimPositions suffix_leading_whitespace = |
124 TrimWhitespace(suffix, TRIM_LEADING, &suffix_trimmed); | 124 TrimWhitespace(suffix, TRIM_LEADING, &suffix_trimmed); |
125 | 125 |
126 if (prefix_trailing_whitespace || suffix_leading_whitespace || | 126 if (prefix_trailing_whitespace || suffix_leading_whitespace || |
127 force_whitespace) { | 127 force_whitespace) { |
128 return prefix_trimmed + ASCIIToUTF16(" ") + suffix_trimmed; | 128 return prefix_trimmed + base::ASCIIToUTF16(" ") + suffix_trimmed; |
129 } else { | 129 } else { |
130 return prefix_trimmed + suffix_trimmed; | 130 return prefix_trimmed + suffix_trimmed; |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 // This is a helper function for the FindChildText() function (see below). | 134 // This is a helper function for the FindChildText() function (see below). |
135 // Search depth is limited with the |depth| parameter. | 135 // Search depth is limited with the |depth| parameter. |
136 base::string16 FindChildTextInner(const WebNode& node, int depth) { | 136 base::string16 FindChildTextInner(const WebNode& node, int depth) { |
137 if (depth <= 0 || node.isNull()) | 137 if (depth <= 0 || node.isNull()) |
138 return base::string16(); | 138 return base::string16(); |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 ExtractMask extract_mask, | 746 ExtractMask extract_mask, |
747 FormFieldData* field) { | 747 FormFieldData* field) { |
748 DCHECK(field); | 748 DCHECK(field); |
749 DCHECK(!element.isNull()); | 749 DCHECK(!element.isNull()); |
750 CR_DEFINE_STATIC_LOCAL(WebString, kAutocomplete, ("autocomplete")); | 750 CR_DEFINE_STATIC_LOCAL(WebString, kAutocomplete, ("autocomplete")); |
751 | 751 |
752 // The label is not officially part of a WebFormControlElement; however, the | 752 // The label is not officially part of a WebFormControlElement; however, the |
753 // labels for all form control elements are scraped from the DOM and set in | 753 // labels for all form control elements are scraped from the DOM and set in |
754 // WebFormElementToFormData. | 754 // WebFormElementToFormData. |
755 field->name = element.nameForAutofill(); | 755 field->name = element.nameForAutofill(); |
756 field->form_control_type = UTF16ToUTF8(element.formControlType()); | 756 field->form_control_type = base::UTF16ToUTF8(element.formControlType()); |
757 field->autocomplete_attribute = | 757 field->autocomplete_attribute = |
758 UTF16ToUTF8(element.getAttribute(kAutocomplete)); | 758 base::UTF16ToUTF8(element.getAttribute(kAutocomplete)); |
759 if (field->autocomplete_attribute.size() > kMaxDataLength) { | 759 if (field->autocomplete_attribute.size() > kMaxDataLength) { |
760 // Discard overly long attribute values to avoid DOS-ing the browser | 760 // Discard overly long attribute values to avoid DOS-ing the browser |
761 // process. However, send over a default string to indicate that the | 761 // process. However, send over a default string to indicate that the |
762 // attribute was present. | 762 // attribute was present. |
763 field->autocomplete_attribute = "x-max-data-length-exceeded"; | 763 field->autocomplete_attribute = "x-max-data-length-exceeded"; |
764 } | 764 } |
765 | 765 |
766 if (!IsAutofillableElement(element)) | 766 if (!IsAutofillableElement(element)) |
767 return; | 767 return; |
768 | 768 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 } | 922 } |
923 | 923 |
924 std::map<base::string16, FormFieldData*>::iterator iter = | 924 std::map<base::string16, FormFieldData*>::iterator iter = |
925 name_map.find(element_name); | 925 name_map.find(element_name); |
926 if (iter != name_map.end()) { | 926 if (iter != name_map.end()) { |
927 base::string16 label_text = FindChildText(label); | 927 base::string16 label_text = FindChildText(label); |
928 | 928 |
929 // Concatenate labels because some sites might have multiple label | 929 // Concatenate labels because some sites might have multiple label |
930 // candidates. | 930 // candidates. |
931 if (!iter->second->label.empty() && !label_text.empty()) | 931 if (!iter->second->label.empty() && !label_text.empty()) |
932 iter->second->label += ASCIIToUTF16(" "); | 932 iter->second->label += base::ASCIIToUTF16(" "); |
933 iter->second->label += label_text; | 933 iter->second->label += label_text; |
934 } | 934 } |
935 } | 935 } |
936 | 936 |
937 // Loop through the form control elements, extracting the label text from | 937 // Loop through the form control elements, extracting the label text from |
938 // the DOM. We use the |fields_extracted| vector to make sure we assign the | 938 // the DOM. We use the |fields_extracted| vector to make sure we assign the |
939 // extracted label to the correct field, as it's possible |form_fields| will | 939 // extracted label to the correct field, as it's possible |form_fields| will |
940 // not contain all of the elements in |control_elements|. | 940 // not contain all of the elements in |control_elements|. |
941 for (size_t i = 0, field_idx = 0; | 941 for (size_t i = 0, field_idx = 0; |
942 i < control_elements.size() && field_idx < form_fields.size(); ++i) { | 942 i < control_elements.size() && field_idx < form_fields.size(); ++i) { |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1151 break; | 1151 break; |
1152 } | 1152 } |
1153 } | 1153 } |
1154 if (!tag_is_allowed) | 1154 if (!tag_is_allowed) |
1155 return false; | 1155 return false; |
1156 } | 1156 } |
1157 return true; | 1157 return true; |
1158 } | 1158 } |
1159 | 1159 |
1160 } // namespace autofill | 1160 } // namespace autofill |
OLD | NEW |