Commit a25a688e authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

Migrate webview Webcontents#getVisibleUrl to GURL

Bug: 783819
Change-Id: Ib1970a41bb45a31907ea91358fd27bee6c6b20a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2039301Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738694}
parent 3f44738a
...@@ -471,6 +471,7 @@ android_library("browser_java") { ...@@ -471,6 +471,7 @@ android_library("browser_java") {
"//third_party/android_deps:androidx_annotation_annotation_java", "//third_party/android_deps:androidx_annotation_annotation_java",
"//third_party/blink/public:blink_headers_java", "//third_party/blink/public:blink_headers_java",
"//ui/android:ui_java", "//ui/android:ui_java",
"//url:gurl_java",
] ]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ] annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
......
...@@ -24,6 +24,7 @@ android_library("glue") { ...@@ -24,6 +24,7 @@ android_library("glue") {
"//content/public/android:content_java", "//content/public/android:content_java",
"//net/android:net_java", "//net/android:net_java",
"//ui/android:ui_java", "//ui/android:ui_java",
"//url:gurl_java",
] ]
annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ] annotation_processor_deps = [ "//base/android/jni_generator:jni_processor" ]
......
...@@ -1096,7 +1096,7 @@ class WebViewChromium implements WebViewProvider, WebViewProvider.ScrollDelegate ...@@ -1096,7 +1096,7 @@ class WebViewChromium implements WebViewProvider, WebViewProvider.ScrollDelegate
return ret; return ret;
} }
sWebViewApiCallSample.record(ApiCall.GET_URL); sWebViewApiCallSample.record(ApiCall.GET_URL);
return mAwContents.getUrl(); return mAwContents.getUrl().getSpec();
} }
@Override @Override
......
...@@ -110,6 +110,7 @@ import org.chromium.ui.base.PageTransition; ...@@ -110,6 +110,7 @@ import org.chromium.ui.base.PageTransition;
import org.chromium.ui.base.ViewAndroidDelegate; import org.chromium.ui.base.ViewAndroidDelegate;
import org.chromium.ui.base.WindowAndroid; import org.chromium.ui.base.WindowAndroid;
import org.chromium.ui.display.DisplayAndroid.DisplayAndroidObserver; import org.chromium.ui.display.DisplayAndroid.DisplayAndroidObserver;
import org.chromium.url.GURL;
import java.io.File; import java.io.File;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
...@@ -1968,10 +1969,10 @@ public class AwContents implements SmartClipProvider { ...@@ -1968,10 +1969,10 @@ public class AwContents implements SmartClipProvider {
* *
* @return The URL of the current page or null if it's empty. * @return The URL of the current page or null if it's empty.
*/ */
public String getUrl() { public GURL getUrl() {
if (isDestroyed(WARN)) return null; if (isDestroyed(WARN)) return null;
String url = mWebContents.getVisibleUrlString(); GURL url = mWebContents.getVisibleUrl();
if (url == null || url.trim().isEmpty()) return null; if (url == null || url.getSpec().trim().isEmpty()) return null;
return url; return url;
} }
......
...@@ -28,6 +28,7 @@ import org.chromium.content_public.browser.test.util.CriteriaHelper; ...@@ -28,6 +28,7 @@ import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.DOMUtils; import org.chromium.content_public.browser.test.util.DOMUtils;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.content_public.browser.test.util.TouchCommon; import org.chromium.content_public.browser.test.util.TouchCommon;
import org.chromium.url.GURL;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
...@@ -326,8 +327,9 @@ public class AwContentsClientFullScreenTest { ...@@ -326,8 +327,9 @@ public class AwContentsClientFullScreenTest {
} }
private boolean shouldPlayOnFullScreenView() throws Exception { private boolean shouldPlayOnFullScreenView() throws Exception {
String testUrl = mTestContainerView.getAwContents().getUrl(); GURL testUrl = mTestContainerView.getAwContents().getUrl();
return VIDEO_TEST_URL.equals(testUrl) && DOMUtils.isFullscreen(getWebContentsOnUiThread()); return new GURL(VIDEO_TEST_URL).equals(testUrl)
&& DOMUtils.isFullscreen(getWebContentsOnUiThread());
} }
private void playVideo() throws Exception { private void playVideo() throws Exception {
......
...@@ -36,6 +36,7 @@ import org.chromium.content_public.browser.test.util.TestCallbackHelperContainer ...@@ -36,6 +36,7 @@ import org.chromium.content_public.browser.test.util.TestCallbackHelperContainer
import org.chromium.content_public.browser.test.util.TestCallbackHelperContainer.OnReceivedErrorHelper; import org.chromium.content_public.browser.test.util.TestCallbackHelperContainer.OnReceivedErrorHelper;
import org.chromium.content_public.common.ContentUrlConstants; import org.chromium.content_public.common.ContentUrlConstants;
import org.chromium.net.test.util.TestWebServer; import org.chromium.net.test.util.TestWebServer;
import org.chromium.url.GURL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -856,7 +857,7 @@ public class AwContentsClientShouldOverrideUrlLoadingTest { ...@@ -856,7 +857,7 @@ public class AwContentsClientShouldOverrideUrlLoadingTest {
clickOnLinkUsingJs(); clickOnLinkUsingJs();
onPageFinishedHelper.waitForCallback(pageFinishedCount); onPageFinishedHelper.waitForCallback(pageFinishedCount);
Assert.assertEquals(linkUrl, mAwContents.getUrl()); Assert.assertEquals(new GURL(linkUrl), mAwContents.getUrl());
Assert.assertTrue("Should have a navigation history", mAwContents.canGoBack()); Assert.assertTrue("Should have a navigation history", mAwContents.canGoBack());
NavigationHistory navHistory = mAwContents.getNavigationHistory(); NavigationHistory navHistory = mAwContents.getNavigationHistory();
Assert.assertEquals(2, navHistory.getEntryCount()); Assert.assertEquals(2, navHistory.getEntryCount());
...@@ -868,7 +869,7 @@ public class AwContentsClientShouldOverrideUrlLoadingTest { ...@@ -868,7 +869,7 @@ public class AwContentsClientShouldOverrideUrlLoadingTest {
onPageFinishedHelper.waitForCallback(pageFinishedCount); onPageFinishedHelper.waitForCallback(pageFinishedCount);
Assert.assertFalse("Should not be able to navigate backward", mAwContents.canGoBack()); Assert.assertFalse("Should not be able to navigate backward", mAwContents.canGoBack());
Assert.assertEquals(firstUrl, mAwContents.getUrl()); Assert.assertEquals(new GURL(firstUrl), mAwContents.getUrl());
navHistory = mAwContents.getNavigationHistory(); navHistory = mAwContents.getNavigationHistory();
Assert.assertEquals(2, navHistory.getEntryCount()); Assert.assertEquals(2, navHistory.getEntryCount());
Assert.assertEquals(0, navHistory.getCurrentEntryIndex()); Assert.assertEquals(0, navHistory.getCurrentEntryIndex());
...@@ -1001,7 +1002,8 @@ public class AwContentsClientShouldOverrideUrlLoadingTest { ...@@ -1001,7 +1002,8 @@ public class AwContentsClientShouldOverrideUrlLoadingTest {
mContentsClient.getOnPageFinishedHelper().waitForCallback( mContentsClient.getOnPageFinishedHelper().waitForCallback(
currentCallCount, 1, WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS); currentCallCount, 1, WAIT_TIMEOUT_MS, TimeUnit.MILLISECONDS);
Assert.assertEquals(ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL, mAwContents.getUrl()); Assert.assertEquals(
new GURL(ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL), mAwContents.getUrl());
} finally { } finally {
mActivityTestRule.getActivity().setIgnoreStartActivity(false); mActivityTestRule.getActivity().setIgnoreStartActivity(false);
} }
......
...@@ -59,6 +59,7 @@ import org.chromium.content_public.browser.test.util.CriteriaHelper; ...@@ -59,6 +59,7 @@ import org.chromium.content_public.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.test.util.TestThreadUtils; import org.chromium.content_public.browser.test.util.TestThreadUtils;
import org.chromium.content_public.common.ContentUrlConstants; import org.chromium.content_public.common.ContentUrlConstants;
import org.chromium.net.test.EmbeddedTestServer; import org.chromium.net.test.EmbeddedTestServer;
import org.chromium.url.GURL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
...@@ -992,9 +993,10 @@ public class SafeBrowsingTest { ...@@ -992,9 +993,10 @@ public class SafeBrowsingTest {
// We'll successfully load IFRAME_HTML_PATH, and will soon call onSafeBrowsingHit // We'll successfully load IFRAME_HTML_PATH, and will soon call onSafeBrowsingHit
mContentsClient.getOnPageFinishedHelper().waitForCallback(pageFinishedCount); mContentsClient.getOnPageFinishedHelper().waitForCallback(pageFinishedCount);
final GURL aboutBlank = new GURL(ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL);
// Wait for the onSafeBrowsingHit to call BACK_TO_SAFETY and navigate back // Wait for the onSafeBrowsingHit to call BACK_TO_SAFETY and navigate back
mActivityTestRule.pollUiThread( mActivityTestRule.pollUiThread(() -> aboutBlank.equals(mAwContents.getUrl()));
() -> ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL.equals(mAwContents.getUrl()));
// Check onSafeBrowsingHit arguments // Check onSafeBrowsingHit arguments
Assert.assertFalse(mContentsClient.getLastRequest().isMainFrame); Assert.assertFalse(mContentsClient.getLastRequest().isMainFrame);
...@@ -1271,7 +1273,7 @@ public class SafeBrowsingTest { ...@@ -1271,7 +1273,7 @@ public class SafeBrowsingTest {
// Make sure the URL was seen for a main frame navigation. // Make sure the URL was seen for a main frame navigation.
Assert.assertTrue(requestsForUrl.isMainFrame); Assert.assertTrue(requestsForUrl.isMainFrame);
} else { } else {
Assert.assertEquals(linkUrl, mAwContents.getUrl()); Assert.assertEquals(new GURL(linkUrl), mAwContents.getUrl());
} }
} }
......
...@@ -71,6 +71,7 @@ android_apk("webview_instrumentation_apk") { ...@@ -71,6 +71,7 @@ android_apk("webview_instrumentation_apk") {
"//third_party/android_support_test_runner:runner_java", "//third_party/android_support_test_runner:runner_java",
"//third_party/junit", "//third_party/junit",
"//ui/android:ui_java", "//ui/android:ui_java",
"//url:gurl_java",
] ]
apk_name = "WebViewInstrumentation" apk_name = "WebViewInstrumentation"
...@@ -189,6 +190,7 @@ instrumentation_test_apk("webview_instrumentation_test_apk") { ...@@ -189,6 +190,7 @@ instrumentation_test_apk("webview_instrumentation_test_apk") {
"//third_party/junit", "//third_party/junit",
"//third_party/metrics_proto:metrics_proto_java", "//third_party/metrics_proto:metrics_proto_java",
"//ui/android:ui_java", "//ui/android:ui_java",
"//url:gurl_java",
] ]
sources = [ sources = [
"../javatests/src/org/chromium/android_webview/test/AcceptLanguageTest.java", "../javatests/src/org/chromium/android_webview/test/AcceptLanguageTest.java",
......
...@@ -270,7 +270,7 @@ public class AwShellActivity extends Activity { ...@@ -270,7 +270,7 @@ public class AwShellActivity extends Activity {
mNextButton.setVisibility(hasFocus ? View.GONE : View.VISIBLE); mNextButton.setVisibility(hasFocus ? View.GONE : View.VISIBLE);
mPrevButton.setVisibility(hasFocus ? View.GONE : View.VISIBLE); mPrevButton.setVisibility(hasFocus ? View.GONE : View.VISIBLE);
if (!hasFocus) { if (!hasFocus) {
mUrlTextView.setText(mWebContents.getVisibleUrlString()); mUrlTextView.setText(mWebContents.getVisibleUrl().getSpec());
} }
}); });
} }
......
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