[go: up one dir, main page]

[Autofill Assistant] Allow setting initial terms&conditions state.

This is the client change required to allow scripters to override the default state of the third party terms&conditions checkbox.

This is the M-76 merge for http://crrev/c/1605202.

(cherry picked from commit 7de788205966702ca9d11df8f5e47fc744dfd1b6)

Bug: 973032
Bug: b/131588758
Change-Id: I3e6a970b3e972405a76e0fc8bf505939bc2459ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1605202
Commit-Queue: Clemens Arbesser <arbesser@google.com>
Reviewed-by: Stephane Zermatten <szermatt@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#666199}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1657840
Reviewed-by: Mathias Carlen <mcarlen@chromium.org>
Cr-Commit-Position: refs/branch-heads/3809@{#285}
Cr-Branched-From: d82dec1a818f378c464ba307ddd9c92133eac355-refs/heads/master@{#665002}
diff --git a/components/autofill_assistant/browser/actions/get_payment_information_action.cc b/components/autofill_assistant/browser/actions/get_payment_information_action.cc
index c4db06d..15f6aec 100644
--- a/components/autofill_assistant/browser/actions/get_payment_information_action.cc
+++ b/components/autofill_assistant/browser/actions/get_payment_information_action.cc
@@ -57,6 +57,17 @@
       get_payment_information.ask_for_payment();
   payment_options->confirm_button_text =
       get_payment_information.confirm_button_text();
+  switch (get_payment_information.terms_and_conditions_state()) {
+    case GetPaymentInformationProto::NOT_SELECTED:
+      payment_options->initial_terms_and_conditions = NOT_SELECTED;
+      break;
+    case GetPaymentInformationProto::ACCEPTED:
+      payment_options->initial_terms_and_conditions = ACCEPTED;
+      break;
+    case GetPaymentInformationProto::REVIEW_REQUIRED:
+      payment_options->initial_terms_and_conditions = REQUIRES_REVIEW;
+      break;
+  }
 
   payment_options->callback =
       base::BindOnce(&GetPaymentInformationAction::OnGetPaymentInformation,
diff --git a/components/autofill_assistant/browser/controller.cc b/components/autofill_assistant/browser/controller.cc
index 619aea1..343ac46 100644
--- a/components/autofill_assistant/browser/controller.cc
+++ b/components/autofill_assistant/browser/controller.cc
@@ -1142,6 +1142,8 @@
     payment_request_info_ = std::make_unique<PaymentInformation>();
 
     // TODO(crbug.com/806868): set initial state according to proto.
+    payment_request_info_->terms_and_conditions =
+        options->initial_terms_and_conditions;
   }
 
   payment_request_options_ = std::move(options);
diff --git a/components/autofill_assistant/browser/payment_request.h b/components/autofill_assistant/browser/payment_request.h
index fa8b56b..9df555f9 100644
--- a/components/autofill_assistant/browser/payment_request.h
+++ b/components/autofill_assistant/browser/payment_request.h
@@ -57,6 +57,7 @@
   std::vector<std::string> supported_basic_card_networks;
   std::string default_email;
   std::string confirm_button_text;
+  TermsAndConditionsState initial_terms_and_conditions = NOT_SELECTED;
 
   base::OnceCallback<void(std::unique_ptr<PaymentInformation>)> callback;
 };
diff --git a/components/autofill_assistant/browser/service.proto b/components/autofill_assistant/browser/service.proto
index 87df20f2..eeb5422 100644
--- a/components/autofill_assistant/browser/service.proto
+++ b/components/autofill_assistant/browser/service.proto
@@ -997,6 +997,15 @@
 // Asks to provide the data used by UseAddressAction and
 // UseCreditCardAction.
 message GetPaymentInformationProto {
+  enum TermsAndConditionsState {
+    // No choice has been made yet.
+    NOT_SELECTED = 0;
+    // The 'accept' radio button is toggled.
+    ACCEPTED = 1;
+    // The 'review' radio button is toggled.
+    REVIEW_REQUIRED = 2;
+  }
+
   optional string prompt = 1;
   // NOTE: Payment request does not ask separately for billing address.
   // The billing address is associated with the credit card that was picked.
@@ -1014,6 +1023,8 @@
   optional ContactDetailsProto contact_details = 5;
   // Override for the text of the confirm button in the payment request.
   optional string confirm_button_text = 7;
+  // The initial state of the terms & conditions choice.
+  optional TermsAndConditionsState terms_and_conditions_state = 8;
   // When 'false', hide the terms and conditions box in the UI.
   optional bool request_terms_and_conditions = 9 [default = true];
 }