Commit 00ccc6bc authored by Mathias Carlen's avatar Mathias Carlen Committed by Chromium LUCI CQ

[Autofill Assistant] Proactively finalize copied autofill profiles.

Before this patch users in autofill feature
AutofillEnableSupportForMoreStructureInNames were not properly
populating first and last names in forms.

This patch finalizes the profiles proactively before they are being used
to fill fields on the website. This has manually been verified to work
on a few websites.

The end goal would be to already receive finalized profiles from
autofill. Meanwhile this patch addresses this regression until that is
solved.

Bug: b/175942816
Change-Id: I86579455b36538e32ca133f61b3f2a24defa498c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2642356Reviewed-by: default avatarMatthias Körber <koerber@google.com>
Commit-Queue: Mathias Carlen <mcarlen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845657}
parent 93ad4fd1
......@@ -1260,7 +1260,7 @@ void CollectUserDataAction::UpdatePersonalDataManagerProfiles(
for (const auto* profile :
delegate_->GetPersonalDataManager()->GetProfilesToSuggest()) {
user_data->available_profiles_.emplace_back(
std::make_unique<autofill::AutofillProfile>(*profile));
MakeUniqueFromProfile(*profile));
if (selected_profile != nullptr &&
CompareContactDetails(*collect_user_data_options_, profile,
......@@ -1292,7 +1292,7 @@ void CollectUserDataAction::UpdatePersonalDataManagerProfiles(
if (default_selection != -1) {
user_data->selected_addresses_.emplace(
collect_user_data_options_->contact_details_name,
std::make_unique<autofill::AutofillProfile>(
MakeUniqueFromProfile(
*(user_data->available_profiles_[default_selection])));
}
}
......@@ -1312,7 +1312,7 @@ void CollectUserDataAction::UpdatePersonalDataManagerProfiles(
if (default_selection != -1) {
user_data->selected_addresses_.emplace(
collect_user_data_options_->shipping_address_name,
std::make_unique<autofill::AutofillProfile>(
MakeUniqueFromProfile(
*(user_data->available_profiles_[default_selection])));
}
}
......@@ -1347,7 +1347,7 @@ void CollectUserDataAction::UpdatePersonalDataManagerCards(
card->billing_address_id());
if (billing_address != nullptr) {
payment_instrument->billing_address =
std::make_unique<autofill::AutofillProfile>(*billing_address);
MakeUniqueFromProfile(*billing_address);
}
}
......
......@@ -10,6 +10,7 @@
#include "base/optional.h"
#include "components/autofill_assistant/browser/actions/action_delegate.h"
#include "components/autofill_assistant/browser/client_status.h"
#include "components/autofill_assistant/browser/user_data_util.h"
#include "components/autofill_assistant/browser/user_model.h"
#include "components/autofill_assistant/browser/web/element.h"
#include "content/public/browser/web_contents.h"
......@@ -325,8 +326,7 @@ void ShowGenericUiAction::OnPersonalDataChanged() {
std::vector<std::unique_ptr<autofill::AutofillProfile>>>();
for (const auto* profile :
delegate_->GetPersonalDataManager()->GetProfilesToSuggest()) {
profiles->emplace_back(
std::make_unique<autofill::AutofillProfile>(*profile));
profiles->emplace_back(MakeUniqueFromProfile(*profile));
}
WriteProfilesToUserModel(std::move(profiles),
proto_.show_generic_ui().request_profiles(),
......
......@@ -17,6 +17,7 @@
#include "components/autofill_assistant/browser/actions/fallback_handler/required_fields_fallback_handler.h"
#include "components/autofill_assistant/browser/client_status.h"
#include "components/autofill_assistant/browser/field_formatter.h"
#include "components/autofill_assistant/browser/user_data_util.h"
#include "components/autofill_assistant/browser/user_model.h"
#include "components/autofill_assistant/browser/value_util.h"
......@@ -69,7 +70,7 @@ void UseAddressAction::InternalProcessAction(
EndAction(ClientStatus(PRECONDITION_FAILED));
return;
}
profile_ = std::make_unique<autofill::AutofillProfile>(*profile);
profile_ = MakeUniqueFromProfile(*profile);
break;
}
case UseAddressProto::kModelIdentifier: {
......@@ -102,7 +103,7 @@ void UseAddressAction::InternalProcessAction(
EndAction(ClientStatus(PRECONDITION_FAILED));
return;
}
profile_ = std::make_unique<autofill::AutofillProfile>(*profile);
profile_ = MakeUniqueFromProfile(*profile);
break;
}
case UseAddressProto::ADDRESS_SOURCE_NOT_SET:
......
......@@ -195,6 +195,15 @@ ClientStatus ExtractProfileAndFormatAutofillValue(
} // namespace
std::unique_ptr<autofill::AutofillProfile> MakeUniqueFromProfile(
const autofill::AutofillProfile& profile) {
auto unique_profile = std::make_unique<autofill::AutofillProfile>(profile);
// Temporary workaround so that fields like first/last name a properly
// populated.
unique_profile->FinalizeAfterImport();
return unique_profile;
}
std::vector<int> SortContactsByCompleteness(
const CollectUserDataOptions& collect_user_data_options,
const std::vector<std::unique_ptr<autofill::AutofillProfile>>& profiles) {
......
......@@ -15,6 +15,9 @@
namespace autofill_assistant {
std::unique_ptr<autofill::AutofillProfile> MakeUniqueFromProfile(
const autofill::AutofillProfile& profile);
// Sorts the given autofill profiles based on completeness, and returns a
// vector of profile indices in sorted order. Full profiles will be ordered
// before empty ones, and for equally complete profiles, this falls back to
......
......@@ -26,6 +26,7 @@
#include "components/autofill_assistant/browser/client_status.h"
#include "components/autofill_assistant/browser/rectf.h"
#include "components/autofill_assistant/browser/string_conversions_util.h"
#include "components/autofill_assistant/browser/user_data_util.h"
#include "components/autofill_assistant/browser/web/web_controller_util.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
......@@ -748,8 +749,7 @@ void WebController::FillAddressForm(
base::OnceCallback<void(const ClientStatus&)> callback) {
VLOG(3) << __func__ << " " << selector;
auto data_to_autofill = std::make_unique<FillFormInputData>();
data_to_autofill->profile =
std::make_unique<autofill::AutofillProfile>(*profile);
data_to_autofill->profile = MakeUniqueFromProfile(*profile);
FindElement(selector,
/* strict_mode= */ true,
base::BindOnce(&WebController::OnFindElementForFillingForm,
......
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