| 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 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 enum FieldFilterMask { | 56 enum FieldFilterMask { |
| 57 FILTER_NONE = 0, | 57 FILTER_NONE = 0, |
| 58 FILTER_DISABLED_ELEMENTS = 1 << 0, | 58 FILTER_DISABLED_ELEMENTS = 1 << 0, |
| 59 FILTER_READONLY_ELEMENTS = 1 << 1, | 59 FILTER_READONLY_ELEMENTS = 1 << 1, |
| 60 FILTER_NON_FOCUSABLE_ELEMENTS = 1 << 2, | 60 FILTER_NON_FOCUSABLE_ELEMENTS = 1 << 2, |
| 61 FILTER_ALL_NON_EDITABLE_ELEMENTS = FILTER_DISABLED_ELEMENTS | | 61 FILTER_ALL_NON_EDITABLE_ELEMENTS = FILTER_DISABLED_ELEMENTS | |
| 62 FILTER_READONLY_ELEMENTS | | 62 FILTER_READONLY_ELEMENTS | |
| 63 FILTER_NON_FOCUSABLE_ELEMENTS, | 63 FILTER_NON_FOCUSABLE_ELEMENTS, |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 RequirementsMask ExtractionRequirements() { | |
| 67 return base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 68 switches::kRespectAutocompleteOffForAutofill) | |
| 69 ? REQUIRE_AUTOCOMPLETE | |
| 70 : REQUIRE_NONE; | |
| 71 } | |
| 72 | |
| 73 void TruncateString(base::string16* str, size_t max_length) { | 66 void TruncateString(base::string16* str, size_t max_length) { |
| 74 if (str->length() > max_length) | 67 if (str->length() > max_length) |
| 75 str->resize(max_length); | 68 str->resize(max_length); |
| 76 } | 69 } |
| 77 | 70 |
| 78 bool IsOptionElement(const WebElement& element) { | 71 bool IsOptionElement(const WebElement& element) { |
| 79 CR_DEFINE_STATIC_LOCAL(WebString, kOption, ("option")); | 72 CR_DEFINE_STATIC_LOCAL(WebString, kOption, ("option")); |
| 80 return element.hasHTMLTagName(kOption); | 73 return element.hasHTMLTagName(kOption); |
| 81 } | 74 } |
| 82 | 75 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 130 |
| 138 std::string tag_name = node.toConst<WebElement>().tagName().utf8(); | 131 std::string tag_name = node.toConst<WebElement>().tagName().utf8(); |
| 139 return (tag_name == "DD" || | 132 return (tag_name == "DD" || |
| 140 tag_name == "DIV" || | 133 tag_name == "DIV" || |
| 141 tag_name == "FIELDSET" || | 134 tag_name == "FIELDSET" || |
| 142 tag_name == "LI" || | 135 tag_name == "LI" || |
| 143 tag_name == "TD" || | 136 tag_name == "TD" || |
| 144 tag_name == "TABLE"); | 137 tag_name == "TABLE"); |
| 145 } | 138 } |
| 146 | 139 |
| 147 // Check whether the given field satisfies the REQUIRE_AUTOCOMPLETE requirement. | |
| 148 bool SatisfiesRequireAutocomplete(const WebInputElement& input_element) { | |
| 149 return input_element.autoComplete(); | |
| 150 } | |
| 151 | |
| 152 // Returns the colspan for a <td> / <th>. Defaults to 1. | 140 // Returns the colspan for a <td> / <th>. Defaults to 1. |
| 153 size_t CalculateTableCellColumnSpan(const WebElement& element) { | 141 size_t CalculateTableCellColumnSpan(const WebElement& element) { |
| 154 DCHECK(element.hasHTMLTagName("td") || element.hasHTMLTagName("th")); | 142 DCHECK(element.hasHTMLTagName("td") || element.hasHTMLTagName("th")); |
| 155 | 143 |
| 156 size_t span = 1; | 144 size_t span = 1; |
| 157 if (element.hasAttribute("colspan")) { | 145 if (element.hasAttribute("colspan")) { |
| 158 base::string16 colspan = element.getAttribute("colspan"); | 146 base::string16 colspan = element.getAttribute("colspan"); |
| 159 // Do not check return value to accept imperfect conversions. | 147 // Do not check return value to accept imperfect conversions. |
| 160 base::StringToSizeT(colspan, &span); | 148 base::StringToSizeT(colspan, &span); |
| 161 // Handle overflow. | 149 // Handle overflow. |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 | 770 |
| 783 // For each autofillable field in |data| that matches a field in the |form|, | 771 // For each autofillable field in |data| that matches a field in the |form|, |
| 784 // the |callback| is invoked with the corresponding |form| field data. | 772 // the |callback| is invoked with the corresponding |form| field data. |
| 785 void ForEachMatchingFormField(const WebFormElement& form_element, | 773 void ForEachMatchingFormField(const WebFormElement& form_element, |
| 786 const WebElement& initiating_element, | 774 const WebElement& initiating_element, |
| 787 const FormData& data, | 775 const FormData& data, |
| 788 FieldFilterMask filters, | 776 FieldFilterMask filters, |
| 789 bool force_override, | 777 bool force_override, |
| 790 const Callback& callback) { | 778 const Callback& callback) { |
| 791 std::vector<WebFormControlElement> control_elements = | 779 std::vector<WebFormControlElement> control_elements = |
| 792 ExtractAutofillableElementsInForm(form_element, ExtractionRequirements()); | 780 ExtractAutofillableElementsInForm(form_element); |
| 793 ForEachMatchingFormFieldCommon(&control_elements, initiating_element, data, | 781 ForEachMatchingFormFieldCommon(&control_elements, initiating_element, data, |
| 794 filters, force_override, callback); | 782 filters, force_override, callback); |
| 795 } | 783 } |
| 796 | 784 |
| 797 // For each autofillable field in |data| that matches a field in the set of | 785 // For each autofillable field in |data| that matches a field in the set of |
| 798 // unowned autofillable form fields, the |callback| is invoked with the | 786 // unowned autofillable form fields, the |callback| is invoked with the |
| 799 // corresponding |data| field. | 787 // corresponding |data| field. |
| 800 void ForEachMatchingUnownedFormField(const WebElement& initiating_element, | 788 void ForEachMatchingUnownedFormField(const WebElement& initiating_element, |
| 801 const FormData& data, | 789 const FormData& data, |
| 802 FieldFilterMask filters, | 790 FieldFilterMask filters, |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 for (size_t i = 0; i < length; ++i) { | 892 for (size_t i = 0; i < length; ++i) { |
| 905 const blink::WebNode& item = children.item(i); | 893 const blink::WebNode& item = children.item(i); |
| 906 if (IsWebNodeVisibleImpl(item, depth - 1)) | 894 if (IsWebNodeVisibleImpl(item, depth - 1)) |
| 907 return true; | 895 return true; |
| 908 } | 896 } |
| 909 return false; | 897 return false; |
| 910 } | 898 } |
| 911 | 899 |
| 912 bool ExtractFieldsFromControlElements( | 900 bool ExtractFieldsFromControlElements( |
| 913 const WebVector<WebFormControlElement>& control_elements, | 901 const WebVector<WebFormControlElement>& control_elements, |
| 914 RequirementsMask requirements, | |
| 915 ExtractMask extract_mask, | 902 ExtractMask extract_mask, |
| 916 ScopedVector<FormFieldData>* form_fields, | 903 ScopedVector<FormFieldData>* form_fields, |
| 917 std::vector<bool>* fields_extracted, | 904 std::vector<bool>* fields_extracted, |
| 918 std::map<WebFormControlElement, FormFieldData*>* element_map) { | 905 std::map<WebFormControlElement, FormFieldData*>* element_map) { |
| 919 for (size_t i = 0; i < control_elements.size(); ++i) { | 906 for (size_t i = 0; i < control_elements.size(); ++i) { |
| 920 const WebFormControlElement& control_element = control_elements[i]; | 907 const WebFormControlElement& control_element = control_elements[i]; |
| 921 | 908 |
| 922 if (!IsAutofillableElement(control_element)) | 909 if (!IsAutofillableElement(control_element)) |
| 923 continue; | 910 continue; |
| 924 | 911 |
| 925 const WebInputElement* input_element = toWebInputElement(&control_element); | |
| 926 if (requirements & REQUIRE_AUTOCOMPLETE && | |
| 927 IsAutofillableInputElement(input_element) && | |
| 928 !SatisfiesRequireAutocomplete(*input_element)) | |
| 929 continue; | |
| 930 | |
| 931 // Create a new FormFieldData, fill it out and map it to the field's name. | 912 // Create a new FormFieldData, fill it out and map it to the field's name. |
| 932 FormFieldData* form_field = new FormFieldData; | 913 FormFieldData* form_field = new FormFieldData; |
| 933 WebFormControlElementToFormField(control_element, extract_mask, form_field); | 914 WebFormControlElementToFormField(control_element, extract_mask, form_field); |
| 934 form_fields->push_back(form_field); | 915 form_fields->push_back(form_field); |
| 935 (*element_map)[control_element] = form_field; | 916 (*element_map)[control_element] = form_field; |
| 936 (*fields_extracted)[i] = true; | 917 (*fields_extracted)[i] = true; |
| 937 } | 918 } |
| 938 | 919 |
| 939 // If we failed to extract any fields, give up. Also, to avoid overly | 920 // If we failed to extract any fields, give up. Also, to avoid overly |
| 940 // expensive computation, we impose a maximum number of allowable fields. | 921 // expensive computation, we impose a maximum number of allowable fields. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1009 // 1) |form_element| and an empty |fieldsets|. | 990 // 1) |form_element| and an empty |fieldsets|. |
| 1010 // or | 991 // or |
| 1011 // 2) a NULL |form_element|. | 992 // 2) a NULL |form_element|. |
| 1012 // | 993 // |
| 1013 // If |field| is not NULL, then |form_control_element| should be not NULL. | 994 // If |field| is not NULL, then |form_control_element| should be not NULL. |
| 1014 bool FormOrFieldsetsToFormData( | 995 bool FormOrFieldsetsToFormData( |
| 1015 const blink::WebFormElement* form_element, | 996 const blink::WebFormElement* form_element, |
| 1016 const blink::WebFormControlElement* form_control_element, | 997 const blink::WebFormControlElement* form_control_element, |
| 1017 const std::vector<blink::WebElement>& fieldsets, | 998 const std::vector<blink::WebElement>& fieldsets, |
| 1018 const WebVector<WebFormControlElement>& control_elements, | 999 const WebVector<WebFormControlElement>& control_elements, |
| 1019 RequirementsMask requirements, | |
| 1020 ExtractMask extract_mask, | 1000 ExtractMask extract_mask, |
| 1021 FormData* form, | 1001 FormData* form, |
| 1022 FormFieldData* field) { | 1002 FormFieldData* field) { |
| 1023 CR_DEFINE_STATIC_LOCAL(WebString, kLabel, ("label")); | 1003 CR_DEFINE_STATIC_LOCAL(WebString, kLabel, ("label")); |
| 1024 | 1004 |
| 1025 if (form_element) | 1005 if (form_element) |
| 1026 DCHECK(fieldsets.empty()); | 1006 DCHECK(fieldsets.empty()); |
| 1027 if (field) | 1007 if (field) |
| 1028 DCHECK(form_control_element); | 1008 DCHECK(form_control_element); |
| 1029 | 1009 |
| 1030 // A map from a FormFieldData's name to the FormFieldData itself. | 1010 // A map from a FormFieldData's name to the FormFieldData itself. |
| 1031 std::map<WebFormControlElement, FormFieldData*> element_map; | 1011 std::map<WebFormControlElement, FormFieldData*> element_map; |
| 1032 | 1012 |
| 1033 // The extracted FormFields. We use pointers so we can store them in | 1013 // The extracted FormFields. We use pointers so we can store them in |
| 1034 // |element_map|. | 1014 // |element_map|. |
| 1035 ScopedVector<FormFieldData> form_fields; | 1015 ScopedVector<FormFieldData> form_fields; |
| 1036 | 1016 |
| 1037 // A vector of bools that indicate whether each field in the form meets the | 1017 // A vector of bools that indicate whether each field in the form meets the |
| 1038 // requirements and thus will be in the resulting |form|. | 1018 // requirements and thus will be in the resulting |form|. |
| 1039 std::vector<bool> fields_extracted(control_elements.size(), false); | 1019 std::vector<bool> fields_extracted(control_elements.size(), false); |
| 1040 | 1020 |
| 1041 if (!ExtractFieldsFromControlElements(control_elements, requirements, | 1021 if (!ExtractFieldsFromControlElements(control_elements, extract_mask, |
| 1042 extract_mask, &form_fields, | 1022 &form_fields, &fields_extracted, |
| 1043 &fields_extracted, &element_map)) { | 1023 &element_map)) { |
| 1044 return false; | 1024 return false; |
| 1045 } | 1025 } |
| 1046 | 1026 |
| 1047 if (form_element) { | 1027 if (form_element) { |
| 1048 // Loop through the label elements inside the form element. For each label | 1028 // Loop through the label elements inside the form element. For each label |
| 1049 // element, get the corresponding form control element, use the form control | 1029 // element, get the corresponding form control element, use the form control |
| 1050 // element's name as a key into the <name, FormFieldData> map to find the | 1030 // element's name as a key into the <name, FormFieldData> map to find the |
| 1051 // previously created FormFieldData and set the FormFieldData's label to the | 1031 // previously created FormFieldData and set the FormFieldData's label to the |
| 1052 // label.firstChild().nodeValue() of the label element. | 1032 // label.firstChild().nodeValue() of the label element. |
| 1053 WebElementCollection labels = | 1033 WebElementCollection labels = |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1142 | 1122 |
| 1143 bool IsWebNodeVisible(const blink::WebNode& node) { | 1123 bool IsWebNodeVisible(const blink::WebNode& node) { |
| 1144 // In the bug http://crbug.com/237216 the form's bounding box is empty | 1124 // In the bug http://crbug.com/237216 the form's bounding box is empty |
| 1145 // however the form has non empty children. Thus we need to look at the | 1125 // however the form has non empty children. Thus we need to look at the |
| 1146 // form's children. | 1126 // form's children. |
| 1147 int kNodeSearchDepth = 2; | 1127 int kNodeSearchDepth = 2; |
| 1148 return IsWebNodeVisibleImpl(node, kNodeSearchDepth); | 1128 return IsWebNodeVisibleImpl(node, kNodeSearchDepth); |
| 1149 } | 1129 } |
| 1150 | 1130 |
| 1151 std::vector<blink::WebFormControlElement> ExtractAutofillableElementsFromSet( | 1131 std::vector<blink::WebFormControlElement> ExtractAutofillableElementsFromSet( |
| 1152 const WebVector<WebFormControlElement>& control_elements, | 1132 const WebVector<WebFormControlElement>& control_elements) { |
| 1153 RequirementsMask requirements) { | |
| 1154 std::vector<blink::WebFormControlElement> autofillable_elements; | 1133 std::vector<blink::WebFormControlElement> autofillable_elements; |
| 1155 for (size_t i = 0; i < control_elements.size(); ++i) { | 1134 for (size_t i = 0; i < control_elements.size(); ++i) { |
| 1156 WebFormControlElement element = control_elements[i]; | 1135 WebFormControlElement element = control_elements[i]; |
| 1157 if (!IsAutofillableElement(element)) | 1136 if (!IsAutofillableElement(element)) |
| 1158 continue; | 1137 continue; |
| 1159 | 1138 |
| 1160 if (requirements & REQUIRE_AUTOCOMPLETE) { | |
| 1161 // TODO(isherman): WebKit currently doesn't handle the autocomplete | |
| 1162 // attribute for select or textarea elements, but it probably should. | |
| 1163 const WebInputElement* input_element = | |
| 1164 toWebInputElement(&control_elements[i]); | |
| 1165 if (IsAutofillableInputElement(input_element) && | |
| 1166 !SatisfiesRequireAutocomplete(*input_element)) | |
| 1167 continue; | |
| 1168 } | |
| 1169 | |
| 1170 autofillable_elements.push_back(element); | 1139 autofillable_elements.push_back(element); |
| 1171 } | 1140 } |
| 1172 return autofillable_elements; | 1141 return autofillable_elements; |
| 1173 } | 1142 } |
| 1174 | 1143 |
| 1175 std::vector<WebFormControlElement> ExtractAutofillableElementsInForm( | 1144 std::vector<WebFormControlElement> ExtractAutofillableElementsInForm( |
| 1176 const WebFormElement& form_element, | 1145 const WebFormElement& form_element) { |
| 1177 RequirementsMask requirements) { | |
| 1178 WebVector<WebFormControlElement> control_elements; | 1146 WebVector<WebFormControlElement> control_elements; |
| 1179 form_element.getFormControlElements(control_elements); | 1147 form_element.getFormControlElements(control_elements); |
| 1180 | 1148 |
| 1181 return ExtractAutofillableElementsFromSet(control_elements, requirements); | 1149 return ExtractAutofillableElementsFromSet(control_elements); |
| 1182 } | 1150 } |
| 1183 | 1151 |
| 1184 void WebFormControlElementToFormField(const WebFormControlElement& element, | 1152 void WebFormControlElementToFormField(const WebFormControlElement& element, |
| 1185 ExtractMask extract_mask, | 1153 ExtractMask extract_mask, |
| 1186 FormFieldData* field) { | 1154 FormFieldData* field) { |
| 1187 DCHECK(field); | 1155 DCHECK(field); |
| 1188 DCHECK(!element.isNull()); | 1156 DCHECK(!element.isNull()); |
| 1189 CR_DEFINE_STATIC_LOCAL(WebString, kAutocomplete, ("autocomplete")); | 1157 CR_DEFINE_STATIC_LOCAL(WebString, kAutocomplete, ("autocomplete")); |
| 1190 CR_DEFINE_STATIC_LOCAL(WebString, kRole, ("role")); | 1158 CR_DEFINE_STATIC_LOCAL(WebString, kRole, ("role")); |
| 1191 | 1159 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1259 // Constrain the maximum data length to prevent a malicious site from DOS'ing | 1227 // Constrain the maximum data length to prevent a malicious site from DOS'ing |
| 1260 // the browser: http://crbug.com/49332 | 1228 // the browser: http://crbug.com/49332 |
| 1261 TruncateString(&value, kMaxDataLength); | 1229 TruncateString(&value, kMaxDataLength); |
| 1262 | 1230 |
| 1263 field->value = value; | 1231 field->value = value; |
| 1264 } | 1232 } |
| 1265 | 1233 |
| 1266 bool WebFormElementToFormData( | 1234 bool WebFormElementToFormData( |
| 1267 const blink::WebFormElement& form_element, | 1235 const blink::WebFormElement& form_element, |
| 1268 const blink::WebFormControlElement& form_control_element, | 1236 const blink::WebFormControlElement& form_control_element, |
| 1269 RequirementsMask requirements, | |
| 1270 ExtractMask extract_mask, | 1237 ExtractMask extract_mask, |
| 1271 FormData* form, | 1238 FormData* form, |
| 1272 FormFieldData* field) { | 1239 FormFieldData* field) { |
| 1273 const WebFrame* frame = form_element.document().frame(); | 1240 const WebFrame* frame = form_element.document().frame(); |
| 1274 if (!frame) | 1241 if (!frame) |
| 1275 return false; | 1242 return false; |
| 1276 | 1243 |
| 1277 if (requirements & REQUIRE_AUTOCOMPLETE && !form_element.autoComplete()) | |
| 1278 return false; | |
| 1279 | |
| 1280 form->name = GetFormIdentifier(form_element); | 1244 form->name = GetFormIdentifier(form_element); |
| 1281 form->origin = frame->document().url(); | 1245 form->origin = frame->document().url(); |
| 1282 form->action = frame->document().completeURL(form_element.action()); | 1246 form->action = frame->document().completeURL(form_element.action()); |
| 1283 form->user_submitted = form_element.wasUserSubmitted(); | 1247 form->user_submitted = form_element.wasUserSubmitted(); |
| 1284 | 1248 |
| 1285 // If the completed URL is not valid, just use the action we get from | 1249 // If the completed URL is not valid, just use the action we get from |
| 1286 // WebKit. | 1250 // WebKit. |
| 1287 if (!form->action.is_valid()) | 1251 if (!form->action.is_valid()) |
| 1288 form->action = GURL(form_element.action()); | 1252 form->action = GURL(form_element.action()); |
| 1289 | 1253 |
| 1290 WebVector<WebFormControlElement> control_elements; | 1254 WebVector<WebFormControlElement> control_elements; |
| 1291 form_element.getFormControlElements(control_elements); | 1255 form_element.getFormControlElements(control_elements); |
| 1292 | 1256 |
| 1293 std::vector<blink::WebElement> dummy_fieldset; | 1257 std::vector<blink::WebElement> dummy_fieldset; |
| 1294 return FormOrFieldsetsToFormData(&form_element, &form_control_element, | 1258 return FormOrFieldsetsToFormData(&form_element, &form_control_element, |
| 1295 dummy_fieldset, control_elements, | 1259 dummy_fieldset, control_elements, |
| 1296 requirements, extract_mask, form, field); | 1260 extract_mask, form, field); |
| 1297 } | 1261 } |
| 1298 | 1262 |
| 1299 std::vector<WebFormControlElement> | 1263 std::vector<WebFormControlElement> |
| 1300 GetUnownedAutofillableFormFieldElements( | 1264 GetUnownedAutofillableFormFieldElements( |
| 1301 const WebElementCollection& elements, | 1265 const WebElementCollection& elements, |
| 1302 std::vector<WebElement>* fieldsets) { | 1266 std::vector<WebElement>* fieldsets) { |
| 1303 std::vector<WebFormControlElement> unowned_fieldset_children; | 1267 std::vector<WebFormControlElement> unowned_fieldset_children; |
| 1304 for (WebElement element = elements.firstItem(); | 1268 for (WebElement element = elements.firstItem(); |
| 1305 !element.isNull(); | 1269 !element.isNull(); |
| 1306 element = elements.nextItem()) { | 1270 element = elements.nextItem()) { |
| 1307 if (element.isFormControlElement()) { | 1271 if (element.isFormControlElement()) { |
| 1308 WebFormControlElement control = element.to<WebFormControlElement>(); | 1272 WebFormControlElement control = element.to<WebFormControlElement>(); |
| 1309 if (control.form().isNull()) | 1273 if (control.form().isNull()) |
| 1310 unowned_fieldset_children.push_back(control); | 1274 unowned_fieldset_children.push_back(control); |
| 1311 } | 1275 } |
| 1312 | 1276 |
| 1313 if (fieldsets && element.hasHTMLTagName("fieldset") && | 1277 if (fieldsets && element.hasHTMLTagName("fieldset") && |
| 1314 !IsElementInsideFormOrFieldSet(element)) { | 1278 !IsElementInsideFormOrFieldSet(element)) { |
| 1315 fieldsets->push_back(element); | 1279 fieldsets->push_back(element); |
| 1316 } | 1280 } |
| 1317 } | 1281 } |
| 1318 return ExtractAutofillableElementsFromSet(unowned_fieldset_children, | 1282 return ExtractAutofillableElementsFromSet(unowned_fieldset_children); |
| 1319 REQUIRE_NONE); | |
| 1320 } | 1283 } |
| 1321 | 1284 |
| 1322 bool UnownedFormElementsAndFieldSetsToFormData( | 1285 bool UnownedFormElementsAndFieldSetsToFormData( |
| 1323 const std::vector<blink::WebElement>& fieldsets, | 1286 const std::vector<blink::WebElement>& fieldsets, |
| 1324 const std::vector<blink::WebFormControlElement>& control_elements, | 1287 const std::vector<blink::WebFormControlElement>& control_elements, |
| 1325 const blink::WebFormControlElement* element, | 1288 const blink::WebFormControlElement* element, |
| 1326 const GURL& origin, | 1289 const GURL& origin, |
| 1327 RequirementsMask requirements, | |
| 1328 ExtractMask extract_mask, | 1290 ExtractMask extract_mask, |
| 1329 FormData* form, | 1291 FormData* form, |
| 1330 FormFieldData* field) { | 1292 FormFieldData* field) { |
| 1331 form->origin = origin; | 1293 form->origin = origin; |
| 1332 form->user_submitted = false; | 1294 form->user_submitted = false; |
| 1333 form->is_form_tag = false; | 1295 form->is_form_tag = false; |
| 1334 | 1296 |
| 1335 return FormOrFieldsetsToFormData(nullptr, element, fieldsets, | 1297 return FormOrFieldsetsToFormData(nullptr, element, fieldsets, |
| 1336 control_elements, requirements, extract_mask, | 1298 control_elements, extract_mask, form, field); |
| 1337 form, field); | |
| 1338 } | 1299 } |
| 1339 | 1300 |
| 1340 bool FindFormAndFieldForFormControlElement(const WebFormControlElement& element, | 1301 bool FindFormAndFieldForFormControlElement(const WebFormControlElement& element, |
| 1341 FormData* form, | 1302 FormData* form, |
| 1342 FormFieldData* field, | 1303 FormFieldData* field) { |
| 1343 RequirementsMask requirements) { | |
| 1344 if (!IsAutofillableElement(element)) | 1304 if (!IsAutofillableElement(element)) |
| 1345 return false; | 1305 return false; |
| 1346 | 1306 |
| 1347 ExtractMask extract_mask = | 1307 ExtractMask extract_mask = |
| 1348 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTIONS); | 1308 static_cast<ExtractMask>(EXTRACT_VALUE | EXTRACT_OPTIONS); |
| 1349 const WebFormElement form_element = element.form(); | 1309 const WebFormElement form_element = element.form(); |
| 1350 if (form_element.isNull()) { | 1310 if (form_element.isNull()) { |
| 1351 // No associated form, try the synthetic form for unowned form elements. | 1311 // No associated form, try the synthetic form for unowned form elements. |
| 1352 WebDocument document = element.document(); | 1312 WebDocument document = element.document(); |
| 1353 std::vector<WebElement> fieldsets; | 1313 std::vector<WebElement> fieldsets; |
| 1354 std::vector<WebFormControlElement> control_elements = | 1314 std::vector<WebFormControlElement> control_elements = |
| 1355 GetUnownedAutofillableFormFieldElements(document.all(), &fieldsets); | 1315 GetUnownedAutofillableFormFieldElements(document.all(), &fieldsets); |
| 1356 return UnownedFormElementsAndFieldSetsToFormData( | 1316 return UnownedFormElementsAndFieldSetsToFormData( |
| 1357 fieldsets, control_elements, &element, document.url(), requirements, | 1317 fieldsets, control_elements, &element, document.url(), extract_mask, |
| 1358 extract_mask, form, field); | 1318 form, field); |
| 1359 } | 1319 } |
| 1360 | 1320 |
| 1361 return WebFormElementToFormData(form_element, | 1321 return WebFormElementToFormData(form_element, |
| 1362 element, | 1322 element, |
| 1363 requirements, | |
| 1364 extract_mask, | 1323 extract_mask, |
| 1365 form, | 1324 form, |
| 1366 field); | 1325 field); |
| 1367 } | 1326 } |
| 1368 | 1327 |
| 1369 void FillForm(const FormData& form, const WebFormControlElement& element) { | 1328 void FillForm(const FormData& form, const WebFormControlElement& element) { |
| 1370 WebFormElement form_element = element.form(); | 1329 WebFormElement form_element = element.form(); |
| 1371 if (form_element.isNull()) { | 1330 if (form_element.isNull()) { |
| 1372 ForEachMatchingUnownedFormField(element, | 1331 ForEachMatchingUnownedFormField(element, |
| 1373 form, | 1332 form, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1424 bool ClearPreviewedFormWithElement(const WebFormControlElement& element, | 1383 bool ClearPreviewedFormWithElement(const WebFormControlElement& element, |
| 1425 bool was_autofilled) { | 1384 bool was_autofilled) { |
| 1426 WebFormElement form_element = element.form(); | 1385 WebFormElement form_element = element.form(); |
| 1427 std::vector<WebFormControlElement> control_elements; | 1386 std::vector<WebFormControlElement> control_elements; |
| 1428 if (form_element.isNull()) { | 1387 if (form_element.isNull()) { |
| 1429 control_elements = GetUnownedAutofillableFormFieldElements( | 1388 control_elements = GetUnownedAutofillableFormFieldElements( |
| 1430 element.document().all(), nullptr); | 1389 element.document().all(), nullptr); |
| 1431 if (!IsElementInControlElementSet(element, control_elements)) | 1390 if (!IsElementInControlElementSet(element, control_elements)) |
| 1432 return false; | 1391 return false; |
| 1433 } else { | 1392 } else { |
| 1434 control_elements = ExtractAutofillableElementsInForm( | 1393 control_elements = ExtractAutofillableElementsInForm(form_element); |
| 1435 form_element, ExtractionRequirements()); | |
| 1436 } | 1394 } |
| 1437 | 1395 |
| 1438 for (size_t i = 0; i < control_elements.size(); ++i) { | 1396 for (size_t i = 0; i < control_elements.size(); ++i) { |
| 1439 // There might be unrelated elements in this form which have already been | 1397 // There might be unrelated elements in this form which have already been |
| 1440 // auto-filled. For example, the user might have already filled the address | 1398 // auto-filled. For example, the user might have already filled the address |
| 1441 // part of a form and now be dealing with the credit card section. We only | 1399 // part of a form and now be dealing with the credit card section. We only |
| 1442 // want to reset the auto-filled status for fields that were previewed. | 1400 // want to reset the auto-filled status for fields that were previewed. |
| 1443 WebFormControlElement control_element = control_elements[i]; | 1401 WebFormControlElement control_element = control_elements[i]; |
| 1444 | 1402 |
| 1445 // Only text input, textarea and select elements can be previewed. | 1403 // Only text input, textarea and select elements can be previewed. |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1540 | 1498 |
| 1541 gfx::RectF GetScaledBoundingBox(float scale, WebElement* element) { | 1499 gfx::RectF GetScaledBoundingBox(float scale, WebElement* element) { |
| 1542 gfx::Rect bounding_box(element->boundsInViewportSpace()); | 1500 gfx::Rect bounding_box(element->boundsInViewportSpace()); |
| 1543 return gfx::RectF(bounding_box.x() * scale, | 1501 return gfx::RectF(bounding_box.x() * scale, |
| 1544 bounding_box.y() * scale, | 1502 bounding_box.y() * scale, |
| 1545 bounding_box.width() * scale, | 1503 bounding_box.width() * scale, |
| 1546 bounding_box.height() * scale); | 1504 bounding_box.height() * scale); |
| 1547 } | 1505 } |
| 1548 | 1506 |
| 1549 } // namespace autofill | 1507 } // namespace autofill |
| OLD | NEW |