| 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 1502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1513 "wallet" | 1513 "wallet" |
| 1514 }; | 1514 }; |
| 1515 | 1515 |
| 1516 for (const auto& keyword : kKeywords) { | 1516 for (const auto& keyword : kKeywords) { |
| 1517 // Compare char16 elements of |title| with char elements of |keyword| using | 1517 // Compare char16 elements of |title| with char elements of |keyword| using |
| 1518 // operator==. | 1518 // operator==. |
| 1519 auto title_pos = std::search(title.begin(), title.end(), | 1519 auto title_pos = std::search(title.begin(), title.end(), |
| 1520 keyword, keyword + strlen(keyword)); | 1520 keyword, keyword + strlen(keyword)); |
| 1521 if (title_pos != title.end() || | 1521 if (title_pos != title.end() || |
| 1522 path.find(keyword) != std::string::npos) { | 1522 path.find(keyword) != std::string::npos) { |
| 1523 form->is_formless_checkout = true; |
| 1523 // Found a keyword: treat this as an unowned form. | 1524 // Found a keyword: treat this as an unowned form. |
| 1524 return UnownedFormElementsAndFieldSetsToFormData( | 1525 return UnownedFormElementsAndFieldSetsToFormData( |
| 1525 fieldsets, control_elements, element, document, extract_mask, form, | 1526 fieldsets, control_elements, element, document, extract_mask, form, |
| 1526 field); | 1527 field); |
| 1527 } | 1528 } |
| 1528 } | 1529 } |
| 1529 | 1530 |
| 1530 return false; | 1531 // Since it's not a checkout flow, only add fields that have a non-"off" |
| 1532 // autocomplete attribute to the formless autofill. |
| 1533 CR_DEFINE_STATIC_LOCAL(WebString, kOffAttribute, ("off")); |
| 1534 std::vector<WebFormControlElement> elements_with_autocomplete; |
| 1535 for (const WebFormControlElement& element : control_elements) { |
| 1536 blink::WebString autocomplete = element.getAttribute("autocomplete"); |
| 1537 if (autocomplete.length() && autocomplete != kOffAttribute) |
| 1538 elements_with_autocomplete.push_back(element); |
| 1539 } |
| 1540 |
| 1541 if (elements_with_autocomplete.empty()) |
| 1542 return false; |
| 1543 |
| 1544 return UnownedFormElementsAndFieldSetsToFormData( |
| 1545 fieldsets, elements_with_autocomplete, element, document, extract_mask, |
| 1546 form, field); |
| 1531 } | 1547 } |
| 1532 | 1548 |
| 1533 bool UnownedPasswordFormElementsAndFieldSetsToFormData( | 1549 bool UnownedPasswordFormElementsAndFieldSetsToFormData( |
| 1534 const std::vector<blink::WebElement>& fieldsets, | 1550 const std::vector<blink::WebElement>& fieldsets, |
| 1535 const std::vector<blink::WebFormControlElement>& control_elements, | 1551 const std::vector<blink::WebFormControlElement>& control_elements, |
| 1536 const blink::WebFormControlElement* element, | 1552 const blink::WebFormControlElement* element, |
| 1537 const blink::WebDocument& document, | 1553 const blink::WebDocument& document, |
| 1538 ExtractMask extract_mask, | 1554 ExtractMask extract_mask, |
| 1539 FormData* form, | 1555 FormData* form, |
| 1540 FormFieldData* field) { | 1556 FormFieldData* field) { |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1735 // Zero selection start is for password manager, which can show usernames | 1751 // Zero selection start is for password manager, which can show usernames |
| 1736 // that do not begin with the user input value. | 1752 // that do not begin with the user input value. |
| 1737 selection_start = (offset == base::string16::npos) ? 0 : offset; | 1753 selection_start = (offset == base::string16::npos) ? 0 : offset; |
| 1738 } | 1754 } |
| 1739 | 1755 |
| 1740 input_element->setSelectionRange(selection_start, suggestion.length()); | 1756 input_element->setSelectionRange(selection_start, suggestion.length()); |
| 1741 } | 1757 } |
| 1742 | 1758 |
| 1743 } // namespace form_util | 1759 } // namespace form_util |
| 1744 } // namespace autofill | 1760 } // namespace autofill |
| OLD | NEW |