| 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 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 continue; | 803 continue; |
| 804 } | 804 } |
| 805 | 805 |
| 806 bool is_initiating_element = (*element == initiating_element); | 806 bool is_initiating_element = (*element == initiating_element); |
| 807 | 807 |
| 808 // Only autofill empty fields (or those with the field's default value | 808 // Only autofill empty fields (or those with the field's default value |
| 809 // attribute) and the field that initiated the filling, i.e. the field the | 809 // attribute) and the field that initiated the filling, i.e. the field the |
| 810 // user is currently editing and interacting with. | 810 // user is currently editing and interacting with. |
| 811 const WebInputElement* input_element = toWebInputElement(element); | 811 const WebInputElement* input_element = toWebInputElement(element); |
| 812 CR_DEFINE_STATIC_LOCAL(WebString, kValue, ("value")); | 812 CR_DEFINE_STATIC_LOCAL(WebString, kValue, ("value")); |
| 813 CR_DEFINE_STATIC_LOCAL(WebString, kPlaceholder, ("placeholder")); |
| 813 if (!force_override && !is_initiating_element && | 814 if (!force_override && !is_initiating_element && |
| 814 // A text field, with a non-empty value that is NOT the value of the | 815 // A text field, with a non-empty value that is NOT the value of the |
| 815 // input field's "value" attribute, is skipped. | 816 // input field's "value" or "placeholder" attribute, is skipped. |
| 816 (IsAutofillableInputElement(input_element) || | 817 (IsAutofillableInputElement(input_element) || |
| 817 IsTextAreaElement(*element)) && | 818 IsTextAreaElement(*element)) && |
| 818 !element->value().isEmpty() && | 819 !element->value().isEmpty() && |
| 819 (!element->hasAttribute(kValue) || | 820 (!element->hasAttribute(kValue) || |
| 820 element->getAttribute(kValue) != element->value())) | 821 element->getAttribute(kValue) != element->value()) && |
| 822 (!element->hasAttribute(kPlaceholder) || |
| 823 element->getAttribute(kPlaceholder) != element->value())) |
| 821 continue; | 824 continue; |
| 822 | 825 |
| 823 if (((filters & FILTER_DISABLED_ELEMENTS) && !element->isEnabled()) || | 826 if (((filters & FILTER_DISABLED_ELEMENTS) && !element->isEnabled()) || |
| 824 ((filters & FILTER_READONLY_ELEMENTS) && element->isReadOnly()) || | 827 ((filters & FILTER_READONLY_ELEMENTS) && element->isReadOnly()) || |
| 825 // See description for FILTER_NON_FOCUSABLE_ELEMENTS. | 828 // See description for FILTER_NON_FOCUSABLE_ELEMENTS. |
| 826 ((filters & FILTER_NON_FOCUSABLE_ELEMENTS) && !element->isFocusable() && | 829 ((filters & FILTER_NON_FOCUSABLE_ELEMENTS) && !element->isFocusable() && |
| 827 !IsSelectElement(*element))) | 830 !IsSelectElement(*element))) |
| 828 continue; | 831 continue; |
| 829 | 832 |
| 830 callback(data.fields[i], is_initiating_element, element); | 833 callback(data.fields[i], is_initiating_element, element); |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1333 return ExtractAutofillableElementsFromSet(control_elements); | 1336 return ExtractAutofillableElementsFromSet(control_elements); |
| 1334 } | 1337 } |
| 1335 | 1338 |
| 1336 void WebFormControlElementToFormField(const WebFormControlElement& element, | 1339 void WebFormControlElementToFormField(const WebFormControlElement& element, |
| 1337 ExtractMask extract_mask, | 1340 ExtractMask extract_mask, |
| 1338 FormFieldData* field) { | 1341 FormFieldData* field) { |
| 1339 DCHECK(field); | 1342 DCHECK(field); |
| 1340 DCHECK(!element.isNull()); | 1343 DCHECK(!element.isNull()); |
| 1341 CR_DEFINE_STATIC_LOCAL(WebString, kAutocomplete, ("autocomplete")); | 1344 CR_DEFINE_STATIC_LOCAL(WebString, kAutocomplete, ("autocomplete")); |
| 1342 CR_DEFINE_STATIC_LOCAL(WebString, kRole, ("role")); | 1345 CR_DEFINE_STATIC_LOCAL(WebString, kRole, ("role")); |
| 1346 CR_DEFINE_STATIC_LOCAL(WebString, kPlaceholder, ("placeholder")); |
| 1343 | 1347 |
| 1344 // The label is not officially part of a WebFormControlElement; however, the | 1348 // The label is not officially part of a WebFormControlElement; however, the |
| 1345 // labels for all form control elements are scraped from the DOM and set in | 1349 // labels for all form control elements are scraped from the DOM and set in |
| 1346 // WebFormElementToFormData. | 1350 // WebFormElementToFormData. |
| 1347 field->name = element.nameForAutofill(); | 1351 field->name = element.nameForAutofill(); |
| 1348 field->form_control_type = element.formControlType().utf8(); | 1352 field->form_control_type = element.formControlType().utf8(); |
| 1349 field->autocomplete_attribute = element.getAttribute(kAutocomplete).utf8(); | 1353 field->autocomplete_attribute = element.getAttribute(kAutocomplete).utf8(); |
| 1350 if (field->autocomplete_attribute.size() > kMaxDataLength) { | 1354 if (field->autocomplete_attribute.size() > kMaxDataLength) { |
| 1351 // Discard overly long attribute values to avoid DOS-ing the browser | 1355 // Discard overly long attribute values to avoid DOS-ing the browser |
| 1352 // process. However, send over a default string to indicate that the | 1356 // process. However, send over a default string to indicate that the |
| 1353 // attribute was present. | 1357 // attribute was present. |
| 1354 field->autocomplete_attribute = "x-max-data-length-exceeded"; | 1358 field->autocomplete_attribute = "x-max-data-length-exceeded"; |
| 1355 } | 1359 } |
| 1356 if (base::LowerCaseEqualsASCII( | 1360 if (base::LowerCaseEqualsASCII( |
| 1357 base::StringPiece16(element.getAttribute(kRole)), "presentation")) | 1361 base::StringPiece16(element.getAttribute(kRole)), "presentation")) |
| 1358 field->role = FormFieldData::ROLE_ATTRIBUTE_PRESENTATION; | 1362 field->role = FormFieldData::ROLE_ATTRIBUTE_PRESENTATION; |
| 1359 | 1363 |
| 1364 field->placeholder = element.getAttribute(kPlaceholder); |
| 1365 |
| 1360 if (!IsAutofillableElement(element)) | 1366 if (!IsAutofillableElement(element)) |
| 1361 return; | 1367 return; |
| 1362 | 1368 |
| 1363 const WebInputElement* input_element = toWebInputElement(&element); | 1369 const WebInputElement* input_element = toWebInputElement(&element); |
| 1364 if (IsAutofillableInputElement(input_element) || | 1370 if (IsAutofillableInputElement(input_element) || |
| 1365 IsTextAreaElement(element) || | 1371 IsTextAreaElement(element) || |
| 1366 IsSelectElement(element)) { | 1372 IsSelectElement(element)) { |
| 1367 field->is_autofilled = element.isAutofilled(); | 1373 field->is_autofilled = element.isAutofilled(); |
| 1368 field->is_focusable = element.isFocusable(); | 1374 field->is_focusable = element.isFocusable(); |
| 1369 field->should_autocomplete = element.autoComplete(); | 1375 field->should_autocomplete = element.autoComplete(); |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1757 // Zero selection start is for password manager, which can show usernames | 1763 // Zero selection start is for password manager, which can show usernames |
| 1758 // that do not begin with the user input value. | 1764 // that do not begin with the user input value. |
| 1759 selection_start = (offset == base::string16::npos) ? 0 : offset; | 1765 selection_start = (offset == base::string16::npos) ? 0 : offset; |
| 1760 } | 1766 } |
| 1761 | 1767 |
| 1762 input_element->setSelectionRange(selection_start, suggestion.length()); | 1768 input_element->setSelectionRange(selection_start, suggestion.length()); |
| 1763 } | 1769 } |
| 1764 | 1770 |
| 1765 } // namespace form_util | 1771 } // namespace form_util |
| 1766 } // namespace autofill | 1772 } // namespace autofill |
| OLD | NEW |