| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/renderer/autofill/form_autofill_util.h" | 5 #include "chrome/renderer/autofill/form_autofill_util.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 // Select the part of the text that the user didn't type. | 528 // Select the part of the text that the user didn't type. |
| 529 input_element->setSelectionRange(input_element->value().length(), | 529 input_element->setSelectionRange(input_element->value().length(), |
| 530 input_element->suggestedValue().length()); | 530 input_element->suggestedValue().length()); |
| 531 } | 531 } |
| 532 } | 532 } |
| 533 | 533 |
| 534 } // namespace | 534 } // namespace |
| 535 | 535 |
| 536 namespace autofill { | 536 namespace autofill { |
| 537 | 537 |
| 538 const size_t kMaxParseableFields = 100; |
| 539 |
| 538 // In HTML5, all text fields except password are text input fields to | 540 // In HTML5, all text fields except password are text input fields to |
| 539 // autocomplete. | 541 // autocomplete. |
| 540 bool IsTextInput(const WebInputElement* element) { | 542 bool IsTextInput(const WebInputElement* element) { |
| 541 if (!element) | 543 if (!element) |
| 542 return false; | 544 return false; |
| 543 | 545 |
| 544 return element->isTextField() && !element->isPasswordField(); | 546 return element->isTextField() && !element->isPasswordField(); |
| 545 } | 547 } |
| 546 | 548 |
| 547 bool IsSelectElement(const WebFormControlElement& element) { | 549 bool IsSelectElement(const WebFormControlElement& element) { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 FormField* form_field = new FormField; | 712 FormField* form_field = new FormField; |
| 711 WebFormControlElementToFormField(control_element, extract_mask, form_field); | 713 WebFormControlElementToFormField(control_element, extract_mask, form_field); |
| 712 form_fields.push_back(form_field); | 714 form_fields.push_back(form_field); |
| 713 // TODO(jhawkins): A label element is mapped to a form control element's id. | 715 // TODO(jhawkins): A label element is mapped to a form control element's id. |
| 714 // field->name() will contain the id only if the name does not exist. Add | 716 // field->name() will contain the id only if the name does not exist. Add |
| 715 // an id() method to WebFormControlElement and use that here. | 717 // an id() method to WebFormControlElement and use that here. |
| 716 name_map[form_field->name] = form_field; | 718 name_map[form_field->name] = form_field; |
| 717 fields_extracted[i] = true; | 719 fields_extracted[i] = true; |
| 718 } | 720 } |
| 719 | 721 |
| 720 // If we failed to extract any fields, give up. | 722 // If we failed to extract any fields, give up. Also, to avoid overly |
| 721 if (form_fields.empty()) | 723 // expensive computation, we impose a maximum number of allowable fields. |
| 724 if (form_fields.empty() || form_fields.size() > kMaxParseableFields) |
| 722 return false; | 725 return false; |
| 723 | 726 |
| 724 // Loop through the label elements inside the form element. For each label | 727 // Loop through the label elements inside the form element. For each label |
| 725 // element, get the corresponding form control element, use the form control | 728 // element, get the corresponding form control element, use the form control |
| 726 // element's name as a key into the <name, FormField> map to find the | 729 // element's name as a key into the <name, FormField> map to find the |
| 727 // previously created FormField and set the FormField's label to the | 730 // previously created FormField and set the FormField's label to the |
| 728 // label.firstChild().nodeValue() of the label element. | 731 // label.firstChild().nodeValue() of the label element. |
| 729 WebNodeList labels = form_element.getElementsByTagName("label"); | 732 WebNodeList labels = form_element.getElementsByTagName("label"); |
| 730 for (unsigned i = 0; i < labels.length(); ++i) { | 733 for (unsigned i = 0; i < labels.length(); ++i) { |
| 731 WebLabelElement label = labels.item(i).to<WebLabelElement>(); | 734 WebLabelElement label = labels.item(i).to<WebLabelElement>(); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 continue; | 895 continue; |
| 893 | 896 |
| 894 if (input_element->isAutofilled()) | 897 if (input_element->isAutofilled()) |
| 895 return true; | 898 return true; |
| 896 } | 899 } |
| 897 | 900 |
| 898 return false; | 901 return false; |
| 899 } | 902 } |
| 900 | 903 |
| 901 } // namespace autofill | 904 } // namespace autofill |
| OLD | NEW |