Chromium Code Reviews| Index: components/autofill/content/renderer/form_autofill_util.cc |
| diff --git a/components/autofill/content/renderer/form_autofill_util.cc b/components/autofill/content/renderer/form_autofill_util.cc |
| index 5c7f0d6102e281c6fa8f457f2e2e7e5acb38a5be..57d989d75773492d9aced89c3610db9dc2ef0a02 100644 |
| --- a/components/autofill/content/renderer/form_autofill_util.cc |
| +++ b/components/autofill/content/renderer/form_autofill_util.cc |
| @@ -1404,36 +1404,53 @@ bool UnownedCheckoutFormElementsAndFieldSetsToFormData( |
| FormFieldData* field) { |
| // Only attempt formless Autofill on checkout flows. This avoids the many |
| // false positives found on the non-checkout web. See |
| - // http://crbug.com/462375. For now this early abort only applies to |
| - // English-language pages, because the regex is not translated. Note that |
| - // an empty "lang" attribute counts as English. A potential problem is that |
| - // this only checks document.title(), but should actually check the main |
| - // frame's title. Thus it may make bad decisions for iframes. |
| + // http://crbug.com/462375. |
| WebElement html_element = document.documentElement(); |
| + |
| + // For now this restriction only applies to English-language pages, because |
| + // the keywords are not translated. Note that an empty "lang" attribute |
| + // counts as English. |
| std::string lang; |
| if (!html_element.isNull()) |
| lang = html_element.getAttribute("lang").utf8(); |
| - if (lang.empty() || |
| - base::StartsWith(lang, "en", base::CompareCase::INSENSITIVE_ASCII)) { |
| - std::string title(base::UTF16ToUTF8(base::string16(document.title()))); |
| - const char* const kKeywords[] = { |
| - "payment", |
| - "checkout", |
| - "address", |
| - "delivery", |
| - "shipping", |
| - }; |
| - |
| - bool found = false; |
| - for (const auto& keyword : kKeywords) { |
| - if (title.find(keyword) != base::string16::npos) { |
| - found = true; |
| - break; |
| - } |
| + if (!lang.empty() && |
| + !base::StartsWith(lang, "en", base::CompareCase::INSENSITIVE_ASCII)) { |
| + return UnownedFormElementsAndFieldSetsToFormData( |
| + fieldsets, control_elements, element, document, extract_mask, form, |
| + field); |
| + } |
| + |
| + // A potential problem is that this only checks document.title(), but should |
| + // actually check the main frame's title. Thus it may make bad decisions for |
| + // iframes. |
| + std::string title = base::ToLowerASCII(base::UTF16ToUTF8(base::string16( |
| + document.title()))); |
| + |
| + // Don't check the path for url's without a standard format path component, |
| + // such as data:. |
| + std::string path; |
| + GURL url(document.url()); |
| + if (url.IsStandard()) |
| + path = base::ToLowerASCII(url.path()); |
| + |
| + const char* const kKeywords[] = { |
| + "payment", |
| + "checkout", |
| + "address", |
| + "delivery", |
| + "shipping", |
| + }; |
| + |
| + bool found = false; |
| + for (const auto& keyword : kKeywords) { |
| + 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.
|
| + path.find(keyword) != base::string16::npos) { |
| + found = true; |
| + break; |
| } |
| - if (!found) |
| - return false; |
| } |
| + if (!found) |
| + return false; |
| return UnownedFormElementsAndFieldSetsToFormData( |
| fieldsets, control_elements, element, document, extract_mask, form, |