Commit d0244453 authored by Jordan Demeulenaere's avatar Jordan Demeulenaere Committed by Commit Bot

[Autofill Assistant] Implement Autofill fallback in case validation failed.

Bug: 806868
Change-Id: I64212a92405c2021e42b37f7c8b60ae28cc86aca
Reviewed-on: https://chromium-review.googlesource.com/1233699Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Commit-Queue: Ganggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592841}
parent fb46cf46
......@@ -10,6 +10,10 @@
#include "base/callback_forward.h"
namespace autofill {
class AutofillProfile;
}
namespace autofill_assistant {
class ClientMemory;
......@@ -71,6 +75,19 @@ class ActionDelegate {
const std::vector<std::vector<std::string>>& selectors_list,
base::OnceCallback<void(const std::vector<std::string>&)> callback) = 0;
// Set the |values| of all fields in |selectors_list| and return the result
// through |callback|. Selectors and values are one on one matched, i.e. the
// value of selectors_list[i] should be set to values[i] (therefore, this
// method requires that selectors_list.size() == values.size()).
virtual void SetFieldsValue(
const std::vector<std::vector<std::string>>& selectors_list,
const std::vector<std::string>& values,
base::OnceCallback<void(bool)> callback) = 0;
// Get the AutofillProfile with ID |guid|, or nullptr if it doesn't exist.
virtual const autofill::AutofillProfile* GetAutofillProfile(
const std::string& guid) = 0;
// Return the current ClientMemory.
virtual ClientMemory* GetClientMemory() = 0;
......
......@@ -13,7 +13,10 @@
#include "base/callback_forward.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
namespace autofill {
class AutofillProfile;
}
namespace autofill_assistant {
// An action to autofill a form using a local address or credit card.
......@@ -27,20 +30,6 @@ class AutofillAction : public Action {
ProcessActionCallback callback) override;
private:
struct Data {
Data();
~Data();
// Name of the address to use. Ignored if autofilling a card.
std::string name;
std::string prompt;
std::vector<std::string> selectors;
std::vector<std::vector<std::string>> required_fields_selectors;
// True if autofilling a card, otherwise we are autofilling an address.
bool is_autofill_card;
};
// Called when the user selected the data.
void OnDataSelected(ActionDelegate* delegate,
ProcessActionCallback callback,
......@@ -48,20 +37,52 @@ class AutofillAction : public Action {
// Fill the form using data with GUID |guid|. Return whether filling succeeded
// or not through |callback|.
void FillFormWithData(std::string guid,
void FillFormWithData(const std::string& guid,
ActionDelegate* delegate,
ProcessActionCallback action_callback);
// Called when the form has been filled.
void OnFormFilled(ActionDelegate* delegate,
void OnFormFilled(const std::string& guid,
ActionDelegate* delegate,
ProcessActionCallback action_callback,
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|
// false, fail the action. If |allow_fallback| is true, try again by filling
// the failed fields without Autofill.
void CheckRequiredFields(const std::string& guid,
ActionDelegate* delegate,
ProcessActionCallback action_callback,
bool allow_fallback);
// Called when we get the value of the required fields.
void OnGetRequiredFieldsValue(ProcessActionCallback action_callback,
void OnGetRequiredFieldsValue(const std::string& guid,
ActionDelegate* delegate,
ProcessActionCallback action_callback,
bool allow_fallback,
const std::vector<std::string>& values);
Data data_;
// Get the value of |address_field| associated to profile |profile|. Return
// empty string if there is no data available.
base::string16 GetAddressFieldValue(
const autofill::AutofillProfile* profile,
const UseAddressProto::RequiredField::AddressField& address_field);
// Called after trying to set form values without Autofill in case of fallback
// after failed validation.
void OnSetFieldsValue(const std::string& guid,
ActionDelegate* delegate,
ProcessActionCallback action_callback,
bool successful);
// Usage of the autofilled address. Ignored if autofilling a card.
std::string name_;
std::string prompt_;
std::vector<std::string> selectors_;
// True if autofilling a card, otherwise we are autofilling an address.
bool is_autofill_card_;
base::WeakPtrFactory<AutofillAction> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(AutofillAction);
......
......@@ -11,6 +11,7 @@
#include "base/callback.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill_assistant/browser/protocol_utils.h"
#include "components/autofill_assistant/browser/service.h"
#include "components/autofill_assistant/browser/ui_controller.h"
......@@ -91,6 +92,20 @@ void ScriptExecutor::GetFieldsValue(
std::move(callback));
}
void ScriptExecutor::SetFieldsValue(
const std::vector<std::vector<std::string>>& selectors_list,
const std::vector<std::string>& values,
base::OnceCallback<void(bool)> callback) {
delegate_->GetWebController()->SetFieldsValue(selectors_list, values,
std::move(callback));
}
const autofill::AutofillProfile* ScriptExecutor::GetAutofillProfile(
const std::string& guid) {
// TODO(crbug.com/806868): Implement GetAutofillProfile.
return nullptr;
}
ClientMemory* ScriptExecutor::GetClientMemory() {
return delegate_->GetClientMemory();
}
......
......@@ -55,6 +55,12 @@ class ScriptExecutor : public ActionDelegate {
const std::vector<std::vector<std::string>>& selectors_list,
base::OnceCallback<void(const std::vector<std::string>&)> callback)
override;
void SetFieldsValue(
const std::vector<std::vector<std::string>>& selectors_list,
const std::vector<std::string>& values,
base::OnceCallback<void(bool)> callback) override;
const autofill::AutofillProfile* GetAutofillProfile(
const std::string& guid) override;
ClientMemory* GetClientMemory() override;
private:
......
......@@ -233,8 +233,29 @@ message FocusElementProto {
// Fill a form with an address if there is, otherwise fail this action.
message UseAddressProto {
// Message used to indicate which form fields should be filled.
message RequiredField { optional ElementReferenceProto element = 2; }
// Message used to indicate what form fields should be filled with what
// information coming from the address.
message RequiredField {
enum AddressField {
UNDEFINED = 0;
FIRST_NAME = 1;
LAST_NAME = 2;
FULL_NAME = 3;
PHONE_NUMBER = 4;
EMAIL = 5;
ORGANIZATION = 6;
COUNTRY_CODE = 7;
REGION = 8; // e.g. state
STREET_ADDRESS = 9;
LOCALITY = 10; // e.g. city
DEPENDANT_LOCALITY = 11;
POSTAL_CODE = 12;
}
optional AddressField address_field = 1;
optional ElementReferenceProto element = 2;
}
// An optional name to allow to handle multiple addresses selection (for
// instance a billing and a delivery address).
......
......@@ -581,4 +581,13 @@ void WebController::GetFieldsValue(
std::move(callback).Run(values);
}
} // namespace autofill_assistant
void WebController::SetFieldsValue(
const std::vector<std::vector<std::string>>& selectors_list,
const std::vector<std::string>& values,
base::OnceCallback<void(bool)> callback) {
DCHECK_EQ(selectors_list.size(), values.size());
// TODO(crbug.com/806868): Implement set fields value operation.
std::move(callback).Run(true);
}
} // namespace autofill_assistant.
......@@ -84,6 +84,15 @@ class WebController {
const std::vector<std::vector<std::string>>& selectors_list,
base::OnceCallback<void(const std::vector<std::string>&)> callback);
// Set the |values| of all fields in |selectors_list| and return the result
// through |callback|. Selectors and values are one on one matched, i.e. the
// value of selectors_list[i] should be set to values[i] (therefore, this
// method requires that selectors_list.size() == values.size()).
virtual void SetFieldsValue(
const std::vector<std::vector<std::string>>& selectors_list,
const std::vector<std::string>& values,
base::OnceCallback<void(bool)> callback);
private:
friend class WebControllerBrowserTest;
......
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