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

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: Fix non-English detection Created 5 years 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 1386 matching lines...) Expand 10 before | Expand all | Expand 10 after
1397 bool UnownedCheckoutFormElementsAndFieldSetsToFormData( 1397 bool UnownedCheckoutFormElementsAndFieldSetsToFormData(
1398 const std::vector<blink::WebElement>& fieldsets, 1398 const std::vector<blink::WebElement>& fieldsets,
1399 const std::vector<blink::WebFormControlElement>& control_elements, 1399 const std::vector<blink::WebFormControlElement>& control_elements,
1400 const blink::WebFormControlElement* element, 1400 const blink::WebFormControlElement* element,
1401 const blink::WebDocument& document, 1401 const blink::WebDocument& document,
1402 ExtractMask extract_mask, 1402 ExtractMask extract_mask,
1403 FormData* form, 1403 FormData* form,
1404 FormFieldData* field) { 1404 FormFieldData* field) {
1405 // Only attempt formless Autofill on checkout flows. This avoids the many 1405 // Only attempt formless Autofill on checkout flows. This avoids the many
1406 // false positives found on the non-checkout web. See 1406 // false positives found on the non-checkout web. See
1407 // http://crbug.com/462375. For now this early abort only applies to 1407 // http://crbug.com/462375.
1408 // English-language pages, because the regex is not translated. Note that
1409 // an empty "lang" attribute counts as English. A potential problem is that
1410 // this only checks document.title(), but should actually check the main
1411 // frame's title. Thus it may make bad decisions for iframes.
1412 WebElement html_element = document.documentElement(); 1408 WebElement html_element = document.documentElement();
1409
1410 // For now this restriction only applies to English-language pages, because
1411 // the keywords are not translated. Note that an empty "lang" attribute
1412 // counts as English.
1413 std::string lang; 1413 std::string lang;
1414 if (!html_element.isNull()) 1414 if (!html_element.isNull())
1415 lang = html_element.getAttribute("lang").utf8(); 1415 lang = html_element.getAttribute("lang").utf8();
1416 if (lang.empty() || 1416 if (!lang.empty() &&
1417 base::StartsWith(lang, "en", base::CompareCase::INSENSITIVE_ASCII)) { 1417 !base::StartsWith(lang, "en", base::CompareCase::INSENSITIVE_ASCII)) {
1418 std::string title(base::UTF16ToUTF8(base::string16(document.title()))); 1418 return UnownedFormElementsAndFieldSetsToFormData(
1419 const char* const kKeywords[] = { 1419 fieldsets, control_elements, element, document, extract_mask, form,
1420 "payment", 1420 field);
1421 "checkout", 1421 }
1422 "address",
1423 "delivery",
1424 "shipping",
1425 };
1426 1422
1427 bool found = false; 1423 // A potential problem is that this only checks document.title(), but should
1428 for (const auto& keyword : kKeywords) { 1424 // actually check the main frame's title. Thus it may make bad decisions for
1429 if (title.find(keyword) != base::string16::npos) { 1425 // iframes.
1430 found = true; 1426 std::string title = base::ToLowerASCII(base::UTF16ToUTF8(base::string16(
1431 break; 1427 document.title())));
1432 } 1428
1429 // Don't check the path for url's without a standard format path component,
1430 // such as data:.
1431 std::string path;
1432 GURL url(document.url());
1433 if (url.IsStandard())
1434 path = base::ToLowerASCII(url.path());
1435
1436 const char* const kKeywords[] = {
1437 "payment",
1438 "checkout",
1439 "address",
1440 "delivery",
1441 "shipping",
1442 };
1443
1444 bool found = false;
1445 for (const auto& keyword : kKeywords) {
1446 if (title.find(keyword) != base::string16::npos ||
Evan Stade 2015/12/10 19:34:00 I think you should use std::find_if with base::Low
Joe Mason 2015/12/10 20:06:58 That would be less efficient since we need to conv
Evan Stade 2015/12/10 21:21:11 You're right, probably not a huge difference, but
Joe Mason 2015/12/11 20:41:43 Done.
1447 path.find(keyword) != base::string16::npos) {
1448 found = true;
1449 break;
1433 } 1450 }
1434 if (!found)
1435 return false;
1436 } 1451 }
1452 if (!found)
1453 return false;
1437 1454
1438 return UnownedFormElementsAndFieldSetsToFormData( 1455 return UnownedFormElementsAndFieldSetsToFormData(
1439 fieldsets, control_elements, element, document, extract_mask, form, 1456 fieldsets, control_elements, element, document, extract_mask, form,
1440 field); 1457 field);
1441 } 1458 }
1442 1459
1443 bool UnownedPasswordFormElementsAndFieldSetsToFormData( 1460 bool UnownedPasswordFormElementsAndFieldSetsToFormData(
1444 const std::vector<blink::WebElement>& fieldsets, 1461 const std::vector<blink::WebElement>& fieldsets,
1445 const std::vector<blink::WebFormControlElement>& control_elements, 1462 const std::vector<blink::WebFormControlElement>& control_elements,
1446 const blink::WebFormControlElement* element, 1463 const blink::WebFormControlElement* element,
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1645 // Zero selection start is for password manager, which can show usernames 1662 // Zero selection start is for password manager, which can show usernames
1646 // that do not begin with the user input value. 1663 // that do not begin with the user input value.
1647 selection_start = (offset == base::string16::npos) ? 0 : offset; 1664 selection_start = (offset == base::string16::npos) ? 0 : offset;
1648 } 1665 }
1649 1666
1650 input_element->setSelectionRange(selection_start, suggestion.length()); 1667 input_element->setSelectionRange(selection_start, suggestion.length());
1651 } 1668 }
1652 1669
1653 } // namespace form_util 1670 } // namespace form_util
1654 } // namespace autofill 1671 } // 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