Commit 418f0d13 authored by Martynas Sinkievic's avatar Martynas Sinkievic Committed by Commit Bot

[Autofill] Make page language available before field type heuristics

Change-Id: Ib1a1dc848604ef9fb49e4a4f6946bf6f888db8e9
Bug: 1121990
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2346246Reviewed-by: default avatarChristoph Schwering <schwering@google.com>
Reviewed-by: default avatarMatthias Körber <koerber@google.com>
Commit-Queue: Martynas Sinkievič <marsin@google.com>
Cr-Commit-Position: refs/heads/master@{#803495}
parent c4c157a1
......@@ -292,6 +292,10 @@ FormStructure* AutofillHandler::ParseForm(const FormData& form,
value_from_dynamic_change_form_ = true;
}
base::Optional<std::string> page_language = GetPageLanguage();
if (page_language)
form_structure->set_page_language(page_language.value());
form_structure->DetermineHeuristicTypes(log_manager_);
// Hold the parsed_form_structure we intend to return. We can use this to
......@@ -309,6 +313,10 @@ FormStructure* AutofillHandler::ParseForm(const FormData& form,
return parsed_form_structure;
}
base::Optional<std::string> AutofillHandler::GetPageLanguage() const {
return base::nullopt;
}
void AutofillHandler::Reset() {
form_structures_.clear();
}
......
......@@ -141,13 +141,18 @@ class AutofillHandler {
AutofillDriver* driver() { return driver_; }
#if defined(UNIT_TEST)
#ifdef UNIT_TEST
// A public wrapper that calls |mutable_form_structures| for testing purposes
// only.
std::map<FormRendererId, std::unique_ptr<FormStructure>>*
mutable_form_structures_for_test() {
return mutable_form_structures();
}
// A public wrapper that calls |ParseForm| for testing purposes only.
FormStructure* ParseFormForTest(const FormData& form) {
return ParseForm(form, nullptr);
}
#endif
protected:
......@@ -206,6 +211,9 @@ class AutofillHandler {
FormStructure* ParseForm(const FormData& form,
const FormStructure* cached_form);
// Returns the page language, if available.
virtual base::Optional<std::string> GetPageLanguage() const;
bool value_from_dynamic_change_form_ = false;
std::map<FormRendererId, std::unique_ptr<FormStructure>>*
......
......@@ -2065,12 +2065,6 @@ void AutofillManager::OnFormsParsed(const std::vector<const FormData*>& forms,
std::set<FormType> current_form_types = form_structure->GetFormTypes();
form_types.insert(current_form_types.begin(), current_form_types.end());
// Annotate the form with the source language of the page.
// TODO(898510): Move this earlier in the form parsing flow. Ideally the
// form structure should be annotated with the page language before the
// heuristics are run.
form_structure->set_page_language(client_->GetPageLanguage());
// Configure the query encoding for this form and add it to the appropriate
// collection of forms: queryable vs non-queryable.
form_structure->set_is_rich_query_enabled(is_rich_query_enabled_);
......@@ -2761,4 +2755,9 @@ FormEventLoggerBase* AutofillManager::GetEventFormLogger(
return nullptr;
}
base::Optional<std::string> AutofillManager::GetPageLanguage() const {
DCHECK(client_);
return base::make_optional(client_->GetPageLanguage());
}
} // namespace autofill
......@@ -606,6 +606,9 @@ class AutofillManager : public AutofillHandler,
std::vector<Suggestion>* suggestions,
SuggestionsContext* context);
// Retrieves the page language from |client_|
base::Optional<std::string> GetPageLanguage() const override;
#if !defined(OS_ANDROID) && !defined(OS_IOS)
// Whether to show the option to use virtual card in the autofill popup.
bool ShouldShowVirtualCardOption(FormStructure* form_structure);
......
......@@ -8684,6 +8684,18 @@ TEST_F(AutofillManagerTest, PossibleFieldTypesForEnhancementVotes) {
ServerFieldTypeSet({UNKNOWN_TYPE}));
}
TEST_F(AutofillManagerTest, PageLanguageGetsCorrectlySet) {
FormData form;
test::CreateTestAddressFormData(&form);
autofill_client_.set_page_language("test_lang");
FormStructure* parsed_form = autofill_manager_->ParseFormForTest(form);
ASSERT_TRUE(parsed_form);
ASSERT_EQ("test_lang", parsed_form->page_language());
}
// AutofillManagerTest with kAutofillDisabledMixedForms feature enabled.
class AutofillManagerTestWithMixedForms : public AutofillManagerTest {
protected:
......
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