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

[PaymentHandler] Toolbar shows initial Url

This CL is regarding the toolbar of the Bottom-sheet Payment Handler UI.

With a slow connection, the toolbar looks empty in the early loading
stage, because the toolbar doesn't show url, title or the security
icon until the Payment Handler UI has received update from the page.

As an improvement, this CL populates the toolbar with the initial url
as soon as it opens the PH UI.

Bug: 999196
Change-Id: I72b3a9fc10976eb6dc1814cc9bda28afa03910b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1944613
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721525}
parent 26c30811
...@@ -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 = PaymentHandlerToolbarCoordinator toolbarCoordinator = new PaymentHandlerToolbarCoordinator(
new PaymentHandlerToolbarCoordinator(activity, webContents, /*observer=*/mediator); activity, webContents, url, /*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();
......
...@@ -12,6 +12,8 @@ import org.chromium.content_public.browser.WebContents; ...@@ -12,6 +12,8 @@ import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.modelutil.PropertyModel; import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModelChangeProcessor; import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
import java.net.URI;
/** /**
* PaymentHandlerToolbar coordinator, which owns the component overall, i.e., creates other objects * PaymentHandlerToolbar coordinator, which owns the component overall, i.e., creates other objects
* in the component and connects them. It decouples the implementation of this component from other * in the component and connects them. It decouples the implementation of this component from other
...@@ -33,9 +35,16 @@ public class PaymentHandlerToolbarCoordinator { ...@@ -33,9 +35,16 @@ public class PaymentHandlerToolbarCoordinator {
void onToolbarCloseButtonClicked(); void onToolbarCloseButtonClicked();
} }
/** Constructs the payment-handler toolbar component coordinator. */ /**
public PaymentHandlerToolbarCoordinator( * Constructs the payment-handler toolbar component coordinator.
Context context, WebContents webContents, PaymentHandlerToolbarObserver observer) { * @param context The main activity.
* @param webContents The {@link WebContents} of the payment handler app.
* @param url The url of the payment handler app, i.e., that of
* "PaymentRequestEvent.openWindow(url)".
* @param observer The observer of this toolbar.
*/
public PaymentHandlerToolbarCoordinator(Context context, WebContents webContents, URI url,
PaymentHandlerToolbarObserver observer) {
mToolbarView = new PaymentHandlerToolbarView(context, observer); 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)
...@@ -44,7 +53,7 @@ public class PaymentHandlerToolbarCoordinator { ...@@ -44,7 +53,7 @@ public class PaymentHandlerToolbarCoordinator {
ConnectionSecurityLevel.NONE) ConnectionSecurityLevel.NONE)
.build(); .build();
PaymentHandlerToolbarMediator mediator = PaymentHandlerToolbarMediator mediator =
new PaymentHandlerToolbarMediator(model, webContents, observer); new PaymentHandlerToolbarMediator(model, webContents, url, observer);
webContents.addObserver(mediator); webContents.addObserver(mediator);
PropertyModelChangeProcessor changeProcessor = PropertyModelChangeProcessor.create( PropertyModelChangeProcessor changeProcessor = PropertyModelChangeProcessor.create(
model, mToolbarView, PaymentHandlerToolbarViewBinder::bind); model, mToolbarView, PaymentHandlerToolbarViewBinder::bind);
......
...@@ -42,16 +42,30 @@ import java.net.URISyntaxException; ...@@ -42,16 +42,30 @@ 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 PaymentHandlerToolbarObserver} when the
* sheet is hidden.
* @param webContents The web-contents that loads the payment app. * @param webContents The web-contents that loads the payment app.
* @param url The url of the payment handler app.
* @param observer The observer of this toolbar.
*/ */
/* package */ PaymentHandlerToolbarMediator( /* package */ PaymentHandlerToolbarMediator(PropertyModel model, WebContents webContents,
PropertyModel model, WebContents webContents, PaymentHandlerToolbarObserver observer) { URI url, PaymentHandlerToolbarObserver observer) {
super(webContents); super(webContents);
mWebContentsRef = webContents; mWebContentsRef = webContents;
mModel = model; mModel = model;
mObserver = observer; mObserver = observer;
formatUrlAndUpdateProperty(url.toString());
}
/** Format the url for displaying purpose and update the origin in the property model. */
private void formatUrlAndUpdateProperty(String url) {
String origin = UrlFormatter.formatUrlForSecurityDisplayOmitScheme(url);
try {
mModel.set(PaymentHandlerToolbarProperties.ORIGIN, new URI(origin));
} catch (URISyntaxException e) {
Log.e(TAG, "Failed to instantiate URI with the origin \"%s\", whose url is \"%s\".",
origin, url);
mObserver.onToolbarError();
}
} }
// WebContentsObserver: // WebContentsObserver:
...@@ -76,17 +90,8 @@ import java.net.URISyntaxException; ...@@ -76,17 +90,8 @@ import java.net.URISyntaxException;
@Override @Override
public void didFinishNavigation(NavigationHandle navigation) { public void didFinishNavigation(NavigationHandle navigation) {
if (navigation.hasCommitted() && navigation.isInMainFrame()) { if (navigation.hasCommitted() && navigation.isInMainFrame()) {
String url = navigation.getUrl(); mModel.set(PaymentHandlerToolbarProperties.PROGRESS_VISIBLE, false);
String origin = UrlFormatter.formatUrlForSecurityDisplayOmitScheme(url); formatUrlAndUpdateProperty(navigation.getUrl());
try {
mModel.set(PaymentHandlerToolbarProperties.PROGRESS_VISIBLE, false);
mModel.set(PaymentHandlerToolbarProperties.ORIGIN, new URI(origin));
} catch (URISyntaxException e) {
Log.e(TAG, "Failed to instantiate URI with the origin \"%s\", whose url is \"%s\".",
origin, url);
mObserver.onToolbarError();
return;
}
} }
} }
......
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