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 {
bottomSheetController.addObserver(mediator);
webContents.addObserver(mediator);
PaymentHandlerToolbarCoordinator toolbarCoordinator =
new PaymentHandlerToolbarCoordinator(activity, webContents, /*observer=*/mediator);
PaymentHandlerToolbarCoordinator toolbarCoordinator = new PaymentHandlerToolbarCoordinator(
activity, webContents, url, /*observer=*/mediator);
PaymentHandlerView view = new PaymentHandlerView(
activity, webContents, webContentView, toolbarCoordinator.getView());
assert toolbarCoordinator.getToolbarHeightPx() == view.getToolbarHeightPx();
......
......@@ -12,6 +12,8 @@ import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.ui.modelutil.PropertyModelChangeProcessor;
import java.net.URI;
/**
* 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
......@@ -33,9 +35,16 @@ public class PaymentHandlerToolbarCoordinator {
void onToolbarCloseButtonClicked();
}
/** Constructs the payment-handler toolbar component coordinator. */
public PaymentHandlerToolbarCoordinator(
Context context, WebContents webContents, PaymentHandlerToolbarObserver observer) {
/**
* Constructs the payment-handler toolbar component coordinator.
* @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);
PropertyModel model = new PropertyModel.Builder(PaymentHandlerToolbarProperties.ALL_KEYS)
.with(PaymentHandlerToolbarProperties.PROGRESS_VISIBLE, true)
......@@ -44,7 +53,7 @@ public class PaymentHandlerToolbarCoordinator {
ConnectionSecurityLevel.NONE)
.build();
PaymentHandlerToolbarMediator mediator =
new PaymentHandlerToolbarMediator(model, webContents, observer);
new PaymentHandlerToolbarMediator(model, webContents, url, observer);
webContents.addObserver(mediator);
PropertyModelChangeProcessor changeProcessor = PropertyModelChangeProcessor.create(
model, mToolbarView, PaymentHandlerToolbarViewBinder::bind);
......
......@@ -42,16 +42,30 @@ 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 PaymentHandlerToolbarObserver} when the
* sheet is hidden.
* @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(
PropertyModel model, WebContents webContents, PaymentHandlerToolbarObserver observer) {
/* package */ PaymentHandlerToolbarMediator(PropertyModel model, WebContents webContents,
URI url, PaymentHandlerToolbarObserver observer) {
super(webContents);
mWebContentsRef = webContents;
mModel = model;
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:
......@@ -76,17 +90,8 @@ import java.net.URISyntaxException;
@Override
public void didFinishNavigation(NavigationHandle navigation) {
if (navigation.hasCommitted() && navigation.isInMainFrame()) {
String url = navigation.getUrl();
String origin = UrlFormatter.formatUrlForSecurityDisplayOmitScheme(url);
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;
}
mModel.set(PaymentHandlerToolbarProperties.PROGRESS_VISIBLE, false);
formatUrlAndUpdateProperty(navigation.getUrl());
}
}
......
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