Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: components/autofill/content/renderer/form_autofill_util.cc

Issue 1508293006: Check url path as well as document title to detect formless autofill page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: – Rebaseline heuristic test output Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1450 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 bool UnownedCheckoutFormElementsAndFieldSetsToFormData( 1461 bool UnownedCheckoutFormElementsAndFieldSetsToFormData(
1462 const std::vector<blink::WebElement>& fieldsets, 1462 const std::vector<blink::WebElement>& fieldsets,
1463 const std::vector<blink::WebFormControlElement>& control_elements, 1463 const std::vector<blink::WebFormControlElement>& control_elements,
1464 const blink::WebFormControlElement* element, 1464 const blink::WebFormControlElement* element,
1465 const blink::WebDocument& document, 1465 const blink::WebDocument& document,
1466 ExtractMask extract_mask, 1466 ExtractMask extract_mask,
1467 FormData* form, 1467 FormData* form,
1468 FormFieldData* field) { 1468 FormFieldData* field) {
1469 // Only attempt formless Autofill on checkout flows. This avoids the many 1469 // Only attempt formless Autofill on checkout flows. This avoids the many
1470 // false positives found on the non-checkout web. See 1470 // false positives found on the non-checkout web. See
1471 // http://crbug.com/462375. For now this early abort only applies to 1471 // http://crbug.com/462375.
1472 // English-language pages, because the regex is not translated. Note that
1473 // an empty "lang" attribute counts as English. A potential problem is that
1474 // this only checks document.title(), but should actually check the main
1475 // frame's title. Thus it may make bad decisions for iframes.
1476 WebElement html_element = document.documentElement(); 1472 WebElement html_element = document.documentElement();
1473
1474 // For now this restriction only applies to English-language pages, because
1475 // the keywords are not translated. Note that an empty "lang" attribute
1476 // counts as English.
1477 std::string lang; 1477 std::string lang;
1478 if (!html_element.isNull()) 1478 if (!html_element.isNull())
1479 lang = html_element.getAttribute("lang").utf8(); 1479 lang = html_element.getAttribute("lang").utf8();
1480 if (lang.empty() || 1480 if (!lang.empty() &&
1481 base::StartsWith(lang, "en", base::CompareCase::INSENSITIVE_ASCII)) { 1481 !base::StartsWith(lang, "en", base::CompareCase::INSENSITIVE_ASCII)) {
1482 std::string title(base::UTF16ToUTF8(base::string16(document.title()))); 1482 return UnownedFormElementsAndFieldSetsToFormData(
1483 const char* const kKeywords[] = { 1483 fieldsets, control_elements, element, document, extract_mask, form,
1484 "payment", 1484 field);
1485 "checkout",
1486 "address",
1487 "delivery",
1488 "shipping",
1489 };
1490
1491 bool found = false;
1492 for (const auto& keyword : kKeywords) {
1493 if (title.find(keyword) != base::string16::npos) {
1494 found = true;
1495 break;
1496 }
1497 }
1498 if (!found)
1499 return false;
1500 } 1485 }
1501 1486
1502 return UnownedFormElementsAndFieldSetsToFormData( 1487 // A potential problem is that this only checks document.title(), but should
1503 fieldsets, control_elements, element, document, extract_mask, form, 1488 // actually check the main frame's title. Thus it may make bad decisions for
1504 field); 1489 // iframes.
1490 base::string16 title(base::ToLowerASCII(base::string16(document.title())));
1491
1492 // Don't check the path for url's without a standard format path component,
1493 // such as data:.
1494 std::string path;
1495 GURL url(document.url());
1496 if (url.IsStandard())
1497 path = base::ToLowerASCII(url.path());
1498
1499 const char* const kKeywords[] = {
1500 "payment",
1501 "checkout",
1502 "address",
1503 "delivery",
1504 "shipping",
1505 };
1506
1507 for (const auto& keyword : kKeywords) {
1508 // Compare char16 elements of |title| with char elements of |keyword| using
1509 // operator==.
1510 auto title_pos = std::search(title.begin(), title.end(),
1511 keyword, keyword + strlen(keyword));
1512 if (title_pos != title.end() ||
1513 path.find(keyword) != std::string::npos) {
1514 // Found a keyword: treat this as an unowned form.
1515 return UnownedFormElementsAndFieldSetsToFormData(
1516 fieldsets, control_elements, element, document, extract_mask, form,
1517 field);
1518 }
1519 }
1520
1521 return false;
1505 } 1522 }
1506 1523
1507 bool UnownedPasswordFormElementsAndFieldSetsToFormData( 1524 bool UnownedPasswordFormElementsAndFieldSetsToFormData(
1508 const std::vector<blink::WebElement>& fieldsets, 1525 const std::vector<blink::WebElement>& fieldsets,
1509 const std::vector<blink::WebFormControlElement>& control_elements, 1526 const std::vector<blink::WebFormControlElement>& control_elements,
1510 const blink::WebFormControlElement* element, 1527 const blink::WebFormControlElement* element,
1511 const blink::WebDocument& document, 1528 const blink::WebDocument& document,
1512 ExtractMask extract_mask, 1529 ExtractMask extract_mask,
1513 FormData* form, 1530 FormData* form,
1514 FormFieldData* field) { 1531 FormFieldData* field) {
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1709 // Zero selection start is for password manager, which can show usernames 1726 // Zero selection start is for password manager, which can show usernames
1710 // that do not begin with the user input value. 1727 // that do not begin with the user input value.
1711 selection_start = (offset == base::string16::npos) ? 0 : offset; 1728 selection_start = (offset == base::string16::npos) ? 0 : offset;
1712 } 1729 }
1713 1730
1714 input_element->setSelectionRange(selection_start, suggestion.length()); 1731 input_element->setSelectionRange(selection_start, suggestion.length());
1715 } 1732 }
1716 1733
1717 } // namespace form_util 1734 } // namespace form_util
1718 } // namespace autofill 1735 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/test/data/autofill/heuristics/output/bug_555010.out ('k') | content/public/test/render_view_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698