Commit aa87186e authored by Mariia Shvedchenko's avatar Mariia Shvedchenko Committed by Commit Bot

[Autofill] Add matching for negative patterns

Applying negative matching, adding finch flag,
using vector<MatchingPattern> instead of single matching pattern in
FormField::ParseField, and FormField::ParseFieldSpecifics.

Change-Id: Id3213ab070267df1c670002effcada174cc85dda
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2431515Reviewed-by: default avatarMatthias Körber <koerber@google.com>
Reviewed-by: default avatarChristoph Schwering <schwering@google.com>
Commit-Queue: Mariia Shvedchenko <mariiash@google.com>
Cr-Commit-Position: refs/heads/master@{#811643}
parent c97490dc
......@@ -11,6 +11,7 @@
#include <string>
#include <utility>
#include "base/feature_list.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
......@@ -159,6 +160,13 @@ bool FormField::ParseField(AutofillScanner* scanner,
return ParseFieldSpecifics(scanner, pattern, MATCH_DEFAULT, match, logging);
}
bool FormField::ParseField(AutofillScanner* scanner,
const std::vector<MatchingPattern>& patterns,
AutofillField** match,
const RegExLogging& logging) {
return ParseFieldSpecifics(scanner, patterns, match, logging);
}
bool FormField::ParseFieldSpecifics(AutofillScanner* scanner,
const base::string16& pattern,
int match_field_attributes,
......@@ -178,6 +186,43 @@ bool FormField::ParseFieldSpecifics(AutofillScanner* scanner,
match_field_input_types, match, logging);
}
bool FormField::ParseFieldSpecifics(
AutofillScanner* scanner,
const std::vector<MatchingPattern>& patterns,
AutofillField** match,
const RegExLogging& logging) {
if (scanner->IsEnd())
return false;
const AutofillField* field = scanner->Cursor();
for (const auto& pattern : patterns) {
if (!MatchesFormControlType(field->form_control_type,
pattern.match_field_input_types)) {
continue;
}
// TODO(crbug.com/1132831): Remove feature check once launched.
if (base::FeatureList::IsEnabled(
features::
kAutofillApplyNegativePatternsForFieldTypeDetectionHeuristics)) {
if (FormField::Match(field, base::UTF8ToUTF16(pattern.negative_pattern),
pattern.match_field_attributes,
pattern.match_field_input_types, logging)) {
continue;
}
}
if (MatchAndAdvance(scanner, base::UTF8ToUTF16(pattern.positive_pattern),
pattern.match_field_attributes,
pattern.match_field_input_types, match, logging)) {
return true;
}
}
return false;
}
// static
bool FormField::ParseFieldSpecifics(AutofillScanner* scanner,
const base::string16& pattern,
......
......@@ -66,6 +66,11 @@ class FormField {
AutofillField** match,
const RegExLogging& logging = {});
static bool ParseField(AutofillScanner* scanner,
const std::vector<MatchingPattern>& patterns,
AutofillField** match,
const RegExLogging& logging = {});
// Parses the stream of fields in |scanner| with regular expression |pattern|
// as specified in the |match_type| bit field (see |MatchType|). If |match|
// is non-NULL and the pattern matches, |match| will be set to the matched
......@@ -77,6 +82,11 @@ class FormField {
AutofillField** match,
const RegExLogging& logging = {});
static bool ParseFieldSpecifics(AutofillScanner* scanner,
const std::vector<MatchingPattern>& patterns,
AutofillField** match,
const RegExLogging& logging = {});
// The same as ParseFieldSpecifics but with splitted match_types into
// MatchAttributes and MatchFieldTypes.
static bool ParseFieldSpecifics(AutofillScanner* scanner,
......
......@@ -9,7 +9,6 @@
#include "base/macros.h"
#include "base/no_destructor.h"
#include "base/synchronization/lock.h"
#include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/browser/form_parsing/autofill_parsing_utils.h"
#include "components/autofill/core/common/autofill_regex_constants.h"
......
......@@ -48,6 +48,13 @@ const base::Feature kAutofillAllowNonHttpActivation{
const base::Feature kAutofillAlwaysFillAddresses{
"AlwaysFillAddresses", base::FEATURE_ENABLED_BY_DEFAULT};
// Controls whether negative patterns are used to parse the field type.
// TODO(crbug.com/1132831): Remove once launched.
const base::Feature
kAutofillApplyNegativePatternsForFieldTypeDetectionHeuristics{
"AutofillApplyNegativePatternsForFieldTypeDetectionHeuristics",
base::FEATURE_DISABLED_BY_DEFAULT};
// Controls the use of GET (instead of POST) to fetch cacheable autofill query
// responses.
const base::Feature kAutofillCacheQueryResponses{
......
......@@ -26,6 +26,8 @@ extern const base::Feature kAutofillAllowDuplicateFormSubmissions;
extern const base::Feature kAutofillAllowHtmlTypeCountryCodesWithFullNames;
extern const base::Feature kAutofillAllowNonHttpActivation;
extern const base::Feature kAutofillAlwaysFillAddresses;
extern const base::Feature
kAutofillApplyNegativePatternsForFieldTypeDetectionHeuristics;
extern const base::Feature kAutofillCacheQueryResponses;
extern const base::Feature kAutofillCreateDataForTest;
extern const base::Feature kAutofillEnableAccountWalletStorage;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment