Commit 6e605e44 authored by Tao Bai's avatar Tao Bai Committed by Commit Bot

Add ExtractAllDatalist feature

Implemented ExtractAllDatalist where WebView needs
This feature will be enabled for WebView and WebLayer.

Bug: 949555
Change-Id: I85478405e7cedd679d31072753b1455c1b843eda
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2203413
Commit-Queue: Tao Bai <michaelbai@chromium.org>
Reviewed-by: default avatarDominic Battré <battre@chromium.org>
Cr-Commit-Position: refs/heads/master@{#770731}
parent 65559050
...@@ -87,6 +87,7 @@ using blink::WebVector; ...@@ -87,6 +87,7 @@ using blink::WebVector;
namespace autofill { namespace autofill {
using form_util::ExtractMask;
using form_util::FindFormAndFieldForFormControlElement; using form_util::FindFormAndFieldForFormControlElement;
using form_util::UnownedCheckoutFormElementsAndFieldSetsToFormData; using form_util::UnownedCheckoutFormElementsAndFieldSetsToFormData;
using mojom::SubmissionSource; using mojom::SubmissionSource;
...@@ -99,6 +100,14 @@ namespace { ...@@ -99,6 +100,14 @@ namespace {
// upon, instead of multiple in close succession (debounce time). // upon, instead of multiple in close succession (debounce time).
size_t kWaitTimeForSelectOptionsChangesMs = 50; size_t kWaitTimeForSelectOptionsChangesMs = 50;
// Helper function to return EXTRACT_DATALIST if kAutofillExtractAllDatalist is
// enabled, otherwise EXTRACT_NONE is returned.
ExtractMask GetExtractDatalistMask() {
return base::FeatureList::IsEnabled(features::kAutofillExtractAllDatalists)
? form_util::EXTRACT_DATALIST
: form_util::EXTRACT_NONE;
}
} // namespace } // namespace
AutofillAgent::ShowSuggestionsOptions::ShowSuggestionsOptions() AutofillAgent::ShowSuggestionsOptions::ShowSuggestionsOptions()
...@@ -264,9 +273,11 @@ void AutofillAgent::DidChangeScrollOffsetImpl( ...@@ -264,9 +273,11 @@ void AutofillAgent::DidChangeScrollOffsetImpl(
FormData form; FormData form;
FormFieldData field; FormFieldData field;
if (FindFormAndFieldForFormControlElement(element_, field_data_manager_.get(), if (FindFormAndFieldForFormControlElement(
form_util::EXTRACT_BOUNDS, &form, element_, field_data_manager_.get(),
&field)) { static_cast<ExtractMask>(form_util::EXTRACT_BOUNDS |
GetExtractDatalistMask()),
&form, &field)) {
form_dynamicity_logger_.LogForm(form); form_dynamicity_logger_.LogForm(form);
GetAutofillDriver()->TextFieldDidScroll(form, field, field.bounds); GetAutofillDriver()->TextFieldDidScroll(form, field, field.bounds);
} }
...@@ -314,9 +325,11 @@ void AutofillAgent::FocusedElementChanged(const WebElement& element) { ...@@ -314,9 +325,11 @@ void AutofillAgent::FocusedElementChanged(const WebElement& element) {
FormData form; FormData form;
FormFieldData field; FormFieldData field;
if (FindFormAndFieldForFormControlElement(element_, field_data_manager_.get(), if (FindFormAndFieldForFormControlElement(
form_util::EXTRACT_BOUNDS, &form, element_, field_data_manager_.get(),
&field)) { static_cast<ExtractMask>(form_util::EXTRACT_BOUNDS |
GetExtractDatalistMask()),
&form, &field)) {
form_dynamicity_logger_.LogForm(form); form_dynamicity_logger_.LogForm(form);
GetAutofillDriver()->FocusOnFormField(form, field, field.bounds); GetAutofillDriver()->FocusOnFormField(form, field, field.bounds);
} }
...@@ -397,9 +410,11 @@ void AutofillAgent::OnTextFieldDidChange(const WebInputElement& element) { ...@@ -397,9 +410,11 @@ void AutofillAgent::OnTextFieldDidChange(const WebInputElement& element) {
FormData form; FormData form;
FormFieldData field; FormFieldData field;
if (FindFormAndFieldForFormControlElement(element, field_data_manager_.get(), if (FindFormAndFieldForFormControlElement(
form_util::EXTRACT_BOUNDS, &form, element, field_data_manager_.get(),
&field)) { static_cast<ExtractMask>(form_util::EXTRACT_BOUNDS |
GetExtractDatalistMask()),
&form, &field)) {
form_dynamicity_logger_.LogForm(form); form_dynamicity_logger_.LogForm(form);
GetAutofillDriver()->TextFieldDidChange(form, field, field.bounds, GetAutofillDriver()->TextFieldDidChange(form, field, field.bounds,
AutofillTickClock::NowTicks()); AutofillTickClock::NowTicks());
...@@ -660,9 +675,8 @@ bool AutofillAgent::CollectFormlessElements(FormData* output) { ...@@ -660,9 +675,8 @@ bool AutofillAgent::CollectFormlessElements(FormData* output) {
if (control_elements.size() > kMaxParseableFields) if (control_elements.size() > kMaxParseableFields)
return false; return false;
const form_util::ExtractMask extract_mask = const ExtractMask extract_mask = static_cast<ExtractMask>(
static_cast<form_util::ExtractMask>(form_util::EXTRACT_VALUE | form_util::EXTRACT_VALUE | form_util::EXTRACT_OPTIONS);
form_util::EXTRACT_OPTIONS);
return UnownedCheckoutFormElementsAndFieldSetsToFormData( return UnownedCheckoutFormElementsAndFieldSetsToFormData(
fieldsets, control_elements, nullptr, document, field_data_manager_.get(), fieldsets, control_elements, nullptr, document, field_data_manager_.get(),
...@@ -829,15 +843,18 @@ void AutofillAgent::QueryAutofillSuggestions( ...@@ -829,15 +843,18 @@ void AutofillAgent::QueryAutofillSuggestions(
FormData form; FormData form;
FormFieldData field; FormFieldData field;
if (!FindFormAndFieldForFormControlElement(element, field_data_manager_.get(), if (!FindFormAndFieldForFormControlElement(
form_util::EXTRACT_BOUNDS, &form, element, field_data_manager_.get(),
&field)) { static_cast<ExtractMask>(form_util::EXTRACT_BOUNDS |
GetExtractDatalistMask()),
&form, &field)) {
// If we didn't find the cached form, at least let autocomplete have a shot // If we didn't find the cached form, at least let autocomplete have a shot
// at providing suggestions. // at providing suggestions.
WebFormControlElementToFormField( WebFormControlElementToFormField(
element, nullptr, element, nullptr,
static_cast<form_util::ExtractMask>(form_util::EXTRACT_VALUE | static_cast<ExtractMask>(form_util::EXTRACT_VALUE |
form_util::EXTRACT_BOUNDS), form_util::EXTRACT_BOUNDS |
GetExtractDatalistMask()),
&field); &field);
} }
form_dynamicity_logger_.LogForm(form); form_dynamicity_logger_.LogForm(form);
...@@ -849,10 +866,12 @@ void AutofillAgent::QueryAutofillSuggestions( ...@@ -849,10 +866,12 @@ void AutofillAgent::QueryAutofillSuggestions(
return; return;
} }
if (const WebInputElement* input_element = ToWebInputElement(&element)) { if (!base::FeatureList::IsEnabled(features::kAutofillExtractAllDatalists)) {
// Find the datalist values and send them to the browser process. if (const WebInputElement* input_element = ToWebInputElement(&element)) {
form_util::GetDataListSuggestions(*input_element, &field.datalist_values, // Find the datalist values and send them to the browser process.
&field.datalist_labels); form_util::GetDataListSuggestions(*input_element, &field.datalist_values,
&field.datalist_labels);
}
} }
is_popup_possibly_visible_ = true; is_popup_possibly_visible_ = true;
...@@ -1085,7 +1104,9 @@ void AutofillAgent::OnProvisionallySaveForm( ...@@ -1085,7 +1104,9 @@ void AutofillAgent::OnProvisionallySaveForm(
FormData form; FormData form;
FormFieldData field; FormFieldData field;
if (FindFormAndFieldForFormControlElement( if (FindFormAndFieldForFormControlElement(
element, field_data_manager_.get(), form_util::EXTRACT_BOUNDS, element, field_data_manager_.get(),
static_cast<ExtractMask>(form_util::EXTRACT_BOUNDS |
GetExtractDatalistMask()),
&form, &field)) { &form, &field)) {
form_dynamicity_logger_.LogForm(form); form_dynamicity_logger_.LogForm(form);
GetAutofillDriver()->SelectControlDidChange(form, field, field.bounds); GetAutofillDriver()->SelectControlDidChange(form, field, field.bounds);
......
...@@ -91,6 +91,13 @@ const base::Feature kAutofillEnforceMinRequiredFieldsForUpload{ ...@@ -91,6 +91,13 @@ const base::Feature kAutofillEnforceMinRequiredFieldsForUpload{
"AutofillEnforceMinRequiredFieldsForUpload", "AutofillEnforceMinRequiredFieldsForUpload",
base::FEATURE_DISABLED_BY_DEFAULT}; base::FEATURE_DISABLED_BY_DEFAULT};
// Controls whether or not all datalist shall be extracted into FormFieldData.
// This feature is enabled in both WebView and WebLayer where all datalists
// instead of only the focused one shall be extracted and sent to Android
// autofill service when the autofill session created.
const base::Feature kAutofillExtractAllDatalists{
"AutofillExtractAllDatalists", base::FEATURE_DISABLED_BY_DEFAULT};
// Autofill uses the local heuristic such that address forms are only filled if // Autofill uses the local heuristic such that address forms are only filled if
// at least 3 fields are fillable according to local heuristics. Unfortunately, // at least 3 fields are fillable according to local heuristics. Unfortunately,
// the criterion for fillability is only that the field type is unknown. So many // the criterion for fillability is only that the field type is unknown. So many
......
...@@ -34,6 +34,7 @@ extern const base::Feature kAutofillEnableHideSuggestionsUI; ...@@ -34,6 +34,7 @@ extern const base::Feature kAutofillEnableHideSuggestionsUI;
extern const base::Feature kAutofillEnforceMinRequiredFieldsForHeuristics; extern const base::Feature kAutofillEnforceMinRequiredFieldsForHeuristics;
extern const base::Feature kAutofillEnforceMinRequiredFieldsForQuery; extern const base::Feature kAutofillEnforceMinRequiredFieldsForQuery;
extern const base::Feature kAutofillEnforceMinRequiredFieldsForUpload; extern const base::Feature kAutofillEnforceMinRequiredFieldsForUpload;
extern const base::Feature kAutofillExtractAllDatalists;
extern const base::Feature kAutofillFixFillableFieldTypes; extern const base::Feature kAutofillFixFillableFieldTypes;
extern const base::Feature kAutofillKeyboardAccessory; extern const base::Feature kAutofillKeyboardAccessory;
extern const base::Feature kAutofillPruneSuggestions; extern const base::Feature kAutofillPruneSuggestions;
......
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