Commit 54ab889d authored by Hwanseung Lee's avatar Hwanseung Lee Committed by Commit Bot

[Payments] Use org.chromium.url.GURL class

Currently payments uses the deprecated org.chromium.url.URI class,
so we should replace URL class with GURL class.
this patch replace it at PaymentHandler area.

Bug: 1065577
Change-Id: I980546c6c57bde62e10401e34cf2cb09a4f814b7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2126333Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Hwanseung Lee <hs1217.lee@samsung.com>
Cr-Commit-Position: refs/heads/master@{#757040}
parent 055935fc
...@@ -39,12 +39,11 @@ import org.chromium.content_public.common.Referrer; ...@@ -39,12 +39,11 @@ import org.chromium.content_public.common.Referrer;
import org.chromium.content_public.common.ResourceRequestBody; import org.chromium.content_public.common.ResourceRequestBody;
import org.chromium.ui.base.PageTransition; import org.chromium.ui.base.PageTransition;
import org.chromium.ui.mojom.WindowOpenDisposition; import org.chromium.ui.mojom.WindowOpenDisposition;
import org.chromium.url.URI; import org.chromium.url.GURL;
import org.chromium.webapk.lib.client.WebApkIdentityServiceClient; import org.chromium.webapk.lib.client.WebApkIdentityServiceClient;
import org.chromium.webapk.lib.client.WebApkNavigationClient; import org.chromium.webapk.lib.client.WebApkNavigationClient;
import org.chromium.webapk.lib.client.WebApkValidator; import org.chromium.webapk.lib.client.WebApkValidator;
import java.net.URISyntaxException;
import java.util.List; import java.util.List;
/** /**
...@@ -73,22 +72,18 @@ public class ServiceTabLauncher { ...@@ -73,22 +72,18 @@ public class ServiceTabLauncher {
* @param postData Post-data to include in the tab URL's request body. * @param postData Post-data to include in the tab URL's request body.
*/ */
@CalledByNative @CalledByNative
public static void launchTab(final int requestId, boolean incognito, String url, public static void launchTab(final int requestId, boolean incognito, GURL url, int disposition,
int disposition, String referrerUrl, int referrerPolicy, String extraHeaders, String referrerUrl, int referrerPolicy, String extraHeaders,
ResourceRequestBody postData) { ResourceRequestBody postData) {
// Open popup window in custom tab. // Open popup window in custom tab.
// Note that this is used by PaymentRequestEvent.openWindow(). // Note that this is used by PaymentRequestEvent.openWindow().
if (disposition == WindowOpenDisposition.NEW_POPUP) { if (disposition == WindowOpenDisposition.NEW_POPUP) {
boolean success = false; boolean success = false;
try { if (PaymentHandlerCoordinator.isEnabled()) {
if (PaymentHandlerCoordinator.isEnabled()) { success = PaymentRequestImpl.openPaymentHandlerWindow(url,
success = PaymentRequestImpl.openPaymentHandlerWindow(new URI(url), (webContents) -> onWebContentsForRequestAvailable(requestId, webContents));
(webContents) } else {
-> onWebContentsForRequestAvailable(requestId, webContents)); success = createPopupCustomTab(requestId, url.getSpec(), incognito);
} else {
success = createPopupCustomTab(requestId, url, incognito);
}
} catch (URISyntaxException e) { /* Intentionally leave blank, so success is false. */
} }
if (!success) { if (!success) {
PostTask.postTask(UiThreadTaskTraits.DEFAULT, PostTask.postTask(UiThreadTaskTraits.DEFAULT,
...@@ -97,8 +92,8 @@ public class ServiceTabLauncher { ...@@ -97,8 +92,8 @@ public class ServiceTabLauncher {
return; return;
} }
dispatchLaunch( dispatchLaunch(requestId, incognito, url.getSpec(), referrerUrl, referrerPolicy,
requestId, incognito, url, referrerUrl, referrerPolicy, extraHeaders, postData); extraHeaders, postData);
} }
/** Dispatches the launch event. */ /** Dispatches the launch event. */
......
...@@ -93,8 +93,8 @@ import org.chromium.payments.mojom.PaymentResponse; ...@@ -93,8 +93,8 @@ import org.chromium.payments.mojom.PaymentResponse;
import org.chromium.payments.mojom.PaymentShippingOption; import org.chromium.payments.mojom.PaymentShippingOption;
import org.chromium.payments.mojom.PaymentShippingType; import org.chromium.payments.mojom.PaymentShippingType;
import org.chromium.payments.mojom.PaymentValidationErrors; import org.chromium.payments.mojom.PaymentValidationErrors;
import org.chromium.url.GURL;
import org.chromium.url.Origin; import org.chromium.url.Origin;
import org.chromium.url.URI;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
...@@ -1356,7 +1356,7 @@ public class PaymentRequestImpl ...@@ -1356,7 +1356,7 @@ public class PaymentRequestImpl
* @return Whether the opening is successful. * @return Whether the opening is successful.
*/ */
public static boolean openPaymentHandlerWindow( public static boolean openPaymentHandlerWindow(
URI url, PaymentHandlerWebContentsObserver paymentHandlerWebContentsObserver) { GURL url, PaymentHandlerWebContentsObserver paymentHandlerWebContentsObserver) {
return sShowingPaymentRequest != null return sShowingPaymentRequest != null
&& sShowingPaymentRequest.openPaymentHandlerWindowInternal( && sShowingPaymentRequest.openPaymentHandlerWindowInternal(
url, paymentHandlerWebContentsObserver); url, paymentHandlerWebContentsObserver);
...@@ -1370,10 +1370,10 @@ public class PaymentRequestImpl ...@@ -1370,10 +1370,10 @@ public class PaymentRequestImpl
* @return Whether the opening is successful. * @return Whether the opening is successful.
*/ */
private boolean openPaymentHandlerWindowInternal( private boolean openPaymentHandlerWindowInternal(
URI url, PaymentHandlerWebContentsObserver paymentHandlerWebContentsObserver) { GURL url, PaymentHandlerWebContentsObserver paymentHandlerWebContentsObserver) {
assert mInvokedPaymentApp != null; assert mInvokedPaymentApp != null;
assert mInvokedPaymentApp instanceof ServiceWorkerPaymentApp; assert mInvokedPaymentApp instanceof ServiceWorkerPaymentApp;
assert org.chromium.components.embedder_support.util.Origin.create(url.toString()) assert org.chromium.components.embedder_support.util.Origin.create(url.getSpec())
.equals(org.chromium.components.embedder_support.util.Origin.create( .equals(org.chromium.components.embedder_support.util.Origin.create(
((ServiceWorkerPaymentApp) mInvokedPaymentApp).getScope().toString())); ((ServiceWorkerPaymentApp) mInvokedPaymentApp).getScope().toString()));
......
...@@ -27,7 +27,7 @@ import org.chromium.ui.base.ActivityWindowAndroid; ...@@ -27,7 +27,7 @@ import org.chromium.ui.base.ActivityWindowAndroid;
import org.chromium.ui.base.ViewAndroidDelegate; import org.chromium.ui.base.ViewAndroidDelegate;
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 org.chromium.url.URI; import org.chromium.url.GURL;
/** /**
* PaymentHandler coordinator, which owns the component overall, i.e., creates other objects in the * PaymentHandler coordinator, which owns the component overall, i.e., creates other objects in the
...@@ -74,7 +74,7 @@ public class PaymentHandlerCoordinator { ...@@ -74,7 +74,7 @@ public class PaymentHandlerCoordinator {
* @param uiObserver The {@link PaymentHandlerUiObserver} that observes this Payment Handler UI. * @param uiObserver The {@link PaymentHandlerUiObserver} that observes this Payment Handler UI.
* @return Whether the payment-handler UI was shown. Can be false if the UI was suppressed. * @return Whether the payment-handler UI was shown. Can be false if the UI was suppressed.
*/ */
public boolean show(ChromeActivity activity, URI url, boolean isIncognito, public boolean show(ChromeActivity activity, GURL url, boolean isIncognito,
PaymentHandlerWebContentsObserver webContentsObserver, PaymentHandlerWebContentsObserver webContentsObserver,
PaymentHandlerUiObserver uiObserver) { PaymentHandlerUiObserver uiObserver) {
assert mHider == null : "Already showing payment-handler UI"; assert mHider == null : "Already showing payment-handler UI";
...@@ -85,7 +85,7 @@ public class PaymentHandlerCoordinator { ...@@ -85,7 +85,7 @@ public class PaymentHandlerCoordinator {
ViewAndroidDelegate.createBasicDelegate(webContentView), webContentView, ViewAndroidDelegate.createBasicDelegate(webContentView), webContentView,
activity.getWindowAndroid(), WebContents.createDefaultInternalsHolder()); activity.getWindowAndroid(), WebContents.createDefaultInternalsHolder());
webContentsObserver.onWebContentsInitialized(mWebContents); webContentsObserver.onWebContentsInitialized(mWebContents);
mWebContents.getNavigationController().loadUrl(new LoadUrlParams(url.toString())); mWebContents.getNavigationController().loadUrl(new LoadUrlParams(url.getSpec()));
mToolbarCoordinator = new PaymentHandlerToolbarCoordinator(activity, mWebContents, url); mToolbarCoordinator = new PaymentHandlerToolbarCoordinator(activity, mWebContents, url);
......
...@@ -180,11 +180,4 @@ import org.chromium.ui.modelutil.PropertyModel; ...@@ -180,11 +180,4 @@ import org.chromium.ui.modelutil.PropertyModel;
ServiceWorkerPaymentAppBridge.onClosingPaymentAppWindow(mWebContentsRef); ServiceWorkerPaymentAppBridge.onClosingPaymentAppWindow(mWebContentsRef);
mHandler.post(mHider); mHandler.post(mHider);
} }
@Override
public void onToolbarError() {
// TODO(maxlg): send an error message to users.
ServiceWorkerPaymentAppBridge.onClosingPaymentAppWindow(mWebContentsRef);
mHandler.post(mHider);
}
} }
...@@ -14,7 +14,7 @@ import org.chromium.content_public.browser.WebContents; ...@@ -14,7 +14,7 @@ import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.DeviceFormFactor; import org.chromium.ui.base.DeviceFormFactor;
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 org.chromium.url.URI; import org.chromium.url.GURL;
/** /**
* PaymentHandlerToolbar coordinator, which owns the component overall, i.e., creates other objects * PaymentHandlerToolbar coordinator, which owns the component overall, i.e., creates other objects
...@@ -32,9 +32,6 @@ public class PaymentHandlerToolbarCoordinator { ...@@ -32,9 +32,6 @@ public class PaymentHandlerToolbarCoordinator {
* Observer for the error of the payment handler toolbar. * Observer for the error of the payment handler toolbar.
*/ */
public interface PaymentHandlerToolbarObserver { public interface PaymentHandlerToolbarObserver {
/** Called when the UI gets an error. */
void onToolbarError();
/** Called when the close button is clicked. */ /** Called when the close button is clicked. */
void onToolbarCloseButtonClicked(); void onToolbarCloseButtonClicked();
} }
...@@ -48,7 +45,7 @@ public class PaymentHandlerToolbarCoordinator { ...@@ -48,7 +45,7 @@ public class PaymentHandlerToolbarCoordinator {
* @param observer The observer of this toolbar. * @param observer The observer of this toolbar.
*/ */
public PaymentHandlerToolbarCoordinator( public PaymentHandlerToolbarCoordinator(
ChromeActivity context, WebContents webContents, URI url) { ChromeActivity context, WebContents webContents, GURL url) {
mWebContents = webContents; mWebContents = webContents;
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)
...@@ -69,7 +66,6 @@ public class PaymentHandlerToolbarCoordinator { ...@@ -69,7 +66,6 @@ public class PaymentHandlerToolbarCoordinator {
/** Set an observer for PaymentHandlerToolbar. */ /** Set an observer for PaymentHandlerToolbar. */
public void setObserver(PaymentHandlerToolbarObserver observer) { public void setObserver(PaymentHandlerToolbarObserver observer) {
mMediator.setObserver(observer);
mToolbarView.setObserver(observer); mToolbarView.setObserver(observer);
} }
......
...@@ -9,11 +9,9 @@ import android.view.View; ...@@ -9,11 +9,9 @@ import android.view.View;
import androidx.annotation.DrawableRes; import androidx.annotation.DrawableRes;
import org.chromium.base.Log;
import org.chromium.chrome.browser.ChromeActivity; import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.offlinepages.OfflinePageUtils; import org.chromium.chrome.browser.offlinepages.OfflinePageUtils;
import org.chromium.chrome.browser.page_info.PageInfoController; import org.chromium.chrome.browser.page_info.PageInfoController;
import org.chromium.chrome.browser.payments.handler.toolbar.PaymentHandlerToolbarCoordinator.PaymentHandlerToolbarObserver;
import org.chromium.chrome.browser.ssl.ChromeSecurityStateModelDelegate; import org.chromium.chrome.browser.ssl.ChromeSecurityStateModelDelegate;
import org.chromium.components.omnibox.SecurityStatusIcon; import org.chromium.components.omnibox.SecurityStatusIcon;
import org.chromium.components.security_state.ConnectionSecurityLevel; import org.chromium.components.security_state.ConnectionSecurityLevel;
...@@ -22,9 +20,6 @@ import org.chromium.content_public.browser.NavigationHandle; ...@@ -22,9 +20,6 @@ import org.chromium.content_public.browser.NavigationHandle;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.content_public.browser.WebContentsObserver; import org.chromium.content_public.browser.WebContentsObserver;
import org.chromium.ui.modelutil.PropertyModel; import org.chromium.ui.modelutil.PropertyModel;
import org.chromium.url.URI;
import java.net.URISyntaxException;
/** /**
* PaymentHandlerToolbar mediator, which is responsible for receiving events from the view and * PaymentHandlerToolbar mediator, which is responsible for receiving events from the view and
...@@ -43,7 +38,6 @@ import java.net.URISyntaxException; ...@@ -43,7 +38,6 @@ import java.net.URISyntaxException;
/* package */ static final float MINIMUM_LOAD_PROGRESS = 0.05f; /* package */ static final float MINIMUM_LOAD_PROGRESS = 0.05f;
private final PropertyModel mModel; private final PropertyModel mModel;
private 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. */
...@@ -68,11 +62,6 @@ import java.net.URISyntaxException; ...@@ -68,11 +62,6 @@ import java.net.URISyntaxException;
mChromeActivity = chromeActivity; mChromeActivity = chromeActivity;
} }
/** Set an observer for this class. */
/* package */ void setObserver(PaymentHandlerToolbarObserver observer) {
mObserver = observer;
}
// WebContentsObserver: // WebContentsObserver:
@Override @Override
public void didFinishLoad(long frameId, String validatedUrl, boolean isMainFrame) { public void didFinishLoad(long frameId, String validatedUrl, boolean isMainFrame) {
...@@ -94,14 +83,7 @@ import java.net.URISyntaxException; ...@@ -94,14 +83,7 @@ import java.net.URISyntaxException;
@Override @Override
public void didFinishNavigation(NavigationHandle navigation) { public void didFinishNavigation(NavigationHandle navigation) {
if (!navigation.hasCommitted() || !navigation.isInMainFrame()) return; if (!navigation.hasCommitted() || !navigation.isInMainFrame()) return;
String url = mWebContentsRef.getVisibleUrl().getSpec(); mModel.set(PaymentHandlerToolbarProperties.URL, mWebContentsRef.getVisibleUrl());
try {
mModel.set(PaymentHandlerToolbarProperties.URL, new URI(url));
} catch (URISyntaxException e) {
Log.e(TAG, "Failed to instantiate a URI with the url \"%s\".", url);
assert mObserver != null;
mObserver.onToolbarError();
}
mModel.set(PaymentHandlerToolbarProperties.PROGRESS_VISIBLE, false); mModel.set(PaymentHandlerToolbarProperties.PROGRESS_VISIBLE, false);
} }
......
...@@ -9,11 +9,11 @@ import org.chromium.ui.modelutil.PropertyModel.WritableBooleanPropertyKey; ...@@ -9,11 +9,11 @@ import org.chromium.ui.modelutil.PropertyModel.WritableBooleanPropertyKey;
import org.chromium.ui.modelutil.PropertyModel.WritableFloatPropertyKey; import org.chromium.ui.modelutil.PropertyModel.WritableFloatPropertyKey;
import org.chromium.ui.modelutil.PropertyModel.WritableIntPropertyKey; import org.chromium.ui.modelutil.PropertyModel.WritableIntPropertyKey;
import org.chromium.ui.modelutil.PropertyModel.WritableObjectPropertyKey; import org.chromium.ui.modelutil.PropertyModel.WritableObjectPropertyKey;
import org.chromium.url.URI; import org.chromium.url.GURL;
/** PaymentHandlerToolbar UI properties, which fully describe the state of the UI. */ /** PaymentHandlerToolbar UI properties, which fully describe the state of the UI. */
/* package */ class PaymentHandlerToolbarProperties { /* package */ class PaymentHandlerToolbarProperties {
/* package */ static final WritableObjectPropertyKey<URI> URL = /* package */ static final WritableObjectPropertyKey<GURL> URL =
new WritableObjectPropertyKey<>(); new WritableObjectPropertyKey<>();
/* package */ static final WritableObjectPropertyKey<String> TITLE = /* package */ static final WritableObjectPropertyKey<String> TITLE =
......
...@@ -20,7 +20,7 @@ import org.chromium.ui.modelutil.PropertyModel; ...@@ -20,7 +20,7 @@ import org.chromium.ui.modelutil.PropertyModel;
PropertyModel model, PaymentHandlerToolbarView view, PropertyKey propertyKey) { PropertyModel model, PaymentHandlerToolbarView view, PropertyKey propertyKey) {
if (PaymentHandlerToolbarProperties.URL == propertyKey) { if (PaymentHandlerToolbarProperties.URL == propertyKey) {
String origin = UrlFormatter.formatUrlForSecurityDisplay( String origin = UrlFormatter.formatUrlForSecurityDisplay(
model.get(PaymentHandlerToolbarProperties.URL).toString(), model.get(PaymentHandlerToolbarProperties.URL),
SchemeDisplay.OMIT_HTTP_AND_HTTPS); SchemeDisplay.OMIT_HTTP_AND_HTTPS);
view.mOriginView.setText(origin); view.mOriginView.setText(origin);
} else if (PaymentHandlerToolbarProperties.TITLE == propertyKey) { } else if (PaymentHandlerToolbarProperties.TITLE == propertyKey) {
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/page_navigator.h" #include "content/public/browser/page_navigator.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "url/android/gurl_android.h"
using base::android::AttachCurrentThread; using base::android::AttachCurrentThread;
using base::android::ConvertUTF8ToJavaString; using base::android::ConvertUTF8ToJavaString;
...@@ -52,8 +53,6 @@ void ServiceTabLauncher::LaunchTab(content::BrowserContext* browser_context, ...@@ -52,8 +53,6 @@ void ServiceTabLauncher::LaunchTab(content::BrowserContext* browser_context,
} }
JNIEnv* env = AttachCurrentThread(); JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jstring> url = ConvertUTF8ToJavaString(
env, params.url.spec());
ScopedJavaLocalRef<jstring> referrer_url = ScopedJavaLocalRef<jstring> referrer_url =
ConvertUTF8ToJavaString(env, params.referrer.url.spec()); ConvertUTF8ToJavaString(env, params.referrer.url.spec());
ScopedJavaLocalRef<jstring> headers = ConvertUTF8ToJavaString( ScopedJavaLocalRef<jstring> headers = ConvertUTF8ToJavaString(
...@@ -67,7 +66,8 @@ void ServiceTabLauncher::LaunchTab(content::BrowserContext* browser_context, ...@@ -67,7 +66,8 @@ void ServiceTabLauncher::LaunchTab(content::BrowserContext* browser_context,
DCHECK_GE(request_id, 1); DCHECK_GE(request_id, 1);
Java_ServiceTabLauncher_launchTab( Java_ServiceTabLauncher_launchTab(
env, request_id, browser_context->IsOffTheRecord(), url, env, request_id, browser_context->IsOffTheRecord(),
url::GURLAndroid::FromNativeGURL(env, params.url),
static_cast<int>(disposition), referrer_url, static_cast<int>(disposition), referrer_url,
static_cast<int>(params.referrer.policy), headers, post_data); static_cast<int>(params.referrer.policy), headers, post_data);
} }
......
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