[go: nahoru, domu]

[GURL] Migrate RenderFrameHost to use GURL.

Bug: 783819
Change-Id: I8f6f3867e3214442d27d343ee0659aecf50b8081
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2689923
Commit-Queue: Yaron Friedman <yfriedman@chromium.org>
Reviewed-by: Michael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#854387}
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/browserservices/digitalgoods/DigitalGoodsImpl.java b/chrome/android/java/src/org/chromium/chrome/browser/browserservices/digitalgoods/DigitalGoodsImpl.java
index bbeb1da..a63d828 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/browserservices/digitalgoods/DigitalGoodsImpl.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/browserservices/digitalgoods/DigitalGoodsImpl.java
@@ -13,6 +13,7 @@
 import org.chromium.payments.mojom.DigitalGoods.AcknowledgeResponse;
 import org.chromium.payments.mojom.DigitalGoods.GetDetailsResponse;
 import org.chromium.payments.mojom.DigitalGoods.ListPurchasesResponse;
+import org.chromium.url.GURL;
 
 /**
  * An implementation of the {@link DigitalGoods} mojo interface that communicates with Trusted Web
@@ -26,7 +27,7 @@
     public interface Delegate {
         /** @return The current URL or null when the frame is being destroyed. */
         @Nullable
-        String getUrl();
+        GURL getUrl();
     }
 
     /** Constructs the object with a given adapter and delegate. */
@@ -37,23 +38,24 @@
 
     @Override
     public void getDetails(String[] itemIds, GetDetailsResponse callback) {
-        String url = mDelegate.getUrl();
-        if (url != null) mAdapter.getDetails(Uri.parse(url), itemIds, callback);
+        GURL url = mDelegate.getUrl();
+        if (url != null) mAdapter.getDetails(Uri.parse(url.getSpec()), itemIds, callback);
     }
 
     @Override
     public void acknowledge(
             String purchaseToken, boolean makeAvailableAgain, AcknowledgeResponse callback) {
-        String url = mDelegate.getUrl();
+        GURL url = mDelegate.getUrl();
         if (url != null) {
-            mAdapter.acknowledge(Uri.parse(url), purchaseToken, makeAvailableAgain, callback);
+            mAdapter.acknowledge(
+                    Uri.parse(url.getSpec()), purchaseToken, makeAvailableAgain, callback);
         }
     }
 
     @Override
     public void listPurchases(ListPurchasesResponse callback) {
-        String url = mDelegate.getUrl();
-        if (url != null) mAdapter.listPurchases(Uri.parse(mDelegate.getUrl()), callback);
+        GURL url = mDelegate.getUrl();
+        if (url != null) mAdapter.listPurchases(Uri.parse(url.getSpec()), callback);
     }
 
     @Override
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/installedapp/InstalledAppProviderFactory.java b/chrome/android/java/src/org/chromium/chrome/browser/installedapp/InstalledAppProviderFactory.java
index cda99ee..e7fc5c1 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/installedapp/InstalledAppProviderFactory.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/installedapp/InstalledAppProviderFactory.java
@@ -24,9 +24,8 @@
 
         @Override
         public GURL getUrl() {
-            String url = mRenderFrameHost.getLastCommittedURL();
-            if (url == null) return GURL.emptyGURL();
-            return new GURL(url);
+            GURL url = mRenderFrameHost.getLastCommittedURL();
+            return (url != null) ? url : GURL.emptyGURL();
         }
 
         @Override
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentAppServiceBridge.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentAppServiceBridge.java
index 88d6c3d..7616012d 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentAppServiceBridge.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/PaymentAppServiceBridge.java
@@ -13,6 +13,7 @@
 import org.chromium.components.payments.PaymentAppFactoryDelegate;
 import org.chromium.components.payments.PaymentAppFactoryInterface;
 import org.chromium.components.payments.PaymentRequestSpec;
+import org.chromium.components.url_formatter.SchemeDisplay;
 import org.chromium.components.url_formatter.UrlFormatter;
 import org.chromium.content_public.browser.RenderFrameHost;
 
@@ -46,7 +47,8 @@
 
         assert delegate.getParams().getPaymentRequestOrigin().equals(
                 UrlFormatter.formatUrlForSecurityDisplay(
-                        delegate.getParams().getRenderFrameHost().getLastCommittedURL()));
+                        delegate.getParams().getRenderFrameHost().getLastCommittedURL(),
+                        SchemeDisplay.SHOW));
 
         PaymentAppServiceCallback callback = new PaymentAppServiceCallback(delegate);
 
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/share/ShareDelegateImpl.java b/chrome/android/java/src/org/chromium/chrome/browser/share/ShareDelegateImpl.java
index 3f48d772..840aad18 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/share/ShareDelegateImpl.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/share/ShareDelegateImpl.java
@@ -9,6 +9,7 @@
 import android.text.TextUtils;
 
 import androidx.annotation.IntDef;
+import androidx.annotation.NonNull;
 import androidx.annotation.VisibleForTesting;
 
 import org.chromium.base.Callback;
@@ -36,14 +37,15 @@
 import org.chromium.components.browser_ui.share.ShareImageFileUtils;
 import org.chromium.components.browser_ui.share.ShareParams;
 import org.chromium.components.embedder_support.util.UrlConstants;
+import org.chromium.components.embedder_support.util.UrlUtilities;
 import org.chromium.components.favicon.LargeIconBridge;
 import org.chromium.components.ui_metrics.CanonicalURLResult;
 import org.chromium.content_public.browser.WebContents;
-import org.chromium.net.GURLUtils;
 import org.chromium.printing.PrintManagerDelegateImpl;
 import org.chromium.printing.PrintingController;
 import org.chromium.printing.PrintingControllerImpl;
 import org.chromium.ui.base.WindowAndroid;
+import org.chromium.url.GURL;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -177,10 +179,10 @@
                 if (shouldFetchCanonicalUrl(currentTab)) {
                     WebContents webContents = currentTab.getWebContents();
                     String title = currentTab.getTitle();
-                    String visibleUrl = currentTab.getUrlString();
-                    webContents.getMainFrame().getCanonicalUrlForSharing(new Callback<String>() {
+                    GURL visibleUrl = currentTab.getUrl();
+                    webContents.getMainFrame().getCanonicalUrlForSharing(new Callback<GURL>() {
                         @Override
-                        public void onResult(String result) {
+                        public void onResult(GURL result) {
                             logCanonicalUrlResult(visibleUrl, result);
 
                             triggerShareWithCanonicalUrlResolved(window, webContents, title,
@@ -189,16 +191,16 @@
                     });
                 } else {
                     triggerShareWithCanonicalUrlResolved(window, currentTab.getWebContents(),
-                            currentTab.getTitle(), currentTab.getUrlString(), null, shareOrigin,
-                            shareDirectly, isIncognito);
+                            currentTab.getTitle(), currentTab.getUrl(), GURL.emptyGURL(),
+                            shareOrigin, shareDirectly, isIncognito);
                 }
             }
         });
     }
 
     private void triggerShareWithCanonicalUrlResolved(final WindowAndroid window,
-            final WebContents webContents, final String title, final String visibleUrl,
-            final String canonicalUrl, @ShareOrigin final int shareOrigin,
+            final WebContents webContents, final String title, final @NonNull GURL visibleUrl,
+            final GURL canonicalUrl, @ShareOrigin final int shareOrigin,
             final boolean shareDirectly, boolean isIncognito) {
         // Share an empty blockingUri in place of screenshot file. The file ready notification is
         // sent by onScreenshotReady call below when the file is written.
@@ -243,7 +245,7 @@
         return true;
     }
 
-    private static void logCanonicalUrlResult(String visibleUrl, String canonicalUrl) {
+    private static void logCanonicalUrlResult(GURL visibleUrl, GURL canonicalUrl) {
         @CanonicalURLResult
         int result = getCanonicalUrlResult(visibleUrl, canonicalUrl);
         RecordHistogram.recordEnumeratedHistogram(CANONICAL_URL_RESULT_HISTOGRAM, result,
@@ -256,30 +258,28 @@
     }
 
     @VisibleForTesting
-    static String getUrlToShare(String visibleUrl, String canonicalUrl) {
-        if (TextUtils.isEmpty(canonicalUrl)) return visibleUrl;
-        // TODO(tedchoc): Can we replace GURLUtils.getScheme with Uri.parse(...).getScheme()
-        //                https://crbug.com/783819
-        if (!UrlConstants.HTTPS_SCHEME.equals(GURLUtils.getScheme(visibleUrl))) {
-            return visibleUrl;
+    static String getUrlToShare(@NonNull GURL visibleUrl, GURL canonicalUrl) {
+        if (canonicalUrl == null || canonicalUrl.isEmpty()) {
+            return visibleUrl.getSpec();
         }
-        String canonicalScheme = GURLUtils.getScheme(canonicalUrl);
-        if (!UrlConstants.HTTP_SCHEME.equals(canonicalScheme)
-                && !UrlConstants.HTTPS_SCHEME.equals(canonicalScheme)) {
-            return visibleUrl;
+        if (!UrlConstants.HTTPS_SCHEME.equals(visibleUrl.getScheme())) {
+            return visibleUrl.getSpec();
         }
-        return canonicalUrl;
+        if (!UrlUtilities.isHttpOrHttps(canonicalUrl)) {
+            return visibleUrl.getSpec();
+        }
+        return canonicalUrl.getSpec();
     }
 
     @CanonicalURLResult
-    private static int getCanonicalUrlResult(String visibleUrl, String canonicalUrl) {
-        if (!UrlConstants.HTTPS_SCHEME.equals(GURLUtils.getScheme(visibleUrl))) {
+    private static int getCanonicalUrlResult(GURL visibleUrl, GURL canonicalUrl) {
+        if (!UrlConstants.HTTPS_SCHEME.equals(visibleUrl.getScheme())) {
             return CanonicalURLResult.FAILED_VISIBLE_URL_NOT_HTTPS;
         }
-        if (TextUtils.isEmpty(canonicalUrl)) {
+        if (canonicalUrl == null || canonicalUrl.isEmpty()) {
             return CanonicalURLResult.FAILED_NO_CANONICAL_URL_DEFINED;
         }
-        String canonicalScheme = GURLUtils.getScheme(canonicalUrl);
+        String canonicalScheme = canonicalUrl.getScheme();
         if (!UrlConstants.HTTPS_SCHEME.equals(canonicalScheme)) {
             if (!UrlConstants.HTTP_SCHEME.equals(canonicalScheme)) {
                 return CanonicalURLResult.FAILED_CANONICAL_URL_INVALID;
@@ -287,7 +287,7 @@
                 return CanonicalURLResult.SUCCESS_CANONICAL_URL_NOT_HTTPS;
             }
         }
-        if (TextUtils.equals(visibleUrl, canonicalUrl)) {
+        if (visibleUrl.equals(canonicalUrl)) {
             return CanonicalURLResult.SUCCESS_CANONICAL_URL_SAME_AS_VISIBLE;
         } else {
             return CanonicalURLResult.SUCCESS_CANONICAL_URL_DIFFERENT_FROM_VISIBLE;
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/browserservices/digitalgoods/DigitalGoodsTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/browserservices/digitalgoods/DigitalGoodsTest.java
index 8c6c27f2..b3af5cb3 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/browserservices/digitalgoods/DigitalGoodsTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/browserservices/digitalgoods/DigitalGoodsTest.java
@@ -46,6 +46,7 @@
 import org.chromium.payments.mojom.DigitalGoods.GetDetailsResponse;
 import org.chromium.payments.mojom.ItemDetails;
 import org.chromium.ui.test.util.UiDisableIf;
+import org.chromium.url.GURL;
 
 import java.util.concurrent.TimeoutException;
 
@@ -206,7 +207,7 @@
 
         // To work around this, we create our own DigitalGoodsImpl with a custom Delegate that
         // provides the URL we want to see.
-        DigitalGoodsImpl.Delegate delegate = () -> TWA_SERVICE_SCOPE;
+        DigitalGoodsImpl.Delegate delegate = () -> new GURL(TWA_SERVICE_SCOPE);
         DigitalGoodsAdapter adapter = new DigitalGoodsAdapter(mClient);
         return new DigitalGoodsImpl(adapter, delegate);
     }
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/share/ShareDelegateImplTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/share/ShareDelegateImplTest.java
index 8c27fde..53e4981 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/share/ShareDelegateImplTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/share/ShareDelegateImplTest.java
@@ -19,6 +19,7 @@
 import org.chromium.content_public.browser.test.mock.MockRenderFrameHost;
 import org.chromium.content_public.browser.test.mock.MockWebContents;
 import org.chromium.content_public.browser.test.util.TestThreadUtils;
+import org.chromium.url.GURL;
 
 import java.util.concurrent.ExecutionException;
 
@@ -67,32 +68,34 @@
     @Test
     @SmallTest
     public void testGetUrlToShare() {
-        Assert.assertNull(ShareDelegateImpl.getUrlToShare(null, null));
-        Assert.assertEquals("", ShareDelegateImpl.getUrlToShare("", null));
+        Assert.assertEquals("", ShareDelegateImpl.getUrlToShare(GURL.emptyGURL(), null));
 
-        final String httpUrl = "http://blah.com";
-        final String otherHttpUrl = "http://eek.com";
-        final String httpsUrl = "https://blah.com";
-        final String otherHttpsUrl = "https://eek.com";
-        final String ftpUrl = "ftp://blah.com";
-        final String contentUrl = "content://eek.com";
+        final GURL httpUrl = new GURL("http://blah.com");
+        final GURL otherHttpUrl = new GURL("http://eek.com");
+        final GURL httpsUrl = new GURL("https://blah.com");
+        final GURL otherHttpsUrl = new GURL("https://eek.com");
+        final GURL ftpUrl = new GURL("ftp://blah.com");
+        final GURL contentUrl = new GURL("content://eek.com");
 
         // HTTP Display URL, HTTP Canonical URL -> HTTP Display URL
-        Assert.assertEquals(httpUrl, ShareDelegateImpl.getUrlToShare(httpUrl, otherHttpUrl));
+        Assert.assertEquals(
+                httpUrl.getSpec(), ShareDelegateImpl.getUrlToShare(httpUrl, otherHttpUrl));
         // HTTP Display URL, HTTPS Canonical URL -> HTTP Display URL
-        Assert.assertEquals(httpUrl, ShareDelegateImpl.getUrlToShare(httpUrl, httpsUrl));
+        Assert.assertEquals(httpUrl.getSpec(), ShareDelegateImpl.getUrlToShare(httpUrl, httpsUrl));
         // HTTPS Display URL, HTTP Canonical URL -> HTTP Canonical URL
-        Assert.assertEquals(httpUrl, ShareDelegateImpl.getUrlToShare(httpsUrl, httpUrl));
+        Assert.assertEquals(httpUrl.getSpec(), ShareDelegateImpl.getUrlToShare(httpsUrl, httpUrl));
 
         // HTTPS Display URL, HTTPS Canonical URL -> HTTPS Canonical URL
-        Assert.assertEquals(httpsUrl, ShareDelegateImpl.getUrlToShare(httpsUrl, httpsUrl));
         Assert.assertEquals(
-                otherHttpsUrl, ShareDelegateImpl.getUrlToShare(httpsUrl, otherHttpsUrl));
+                httpsUrl.getSpec(), ShareDelegateImpl.getUrlToShare(httpsUrl, httpsUrl));
+        Assert.assertEquals(
+                otherHttpsUrl.getSpec(), ShareDelegateImpl.getUrlToShare(httpsUrl, otherHttpsUrl));
 
         // HTTPS Display URL, FTP URL -> HTTPS Display URL
-        Assert.assertEquals(httpsUrl, ShareDelegateImpl.getUrlToShare(httpsUrl, ftpUrl));
+        Assert.assertEquals(httpsUrl.getSpec(), ShareDelegateImpl.getUrlToShare(httpsUrl, ftpUrl));
         // HTTPS Display URL, Content URL -> HTTPS Display URL
-        Assert.assertEquals(httpsUrl, ShareDelegateImpl.getUrlToShare(httpsUrl, contentUrl));
+        Assert.assertEquals(
+                httpsUrl.getSpec(), ShareDelegateImpl.getUrlToShare(httpsUrl, contentUrl));
     }
 
     private static class MockUrlTab extends MockTab {
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/webauth/Fido2CredentialRequestTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/webauth/Fido2CredentialRequestTest.java
index ff327b64..26130c7 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/webauth/Fido2CredentialRequestTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/webauth/Fido2CredentialRequestTest.java
@@ -355,11 +355,11 @@
     }
 
     private static class MockAuthenticatorRenderFrameHost extends MockRenderFrameHost {
-        private String mLastUrl;
+        private GURL mLastUrl;
         private MockOrigin mLastOrigin;
 
         @Override
-        public String getLastCommittedURL() {
+        public GURL getLastCommittedURL() {
             return mLastUrl;
         }
 
@@ -368,10 +368,10 @@
             return mLastOrigin;
         }
 
-        public void setLastCommittedURL(String url) {
+        public void setLastCommittedURL(GURL url) {
             mLastUrl = url;
             mLastOrigin = new MockOrigin();
-            mLastOrigin.setUrl(url);
+            mLastOrigin.setUrl(url.getSpec());
         }
     }
 
@@ -384,7 +384,7 @@
                 "subdomain.example.test", "/content/test/data/android/authenticator.html");
         sActivityTestRule.loadUrl(mUrl);
         mFrameHost = new MockAuthenticatorRenderFrameHost();
-        mFrameHost.setLastCommittedURL(mUrl);
+        mFrameHost.setLastCommittedURL(new GURL(mUrl));
         mOrigin = mFrameHost.getLastCommittedOrigin();
         mRequest = new Fido2CredentialRequest();
         mRequest.setWebContentsForTesting(new MockWebContents());
diff --git a/chrome/browser/payments/android/java/src/org/chromium/chrome/browser/payments/test_support/PaymentRequestParamsBuilder.java b/chrome/browser/payments/android/java/src/org/chromium/chrome/browser/payments/test_support/PaymentRequestParamsBuilder.java
index e0f5dfe..3c18ba1 100644
--- a/chrome/browser/payments/android/java/src/org/chromium/chrome/browser/payments/test_support/PaymentRequestParamsBuilder.java
+++ b/chrome/browser/payments/android/java/src/org/chromium/chrome/browser/payments/test_support/PaymentRequestParamsBuilder.java
@@ -76,7 +76,10 @@
                 .when(mWebContents)
                 .getLastCommittedUrl();
         mRenderFrameHost = Mockito.mock(RenderFrameHost.class);
-        Mockito.doReturn("https://frame.origin").when(mRenderFrameHost).getLastCommittedURL();
+        // subframe
+        Mockito.doReturn(JUnitTestGURLs.getGURL(JUnitTestGURLs.URL_2))
+                .when(mRenderFrameHost)
+                .getLastCommittedURL();
         Origin origin = Mockito.mock(Origin.class);
         Mockito.doReturn(origin).when(mRenderFrameHost).getLastCommittedOrigin();
         mMethodData = new PaymentMethodData[1];
@@ -169,8 +172,8 @@
     }
 
     @Override
-    public String formatUrlForSecurityDisplay(String uri) {
-        return uri;
+    public String formatUrlForSecurityDisplay(GURL uri) {
+        return uri.getSpec();
     }
 
     @Override
diff --git a/components/payments/content/android/java/src/org/chromium/components/payments/PaymentRequestService.java b/components/payments/content/android/java/src/org/chromium/components/payments/PaymentRequestService.java
index 72ef34a..12b8c633 100644
--- a/components/payments/content/android/java/src/org/chromium/components/payments/PaymentRequestService.java
+++ b/components/payments/content/android/java/src/org/chromium/components/payments/PaymentRequestService.java
@@ -15,6 +15,7 @@
 import org.chromium.base.Log;
 import org.chromium.components.embedder_support.util.UrlConstants;
 import org.chromium.components.page_info.CertificateChainHelper;
+import org.chromium.components.url_formatter.SchemeDisplay;
 import org.chromium.components.url_formatter.UrlFormatter;
 import org.chromium.content_public.browser.RenderFrameHost;
 import org.chromium.content_public.browser.WebContents;
@@ -246,8 +247,8 @@
          * @return Stripped-down String containing the essential bits of the URL, or the original
          *         URL if it fails to parse it.
          */
-        default String formatUrlForSecurityDisplay(String uri) {
-            return UrlFormatter.formatUrlForSecurityDisplay(uri);
+        default String formatUrlForSecurityDisplay(GURL uri) {
+            return UrlFormatter.formatUrlForSecurityDisplay(uri, SchemeDisplay.SHOW);
         }
 
         /**
@@ -429,8 +430,7 @@
             return false;
         }
         // TODO(crbug.com/992593): replace UrlFormatter with GURL operations.
-        mTopLevelOrigin =
-                mDelegate.formatUrlForSecurityDisplay(mWebContents.getLastCommittedUrl().getSpec());
+        mTopLevelOrigin = mDelegate.formatUrlForSecurityDisplay(mWebContents.getLastCommittedUrl());
 
         mMerchantName = mWebContents.getTitle();
         mCertificateChain = mDelegate.getCertificateChain(mWebContents);
diff --git a/components/payments/content/android/junit/src/org/chromium/components/payments/test_support/PaymentRequestServiceBuilder.java b/components/payments/content/android/junit/src/org/chromium/components/payments/test_support/PaymentRequestServiceBuilder.java
index 821edf9..6abebe7a 100644
--- a/components/payments/content/android/junit/src/org/chromium/components/payments/test_support/PaymentRequestServiceBuilder.java
+++ b/components/payments/content/android/junit/src/org/chromium/components/payments/test_support/PaymentRequestServiceBuilder.java
@@ -69,7 +69,7 @@
         mWebContents = Mockito.mock(WebContents.class);
         setTopLevelOrigin(JUnitTestGURLs.getGURL(JUnitTestGURLs.URL_1));
         mRenderFrameHost = Mockito.mock(RenderFrameHost.class);
-        setFrameOrigin("https://frame.origin");
+        setFrameOrigin(JUnitTestGURLs.getGURL(JUnitTestGURLs.URL_2));
         Origin origin = Mockito.mock(Origin.class);
         Mockito.doReturn(origin).when(mRenderFrameHost).getLastCommittedOrigin();
         mJourneyLogger = journeyLogger;
@@ -139,8 +139,8 @@
     }
 
     @Override
-    public String formatUrlForSecurityDisplay(String url) {
-        return url;
+    public String formatUrlForSecurityDisplay(GURL url) {
+        return url.getSpec();
     }
 
     @Override
@@ -175,7 +175,7 @@
         return this;
     }
 
-    public PaymentRequestServiceBuilder setRenderFrameHostLastCommittedURL(String url) {
+    public PaymentRequestServiceBuilder setRenderFrameHostLastCommittedURL(GURL url) {
         Mockito.doReturn(url).when(mRenderFrameHost).getLastCommittedURL();
         return this;
     }
@@ -240,7 +240,7 @@
         return this;
     }
 
-    public PaymentRequestServiceBuilder setFrameOrigin(String frameOrigin) {
+    public PaymentRequestServiceBuilder setFrameOrigin(GURL frameOrigin) {
         Mockito.doReturn(frameOrigin).when(mRenderFrameHost).getLastCommittedURL();
         return this;
     }
diff --git a/content/browser/renderer_host/render_frame_host_android.cc b/content/browser/renderer_host/render_frame_host_android.cc
index f9b3317b..df3eb4a 100644
--- a/content/browser/renderer_host/render_frame_host_android.cc
+++ b/content/browser/renderer_host/render_frame_host_android.cc
@@ -21,6 +21,7 @@
 #include "services/service_manager/public/cpp/interface_provider.h"
 #include "third_party/blink/public/mojom/feature_policy/feature_policy_feature.mojom-shared.h"
 #include "third_party/blink/public/mojom/frame/user_activation_notification_type.mojom.h"
+#include "url/android/gurl_android.h"
 #include "url/origin.h"
 
 using base::android::AttachCurrentThread;
@@ -35,13 +36,15 @@
 void OnGetCanonicalUrlForSharing(
     const base::android::JavaRef<jobject>& jcallback,
     const base::Optional<GURL>& url) {
+  JNIEnv* env = base::android::AttachCurrentThread();
   if (!url) {
     base::android::RunObjectCallbackAndroid(jcallback,
-                                            ScopedJavaLocalRef<jstring>());
+                                            url::GURLAndroid::EmptyGURL(env));
     return;
   }
 
-  base::android::RunStringCallbackAndroid(jcallback, url->spec());
+  base::android::RunObjectCallbackAndroid(
+      jcallback, url::GURLAndroid::FromNativeGURL(env, url.value()));
 }
 }  // namespace
 
@@ -94,11 +97,11 @@
   return obj_.get(env);
 }
 
-ScopedJavaLocalRef<jstring> RenderFrameHostAndroid::GetLastCommittedURL(
+ScopedJavaLocalRef<jobject> RenderFrameHostAndroid::GetLastCommittedURL(
     JNIEnv* env,
     const JavaParamRef<jobject>& obj) const {
-  return ConvertUTF8ToJavaString(
-      env, render_frame_host_->GetLastCommittedURL().spec());
+  return url::GURLAndroid::FromNativeGURL(
+      env, render_frame_host_->GetLastCommittedURL());
 }
 
 ScopedJavaLocalRef<jobject> RenderFrameHostAndroid::GetLastCommittedOrigin(
diff --git a/content/browser/renderer_host/render_frame_host_android.h b/content/browser/renderer_host/render_frame_host_android.h
index 7b70f6b..714f46f 100644
--- a/content/browser/renderer_host/render_frame_host_android.h
+++ b/content/browser/renderer_host/render_frame_host_android.h
@@ -32,7 +32,7 @@
   base::android::ScopedJavaLocalRef<jobject> GetJavaObject();
 
   // Methods called from Java
-  base::android::ScopedJavaLocalRef<jstring> GetLastCommittedURL(
+  base::android::ScopedJavaLocalRef<jobject> GetLastCommittedURL(
       JNIEnv* env,
       const base::android::JavaParamRef<jobject>&) const;
 
diff --git a/content/public/android/java/src/org/chromium/content/browser/framehost/RenderFrameHostImpl.java b/content/public/android/java/src/org/chromium/content/browser/framehost/RenderFrameHostImpl.java
index 3967e71..a8224a2 100644
--- a/content/public/android/java/src/org/chromium/content/browser/framehost/RenderFrameHostImpl.java
+++ b/content/public/android/java/src/org/chromium/content/browser/framehost/RenderFrameHostImpl.java
@@ -18,6 +18,7 @@
 import org.chromium.mojo.bindings.InterfaceRequest;
 import org.chromium.mojo.system.Pair;
 import org.chromium.mojo.system.impl.CoreImpl;
+import org.chromium.url.GURL;
 import org.chromium.url.Origin;
 
 /**
@@ -72,7 +73,7 @@
 
     @Override
     @Nullable
-    public String getLastCommittedURL() {
+    public GURL getLastCommittedURL() {
         if (mNativeRenderFrameHostAndroid == 0) return null;
         return RenderFrameHostImplJni.get().getLastCommittedURL(
                 mNativeRenderFrameHostAndroid, RenderFrameHostImpl.this);
@@ -87,7 +88,7 @@
     }
 
     @Override
-    public void getCanonicalUrlForSharing(Callback<String> callback) {
+    public void getCanonicalUrlForSharing(Callback<GURL> callback) {
         if (mNativeRenderFrameHostAndroid == 0) {
             callback.onResult(null);
             return;
@@ -182,11 +183,11 @@
 
     @NativeMethods
     interface Natives {
-        String getLastCommittedURL(long nativeRenderFrameHostAndroid, RenderFrameHostImpl caller);
+        GURL getLastCommittedURL(long nativeRenderFrameHostAndroid, RenderFrameHostImpl caller);
         Origin getLastCommittedOrigin(
                 long nativeRenderFrameHostAndroid, RenderFrameHostImpl caller);
         void getCanonicalUrlForSharing(long nativeRenderFrameHostAndroid,
-                RenderFrameHostImpl caller, Callback<String> callback);
+                RenderFrameHostImpl caller, Callback<GURL> callback);
         boolean isFeatureEnabled(long nativeRenderFrameHostAndroid, RenderFrameHostImpl caller,
                 @FeaturePolicyFeature int feature);
         UnguessableToken getAndroidOverlayRoutingToken(
diff --git a/content/public/android/java/src/org/chromium/content_public/browser/RenderFrameHost.java b/content/public/android/java/src/org/chromium/content_public/browser/RenderFrameHost.java
index bff32790..606b651 100644
--- a/content/public/android/java/src/org/chromium/content_public/browser/RenderFrameHost.java
+++ b/content/public/android/java/src/org/chromium/content_public/browser/RenderFrameHost.java
@@ -8,6 +8,7 @@
 
 import org.chromium.base.Callback;
 import org.chromium.mojo.bindings.Interface;
+import org.chromium.url.GURL;
 import org.chromium.url.Origin;
 
 /**
@@ -20,7 +21,7 @@
      * @return The last committed URL of the frame or null when being destroyed.
      */
     @Nullable
-    String getLastCommittedURL();
+    GURL getLastCommittedURL();
 
     /**
      * Get the last committed Origin of the frame. This is not always the same as scheme/host/port
@@ -37,7 +38,7 @@
      *
      * @param callback The callback to be notified once the canonical URL has been fetched.
      */
-    void getCanonicalUrlForSharing(Callback<String> callback);
+    void getCanonicalUrlForSharing(Callback<GURL> callback);
 
     /**
      * Returns whether the feature policy allows the feature in this frame.
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/webcontents/WebContentsTest.java b/content/public/android/javatests/src/org/chromium/content/browser/webcontents/WebContentsTest.java
index 3411789..16ecf30a 100644
--- a/content/public/android/javatests/src/org/chromium/content/browser/webcontents/WebContentsTest.java
+++ b/content/public/android/javatests/src/org/chromium/content/browser/webcontents/WebContentsTest.java
@@ -351,7 +351,7 @@
                 Assert.assertNotNull(frameHost);
 
                 Assert.assertEquals("RenderFrameHost has incorrect last committed URL", TEST_URL_2,
-                        frameHost.getLastCommittedURL());
+                        frameHost.getLastCommittedURL().getSpec());
 
                 WebContents associatedWebContents =
                         WebContentsStatics.fromRenderFrameHost(frameHost);
diff --git a/content/public/test/android/javatests/src/org/chromium/content_public/browser/test/mock/MockRenderFrameHost.java b/content/public/test/android/javatests/src/org/chromium/content_public/browser/test/mock/MockRenderFrameHost.java
index eb77bb7..a007784 100644
--- a/content/public/test/android/javatests/src/org/chromium/content_public/browser/test/mock/MockRenderFrameHost.java
+++ b/content/public/test/android/javatests/src/org/chromium/content_public/browser/test/mock/MockRenderFrameHost.java
@@ -8,6 +8,7 @@
 import org.chromium.content_public.browser.FeaturePolicyFeature;
 import org.chromium.content_public.browser.RenderFrameHost;
 import org.chromium.mojo.bindings.Interface;
+import org.chromium.url.GURL;
 import org.chromium.url.Origin;
 
 /**
@@ -15,7 +16,7 @@
  */
 public class MockRenderFrameHost implements RenderFrameHost {
     @Override
-    public String getLastCommittedURL() {
+    public GURL getLastCommittedURL() {
         return null;
     }
 
@@ -25,7 +26,7 @@
     }
 
     @Override
-    public void getCanonicalUrlForSharing(Callback<String> callback) {}
+    public void getCanonicalUrlForSharing(Callback<GURL> callback) {}
 
     @Override
     public boolean isFeatureEnabled(@FeaturePolicyFeature int feature) {
diff --git a/net/android/gurl_utils.cc b/net/android/gurl_utils.cc
index 764324b..a495cfe 100644
--- a/net/android/gurl_utils.cc
+++ b/net/android/gurl_utils.cc
@@ -19,12 +19,4 @@
   return base::android::ConvertUTF8ToJavaString(env, host.GetOrigin().spec());
 }
 
-ScopedJavaLocalRef<jstring> JNI_GURLUtils_GetScheme(
-    JNIEnv* env,
-    const JavaParamRef<jstring>& url) {
-  GURL host(base::android::ConvertJavaStringToUTF16(env, url));
-
-  return base::android::ConvertUTF8ToJavaString(env, host.scheme());
-}
-
 }  // namespace net
diff --git a/net/android/java/src/org/chromium/net/GURLUtils.java b/net/android/java/src/org/chromium/net/GURLUtils.java
index 4aab16f..7232bba 100644
--- a/net/android/java/src/org/chromium/net/GURLUtils.java
+++ b/net/android/java/src/org/chromium/net/GURLUtils.java
@@ -26,20 +26,9 @@
         return GURLUtilsJni.get().getOrigin(url);
     }
 
-    /**
-     * Get the scheme of the url (e.g. http, https, file). The returned string
-     * contains everything before the "://".
-     *
-     * @return The scheme of the url.
-     */
-    public static String getScheme(String url) {
-        return GURLUtilsJni.get().getScheme(url);
-    }
-
     @VisibleForTesting
     @NativeMethods
     public interface Natives {
         String getOrigin(String url);
-        String getScheme(String url);
     }
 }
diff --git a/weblayer/browser/java/org/chromium/weblayer_private/payments/test_support/WebLayerPaymentRequestBuilder.java b/weblayer/browser/java/org/chromium/weblayer_private/payments/test_support/WebLayerPaymentRequestBuilder.java
index 9214c2b..a2b0eae 100644
--- a/weblayer/browser/java/org/chromium/weblayer_private/payments/test_support/WebLayerPaymentRequestBuilder.java
+++ b/weblayer/browser/java/org/chromium/weblayer_private/payments/test_support/WebLayerPaymentRequestBuilder.java
@@ -67,7 +67,9 @@
                 .when(mWebContents)
                 .getLastCommittedUrl();
         mRenderFrameHost = Mockito.mock(RenderFrameHost.class);
-        Mockito.doReturn("https://frame.origin").when(mRenderFrameHost).getLastCommittedURL();
+        Mockito.doReturn(JUnitTestGURLs.getGURL(JUnitTestGURLs.URL_2))
+                .when(mRenderFrameHost)
+                .getLastCommittedURL();
         Origin origin = Mockito.mock(Origin.class);
         Mockito.doReturn(origin).when(mRenderFrameHost).getLastCommittedOrigin();
         mMethodData = new PaymentMethodData[1];
@@ -159,8 +161,8 @@
     }
 
     @Override
-    public String formatUrlForSecurityDisplay(String uri) {
-        return uri;
+    public String formatUrlForSecurityDisplay(GURL uri) {
+        return uri.getSpec();
     }
 
     @Override