Commit a9bf425a authored by Liquan (Max) Gu's avatar Liquan (Max) Gu Committed by Commit Bot

[PaymentHandler] Implement toolbar close button

This CL is to implement the PaymentHandler toolbar's close button.

Given the fact that the sheet_tab_toolbar layout has added a close
button, PaymentHandler UI who implements the layout should implement
the button as well.

Q: Why does the mediator of the PaymentHandlerUI observe the toolbar UI?
A: The mediator is in charge of observing the components external to the
PH UI itself, so it should observe the toolbar UI.

Bug: 999196
Change-Id: Ic82053a38fc5a08924d764ef349b33b7af77f90e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1944609Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720352}
parent 3ac7ec19
......@@ -71,8 +71,8 @@ public class PaymentHandlerCoordinator {
bottomSheetController.addObserver(mediator);
webContents.addObserver(mediator);
PaymentHandlerToolbarCoordinator toolbarCoordinator = new PaymentHandlerToolbarCoordinator(
activity, webContents, () -> { mHider.run(); });
PaymentHandlerToolbarCoordinator toolbarCoordinator =
new PaymentHandlerToolbarCoordinator(activity, webContents, /*observer=*/mediator);
PaymentHandlerView view = new PaymentHandlerView(
activity, webContents, webContentView, toolbarCoordinator.getView());
assert toolbarCoordinator.getToolbarHeightPx() == view.getToolbarHeightPx();
......
......@@ -8,6 +8,7 @@ import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.StateChange
import org.chromium.chrome.browser.payments.ServiceWorkerPaymentAppBridge;
import org.chromium.chrome.browser.payments.SslValidityChecker;
import org.chromium.chrome.browser.payments.handler.PaymentHandlerCoordinator.PaymentHandlerUiObserver;
import org.chromium.chrome.browser.payments.handler.toolbar.PaymentHandlerToolbarCoordinator.PaymentHandlerToolbarObserver;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetContent;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController.SheetState;
......@@ -21,7 +22,7 @@ import org.chromium.ui.modelutil.PropertyModel;
* backend (the coordinator).
*/
/* package */ class PaymentHandlerMediator
extends WebContentsObserver implements BottomSheetObserver {
extends WebContentsObserver implements BottomSheetObserver, PaymentHandlerToolbarObserver {
private final PropertyModel mModel;
private final Runnable mHider;
// Postfixed with "Ref" to distinguish from mWebContent in WebContentsObserver. Although
......@@ -107,4 +108,18 @@ import org.chromium.ui.modelutil.PropertyModel;
ServiceWorkerPaymentAppBridge.onClosingPaymentAppWindow(mWebContentsRef);
mHider.run();
}
// PaymentHandlerToolbarObserver:
@Override
public void onToolbarCloseButtonClicked() {
ServiceWorkerPaymentAppBridge.onClosingPaymentAppWindow(mWebContentsRef);
mHider.run();
}
@Override
public void onToolbarError() {
// TODO(maxlg): send an error message to users.
ServiceWorkerPaymentAppBridge.onClosingPaymentAppWindow(mWebContentsRef);
mHider.run();
}
}
......@@ -25,17 +25,18 @@ public class PaymentHandlerToolbarCoordinator {
/**
* Observer for the error of the payment handler toolbar.
*/
public interface ErrorObserver {
/**
* Called when the UI gets an error
*/
void onError();
public interface PaymentHandlerToolbarObserver {
/** Called when the UI gets an error. */
void onToolbarError();
/** Called when the close button is clicked. */
void onToolbarCloseButtonClicked();
}
/** Constructs the payment-handler toolbar component coordinator. */
public PaymentHandlerToolbarCoordinator(
Context context, WebContents webContents, ErrorObserver errorObserver) {
mToolbarView = new PaymentHandlerToolbarView(context);
Context context, WebContents webContents, PaymentHandlerToolbarObserver observer) {
mToolbarView = new PaymentHandlerToolbarView(context, observer);
PropertyModel model = new PropertyModel.Builder(PaymentHandlerToolbarProperties.ALL_KEYS)
.with(PaymentHandlerToolbarProperties.PROGRESS_VISIBLE, true)
.with(PaymentHandlerToolbarProperties.LOAD_PROGRESS, 0)
......@@ -43,7 +44,7 @@ public class PaymentHandlerToolbarCoordinator {
ConnectionSecurityLevel.NONE)
.build();
PaymentHandlerToolbarMediator mediator =
new PaymentHandlerToolbarMediator(model, webContents, errorObserver);
new PaymentHandlerToolbarMediator(model, webContents, observer);
webContents.addObserver(mediator);
PropertyModelChangeProcessor changeProcessor = PropertyModelChangeProcessor.create(
model, mToolbarView, PaymentHandlerToolbarViewBinder::bind);
......
......@@ -9,7 +9,7 @@ import android.support.annotation.DrawableRes;
import org.chromium.base.Log;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.payments.handler.toolbar.PaymentHandlerToolbarCoordinator.ErrorObserver;
import org.chromium.chrome.browser.payments.handler.toolbar.PaymentHandlerToolbarCoordinator.PaymentHandlerToolbarObserver;
import org.chromium.chrome.browser.ssl.SecurityStateModel;
import org.chromium.components.security_state.ConnectionSecurityLevel;
import org.chromium.components.url_formatter.UrlFormatter;
......@@ -32,7 +32,7 @@ import java.net.URISyntaxException;
private static final long HIDE_PROGRESS_BAR_DELAY_MS = (1000 / 60) * 4;
private final PropertyModel mModel;
private final ErrorObserver mErrorObserver;
private final PaymentHandlerToolbarObserver mObserver;
/** The handler to delay hiding the progress bar. */
private Handler mHideProgressBarHandler;
/** Postfixed with "Ref" to distinguish from mWebContent in WebContentsObserver. */
......@@ -42,16 +42,16 @@ import java.net.URISyntaxException;
* Build a new mediator that handle events from outside the payment handler toolbar component.
* @param model The {@link PaymentHandlerToolbarProperties} that holds all the view state for
* the payment handler toolbar component.
* @param hider The callback to clean up the {@link ErrorObserver} when the sheet is
* hidden.
* @param hider The callback to clean up the {@link PaymentHandlerToolbarObserver} when the
* sheet is hidden.
* @param webContents The web-contents that loads the payment app.
*/
/* package */ PaymentHandlerToolbarMediator(
PropertyModel model, WebContents webContents, ErrorObserver errorObserver) {
PropertyModel model, WebContents webContents, PaymentHandlerToolbarObserver observer) {
super(webContents);
mWebContentsRef = webContents;
mModel = model;
mErrorObserver = errorObserver;
mObserver = observer;
}
// WebContentsObserver:
......@@ -84,7 +84,7 @@ import java.net.URISyntaxException;
} catch (URISyntaxException e) {
Log.e(TAG, "Failed to instantiate URI with the origin \"%s\", whose url is \"%s\".",
origin, url);
mErrorObserver.onError();
mObserver.onToolbarError();
return;
}
}
......
......@@ -13,6 +13,7 @@ import android.widget.TextView;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.payments.handler.toolbar.PaymentHandlerToolbarCoordinator.PaymentHandlerToolbarObserver;
import org.chromium.chrome.browser.ui.widget.FadingShadow;
import org.chromium.chrome.browser.ui.widget.FadingShadowView;
......@@ -31,7 +32,8 @@ import org.chromium.chrome.browser.ui.widget.FadingShadowView;
*
* @param context The context where the bottome-sheet should be shown.
*/
/* package */ PaymentHandlerToolbarView(Context context) {
/* package */ PaymentHandlerToolbarView(
Context context, PaymentHandlerToolbarObserver observer) {
mToolbarHeightPx =
context.getResources().getDimensionPixelSize(R.dimen.sheet_tab_toolbar_height);
......@@ -40,6 +42,8 @@ import org.chromium.chrome.browser.ui.widget.FadingShadowView;
mTitleView = mToolbarView.findViewById(R.id.title);
mProgressBar = mToolbarView.findViewById(R.id.progress_bar);
mSecurityIconView = mToolbarView.findViewById(R.id.security_icon);
View closeButton = mToolbarView.findViewById(R.id.close);
closeButton.setOnClickListener(view -> observer.onToolbarCloseButtonClicked());
// These parts from sheet_tab_toolbar are not needed in this component.
mToolbarView.findViewById(R.id.open_in_new_tab).setVisibility(View.GONE);
......
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