Commit 791e8d73 authored by Clemens Arbesser's avatar Clemens Arbesser Committed by Commit Bot

The title of the payment request UI can be set via the `prompt` field

More specifically, the `prompt` field of the `CollectDataSpecification` message was previously unused, but is now passed along to AutofillAssistantPaymentRequest, which will show the prompt in the title of the UI. If not set, the UI defaults to the title of the web-contents (as before).

Bug: 806868
Change-Id: I37b8d9570b5833095eca6070871c211a7a775c24
Reviewed-on: https://chromium-review.googlesource.com/c/1301441
Commit-Queue: Clemens Arbesser <arbesser@google.com>
Reviewed-by: default avatarGanggui Tang <gogerald@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603465}
parent 2d48cef0
...@@ -227,7 +227,7 @@ public class AutofillAssistantUiController implements AutofillAssistantUiDelegat ...@@ -227,7 +227,7 @@ public class AutofillAssistantUiController implements AutofillAssistantUiDelegat
@CalledByNative @CalledByNative
private void onRequestPaymentInformation(boolean requestShipping, boolean requestPayerName, private void onRequestPaymentInformation(boolean requestShipping, boolean requestPayerName,
boolean requestPayerPhone, boolean requestPayerEmail, int shippingType) { boolean requestPayerPhone, boolean requestPayerEmail, int shippingType, String title) {
PaymentOptions paymentOtions = new PaymentOptions(); PaymentOptions paymentOtions = new PaymentOptions();
paymentOtions.requestShipping = requestShipping; paymentOtions.requestShipping = requestShipping;
paymentOtions.requestPayerName = requestPayerName; paymentOtions.requestPayerName = requestPayerName;
...@@ -235,7 +235,7 @@ public class AutofillAssistantUiController implements AutofillAssistantUiDelegat ...@@ -235,7 +235,7 @@ public class AutofillAssistantUiController implements AutofillAssistantUiDelegat
paymentOtions.requestPayerEmail = requestPayerEmail; paymentOtions.requestPayerEmail = requestPayerEmail;
paymentOtions.shippingType = shippingType; paymentOtions.shippingType = shippingType;
mAutofillAssistantPaymentRequest = mAutofillAssistantPaymentRequest =
new AutofillAssistantPaymentRequest(mWebContents, paymentOtions); new AutofillAssistantPaymentRequest(mWebContents, paymentOtions, title);
mUiDelegateHolder.performUiOperation( mUiDelegateHolder.performUiOperation(
uiDelegate -> mAutofillAssistantPaymentRequest.show(selectedPaymentInformation -> { uiDelegate -> mAutofillAssistantPaymentRequest.show(selectedPaymentInformation -> {
......
...@@ -48,6 +48,7 @@ public class AutofillAssistantPaymentRequest implements PaymentRequestUI.Client ...@@ -48,6 +48,7 @@ public class AutofillAssistantPaymentRequest implements PaymentRequestUI.Client
private final WebContents mWebContents; private final WebContents mWebContents;
private final PaymentOptions mPaymentOptions; private final PaymentOptions mPaymentOptions;
private final String mTitle;
private final CardEditor mCardEditor; private final CardEditor mCardEditor;
private final AddressEditor mAddressEditor; private final AddressEditor mAddressEditor;
private final Map<String, PaymentMethodData> mMethodData; private final Map<String, PaymentMethodData> mMethodData;
...@@ -89,10 +90,13 @@ public class AutofillAssistantPaymentRequest implements PaymentRequestUI.Client ...@@ -89,10 +90,13 @@ public class AutofillAssistantPaymentRequest implements PaymentRequestUI.Client
* *
* @webContents The web contents of the payment request associated with. * @webContents The web contents of the payment request associated with.
* @paymentOptions The options to request payment information. * @paymentOptions The options to request payment information.
* @title The title to display in the payment request.
*/ */
public AutofillAssistantPaymentRequest(WebContents webContents, PaymentOptions paymentOptions) { public AutofillAssistantPaymentRequest(
WebContents webContents, PaymentOptions paymentOptions, String title) {
mWebContents = webContents; mWebContents = webContents;
mPaymentOptions = paymentOptions; mPaymentOptions = paymentOptions;
mTitle = title;
// This feature should only works in non-incognito mode. // This feature should only works in non-incognito mode.
mAddressEditor = new AddressEditor(/* emailFieldIncluded= */ true, /* saveToDisk= */ true); mAddressEditor = new AddressEditor(/* emailFieldIncluded= */ true, /* saveToDisk= */ true);
...@@ -158,7 +162,8 @@ public class AutofillAssistantPaymentRequest implements PaymentRequestUI.Client ...@@ -158,7 +162,8 @@ public class AutofillAssistantPaymentRequest implements PaymentRequestUI.Client
/* requestShippingOption= */ false, /* requestShippingOption= */ false,
mPaymentOptions.requestPayerName || mPaymentOptions.requestPayerPhone mPaymentOptions.requestPayerName || mPaymentOptions.requestPayerPhone
|| mPaymentOptions.requestPayerEmail, || mPaymentOptions.requestPayerEmail,
/* canAddCards= */ true, /* showDataSource= */ true, mWebContents.getTitle(), /* canAddCards= */ true, /* showDataSource= */ true,
mTitle.isEmpty() ? mWebContents.getTitle() : mTitle,
UrlFormatter.formatUrlForSecurityDisplay(mWebContents.getLastCommittedUrl()), UrlFormatter.formatUrlForSecurityDisplay(mWebContents.getLastCommittedUrl()),
SecurityStateModel.getSecurityLevelForWebContents(mWebContents), SecurityStateModel.getSecurityLevelForWebContents(mWebContents),
new ShippingStrings(mPaymentOptions.shippingType)); new ShippingStrings(mPaymentOptions.shippingType));
......
...@@ -219,15 +219,18 @@ void UiControllerAndroid::ChooseCard( ...@@ -219,15 +219,18 @@ void UiControllerAndroid::ChooseCard(
void UiControllerAndroid::GetPaymentInformation( void UiControllerAndroid::GetPaymentInformation(
payments::mojom::PaymentOptionsPtr payment_options, payments::mojom::PaymentOptionsPtr payment_options,
base::OnceCallback<void(std::unique_ptr<PaymentInformation>)> callback) { base::OnceCallback<void(std::unique_ptr<PaymentInformation>)> callback,
const std::string& title) {
DCHECK(!get_payment_information_callback_); DCHECK(!get_payment_information_callback_);
get_payment_information_callback_ = std::move(callback); get_payment_information_callback_ = std::move(callback);
JNIEnv* env = AttachCurrentThread();
Java_AutofillAssistantUiController_onRequestPaymentInformation( Java_AutofillAssistantUiController_onRequestPaymentInformation(
AttachCurrentThread(), java_autofill_assistant_ui_controller_, env, java_autofill_assistant_ui_controller_,
payment_options->request_shipping, payment_options->request_payer_name, payment_options->request_shipping, payment_options->request_payer_name,
payment_options->request_payer_phone, payment_options->request_payer_phone,
payment_options->request_payer_email, payment_options->request_payer_email,
static_cast<int>(payment_options->shipping_type)); static_cast<int>(payment_options->shipping_type),
base::android::ConvertUTF8ToJavaString(env, title));
} }
void UiControllerAndroid::HideDetails() { void UiControllerAndroid::HideDetails() {
......
...@@ -38,8 +38,8 @@ class UiControllerAndroid : public UiController, public Client { ...@@ -38,8 +38,8 @@ class UiControllerAndroid : public UiController, public Client {
base::OnceCallback<void(const std::string&)> callback) override; base::OnceCallback<void(const std::string&)> callback) override;
void GetPaymentInformation( void GetPaymentInformation(
payments::mojom::PaymentOptionsPtr payment_options, payments::mojom::PaymentOptionsPtr payment_options,
base::OnceCallback<void(std::unique_ptr<PaymentInformation>)> callback) base::OnceCallback<void(std::unique_ptr<PaymentInformation>)> callback,
override; const std::string& title) override;
void HideDetails() override; void HideDetails() override;
void ShowDetails(const DetailsProto& details) override; void ShowDetails(const DetailsProto& details) override;
void ShowProgressBar(int progress, const std::string& message) override; void ShowProgressBar(int progress, const std::string& message) override;
......
...@@ -68,8 +68,8 @@ class ActionDelegate { ...@@ -68,8 +68,8 @@ class ActionDelegate {
// UseCreditCardAction. // UseCreditCardAction.
virtual void GetPaymentInformation( virtual void GetPaymentInformation(
payments::mojom::PaymentOptionsPtr payment_options, payments::mojom::PaymentOptionsPtr payment_options,
base::OnceCallback<void(std::unique_ptr<PaymentInformation>)> base::OnceCallback<void(std::unique_ptr<PaymentInformation>)> callback,
callback) = 0; const std::string& title) = 0;
// Fill the address form given by |selectors| with the given address |guid| in // Fill the address form given by |selectors| with the given address |guid| in
// personal data manager. // personal data manager.
......
...@@ -42,7 +42,8 @@ void GetPaymentInformationAction::InternalProcessAction( ...@@ -42,7 +42,8 @@ void GetPaymentInformationAction::InternalProcessAction(
std::move(payment_options), std::move(payment_options),
base::BindOnce(&GetPaymentInformationAction::OnGetPaymentInformation, base::BindOnce(&GetPaymentInformationAction::OnGetPaymentInformation,
weak_ptr_factory_.GetWeakPtr(), delegate, weak_ptr_factory_.GetWeakPtr(), delegate,
std::move(get_payment_information), std::move(callback))); std::move(get_payment_information), std::move(callback)),
get_payment_information.prompt());
} }
void GetPaymentInformationAction::OnGetPaymentInformation( void GetPaymentInformationAction::OnGetPaymentInformation(
......
...@@ -87,11 +87,12 @@ class MockActionDelegate : public ActionDelegate { ...@@ -87,11 +87,12 @@ class MockActionDelegate : public ActionDelegate {
void(const std::vector<std::string>& selectors, void(const std::vector<std::string>& selectors,
base::OnceCallback<void(bool)> callback)); base::OnceCallback<void(bool)> callback));
MOCK_METHOD2( MOCK_METHOD3(
GetPaymentInformation, GetPaymentInformation,
void(payments::mojom::PaymentOptionsPtr payment_options, void(payments::mojom::PaymentOptionsPtr payment_options,
base::OnceCallback<void(std::unique_ptr<PaymentInformation>)> base::OnceCallback<void(std::unique_ptr<PaymentInformation>)>
callback)); callback,
const std::string& title));
void SetFieldValue(const std::vector<std::string>& selectors, void SetFieldValue(const std::vector<std::string>& selectors,
const std::string& value, const std::string& value,
......
...@@ -40,11 +40,12 @@ class MockUiController : public UiController { ...@@ -40,11 +40,12 @@ class MockUiController : public UiController {
} }
MOCK_METHOD1(OnChooseCard, MOCK_METHOD1(OnChooseCard,
void(base::OnceCallback<void(const std::string&)>& callback)); void(base::OnceCallback<void(const std::string&)>& callback));
MOCK_METHOD2( MOCK_METHOD3(
GetPaymentInformation, GetPaymentInformation,
void(payments::mojom::PaymentOptionsPtr payment_options, void(payments::mojom::PaymentOptionsPtr payment_options,
base::OnceCallback<void(std::unique_ptr<PaymentInformation>)> base::OnceCallback<void(std::unique_ptr<PaymentInformation>)>
callback)); callback,
const std::string& title));
MOCK_METHOD0(HideDetails, void()); MOCK_METHOD0(HideDetails, void());
MOCK_METHOD1(ShowDetails, void(const DetailsProto& details)); MOCK_METHOD1(ShowDetails, void(const DetailsProto& details));
MOCK_METHOD2(ShowProgressBar, void(int progress, const std::string& message)); MOCK_METHOD2(ShowProgressBar, void(int progress, const std::string& message));
......
...@@ -87,9 +87,10 @@ void ScriptExecutor::ClickElement(const std::vector<std::string>& selectors, ...@@ -87,9 +87,10 @@ void ScriptExecutor::ClickElement(const std::vector<std::string>& selectors,
void ScriptExecutor::GetPaymentInformation( void ScriptExecutor::GetPaymentInformation(
payments::mojom::PaymentOptionsPtr payment_options, payments::mojom::PaymentOptionsPtr payment_options,
base::OnceCallback<void(std::unique_ptr<PaymentInformation>)> callback) { base::OnceCallback<void(std::unique_ptr<PaymentInformation>)> callback,
const std::string& title) {
delegate_->GetUiController()->GetPaymentInformation( delegate_->GetUiController()->GetPaymentInformation(
std::move(payment_options), std::move(callback)); std::move(payment_options), std::move(callback), title);
} }
void ScriptExecutor::ChooseAddress( void ScriptExecutor::ChooseAddress(
......
...@@ -71,8 +71,8 @@ class ScriptExecutor : public ActionDelegate { ...@@ -71,8 +71,8 @@ class ScriptExecutor : public ActionDelegate {
base::OnceCallback<void(bool)> callback) override; base::OnceCallback<void(bool)> callback) override;
void GetPaymentInformation( void GetPaymentInformation(
payments::mojom::PaymentOptionsPtr payment_options, payments::mojom::PaymentOptionsPtr payment_options,
base::OnceCallback<void(std::unique_ptr<PaymentInformation>)> callback) base::OnceCallback<void(std::unique_ptr<PaymentInformation>)> callback,
override; const std::string& title) override;
void ChooseAddress( void ChooseAddress(
base::OnceCallback<void(const std::string&)> callback) override; base::OnceCallback<void(const std::string&)> callback) override;
void FillAddressForm(const std::string& guid, void FillAddressForm(const std::string& guid,
......
...@@ -63,8 +63,8 @@ class UiController { ...@@ -63,8 +63,8 @@ class UiController {
// forms. // forms.
virtual void GetPaymentInformation( virtual void GetPaymentInformation(
payments::mojom::PaymentOptionsPtr payment_options, payments::mojom::PaymentOptionsPtr payment_options,
base::OnceCallback<void(std::unique_ptr<PaymentInformation>)> base::OnceCallback<void(std::unique_ptr<PaymentInformation>)> callback,
callback) = 0; const std::string& title) = 0;
// Hide contextual information. // Hide contextual information.
virtual void HideDetails() = 0; virtual void HideDetails() = 0;
......
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