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
@CalledByNative
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();
paymentOtions.requestShipping = requestShipping;
paymentOtions.requestPayerName = requestPayerName;
......@@ -235,7 +235,7 @@ public class AutofillAssistantUiController implements AutofillAssistantUiDelegat
paymentOtions.requestPayerEmail = requestPayerEmail;
paymentOtions.shippingType = shippingType;
mAutofillAssistantPaymentRequest =
new AutofillAssistantPaymentRequest(mWebContents, paymentOtions);
new AutofillAssistantPaymentRequest(mWebContents, paymentOtions, title);
mUiDelegateHolder.performUiOperation(
uiDelegate -> mAutofillAssistantPaymentRequest.show(selectedPaymentInformation -> {
......
......@@ -48,6 +48,7 @@ public class AutofillAssistantPaymentRequest implements PaymentRequestUI.Client
private final WebContents mWebContents;
private final PaymentOptions mPaymentOptions;
private final String mTitle;
private final CardEditor mCardEditor;
private final AddressEditor mAddressEditor;
private final Map<String, PaymentMethodData> mMethodData;
......@@ -89,10 +90,13 @@ public class AutofillAssistantPaymentRequest implements PaymentRequestUI.Client
*
* @webContents The web contents of the payment request associated with.
* @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;
mPaymentOptions = paymentOptions;
mTitle = title;
// This feature should only works in non-incognito mode.
mAddressEditor = new AddressEditor(/* emailFieldIncluded= */ true, /* saveToDisk= */ true);
......@@ -158,7 +162,8 @@ public class AutofillAssistantPaymentRequest implements PaymentRequestUI.Client
/* requestShippingOption= */ false,
mPaymentOptions.requestPayerName || mPaymentOptions.requestPayerPhone
|| mPaymentOptions.requestPayerEmail,
/* canAddCards= */ true, /* showDataSource= */ true, mWebContents.getTitle(),
/* canAddCards= */ true, /* showDataSource= */ true,
mTitle.isEmpty() ? mWebContents.getTitle() : mTitle,
UrlFormatter.formatUrlForSecurityDisplay(mWebContents.getLastCommittedUrl()),
SecurityStateModel.getSecurityLevelForWebContents(mWebContents),
new ShippingStrings(mPaymentOptions.shippingType));
......
......@@ -219,15 +219,18 @@ void UiControllerAndroid::ChooseCard(
void UiControllerAndroid::GetPaymentInformation(
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_);
get_payment_information_callback_ = std::move(callback);
JNIEnv* env = AttachCurrentThread();
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_payer_phone,
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() {
......
......@@ -38,8 +38,8 @@ class UiControllerAndroid : public UiController, public Client {
base::OnceCallback<void(const std::string&)> callback) override;
void GetPaymentInformation(
payments::mojom::PaymentOptionsPtr payment_options,
base::OnceCallback<void(std::unique_ptr<PaymentInformation>)> callback)
override;
base::OnceCallback<void(std::unique_ptr<PaymentInformation>)> callback,
const std::string& title) override;
void HideDetails() override;
void ShowDetails(const DetailsProto& details) override;
void ShowProgressBar(int progress, const std::string& message) override;
......
......@@ -68,8 +68,8 @@ class ActionDelegate {
// UseCreditCardAction.
virtual void GetPaymentInformation(
payments::mojom::PaymentOptionsPtr payment_options,
base::OnceCallback<void(std::unique_ptr<PaymentInformation>)>
callback) = 0;
base::OnceCallback<void(std::unique_ptr<PaymentInformation>)> callback,
const std::string& title) = 0;
// Fill the address form given by |selectors| with the given address |guid| in
// personal data manager.
......
......@@ -42,7 +42,8 @@ void GetPaymentInformationAction::InternalProcessAction(
std::move(payment_options),
base::BindOnce(&GetPaymentInformationAction::OnGetPaymentInformation,
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(
......
......@@ -87,11 +87,12 @@ class MockActionDelegate : public ActionDelegate {
void(const std::vector<std::string>& selectors,
base::OnceCallback<void(bool)> callback));
MOCK_METHOD2(
MOCK_METHOD3(
GetPaymentInformation,
void(payments::mojom::PaymentOptionsPtr payment_options,
base::OnceCallback<void(std::unique_ptr<PaymentInformation>)>
callback));
callback,
const std::string& title));
void SetFieldValue(const std::vector<std::string>& selectors,
const std::string& value,
......
......@@ -40,11 +40,12 @@ class MockUiController : public UiController {
}
MOCK_METHOD1(OnChooseCard,
void(base::OnceCallback<void(const std::string&)>& callback));
MOCK_METHOD2(
MOCK_METHOD3(
GetPaymentInformation,
void(payments::mojom::PaymentOptionsPtr payment_options,
base::OnceCallback<void(std::unique_ptr<PaymentInformation>)>
callback));
callback,
const std::string& title));
MOCK_METHOD0(HideDetails, void());
MOCK_METHOD1(ShowDetails, void(const DetailsProto& details));
MOCK_METHOD2(ShowProgressBar, void(int progress, const std::string& message));
......
......@@ -87,9 +87,10 @@ void ScriptExecutor::ClickElement(const std::vector<std::string>& selectors,
void ScriptExecutor::GetPaymentInformation(
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(
std::move(payment_options), std::move(callback));
std::move(payment_options), std::move(callback), title);
}
void ScriptExecutor::ChooseAddress(
......
......@@ -71,8 +71,8 @@ class ScriptExecutor : public ActionDelegate {
base::OnceCallback<void(bool)> callback) override;
void GetPaymentInformation(
payments::mojom::PaymentOptionsPtr payment_options,
base::OnceCallback<void(std::unique_ptr<PaymentInformation>)> callback)
override;
base::OnceCallback<void(std::unique_ptr<PaymentInformation>)> callback,
const std::string& title) override;
void ChooseAddress(
base::OnceCallback<void(const std::string&)> callback) override;
void FillAddressForm(const std::string& guid,
......
......@@ -63,8 +63,8 @@ class UiController {
// forms.
virtual void GetPaymentInformation(
payments::mojom::PaymentOptionsPtr payment_options,
base::OnceCallback<void(std::unique_ptr<PaymentInformation>)>
callback) = 0;
base::OnceCallback<void(std::unique_ptr<PaymentInformation>)> callback,
const std::string& title) = 0;
// Hide contextual information.
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