| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_manager.h" | 5 #include "chrome/renderer/autofill/form_manager.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 element_name = label.getAttribute("for"); | 757 element_name = label.getAttribute("for"); |
| 758 } else if ( | 758 } else if ( |
| 759 !field_element.isFormControlElement() || | 759 !field_element.isFormControlElement() || |
| 760 field_element.formControlType() == WebString::fromUTF8("hidden")) { | 760 field_element.formControlType() == WebString::fromUTF8("hidden")) { |
| 761 continue; | 761 continue; |
| 762 } else { | 762 } else { |
| 763 element_name = field_element.nameForAutofill(); | 763 element_name = field_element.nameForAutofill(); |
| 764 } | 764 } |
| 765 | 765 |
| 766 std::map<string16, FormField*>::iterator iter = name_map.find(element_name); | 766 std::map<string16, FormField*>::iterator iter = name_map.find(element_name); |
| 767 // Concatenate labels because some sites might have multiple label | 767 if (iter != name_map.end()) { |
| 768 // candidates. | 768 string16 label_text = FindChildText(label); |
| 769 if (iter != name_map.end()) | 769 |
| 770 iter->second->label += FindChildText(label); | 770 // Concatenate labels because some sites might have multiple label |
| 771 // candidates. |
| 772 if (!iter->second->label.empty() && !label_text.empty()) |
| 773 iter->second->label += ASCIIToUTF16(" "); |
| 774 iter->second->label += label_text; |
| 775 } |
| 771 } | 776 } |
| 772 | 777 |
| 773 // Loop through the form control elements, extracting the label text from | 778 // Loop through the form control elements, extracting the label text from |
| 774 // the DOM. We use the |fields_extracted| vector to make sure we assign the | 779 // the DOM. We use the |fields_extracted| vector to make sure we assign the |
| 775 // extracted label to the correct field, as it's possible |form_fields| will | 780 // extracted label to the correct field, as it's possible |form_fields| will |
| 776 // not contain all of the elements in |control_elements|. | 781 // not contain all of the elements in |control_elements|. |
| 777 for (size_t i = 0, field_idx = 0; | 782 for (size_t i = 0, field_idx = 0; |
| 778 i < control_elements.size() && field_idx < form_fields.size(); ++i) { | 783 i < control_elements.size() && field_idx < form_fields.size(); ++i) { |
| 779 // This field didn't meet the requirements, so don't try to find a label | 784 // This field didn't meet the requirements, so don't try to find a label |
| 780 // for it. | 785 // for it. |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1094 if (element_name == form.name && action == form.action) { | 1099 if (element_name == form.name && action == form.action) { |
| 1095 *form_element = *form_iter; | 1100 *form_element = *form_iter; |
| 1096 return true; | 1101 return true; |
| 1097 } | 1102 } |
| 1098 } | 1103 } |
| 1099 | 1104 |
| 1100 return false; | 1105 return false; |
| 1101 } | 1106 } |
| 1102 | 1107 |
| 1103 } // namespace autofill | 1108 } // namespace autofill |
| OLD | NEW |