Commit f3fe32fc authored by Mathias Carlen's avatar Mathias Carlen Committed by Commit Bot

[Autofill Assistant] Handle payment request dismiss.

Before this patch the payment request UI did not properly handle cancel
and back button.

This patch notifies the Autofill Assistant controller to shut down
gracefully with a 'give up' message whenever the payment request UI has
been canceled.

Bug: 806868
Change-Id: Ie3d83bf48a2004f0a6a72763c4b509b3db023ff9
Reviewed-on: https://chromium-review.googlesource.com/c/1326499
Commit-Queue: Mathias Carlen <mcarlen@chromium.org>
Reviewed-by: default avatarStephane Zermatten <szermatt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606883}
parent 687313c5
...@@ -244,7 +244,7 @@ public class AutofillAssistantPaymentRequest { ...@@ -244,7 +244,7 @@ public class AutofillAssistantPaymentRequest {
/* package */ void close() { /* package */ void close() {
if (mUI != null) { if (mUI != null) {
// Close the UI immediately and do not wait for finishing animations. // Close the UI immediately and do not wait for finishing animations.
mUI.close(/* shouldCloseImmediately = */ true, () -> {}); mUI.close();
mUI = null; mUI = null;
} }
...@@ -518,7 +518,6 @@ public class AutofillAssistantPaymentRequest { ...@@ -518,7 +518,6 @@ public class AutofillAssistantPaymentRequest {
mCallback.onResult(selectedPaymentInformation); mCallback.onResult(selectedPaymentInformation);
mCallback = null; mCallback = null;
} }
close(); close();
} }
......
...@@ -320,14 +320,24 @@ public class AutofillAssistantUiController implements AutofillAssistantUiDelegat ...@@ -320,14 +320,24 @@ public class AutofillAssistantUiController implements AutofillAssistantUiDelegat
mUiDelegateHolder.performUiOperation(uiDelegate -> { mUiDelegateHolder.performUiOperation(uiDelegate -> {
uiDelegate.showPaymentRequest(mWebContents, paymentOptions, title, uiDelegate.showPaymentRequest(mWebContents, paymentOptions, title,
supportedBasicCardNetworks, (selectedPaymentInformation -> { supportedBasicCardNetworks, (selectedPaymentInformation -> {
nativeOnGetPaymentInformation(mUiControllerAndroid,
selectedPaymentInformation.succeed, selectedPaymentInformation.card,
selectedPaymentInformation.address,
selectedPaymentInformation.payerName,
selectedPaymentInformation.payerPhone,
selectedPaymentInformation.payerEmail,
selectedPaymentInformation.isTermsAndConditionsAccepted);
uiDelegate.closePaymentRequest(); uiDelegate.closePaymentRequest();
if (selectedPaymentInformation.succeed) {
nativeOnGetPaymentInformation(mUiControllerAndroid,
selectedPaymentInformation.succeed,
selectedPaymentInformation.card,
selectedPaymentInformation.address,
selectedPaymentInformation.payerName,
selectedPaymentInformation.payerPhone,
selectedPaymentInformation.payerEmail,
selectedPaymentInformation.isTermsAndConditionsAccepted);
} else {
// A failed payment request flow indicates that the UI was either
// dismissed or the back button was clicked. In that case we gracefully
// shut down.
onHideOverlay();
uiDelegate.showGiveUpMessage();
onShutdownGracefully();
}
})); }));
}); });
} }
......
...@@ -500,6 +500,11 @@ class AutofillAssistantUiDelegate { ...@@ -500,6 +500,11 @@ class AutofillAssistantUiDelegate {
mBottomBarAnimations.hideDetails(); mBottomBarAnimations.hideDetails();
} }
/** Called to show a message in the status bar that autofill assistant is done. */
public void showGiveUpMessage() {
showStatusMessage(mActivity.getString(R.string.autofill_assistant_give_up));
}
/** Called to show contextual information. */ /** Called to show contextual information. */
public void showDetails(Details details) { public void showDetails(Details details) {
// keep a copy of most recent movie details for feedback purposes // keep a copy of most recent movie details for feedback purposes
......
...@@ -116,7 +116,7 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View ...@@ -116,7 +116,7 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View
private FadingEdgeScrollView mPaymentContainer; private FadingEdgeScrollView mPaymentContainer;
private LinearLayout mPaymentContainerLayout; private LinearLayout mPaymentContainerLayout;
private ViewGroup mBottomBar; private ViewGroup mBottomBar;
private Button mEditButton; private Button mCancelButton;
private Button mPayButton; private Button mPayButton;
private View mSpinnyLayout; private View mSpinnyLayout;
private CheckBox mTermsCheckBox; private CheckBox mTermsCheckBox;
...@@ -314,8 +314,8 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View ...@@ -314,8 +314,8 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View
mBottomBar = (ViewGroup) mRequestView.findViewById(R.id.bottom_bar); mBottomBar = (ViewGroup) mRequestView.findViewById(R.id.bottom_bar);
mPayButton = (Button) mBottomBar.findViewById(R.id.button_primary); mPayButton = (Button) mBottomBar.findViewById(R.id.button_primary);
mPayButton.setOnClickListener(this); mPayButton.setOnClickListener(this);
mEditButton = (Button) mBottomBar.findViewById(R.id.button_secondary); mCancelButton = (Button) mBottomBar.findViewById(R.id.button_secondary);
mEditButton.setOnClickListener(this); mCancelButton.setOnClickListener(this);
// Terms and services accepted checkbox. The state is passively propagated along to the // Terms and services accepted checkbox. The state is passively propagated along to the
// client when the pay/continue button is clicked. // client when the pay/continue button is clicked.
...@@ -403,14 +403,8 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View ...@@ -403,14 +403,8 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View
* Does not call Client.onDismissed(). * Does not call Client.onDismissed().
* *
* Should not be called multiple times. * Should not be called multiple times.
*
* @param shouldCloseImmediately If true, this function will immediately dismiss the dialog
* without describing the error.
* @param callback The callback to notify of finished animations.
*/ */
public void close(boolean shouldCloseImmediately, final Runnable callback) { public void close() {
mIsClientClosing = true;
// Restore the UI before we showed the payment request. // Restore the UI before we showed the payment request.
ViewGroup parent = (ViewGroup) mRequestView.getParent(); ViewGroup parent = (ViewGroup) mRequestView.getParent();
assert parent != null; assert parent != null;
...@@ -418,24 +412,6 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View ...@@ -418,24 +412,6 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View
parent.removeView(mRequestView); parent.removeView(mRequestView);
parent.addView(mBackupView, index); parent.addView(mBackupView, index);
mBackupView = null; mBackupView = null;
Runnable dismissRunnable = new Runnable() {
@Override
public void run() {
dismissDialog(false);
if (callback != null) callback.run();
}
};
if (shouldCloseImmediately) {
// The shouldCloseImmediately boolean is true when the merchant calls
// instrumentResponse.complete("success") or instrumentResponse.complete("")
// in JavaScript.
dismissRunnable.run();
} else {
// TODO(crbug.com/806868): Show the mErrorView error dialog.
mErrorView.setDismissRunnable(dismissRunnable);
}
} }
/** /**
...@@ -635,26 +611,14 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View ...@@ -635,26 +611,14 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View
expand(mPaymentMethodSection); expand(mPaymentMethodSection);
} else if (v == mPayButton) { } else if (v == mPayButton) {
processPayButton(); processPayButton();
} else if (v == mEditButton) { } else if (v == mCancelButton) {
if (mIsExpandedToFullHeight) { dismiss();
dismissDialog(true); return;
} else {
expand(mOrderSummarySection);
}
} }
updatePayButtonEnabled(); updatePayButtonEnabled();
} }
/**
* Dismiss the dialog.
*
* @param isAnimated If true, the dialog dismissal is animated.
*/
private void dismissDialog(boolean isAnimated) {
mIsClosing = true;
}
private void processPayButton() { private void processPayButton() {
assert !mIsShowingSpinner; assert !mIsShowingSpinner;
mIsProcessingPayClicked = true; mIsProcessingPayClicked = true;
...@@ -787,7 +751,7 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View ...@@ -787,7 +751,7 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View
mPaymentContainerLayout.requestLayout(); mPaymentContainerLayout.requestLayout();
// Switch the 'edit' button to a 'cancel' button. // Switch the 'edit' button to a 'cancel' button.
mEditButton.setText(mContext.getString(R.string.cancel)); mCancelButton.setText(mContext.getString(R.string.cancel));
// Disable all but the first button. // Disable all but the first button.
updateSectionButtons(); updateSectionButtons();
...@@ -907,10 +871,14 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View ...@@ -907,10 +871,14 @@ public class PaymentRequestUI implements DialogInterface.OnDismissListener, View
*/ */
@Override @Override
public void onDismiss(DialogInterface dialog) { public void onDismiss(DialogInterface dialog) {
dismiss();
}
private void dismiss() {
mIsClosing = true; mIsClosing = true;
if (mEditorDialog.isShowing()) mEditorDialog.dismiss(); if (mEditorDialog.isShowing()) mEditorDialog.dismiss();
if (mCardEditorDialog.isShowing()) mCardEditorDialog.dismiss(); if (mCardEditorDialog.isShowing()) mCardEditorDialog.dismiss();
if (!mIsClientClosing) mClient.onDismiss(); mClient.onDismiss();
} }
@Override @Override
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<message name="IDS_AUTOFILL_ASSISTANT_DEFAULT_ERROR" desc="Text label that is shown when autofill assistant cannot help anymore, because something went wrong."> <message name="IDS_AUTOFILL_ASSISTANT_DEFAULT_ERROR" desc="Text label that is shown when autofill assistant cannot help anymore, because something went wrong.">
Something went wrong. You can finish your order on the website. Something went wrong. You can finish your order on the website.
</message> </message>
<message name="IDS_AUTOFILL_ASSISTANT_GIVE_UP" desc="Text label that is shown when autofill assistant cannot help anymore, because of a user action."> <message name="IDS_AUTOFILL_ASSISTANT_GIVE_UP" desc="Text label that is shown when autofill assistant cannot help anymore, because of a user action." formatter_data="android_java">
It looks like you want to do this by yourself. It's ok to continue on without my help. It looks like you want to do this by yourself. It's ok to continue on without my help.
</message> </message>
<message name="IDS_AUTOFILL_ASSISTANT_LOADING" desc="Text label that is shown during the loading of the first page, right after being triggered."> <message name="IDS_AUTOFILL_ASSISTANT_LOADING" desc="Text label that is shown during the loading of the first page, right after being triggered.">
......
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