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 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
668 continue; | 668 continue; |
669 | 669 |
670 tag_names.push_back(parent_node.to<WebElement>().tagName().utf8()); | 670 tag_names.push_back(parent_node.to<WebElement>().tagName().utf8()); |
671 } | 671 } |
672 return tag_names; | 672 return tag_names; |
673 } | 673 } |
674 | 674 |
675 bool IsLabelValid(base::StringPiece16 inferred_label, | 675 bool IsLabelValid(base::StringPiece16 inferred_label, |
676 const std::vector<base::char16>& stop_words) { | 676 const std::vector<base::char16>& stop_words) { |
677 // If |inferred_label| has any character other than those in |stop_words|. | 677 // If |inferred_label| has any character other than those in |stop_words|. |
678 auto first_non_stop_word = std::find_if(inferred_label.begin(), | 678 auto* first_non_stop_word = std::find_if( |
679 inferred_label.end(), [&stop_words](base::char16 c) { | 679 inferred_label.begin(), inferred_label.end(), |
680 return !ContainsValue(stop_words, c); | 680 [&stop_words](base::char16 c) { return !ContainsValue(stop_words, c); }); |
681 }); | |
682 return first_non_stop_word != inferred_label.end(); | 681 return first_non_stop_word != inferred_label.end(); |
683 } | 682 } |
684 | 683 |
685 // Infers corresponding label for |element| from surrounding context in the DOM, | 684 // Infers corresponding label for |element| from surrounding context in the DOM, |
686 // e.g. the contents of the preceding <p> tag or text element. | 685 // e.g. the contents of the preceding <p> tag or text element. |
687 base::string16 InferLabelForElement(const WebFormControlElement& element, | 686 base::string16 InferLabelForElement(const WebFormControlElement& element, |
688 const std::vector<base::char16>& stop_words) { | 687 const std::vector<base::char16>& stop_words) { |
689 base::string16 inferred_label; | 688 base::string16 inferred_label; |
690 | 689 |
691 if (IsCheckableElement(toWebInputElement(&element))) { | 690 if (IsCheckableElement(toWebInputElement(&element))) { |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1139 } | 1138 } |
1140 TruncateString(&form_fields[field_idx]->label, kMaxDataLength); | 1139 TruncateString(&form_fields[field_idx]->label, kMaxDataLength); |
1141 | 1140 |
1142 if (field && *form_control_element == control_element) | 1141 if (field && *form_control_element == control_element) |
1143 *field = *form_fields[field_idx]; | 1142 *field = *form_fields[field_idx]; |
1144 | 1143 |
1145 ++field_idx; | 1144 ++field_idx; |
1146 } | 1145 } |
1147 | 1146 |
1148 // Copy the created FormFields into the resulting FormData object. | 1147 // Copy the created FormFields into the resulting FormData object. |
1149 for (const auto& iter : form_fields) | 1148 for (auto* iter : form_fields) |
vabr (Chromium)
2016/07/19 07:54:08
optional: This could even be "const auto*".
vmpstr
2016/07/19 19:49:30
Done.
| |
1150 form->fields.push_back(*iter); | 1149 form->fields.push_back(*iter); |
1151 return true; | 1150 return true; |
1152 } | 1151 } |
1153 | 1152 |
1154 bool UnownedFormElementsAndFieldSetsToFormData( | 1153 bool UnownedFormElementsAndFieldSetsToFormData( |
1155 const std::vector<blink::WebElement>& fieldsets, | 1154 const std::vector<blink::WebElement>& fieldsets, |
1156 const std::vector<blink::WebFormControlElement>& control_elements, | 1155 const std::vector<blink::WebFormControlElement>& control_elements, |
1157 const blink::WebFormControlElement* element, | 1156 const blink::WebFormControlElement* element, |
1158 const blink::WebDocument& document, | 1157 const blink::WebDocument& document, |
1159 ExtractMask extract_mask, | 1158 ExtractMask extract_mask, |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1544 | 1543 |
1545 const char* const kKeywords[] = { | 1544 const char* const kKeywords[] = { |
1546 "payment", | 1545 "payment", |
1547 "checkout", | 1546 "checkout", |
1548 "address", | 1547 "address", |
1549 "delivery", | 1548 "delivery", |
1550 "shipping", | 1549 "shipping", |
1551 "wallet" | 1550 "wallet" |
1552 }; | 1551 }; |
1553 | 1552 |
1554 for (const auto& keyword : kKeywords) { | 1553 for (auto* keyword : kKeywords) { |
vabr (Chromium)
2016/07/19 07:54:08
nit: "const auto*" to emphasise that |keyword| poi
vmpstr
2016/07/19 19:49:30
Done.
| |
1555 // Compare char16 elements of |title| with char elements of |keyword| using | 1554 // Compare char16 elements of |title| with char elements of |keyword| using |
1556 // operator==. | 1555 // operator==. |
1557 auto title_pos = std::search(title.begin(), title.end(), | 1556 auto title_pos = std::search(title.begin(), title.end(), |
1558 keyword, keyword + strlen(keyword)); | 1557 keyword, keyword + strlen(keyword)); |
1559 if (title_pos != title.end() || | 1558 if (title_pos != title.end() || |
1560 path.find(keyword) != std::string::npos) { | 1559 path.find(keyword) != std::string::npos) { |
1561 form->is_formless_checkout = true; | 1560 form->is_formless_checkout = true; |
1562 // Found a keyword: treat this as an unowned form. | 1561 // Found a keyword: treat this as an unowned form. |
1563 return UnownedFormElementsAndFieldSetsToFormData( | 1562 return UnownedFormElementsAndFieldSetsToFormData( |
1564 fieldsets, control_elements, element, document, extract_mask, form, | 1563 fieldsets, control_elements, element, document, extract_mask, form, |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1789 // Zero selection start is for password manager, which can show usernames | 1788 // Zero selection start is for password manager, which can show usernames |
1790 // that do not begin with the user input value. | 1789 // that do not begin with the user input value. |
1791 selection_start = (offset == base::string16::npos) ? 0 : offset; | 1790 selection_start = (offset == base::string16::npos) ? 0 : offset; |
1792 } | 1791 } |
1793 | 1792 |
1794 input_element->setSelectionRange(selection_start, suggestion.length()); | 1793 input_element->setSelectionRange(selection_start, suggestion.length()); |
1795 } | 1794 } |
1796 | 1795 |
1797 } // namespace form_util | 1796 } // namespace form_util |
1798 } // namespace autofill | 1797 } // namespace autofill |
OLD | NEW |