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

[PaymentHandler] Fix URI Syntax Exception

Component: the toolbar of the Bottom-sheet based Payment Handler UI.

Description: the toolbar instantiates a URI with a shortened
(ripped off the scheme and keep only the origin) URL. However, the URI
instantiation should take a URL that has a scheme, otherwise, throws
URISyntaxException. This is an insidious bug because a domain url like
"www.google.com:1234" wouldn't cause exception because it would be
accepted as a scheme.

Before change: when the toolbar takes a URL that is "IP + port"
(no scheme), the Payment Handler UI would fail with a
URISyntaxException. An example of url is "192.168.1.1:1234".

After change: a URL "IP + port" (no scheme) wouldn't cause
URISyntaxException any more.

Change: after shortening a URI string, no longer instantiate a URI from
the shortened string.

Bug: 999196

Change-Id: If7cb8e0eff6bc24d973785f9d60b0e02666836e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1988513Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Liquan (Max) Gu <maxlg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728632}
parent 2170efea
......@@ -65,9 +65,10 @@ public class PaymentHandlerToolbarCoordinator {
PaymentHandlerToolbarMediator.MINIMUM_LOAD_PROGRESS)
.with(PaymentHandlerToolbarProperties.SECURITY_ICON,
ConnectionSecurityLevel.NONE)
.with(PaymentHandlerToolbarProperties.URL, url)
.build();
PaymentHandlerToolbarMediator mediator =
new PaymentHandlerToolbarMediator(model, webContents, url, observer);
new PaymentHandlerToolbarMediator(model, webContents, observer);
webContents.addObserver(mediator);
PropertyModelChangeProcessor changeProcessor = PropertyModelChangeProcessor.create(
model, mToolbarView, PaymentHandlerToolbarViewBinder::bind);
......
......@@ -12,7 +12,6 @@ import org.chromium.chrome.R;
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;
import org.chromium.content_public.browser.NavigationHandle;
import org.chromium.content_public.browser.WebContents;
import org.chromium.content_public.browser.WebContentsObserver;
......@@ -48,29 +47,14 @@ import java.net.URISyntaxException;
* @param model The {@link PaymentHandlerToolbarProperties} that holds all the view state for
* the payment handler toolbar component.
* @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,
URI url, PaymentHandlerToolbarObserver observer) {
/* package */ PaymentHandlerToolbarMediator(
PropertyModel model, WebContents webContents, 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:
......@@ -94,9 +78,15 @@ import java.net.URISyntaxException;
@Override
public void didFinishNavigation(NavigationHandle navigation) {
if (navigation.hasCommitted() && navigation.isInMainFrame()) {
mModel.set(PaymentHandlerToolbarProperties.PROGRESS_VISIBLE, false);
formatUrlAndUpdateProperty(navigation.getUrl());
if (!navigation.hasCommitted() || !navigation.isInMainFrame()) return;
mModel.set(PaymentHandlerToolbarProperties.PROGRESS_VISIBLE, false);
String url = navigation.getUrl();
try {
mModel.set(PaymentHandlerToolbarProperties.URL, new URI(url));
} catch (URISyntaxException e) {
Log.e(TAG, "Failed to instantiate a URI with the url \"%s\".", url);
mObserver.onToolbarError();
}
}
......
......@@ -14,7 +14,7 @@ import java.net.URI;
/** PaymentHandlerToolbar UI properties, which fully describe the state of the UI. */
/* package */ class PaymentHandlerToolbarProperties {
/* package */ static final WritableObjectPropertyKey<URI> ORIGIN =
/* package */ static final WritableObjectPropertyKey<URI> URL =
new WritableObjectPropertyKey<>();
/* package */ static final WritableObjectPropertyKey<String> TITLE =
......@@ -29,7 +29,7 @@ import java.net.URI;
/* package */ static final WritableIntPropertyKey SECURITY_ICON = new WritableIntPropertyKey();
/* package */ static final PropertyKey[] ALL_KEYS =
new PropertyKey[] {ORIGIN, TITLE, LOAD_PROGRESS, PROGRESS_VISIBLE, SECURITY_ICON};
new PropertyKey[] {URL, TITLE, LOAD_PROGRESS, PROGRESS_VISIBLE, SECURITY_ICON};
// Prevent instantiation.
private PaymentHandlerToolbarProperties() {}
......
......@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.payments.handler.toolbar;
import android.view.View;
import org.chromium.components.url_formatter.UrlFormatter;
import org.chromium.ui.modelutil.PropertyKey;
import org.chromium.ui.modelutil.PropertyModel;
......@@ -16,8 +17,10 @@ import org.chromium.ui.modelutil.PropertyModel;
/* package */ class PaymentHandlerToolbarViewBinder {
/* package */ static void bind(
PropertyModel model, PaymentHandlerToolbarView view, PropertyKey propertyKey) {
if (PaymentHandlerToolbarProperties.ORIGIN == propertyKey) {
view.mOriginView.setText(model.get(PaymentHandlerToolbarProperties.ORIGIN).toString());
if (PaymentHandlerToolbarProperties.URL == propertyKey) {
String origin = UrlFormatter.formatUrlForSecurityDisplayOmitScheme(
model.get(PaymentHandlerToolbarProperties.URL).toString());
view.mOriginView.setText(origin);
} else if (PaymentHandlerToolbarProperties.TITLE == propertyKey) {
view.mTitleView.setText(model.get(PaymentHandlerToolbarProperties.TITLE));
} else if (PaymentHandlerToolbarProperties.LOAD_PROGRESS == propertyKey) {
......
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