Chromium Code Reviews| 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 1386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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(); |
|
jungshik at Google
2015/12/16 21:14:04
Although not very common, there are documents with
| |
| 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. | |
|
jungshik at Google
2015/12/14 23:53:56
It'd better to treat an empty 'lang' as in the cur
| |
| 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)) { |
|
jungshik at Google
2015/12/14 23:53:57
This assumes that there is no language code (3-let
| |
| 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 base::string16 title(base::ToLowerASCII(base::string16(document.title()))); |
| 1431 break; | 1427 |
| 1432 } | 1428 // Don't check the path for url's without a standard format path component, |
| 1429 // such as data:. | |
| 1430 std::string path; | |
| 1431 GURL url(document.url()); | |
| 1432 if (url.IsStandard()) | |
| 1433 path = base::ToLowerASCII(url.path()); | |
| 1434 | |
| 1435 const char* const kKeywords[] = { | |
| 1436 "payment", | |
| 1437 "checkout", | |
| 1438 "address", | |
| 1439 "delivery", | |
| 1440 "shipping", | |
| 1441 }; | |
| 1442 | |
| 1443 bool found = false; | |
| 1444 for (const auto& keyword : kKeywords) { | |
| 1445 // Compare char16 elements of |title| with char elements of |keyword| using | |
| 1446 // operator==. | |
| 1447 auto title_pos = std::search(title.begin(), title.end(), | |
| 1448 keyword, keyword + strlen(keyword)); | |
| 1449 if (title_pos != title.end() || | |
| 1450 path.find(keyword) != std::string::npos) { | |
| 1451 found = true; | |
| 1452 break; | |
| 1433 } | 1453 } |
| 1434 if (!found) | |
| 1435 return false; | |
| 1436 } | 1454 } |
| 1455 if (!found) | |
| 1456 return false; | |
| 1437 | 1457 |
| 1438 return UnownedFormElementsAndFieldSetsToFormData( | 1458 return UnownedFormElementsAndFieldSetsToFormData( |
|
Evan Stade
2016/01/08 21:53:16
seems like you can just stick this inside the loop
| |
| 1439 fieldsets, control_elements, element, document, extract_mask, form, | 1459 fieldsets, control_elements, element, document, extract_mask, form, |
| 1440 field); | 1460 field); |
| 1441 } | 1461 } |
| 1442 | 1462 |
| 1443 bool UnownedPasswordFormElementsAndFieldSetsToFormData( | 1463 bool UnownedPasswordFormElementsAndFieldSetsToFormData( |
| 1444 const std::vector<blink::WebElement>& fieldsets, | 1464 const std::vector<blink::WebElement>& fieldsets, |
| 1445 const std::vector<blink::WebFormControlElement>& control_elements, | 1465 const std::vector<blink::WebFormControlElement>& control_elements, |
| 1446 const blink::WebFormControlElement* element, | 1466 const blink::WebFormControlElement* element, |
| 1447 const blink::WebDocument& document, | 1467 const blink::WebDocument& document, |
| 1448 ExtractMask extract_mask, | 1468 ExtractMask extract_mask, |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1645 // Zero selection start is for password manager, which can show usernames | 1665 // Zero selection start is for password manager, which can show usernames |
| 1646 // that do not begin with the user input value. | 1666 // that do not begin with the user input value. |
| 1647 selection_start = (offset == base::string16::npos) ? 0 : offset; | 1667 selection_start = (offset == base::string16::npos) ? 0 : offset; |
| 1648 } | 1668 } |
| 1649 | 1669 |
| 1650 input_element->setSelectionRange(selection_start, suggestion.length()); | 1670 input_element->setSelectionRange(selection_start, suggestion.length()); |
| 1651 } | 1671 } |
| 1652 | 1672 |
| 1653 } // namespace form_util | 1673 } // namespace form_util |
| 1654 } // namespace autofill | 1674 } // namespace autofill |
| OLD | NEW |