Commit 168a9ed9 authored by Maria Kazinova's avatar Maria Kazinova Committed by Commit Bot

Enabled FieldDataManager usage for more form extractions in Autofill.

Primarily to let it keep track of fields that have user input.
CL 2035983 allowed AutoFillAgent to use FieldDataManager but it was
still not used for some FormData extractions. This fixes it.

Bug: 957444, 1006745.
Change-Id: If4b3e080e05bb64e144bf4c9b8b08ba62aea997b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2041592
Commit-Queue: Maria Kazinova <kazinova@google.com>
Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738958}
parent f478aa65
...@@ -83,6 +83,8 @@ using blink::WebVector; ...@@ -83,6 +83,8 @@ using blink::WebVector;
namespace autofill { namespace autofill {
using form_util::FindFormAndFieldForFormControlElement;
using form_util::UnownedCheckoutFormElementsAndFieldSetsToFormData;
using mojom::SubmissionSource; using mojom::SubmissionSource;
namespace { namespace {
...@@ -216,8 +218,8 @@ void AutofillAgent::DidChangeScrollOffsetImpl( ...@@ -216,8 +218,8 @@ void AutofillAgent::DidChangeScrollOffsetImpl(
FormData form; FormData form;
FormFieldData field; FormFieldData field;
if (form_util::FindFormAndFieldForFormControlElement(element_, &form, if (FindFormAndFieldForFormControlElement(element_, field_data_manager_.get(),
&field)) { &form, &field)) {
GetAutofillDriver()->TextFieldDidScroll( GetAutofillDriver()->TextFieldDidScroll(
form, field, render_frame()->ElementBoundsInWindow(element_)); form, field, render_frame()->ElementBoundsInWindow(element_));
} }
...@@ -265,8 +267,8 @@ void AutofillAgent::FocusedElementChanged(const WebElement& element) { ...@@ -265,8 +267,8 @@ void AutofillAgent::FocusedElementChanged(const WebElement& element) {
FormData form; FormData form;
FormFieldData field; FormFieldData field;
if (form_util::FindFormAndFieldForFormControlElement(element_, &form, if (FindFormAndFieldForFormControlElement(element_, field_data_manager_.get(),
&field)) { &form, &field)) {
GetAutofillDriver()->FocusOnFormField( GetAutofillDriver()->FocusOnFormField(
form, field, render_frame()->ElementBoundsInWindow(element_)); form, field, render_frame()->ElementBoundsInWindow(element_));
} }
...@@ -345,8 +347,8 @@ void AutofillAgent::OnTextFieldDidChange(const WebInputElement& element) { ...@@ -345,8 +347,8 @@ void AutofillAgent::OnTextFieldDidChange(const WebInputElement& element) {
FormData form; FormData form;
FormFieldData field; FormFieldData field;
if (form_util::FindFormAndFieldForFormControlElement(element, &form, if (FindFormAndFieldForFormControlElement(element, field_data_manager_.get(),
&field)) { &form, &field)) {
GetAutofillDriver()->TextFieldDidChange( GetAutofillDriver()->TextFieldDidChange(
form, field, render_frame()->ElementBoundsInWindow(element), form, field, render_frame()->ElementBoundsInWindow(element),
AutofillTickClock::NowTicks()); AutofillTickClock::NowTicks());
...@@ -423,8 +425,8 @@ void AutofillAgent::TriggerRefillIfNeeded(const FormData& form) { ...@@ -423,8 +425,8 @@ void AutofillAgent::TriggerRefillIfNeeded(const FormData& form) {
FormFieldData field; FormFieldData field;
FormData updated_form; FormData updated_form;
if (form_util::FindFormAndFieldForFormControlElement(element_, &updated_form, if (FindFormAndFieldForFormControlElement(element_, field_data_manager_.get(),
&field) && &updated_form, &field) &&
(!element_.IsAutofilled() || !form.DynamicallySameFormAs(updated_form))) { (!element_.IsAutofilled() || !form.DynamicallySameFormAs(updated_form))) {
base::TimeTicks forms_seen_timestamp = AutofillTickClock::NowTicks(); base::TimeTicks forms_seen_timestamp = AutofillTickClock::NowTicks();
WebLocalFrame* frame = render_frame()->GetWebFrame(); WebLocalFrame* frame = render_frame()->GetWebFrame();
...@@ -600,9 +602,9 @@ bool AutofillAgent::CollectFormlessElements(FormData* output) { ...@@ -600,9 +602,9 @@ bool AutofillAgent::CollectFormlessElements(FormData* output) {
static_cast<form_util::ExtractMask>(form_util::EXTRACT_VALUE | static_cast<form_util::ExtractMask>(form_util::EXTRACT_VALUE |
form_util::EXTRACT_OPTIONS); form_util::EXTRACT_OPTIONS);
return form_util::UnownedCheckoutFormElementsAndFieldSetsToFormData( return UnownedCheckoutFormElementsAndFieldSetsToFormData(
fieldsets, control_elements, nullptr, document, extract_mask, output, fieldsets, control_elements, nullptr, document, field_data_manager_.get(),
nullptr); extract_mask, output, nullptr);
} }
void AutofillAgent::ShowSuggestions(const WebFormControlElement& element, void AutofillAgent::ShowSuggestions(const WebFormControlElement& element,
...@@ -693,8 +695,8 @@ void AutofillAgent::GetElementFormAndFieldData( ...@@ -693,8 +695,8 @@ void AutofillAgent::GetElementFormAndFieldData(
blink::WebFormControlElement target_form_control_element = blink::WebFormControlElement target_form_control_element =
target_element.To<blink::WebFormControlElement>(); target_element.To<blink::WebFormControlElement>();
bool success = form_util::FindFormAndFieldForFormControlElement( bool success = FindFormAndFieldForFormControlElement(
target_form_control_element, &form, &field); target_form_control_element, field_data_manager_.get(), &form, &field);
if (success) { if (success) {
// Remember this element so as to autofill the form without focusing the // Remember this element so as to autofill the form without focusing the
// field for Autofill Assistant. // field for Autofill Assistant.
...@@ -755,8 +757,8 @@ void AutofillAgent::QueryAutofillSuggestions( ...@@ -755,8 +757,8 @@ void AutofillAgent::QueryAutofillSuggestions(
FormData form; FormData form;
FormFieldData field; FormFieldData field;
if (!form_util::FindFormAndFieldForFormControlElement(element, &form, if (!FindFormAndFieldForFormControlElement(element, field_data_manager_.get(),
&field)) { &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(element, nullptr, form_util::EXTRACT_VALUE, WebFormControlElementToFormField(element, nullptr, form_util::EXTRACT_VALUE,
...@@ -813,7 +815,8 @@ void AutofillAgent::ProcessForms() { ...@@ -813,7 +815,8 @@ void AutofillAgent::ProcessForms() {
base::TimeTicks forms_seen_timestamp = AutofillTickClock::NowTicks(); base::TimeTicks forms_seen_timestamp = AutofillTickClock::NowTicks();
WebLocalFrame* frame = render_frame()->GetWebFrame(); WebLocalFrame* frame = render_frame()->GetWebFrame();
std::vector<FormData> forms = form_cache_.ExtractNewForms(); std::vector<FormData> forms =
form_cache_.ExtractNewForms(field_data_manager_.get());
// Always communicate to browser process for topmost frame. // Always communicate to browser process for topmost frame.
if (!forms.empty() || !frame->Parent()) { if (!forms.empty() || !frame->Parent()) {
...@@ -911,8 +914,8 @@ void AutofillAgent::SelectWasUpdated( ...@@ -911,8 +914,8 @@ void AutofillAgent::SelectWasUpdated(
// found, notify the driver that the the form was modified dynamically. // found, notify the driver that the the form was modified dynamically.
FormData form; FormData form;
FormFieldData field; FormFieldData field;
if (form_util::FindFormAndFieldForFormControlElement(element, &form, if (FindFormAndFieldForFormControlElement(element_, field_data_manager_.get(),
&field) && &form, &field) &&
!field.option_values.empty()) { !field.option_values.empty()) {
GetAutofillDriver()->SelectFieldOptionsDidChange(form); GetAutofillDriver()->SelectFieldOptionsDidChange(form);
} }
...@@ -1006,8 +1009,8 @@ void AutofillAgent::OnProvisionallySaveForm( ...@@ -1006,8 +1009,8 @@ void AutofillAgent::OnProvisionallySaveForm(
else { else {
FormData form; FormData form;
FormFieldData field; FormFieldData field;
if (form_util::FindFormAndFieldForFormControlElement(element, &form, if (FindFormAndFieldForFormControlElement(
&field)) { element, field_data_manager_.get(), &form, &field)) {
GetAutofillDriver()->SelectControlDidChange( GetAutofillDriver()->SelectControlDidChange(
form, field, render_frame()->ElementBoundsInWindow(element)); form, field, render_frame()->ElementBoundsInWindow(element));
} }
......
...@@ -1829,14 +1829,15 @@ bool UnownedCheckoutFormElementsAndFieldSetsToFormData( ...@@ -1829,14 +1829,15 @@ bool UnownedCheckoutFormElementsAndFieldSetsToFormData(
const std::vector<blink::WebFormControlElement>& control_elements, const std::vector<blink::WebFormControlElement>& control_elements,
const blink::WebFormControlElement* element, const blink::WebFormControlElement* element,
const blink::WebDocument& document, const blink::WebDocument& document,
const FieldDataManager* field_data_manager,
ExtractMask extract_mask, ExtractMask extract_mask,
FormData* form, FormData* form,
FormFieldData* field) { FormFieldData* field) {
if (!base::FeatureList::IsEnabled( if (!base::FeatureList::IsEnabled(
features::kAutofillRestrictUnownedFieldsToFormlessCheckout)) { features::kAutofillRestrictUnownedFieldsToFormlessCheckout)) {
return UnownedFormElementsAndFieldSetsToFormData( return UnownedFormElementsAndFieldSetsToFormData(
fieldsets, control_elements, element, document, nullptr, extract_mask, fieldsets, control_elements, element, document, field_data_manager,
form, field); extract_mask, form, field);
} }
// Only attempt formless Autofill on checkout flows. This avoids the many // Only attempt formless Autofill on checkout flows. This avoids the many
...@@ -1853,8 +1854,8 @@ bool UnownedCheckoutFormElementsAndFieldSetsToFormData( ...@@ -1853,8 +1854,8 @@ bool UnownedCheckoutFormElementsAndFieldSetsToFormData(
if (!lang.empty() && if (!lang.empty() &&
!base::StartsWith(lang, "en", base::CompareCase::INSENSITIVE_ASCII)) { !base::StartsWith(lang, "en", base::CompareCase::INSENSITIVE_ASCII)) {
return UnownedFormElementsAndFieldSetsToFormData( return UnownedFormElementsAndFieldSetsToFormData(
fieldsets, control_elements, element, document, nullptr, extract_mask, fieldsets, control_elements, element, document, field_data_manager,
form, field); extract_mask, form, field);
} }
// A potential problem is that this only checks document.title(), but should // A potential problem is that this only checks document.title(), but should
...@@ -1888,8 +1889,8 @@ bool UnownedCheckoutFormElementsAndFieldSetsToFormData( ...@@ -1888,8 +1889,8 @@ bool UnownedCheckoutFormElementsAndFieldSetsToFormData(
form->is_formless_checkout = true; form->is_formless_checkout = true;
// Found a keyword: treat this as an unowned form. // Found a keyword: treat this as an unowned form.
return UnownedFormElementsAndFieldSetsToFormData( return UnownedFormElementsAndFieldSetsToFormData(
fieldsets, control_elements, element, document, nullptr, extract_mask, fieldsets, control_elements, element, document, field_data_manager,
form, field); extract_mask, form, field);
} }
} }
...@@ -1919,8 +1920,8 @@ bool UnownedCheckoutFormElementsAndFieldSetsToFormData( ...@@ -1919,8 +1920,8 @@ bool UnownedCheckoutFormElementsAndFieldSetsToFormData(
return false; return false;
return UnownedFormElementsAndFieldSetsToFormData( return UnownedFormElementsAndFieldSetsToFormData(
fieldsets, elements_with_autocomplete, element, document, nullptr, fieldsets, elements_with_autocomplete, element, document,
extract_mask, form, field); field_data_manager, extract_mask, form, field);
} }
bool UnownedPasswordFormElementsAndFieldSetsToFormData( bool UnownedPasswordFormElementsAndFieldSetsToFormData(
...@@ -1937,10 +1938,11 @@ bool UnownedPasswordFormElementsAndFieldSetsToFormData( ...@@ -1937,10 +1938,11 @@ bool UnownedPasswordFormElementsAndFieldSetsToFormData(
extract_mask, form, field); extract_mask, form, field);
} }
bool FindFormAndFieldForFormControlElement(
bool FindFormAndFieldForFormControlElement(const WebFormControlElement& element, const WebFormControlElement& element,
FormData* form, const FieldDataManager* field_data_manager,
FormFieldData* field) { FormData* form,
FormFieldData* field) {
DCHECK(!element.IsNull()); DCHECK(!element.IsNull());
if (!IsAutofillableElement(element)) if (!IsAutofillableElement(element))
...@@ -1956,12 +1958,12 @@ bool FindFormAndFieldForFormControlElement(const WebFormControlElement& element, ...@@ -1956,12 +1958,12 @@ bool FindFormAndFieldForFormControlElement(const WebFormControlElement& element,
std::vector<WebFormControlElement> control_elements = std::vector<WebFormControlElement> control_elements =
GetUnownedAutofillableFormFieldElements(document.All(), &fieldsets); GetUnownedAutofillableFormFieldElements(document.All(), &fieldsets);
return UnownedCheckoutFormElementsAndFieldSetsToFormData( return UnownedCheckoutFormElementsAndFieldSetsToFormData(
fieldsets, control_elements, &element, document, extract_mask, fieldsets, control_elements, &element, document, field_data_manager,
form, field); extract_mask, form, field);
} }
return WebFormElementToFormData(form_element, element, nullptr, extract_mask, return WebFormElementToFormData(form_element, element, field_data_manager,
form, field); extract_mask, form, field);
} }
void FillForm(const FormData& form, const WebFormControlElement& element) { void FillForm(const FormData& form, const WebFormControlElement& element) {
......
...@@ -193,6 +193,7 @@ bool UnownedCheckoutFormElementsAndFieldSetsToFormData( ...@@ -193,6 +193,7 @@ bool UnownedCheckoutFormElementsAndFieldSetsToFormData(
const std::vector<blink::WebFormControlElement>& control_elements, const std::vector<blink::WebFormControlElement>& control_elements,
const blink::WebFormControlElement* element, const blink::WebFormControlElement* element,
const blink::WebDocument& document, const blink::WebDocument& document,
const FieldDataManager* field_data_manager,
ExtractMask extract_mask, ExtractMask extract_mask,
FormData* form, FormData* form,
FormFieldData* field); FormFieldData* field);
...@@ -216,6 +217,7 @@ bool UnownedPasswordFormElementsAndFieldSetsToFormData( ...@@ -216,6 +217,7 @@ bool UnownedPasswordFormElementsAndFieldSetsToFormData(
// Returns false if the form is not found or cannot be serialized. // Returns false if the form is not found or cannot be serialized.
bool FindFormAndFieldForFormControlElement( bool FindFormAndFieldForFormControlElement(
const blink::WebFormControlElement& element, const blink::WebFormControlElement& element,
const FieldDataManager* field_data_manager,
FormData* form, FormData* form,
FormFieldData* field); FormFieldData* field);
......
...@@ -204,7 +204,8 @@ bool IsFormInteresting(const FormData& form, size_t num_editable_elements) { ...@@ -204,7 +204,8 @@ bool IsFormInteresting(const FormData& form, size_t num_editable_elements) {
FormCache::FormCache(WebLocalFrame* frame) : frame_(frame) {} FormCache::FormCache(WebLocalFrame* frame) : frame_(frame) {}
FormCache::~FormCache() = default; FormCache::~FormCache() = default;
std::vector<FormData> FormCache::ExtractNewForms() { std::vector<FormData> FormCache::ExtractNewForms(
const FieldDataManager* field_data_manager) {
std::vector<FormData> forms; std::vector<FormData> forms;
WebDocument document = frame_->GetDocument(); WebDocument document = frame_->GetDocument();
if (document.IsNull()) if (document.IsNull())
...@@ -237,7 +238,8 @@ std::vector<FormData> FormCache::ExtractNewForms() { ...@@ -237,7 +238,8 @@ std::vector<FormData> FormCache::ExtractNewForms() {
FormData form; FormData form;
if (!WebFormElementToFormData(form_element, WebFormControlElement(), if (!WebFormElementToFormData(form_element, WebFormControlElement(),
nullptr, extract_mask, &form, nullptr)) { field_data_manager, extract_mask, &form,
nullptr)) {
continue; continue;
} }
...@@ -280,8 +282,8 @@ std::vector<FormData> FormCache::ExtractNewForms() { ...@@ -280,8 +282,8 @@ std::vector<FormData> FormCache::ExtractNewForms() {
FormData synthetic_form; FormData synthetic_form;
if (!UnownedCheckoutFormElementsAndFieldSetsToFormData( if (!UnownedCheckoutFormElementsAndFieldSetsToFormData(
fieldsets, control_elements, nullptr, document, extract_mask, fieldsets, control_elements, nullptr, document, field_data_manager,
&synthetic_form, nullptr)) { extract_mask, &synthetic_form, nullptr)) {
PruneInitialValueCaches(observed_unique_renderer_ids); PruneInitialValueCaches(observed_unique_renderer_ids);
return forms; return forms;
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/gtest_prod_util.h" #include "base/gtest_prod_util.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "components/autofill/content/renderer/field_data_manager.h"
#include "components/autofill/core/common/form_data.h" #include "components/autofill/core/common/form_data.h"
namespace blink { namespace blink {
...@@ -35,7 +36,8 @@ class FormCache { ...@@ -35,7 +36,8 @@ class FormCache {
// Scans the DOM in |frame_| extracting and storing forms that have not been // Scans the DOM in |frame_| extracting and storing forms that have not been
// seen before. Returns the extracted forms. Note that modified forms are // seen before. Returns the extracted forms. Note that modified forms are
// considered new forms. // considered new forms.
std::vector<FormData> ExtractNewForms(); std::vector<FormData> ExtractNewForms(
const FieldDataManager* field_data_manager);
// Resets the forms. // Resets the forms.
void Reset(); void Reset();
......
...@@ -49,7 +49,7 @@ TEST_F(FormCacheBrowserTest, ExtractForms) { ...@@ -49,7 +49,7 @@ TEST_F(FormCacheBrowserTest, ExtractForms) {
)"); )");
FormCache form_cache(GetMainFrame()); FormCache form_cache(GetMainFrame());
std::vector<FormData> forms = form_cache.ExtractNewForms(); std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
const FormData* form1 = GetFormByName(forms, "form1"); const FormData* form1 = GetFormByName(forms, "form1");
ASSERT_TRUE(form1); ASSERT_TRUE(form1);
...@@ -71,9 +71,9 @@ TEST_F(FormCacheBrowserTest, ExtractFormsTwice) { ...@@ -71,9 +71,9 @@ TEST_F(FormCacheBrowserTest, ExtractFormsTwice) {
)"); )");
FormCache form_cache(GetMainFrame()); FormCache form_cache(GetMainFrame());
std::vector<FormData> forms = form_cache.ExtractNewForms(); std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
forms = form_cache.ExtractNewForms(); forms = form_cache.ExtractNewForms(nullptr);
// As nothing has changed, there are no new forms and |forms| should be empty. // As nothing has changed, there are no new forms and |forms| should be empty.
EXPECT_TRUE(forms.empty()); EXPECT_TRUE(forms.empty());
} }
...@@ -89,7 +89,7 @@ TEST_F(FormCacheBrowserTest, ExtractFormsAfterModification) { ...@@ -89,7 +89,7 @@ TEST_F(FormCacheBrowserTest, ExtractFormsAfterModification) {
)"); )");
FormCache form_cache(GetMainFrame()); FormCache form_cache(GetMainFrame());
std::vector<FormData> forms = form_cache.ExtractNewForms(); std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
// Append an input element to the form and to the list of unowned inputs. // Append an input element to the form and to the list of unowned inputs.
ExecuteJavaScriptForTests(R"( ExecuteJavaScriptForTests(R"(
...@@ -106,7 +106,7 @@ TEST_F(FormCacheBrowserTest, ExtractFormsAfterModification) { ...@@ -106,7 +106,7 @@ TEST_F(FormCacheBrowserTest, ExtractFormsAfterModification) {
document.body.appendChild(new_input_2); document.body.appendChild(new_input_2);
)"); )");
forms = form_cache.ExtractNewForms(); forms = form_cache.ExtractNewForms(nullptr);
const FormData* form1 = GetFormByName(forms, "form1"); const FormData* form1 = GetFormByName(forms, "form1");
ASSERT_TRUE(form1); ASSERT_TRUE(form1);
...@@ -128,7 +128,7 @@ TEST_F(FormCacheBrowserTest, FillAndClear) { ...@@ -128,7 +128,7 @@ TEST_F(FormCacheBrowserTest, FillAndClear) {
)"); )");
FormCache form_cache(GetMainFrame()); FormCache form_cache(GetMainFrame());
std::vector<FormData> forms = form_cache.ExtractNewForms(); std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
ASSERT_EQ(1u, forms.size()); ASSERT_EQ(1u, forms.size());
FormData values_to_fill = forms[0]; FormData values_to_fill = forms[0];
...@@ -173,7 +173,7 @@ TEST_F(FormCacheBrowserTest, FreeDataOnElementRemoval) { ...@@ -173,7 +173,7 @@ TEST_F(FormCacheBrowserTest, FreeDataOnElementRemoval) {
)"); )");
FormCache form_cache(GetMainFrame()); FormCache form_cache(GetMainFrame());
form_cache.ExtractNewForms(); form_cache.ExtractNewForms(nullptr);
EXPECT_EQ(1u, form_cache.initial_select_values_.size()); EXPECT_EQ(1u, form_cache.initial_select_values_.size());
EXPECT_EQ(1u, form_cache.initial_checked_state_.size()); EXPECT_EQ(1u, form_cache.initial_checked_state_.size());
...@@ -185,7 +185,7 @@ TEST_F(FormCacheBrowserTest, FreeDataOnElementRemoval) { ...@@ -185,7 +185,7 @@ TEST_F(FormCacheBrowserTest, FreeDataOnElementRemoval) {
} }
)"); )");
std::vector<FormData> forms = form_cache.ExtractNewForms(); std::vector<FormData> forms = form_cache.ExtractNewForms(nullptr);
EXPECT_EQ(0u, forms.size()); EXPECT_EQ(0u, forms.size());
EXPECT_EQ(0u, form_cache.initial_select_values_.size()); EXPECT_EQ(0u, form_cache.initial_select_values_.size());
EXPECT_EQ(0u, form_cache.initial_checked_state_.size()); EXPECT_EQ(0u, form_cache.initial_checked_state_.size());
......
...@@ -1397,7 +1397,8 @@ bool PasswordAutofillAgent::ShowSuggestionPopup( ...@@ -1397,7 +1397,8 @@ bool PasswordAutofillAgent::ShowSuggestionPopup(
FormData form; FormData form;
FormFieldData field; FormFieldData field;
form_util::FindFormAndFieldForFormControlElement(user_input, &form, &field); form_util::FindFormAndFieldForFormControlElement(
user_input, field_data_manager_.get(), &form, &field);
int options = 0; int options = 0;
if (show_all) if (show_all)
......
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