Commit e22a42d4 authored by Lukasz Suder's avatar Lukasz Suder Committed by Commit Bot

[Autofill Assistant] Creates profile out of details from PR.

Payment request returns details that are detached from profile.
In order to use them by autofill a profile is needed, which we
now create on the fly.


Bug: 806868
Change-Id: Ic5ef1b4767b0978d2ef47557a5c10b8a2e7c5cfb
Reviewed-on: https://chromium-review.googlesource.com/c/1304518
Commit-Queue: Lukasz Suder <lsuder@google.com>
Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604913}
parent 7eb68f62
......@@ -234,9 +234,12 @@ void AutofillAction::OnWaitForElement(ActionDelegate* delegate,
return;
}
const autofill::AutofillProfile* profile =
delegate->GetClientMemory()->selected_address(name_);
DCHECK(profile);
delegate->FillAddressForm(
delegate->GetClientMemory()->selected_address(name_), selectors_,
base::BindOnce(&AutofillAction::OnFormFilled,
profile, selectors_,
base::BindOnce(&AutofillAction::OnAddressFormFilled,
weak_ptr_factory_.GetWeakPtr(), delegate));
}
......@@ -250,13 +253,19 @@ void AutofillAction::OnGetFullCard(ActionDelegate* delegate,
return;
}
delegate->FillCardForm(
std::move(card), cvc, selectors_,
base::BindOnce(&AutofillAction::OnFormFilled,
weak_ptr_factory_.GetWeakPtr(), delegate));
delegate->FillCardForm(std::move(card), cvc, selectors_,
base::BindOnce(&AutofillAction::OnCardFormFilled,
weak_ptr_factory_.GetWeakPtr()));
}
void AutofillAction::OnFormFilled(ActionDelegate* delegate, bool successful) {
void AutofillAction::OnCardFormFilled(bool successful) {
// TODO(crbug.com/806868): Implement required fields checking for cards.
EndAction(successful);
return;
}
void AutofillAction::OnAddressFormFilled(ActionDelegate* delegate,
bool successful) {
// In case Autofill failed, we fail the action.
if (!successful) {
EndAction(/* successful= */ false);
......@@ -268,12 +277,6 @@ void AutofillAction::OnFormFilled(ActionDelegate* delegate, bool successful) {
void AutofillAction::CheckRequiredFields(ActionDelegate* delegate,
bool allow_fallback) {
if (is_autofill_card_) {
// TODO(crbug.com/806868): Implement required fields checking for cards.
EndAction(/* successful= */ true);
return;
}
// If there are no required fields, finish the action successfully.
if (proto_.use_address().required_fields().empty()) {
EndAction(/* successful= */ true);
......
......@@ -18,7 +18,7 @@
namespace autofill {
class AutofillProfile;
class CreditCard;
}
} // namespace autofill
namespace autofill_assistant {
// An action to autofill a form using a local address or credit card.
......@@ -41,7 +41,7 @@ class AutofillAction : public Action {
const std::string& guid);
// Fill the form using data in client memory. Return whether filling succeeded
// or not through |callback|.
// or not through OnAddressFormFilled or OnCardFormFilled.
void FillFormWithData(ActionDelegate* delegate);
void OnWaitForElement(ActionDelegate* delegate, bool element_found);
......@@ -50,8 +50,11 @@ class AutofillAction : public Action {
std::unique_ptr<autofill::CreditCard> card,
const base::string16& cvc);
// Called when the form has been filled.
void OnFormFilled(ActionDelegate* delegate, bool successful);
// Called when the credit card form has been filled.
void OnCardFormFilled(bool successful);
// Called when the address form has been filled.
void OnAddressFormFilled(ActionDelegate* delegate, bool successful);
// Check whether all required fields have a non-empty value. If it is the
// case, finish the action successfully. If it's not and |allow_fallback|
......
......@@ -8,7 +8,9 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/browser/autofill_data_util.h"
#include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/credit_card.h"
#include "components/autofill_assistant/browser/actions/action_delegate.h"
#include "components/autofill_assistant/browser/client_memory.h"
......@@ -32,6 +34,14 @@ void GetPaymentInformationAction::InternalProcessAction(
payments::mojom::PaymentOptionsPtr payment_options =
payments::mojom::PaymentOptions::New();
if (get_payment_information.has_contact_details()) {
auto contact_details = get_payment_information.contact_details();
payment_options->request_payer_email =
contact_details.request_payer_email();
payment_options->request_payer_name = contact_details.request_payer_name();
payment_options->request_payer_phone =
contact_details.request_payer_phone();
}
bool ask_for_payment = get_payment_information.ask_for_payment();
payment_options->request_payer_email = ask_for_payment;
payment_options->request_payer_name = ask_for_payment;
......@@ -75,6 +85,31 @@ void GetPaymentInformationAction::OnGetPaymentInformation(
get_payment_information.shipping_address_name(),
std::move(payment_information->address));
}
if (get_payment_information.has_contact_details()) {
auto contact_details_proto = get_payment_information.contact_details();
autofill::AutofillProfile contact_profile;
contact_profile.SetRawInfo(
autofill::ServerFieldType::NAME_FULL,
base::ASCIIToUTF16(payment_information->payer_name));
autofill::data_util::NameParts parts = autofill::data_util::SplitName(
base::ASCIIToUTF16(payment_information->payer_name));
contact_profile.SetRawInfo(autofill::ServerFieldType::NAME_FIRST,
parts.given);
contact_profile.SetRawInfo(autofill::ServerFieldType::NAME_MIDDLE,
parts.middle);
contact_profile.SetRawInfo(autofill::ServerFieldType::NAME_LAST,
parts.family);
contact_profile.SetRawInfo(
autofill::ServerFieldType::EMAIL_ADDRESS,
base::ASCIIToUTF16(payment_information->payer_email));
contact_profile.SetRawInfo(
autofill::ServerFieldType::PHONE_HOME_WHOLE_NUMBER,
base::ASCIIToUTF16(payment_information->payer_phone));
delegate->GetClientMemory()->set_selected_address(
contact_details_proto.contact_details_name(),
std::make_unique<autofill::AutofillProfile>(contact_profile));
}
}
UpdateProcessedAction(succeed ? ACTION_APPLIED : PAYMENT_REQUEST_ERROR);
......
......@@ -378,6 +378,7 @@ message ShowProgressBarProto {
// Value between 0 and 100 indicating the current progress. Values above 100
// will be capped to 100, values below 0 will be capped to 0 by the client.
// NOTE: Setting |progress| to 100 is an equivalent of setting |done| to true.
optional int32 progress = 6;
}
......@@ -392,23 +393,35 @@ message NavigateProto {
optional string url = 1;
}
// Asks user to provide the data used by UseAddressAction and
message ContactDetailsProto {
// Data saved under this name can be reused by UseAddressAction.
optional string contact_details_name = 1;
// If true asks user for full name.
optional bool request_payer_name = 2;
// If true asks user for email.
optional bool request_payer_email = 3;
// If true asks user for phone.
optional bool request_payer_phone = 4;
}
// Asks to provide the data used by UseAddressAction and
// UseCreditCardAction.
message GetPaymentInformationProto {
optional string prompt = 1;
// If present will save the billing address inside the memory under the
// specified name. If empty we won't ask for the billing address. Data saved
// under this name can be reused by UseAddressAction.
// NOTE: Payment request does not ask separately for billing address.
// The billing address is associated with the credit card that was picked.
optional string billing_address_name = 2;
// If present will save the shipping address inside the memory under the
// specified name. If empty we won't ask for the shipping address. Data saved
// under this name can be reused by UseAddressAction.
optional string shipping_address_name = 3;
// When 'true' will ask the user for the credit card.
// When 'true' will ask for the credit card.
optional bool ask_for_payment = 4;
// If non-empty, the UI will filter the available basic-card networks
// accordingly (e.g., only `visa' and `mastercard').
repeated string supported_basic_card_networks = 6;
// Contact details that should be gathered.
optional ContactDetailsProto contact_details = 5;
}
// Resets Autofill Assistant: clears any state and server payload.
......
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