diff options
author | estade <estade@chromium.org> | 2015-04-27 13:05:17 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-27 20:05:22 +0000 |
commit | aa3219ce27ef5471c19670fe5145b136925cbc89 (patch) | |
tree | f6df2ab9bf44f52e682d0f0d7ebfd54a94666062 /components | |
parent | 70027abd1a6d6e23f05c40128203b95f13b6761b (diff) | |
download | chromium_src-aa3219ce27ef5471c19670fe5145b136925cbc89.zip chromium_src-aa3219ce27ef5471c19670fe5145b136925cbc89.tar.gz chromium_src-aa3219ce27ef5471c19670fe5145b136925cbc89.tar.bz2 |
Limit form-less Autofilling to pages that look like checkout pages.
This should hopefully stem the tide of false positives on non-checkout pages, while preserving desired behavior on Best Buy and Apple checkout.
Fixing FormStructureBrowserTests: I went back and added <form>s that were present in the source pages but not in the local copies. I also added the original <title> tags, except for ones that did /not/ include any of the checkout keywords. For these, I added the checkout keywords to the title, so that the test still had some value (instead of passing trivially because the title was "Google Calendar" and not something like "Payment information").
BUG=471090,477466
Review URL: https://codereview.chromium.org/1081803003
Cr-Commit-Position: refs/heads/master@{#327108}
Diffstat (limited to 'components')
14 files changed, 43 insertions, 24 deletions
diff --git a/components/autofill.gypi b/components/autofill.gypi index 25f6909..283881c 100644 --- a/components/autofill.gypi +++ b/components/autofill.gypi @@ -27,6 +27,8 @@ 'autofill/core/common/autofill_l10n_util.h', 'autofill/core/common/autofill_pref_names.cc', 'autofill/core/common/autofill_pref_names.h', + 'autofill/core/common/autofill_regexes.cc', + 'autofill/core/common/autofill_regexes.h', 'autofill/core/common/autofill_switches.cc', 'autofill/core/common/autofill_switches.h', 'autofill/core/common/form_data.cc', @@ -48,6 +50,9 @@ 'autofill/core/common/web_element_descriptor.cc', 'autofill/core/common/web_element_descriptor.h', ], + + # TODO(jschuh): crbug.com/167187 fix size_t to int truncations. + 'msvs_disabled_warnings': [4267, ], }, { @@ -126,8 +131,6 @@ 'autofill/core/browser/autofill_profile.h', 'autofill/core/browser/autofill_regex_constants.cc', 'autofill/core/browser/autofill_regex_constants.h', - 'autofill/core/browser/autofill_regexes.cc', - 'autofill/core/browser/autofill_regexes.h', 'autofill/core/browser/autofill_scanner.cc', 'autofill/core/browser/autofill_scanner.h', 'autofill/core/browser/autofill_server_field_info.h', diff --git a/components/autofill/content/renderer/form_autofill_util.cc b/components/autofill/content/renderer/form_autofill_util.cc index b1f3056..ab28cde 100644 --- a/components/autofill/content/renderer/form_autofill_util.cc +++ b/components/autofill/content/renderer/form_autofill_util.cc @@ -14,6 +14,7 @@ #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "components/autofill/core/common/autofill_data_validation.h" +#include "components/autofill/core/common/autofill_regexes.h" #include "components/autofill/core/common/autofill_switches.h" #include "components/autofill/core/common/form_data.h" #include "components/autofill/core/common/form_field_data.h" @@ -1161,9 +1162,8 @@ void WebFormControlElementToFormField(const WebFormControlElement& element, // labels for all form control elements are scraped from the DOM and set in // WebFormElementToFormData. field->name = element.nameForAutofill(); - field->form_control_type = base::UTF16ToUTF8(element.formControlType()); - field->autocomplete_attribute = - base::UTF16ToUTF8(element.getAttribute(kAutocomplete)); + field->form_control_type = element.formControlType().utf8(); + field->autocomplete_attribute = element.getAttribute(kAutocomplete).utf8(); if (field->autocomplete_attribute.size() > kMaxDataLength) { // Discard overly long attribute values to avoid DOS-ing the browser // process. However, send over a default string to indicate that the @@ -1286,11 +1286,28 @@ bool UnownedFormElementsAndFieldSetsToFormData( const std::vector<blink::WebElement>& fieldsets, const std::vector<blink::WebFormControlElement>& control_elements, const blink::WebFormControlElement* element, - const GURL& origin, + const blink::WebDocument& document, ExtractMask extract_mask, FormData* form, FormFieldData* field) { - form->origin = origin; + // 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. + WebElement html_element = document.documentElement(); + std::string lang; + if (!html_element.isNull()) + lang = html_element.getAttribute("lang").utf8(); + if ((lang.empty() || StartsWithASCII(lang, "en", false)) && + !MatchesPattern(document.title(), + base::UTF8ToUTF16("payment|checkout|address|delivery|shipping"))) { + return false; + } + + form->origin = document.url(); form->user_submitted = false; form->is_form_tag = false; @@ -1314,7 +1331,7 @@ bool FindFormAndFieldForFormControlElement(const WebFormControlElement& element, std::vector<WebFormControlElement> control_elements = GetUnownedAutofillableFormFieldElements(document.all(), &fieldsets); return UnownedFormElementsAndFieldSetsToFormData( - fieldsets, control_elements, &element, document.url(), extract_mask, + fieldsets, control_elements, &element, document, extract_mask, form, field); } diff --git a/components/autofill/content/renderer/form_autofill_util.h b/components/autofill/content/renderer/form_autofill_util.h index 0faf82c..1be05cd 100644 --- a/components/autofill/content/renderer/form_autofill_util.h +++ b/components/autofill/content/renderer/form_autofill_util.h @@ -122,7 +122,7 @@ bool UnownedFormElementsAndFieldSetsToFormData( const std::vector<blink::WebElement>& fieldsets, const std::vector<blink::WebFormControlElement>& control_elements, const blink::WebFormControlElement* element, - const GURL& origin, + const blink::WebDocument& document, ExtractMask extract_mask, FormData* form, FormFieldData* field); diff --git a/components/autofill/content/renderer/form_cache.cc b/components/autofill/content/renderer/form_cache.cc index 029c5fa..c1a41a8 100644 --- a/components/autofill/content/renderer/form_cache.cc +++ b/components/autofill/content/renderer/form_cache.cc @@ -133,7 +133,7 @@ std::vector<FormData> FormCache::ExtractNewForms() { FormData synthetic_form; if (!UnownedFormElementsAndFieldSetsToFormData( - fieldsets, control_elements, nullptr, document.url(), extract_mask, + fieldsets, control_elements, nullptr, document, extract_mask, &synthetic_form, nullptr)) { return forms; } diff --git a/components/autofill/core/browser/BUILD.gn b/components/autofill/core/browser/BUILD.gn index 6c2d3d1..a689000 100644 --- a/components/autofill/core/browser/BUILD.gn +++ b/components/autofill/core/browser/BUILD.gn @@ -42,8 +42,6 @@ static_library("browser") { "autofill_profile.h", "autofill_regex_constants.cc", "autofill_regex_constants.h", - "autofill_regexes.cc", - "autofill_regexes.h", "autofill_scanner.cc", "autofill_scanner.h", "autofill_server_field_info.h", @@ -207,7 +205,6 @@ source_set("unit_tests") { "autofill_merge_unittest.cc", "autofill_metrics_unittest.cc", "autofill_profile_unittest.cc", - "autofill_regexes_unittest.cc", "autofill_type_unittest.cc", "autofill_xml_parser_unittest.cc", "contact_info_unittest.cc", diff --git a/components/autofill/core/browser/credit_card.cc b/components/autofill/core/browser/credit_card.cc index 8bdab44..b4c1c9e 100644 --- a/components/autofill/core/browser/credit_card.cc +++ b/components/autofill/core/browser/credit_card.cc @@ -20,10 +20,10 @@ #include "base/strings/utf_string_conversions.h" #include "base/time/time.h" #include "components/autofill/core/browser/autofill_field.h" -#include "components/autofill/core/browser/autofill_regexes.h" #include "components/autofill/core/browser/autofill_type.h" #include "components/autofill/core/browser/validation.h" #include "components/autofill/core/common/autofill_l10n_util.h" +#include "components/autofill/core/common/autofill_regexes.h" #include "components/autofill/core/common/form_field_data.h" #include "grit/components_scaled_resources.h" #include "grit/components_strings.h" diff --git a/components/autofill/core/browser/credit_card_field.cc b/components/autofill/core/browser/credit_card_field.cc index 7d48bd5..d6b67dc 100644 --- a/components/autofill/core/browser/credit_card_field.cc +++ b/components/autofill/core/browser/credit_card_field.cc @@ -15,9 +15,9 @@ #include "base/time/time.h" #include "components/autofill/core/browser/autofill_field.h" #include "components/autofill/core/browser/autofill_regex_constants.h" -#include "components/autofill/core/browser/autofill_regexes.h" #include "components/autofill/core/browser/autofill_scanner.h" #include "components/autofill/core/browser/field_types.h" +#include "components/autofill/core/common/autofill_regexes.h" #include "grit/components_strings.h" #include "ui/base/l10n/l10n_util.h" diff --git a/components/autofill/core/browser/form_field.cc b/components/autofill/core/browser/form_field.cc index 7ea3ce4..50d7e8a 100644 --- a/components/autofill/core/browser/form_field.cc +++ b/components/autofill/core/browser/form_field.cc @@ -15,13 +15,13 @@ #include "base/strings/utf_string_conversions.h" #include "components/autofill/core/browser/address_field.h" #include "components/autofill/core/browser/autofill_field.h" -#include "components/autofill/core/browser/autofill_regexes.h" #include "components/autofill/core/browser/autofill_scanner.h" #include "components/autofill/core/browser/credit_card_field.h" #include "components/autofill/core/browser/email_field.h" #include "components/autofill/core/browser/form_structure.h" #include "components/autofill/core/browser/name_field.h" #include "components/autofill/core/browser/phone_field.h" +#include "components/autofill/core/common/autofill_regexes.h" namespace autofill { namespace { diff --git a/components/autofill/core/browser/validation.cc b/components/autofill/core/browser/validation.cc index 0688c29..ef7c330 100644 --- a/components/autofill/core/browser/validation.cc +++ b/components/autofill/core/browser/validation.cc @@ -9,10 +9,9 @@ #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "base/time/time.h" -#include "components/autofill/core/browser/autofill_regexes.h" #include "components/autofill/core/browser/credit_card.h" #include "components/autofill/core/browser/state_names.h" - +#include "components/autofill/core/common/autofill_regexes.h" namespace autofill { diff --git a/components/autofill/core/common/BUILD.gn b/components/autofill/core/common/BUILD.gn index 9ba33f3..cf884d9 100644 --- a/components/autofill/core/common/BUILD.gn +++ b/components/autofill/core/common/BUILD.gn @@ -12,6 +12,8 @@ static_library("common") { "autofill_l10n_util.h", "autofill_pref_names.cc", "autofill_pref_names.h", + "autofill_regexes.cc", + "autofill_regexes.h", "autofill_switches.cc", "autofill_switches.h", "form_data.cc", @@ -50,6 +52,7 @@ static_library("common") { source_set("unit_tests") { testonly = true sources = [ + "autofill_regexes_unittest.cc", "form_data_unittest.cc", "form_field_data_unittest.cc", "password_form_fill_data_unittest.cc", diff --git a/components/autofill/core/browser/autofill_regexes.cc b/components/autofill/core/common/autofill_regexes.cc index bd5c0e9..64a60f6 100644 --- a/components/autofill/core/browser/autofill_regexes.cc +++ b/components/autofill/core/common/autofill_regexes.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "components/autofill/core/browser/autofill_regexes.h" +#include "components/autofill/core/common/autofill_regexes.h" #include "base/containers/scoped_ptr_hash_map.h" #include "base/logging.h" diff --git a/components/autofill/core/browser/autofill_regexes.h b/components/autofill/core/common/autofill_regexes.h index f4b5775..1bf1aa7 100644 --- a/components/autofill/core/browser/autofill_regexes.h +++ b/components/autofill/core/common/autofill_regexes.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_REGEXES_H_ -#define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_REGEXES_H_ +#ifndef COMPONENTS_AUTOFILL_CORE_COMMON_AUTOFILL_REGEXES_H_ +#define COMPONENTS_AUTOFILL_CORE_COMMON_AUTOFILL_REGEXES_H_ #include "base/strings/string16.h" @@ -17,4 +17,4 @@ bool MatchesPattern(const base::string16& input, } // namespace autofill -#endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_REGEXES_H_ +#endif // COMPONENTS_AUTOFILL_CORE_COMMON_AUTOFILL_REGEXES_H_ diff --git a/components/autofill/core/browser/autofill_regexes_unittest.cc b/components/autofill/core/common/autofill_regexes_unittest.cc index d77afa7..954a7e8 100644 --- a/components/autofill/core/browser/autofill_regexes_unittest.cc +++ b/components/autofill/core/common/autofill_regexes_unittest.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "components/autofill/core/browser/autofill_regexes.h" +#include "components/autofill/core/common/autofill_regexes.h" #include "base/strings/string16.h" #include "base/strings/utf_string_conversions.h" diff --git a/components/components_tests.gyp b/components/components_tests.gyp index c9191c7..a9af680 100644 --- a/components/components_tests.gyp +++ b/components/components_tests.gyp @@ -41,7 +41,6 @@ 'autofill/core/browser/autofill_merge_unittest.cc', 'autofill/core/browser/autofill_metrics_unittest.cc', 'autofill/core/browser/autofill_profile_unittest.cc', - 'autofill/core/browser/autofill_regexes_unittest.cc', 'autofill/core/browser/autofill_type_unittest.cc', 'autofill/core/browser/autofill_xml_parser_unittest.cc', 'autofill/core/browser/contact_info_unittest.cc', @@ -59,6 +58,7 @@ 'autofill/core/browser/webdata/autofill_profile_syncable_service_unittest.cc', 'autofill/core/browser/webdata/autofill_table_unittest.cc', 'autofill/core/browser/webdata/web_data_service_unittest.cc', + 'autofill/core/common/autofill_regexes_unittest.cc', 'autofill/core/common/form_data_unittest.cc', 'autofill/core/common/form_field_data_unittest.cc', 'autofill/core/common/password_form_fill_data_unittest.cc', |