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