diff options
author | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-29 23:13:38 +0000 |
---|---|---|
committer | joth@chromium.org <joth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-29 23:13:38 +0000 |
commit | 6f65cc4b59bbfe736071e26a56f9601003f75ad3 (patch) | |
tree | 32d436fc587b99e01756165a9dcb44de454a563f /android_webview | |
parent | 8896130f2cb7940e74438f3bb5064b78d85dd25d (diff) | |
download | chromium_src-6f65cc4b59bbfe736071e26a56f9601003f75ad3.zip chromium_src-6f65cc4b59bbfe736071e26a56f9601003f75ad3.tar.gz chromium_src-6f65cc4b59bbfe736071e26a56f9601003f75ad3.tar.bz2 |
AwContentClient no longer extends ContentViewClient
This keeps the layers better isolated, and avoids the aw embedder having
to use content layer classes directly.
BUG=
Review URL: https://chromiumcodereview.appspot.com/13136002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@197181 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview')
-rw-r--r-- | android_webview/java/src/org/chromium/android_webview/AwContents.java | 18 | ||||
-rw-r--r-- | android_webview/java/src/org/chromium/android_webview/AwContentsClient.java | 76 | ||||
-rw-r--r-- | android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientShouldOverrideUrlLoadingTest.java (renamed from android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientShouldIgnoreNavigationTest.java) | 258 | ||||
-rw-r--r-- | android_webview/javatests/src/org/chromium/android_webview/test/TestAwContentsClient.java | 2 | ||||
-rw-r--r-- | android_webview/test/shell/src/org/chromium/android_webview/test/NullContentsClient.java | 11 |
5 files changed, 198 insertions, 167 deletions
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java index 00b7b6f..4118f49 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwContents.java +++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java @@ -225,26 +225,26 @@ public class AwContents { mLastLoadUrlAddress = null; // If the embedder requested the load of a certain URL via the loadUrl API, then we - // do not offer it to AwContentsClient.shouldIgnoreNavigation. + // do not offer it to AwContentsClient.shouldOverrideUrlLoading. // The embedder is also not allowed to intercept POST requests because of // crbug.com/155250. } else if (!navigationParams.isPost) { - ignoreNavigation = mContentsClient.shouldIgnoreNavigation(url); + ignoreNavigation = mContentsClient.shouldOverrideUrlLoading(url); } - // The existing contract is that shouldIgnoreNavigation callbacks are delivered before + // The existing contract is that shouldOverrideUrlLoading callbacks are delivered before // onPageStarted callbacks; third party apps depend on this behavior. // Using a ResouceThrottle to implement the navigation interception feature results in // the WebContentsObserver.didStartLoading callback happening before the // ResourceThrottle has a chance to run. // To preserve the ordering the onPageStarted callback is synthesized from the - // shouldIgnoreNavigationCallback, and only if the navigation was not ignored (this + // shouldOverrideUrlLoading, and only if the navigation was not ignored (this // balances out with the onPageFinished callback, which is suppressed in the // AwContentsClient if the navigation was ignored). if (!ignoreNavigation) { - // The shouldIgnoreNavigation call might have resulted in posting messages to the + // The shouldOverrideUrlLoading call might have resulted in posting messages to the // UI thread. Using sendMessage here (instead of calling onPageStarted directly) - // will allow those to run. + // will allow those to run in order. mContentsClient.getCallbackHelper().postOnPageStarted(url); } @@ -329,7 +329,7 @@ public class AwContents { int nativeWebContents = nativeGetWebContents(mNativeAwContents); mContentViewCore.initialize(containerView, internalAccessAdapter, nativeWebContents, null); - mContentViewCore.setContentViewClient(mContentsClient); + mContentViewCore.setContentViewClient(mContentsClient.getContentViewClient()); mContentsClient.installWebContentsObserver(mContentViewCore); mSettings = new AwSettings(mContentViewCore.getContext(), nativeWebContents, @@ -572,7 +572,7 @@ public class AwContents { ContentViewCore newCore = new ContentViewCore(mContainerView.getContext(), ContentViewCore.PERSONALITY_VIEW); newCore.initialize(mContainerView, mInternalAccessAdapter, newWebContentsPtr, null); - newCore.setContentViewClient(mContentsClient); + newCore.setContentViewClient(mContentsClient.getContentViewClient()); mContentsClient.installWebContentsObserver(newCore); ContentSettings oldSettings = mContentViewCore.getContentSettings(); @@ -1132,7 +1132,7 @@ public class AwContents { // but is optimized out in the restoreState case because the title is // already restored. See WebContentsImpl::UpdateTitleForEntry. So we // call the callback explicitly here. - if (result) mContentsClient.onUpdateTitle(mContentViewCore.getTitle()); + if (result) mContentsClient.onReceivedTitle(mContentViewCore.getTitle()); return result; } diff --git a/android_webview/java/src/org/chromium/android_webview/AwContentsClient.java b/android_webview/java/src/org/chromium/android_webview/AwContentsClient.java index 8f9f0f9..70cd68c 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwContentsClient.java +++ b/android_webview/java/src/org/chromium/android_webview/AwContentsClient.java @@ -5,6 +5,7 @@ package org.chromium.android_webview; import android.content.pm.ActivityInfo; +import android.content.Context; import android.graphics.Bitmap; import android.graphics.Picture; import android.graphics.Rect; @@ -36,7 +37,7 @@ import org.chromium.net.NetError; * new abstract methods that the our own client must implement. * i.e.: all methods in this class should either be final, or abstract. */ -public abstract class AwContentsClient extends ContentViewClient { +public abstract class AwContentsClient { private static final String TAG = "AwContentsClient"; private final AwContentsClientCallbackHelper mCallbackHelper = @@ -44,6 +45,8 @@ public abstract class AwContentsClient extends ContentViewClient { private AwWebContentsObserver mWebContentsObserver; + private AwContentViewClient mContentViewClient = new AwContentViewClient(); + private double mDIPScale; class AwWebContentsObserver extends WebContentsObserverAndroid { @@ -62,7 +65,7 @@ public abstract class AwContentsClient extends ContentViewClient { if (errorCode == NetError.ERR_ABORTED) { // This error code is generated for the following reasons: // - WebView.stopLoading is called, - // - the navigation is intercepted by the embedder via shouldIgnoreNavigation. + // - the navigation is intercepted by the embedder via shouldOverrideNavigation. // // The Android WebView does not notify the embedder of these situations using this // error code with the WebViewClient.onReceivedError callback. @@ -83,14 +86,46 @@ public abstract class AwContentsClient extends ContentViewClient { } - void installWebContentsObserver(ContentViewCore contentViewCore) { + private class AwContentViewClient extends ContentViewClient { + + @Override + public void onScaleChanged(float oldScale, float newScale) { + AwContentsClient.this.onScaleChangedScaled((float)(oldScale * mDIPScale), + (float)(newScale * mDIPScale)); + } + + @Override + public void onStartContentIntent(Context context, String contentUrl) { + // Callback when detecting a click on a content link. + AwContentsClient.this.shouldOverrideUrlLoading(contentUrl); + } + + @Override + public void onTabCrash() { + // This is not possible so long as the webview is run single process! + throw new RuntimeException("Renderer crash reported."); + } + + @Override + public void onUpdateTitle(String title) { + AwContentsClient.this.onReceivedTitle(title); + } + + @Override + public boolean shouldOverrideKeyEvent(KeyEvent event) { + return AwContentsClient.this.shouldOverrideKeyEvent(event); + } + + } + + final void installWebContentsObserver(ContentViewCore contentViewCore) { if (mWebContentsObserver != null) { mWebContentsObserver.detachFromWebContents(); } mWebContentsObserver = new AwWebContentsObserver(contentViewCore); } - void setDIPScale(double dipScale) { + final void setDIPScale(double dipScale) { mDIPScale = dipScale; } @@ -98,6 +133,10 @@ public abstract class AwContentsClient extends ContentViewClient { return mCallbackHelper; } + final ContentViewClient getContentViewClient() { + return mContentViewClient; + } + //-------------------------------------------------------------------------------------------- // WebView specific methods that map directly to WebViewClient / WebChromeClient //-------------------------------------------------------------------------------------------- @@ -110,9 +149,11 @@ public abstract class AwContentsClient extends ContentViewClient { public abstract InterceptedRequestData shouldInterceptRequest(String url); - public abstract void onLoadResource(String url); + public abstract boolean shouldOverrideKeyEvent(KeyEvent event); - public abstract boolean shouldIgnoreNavigation(String url); + public abstract boolean shouldOverrideUrlLoading(String url); + + public abstract void onLoadResource(String url); public abstract void onUnhandledKeyEvent(KeyEvent event); @@ -135,10 +176,6 @@ public abstract class AwContentsClient extends ContentViewClient { public abstract void onGeolocationPermissionsHidePrompt(); - public final void onScaleChanged(float oldScale, float newScale) { - onScaleChangedScaled((float)(oldScale * mDIPScale), (float)(newScale * mDIPScale)); - } - public abstract void onScaleChangedScaled(float oldScale, float newScale); protected abstract void handleJsAlert(String url, String message, JsResultReceiver receiver); @@ -159,6 +196,8 @@ public abstract class AwContentsClient extends ContentViewClient { public abstract void onReceivedIcon(Bitmap bitmap); + public abstract void onReceivedTitle(String title); + protected abstract void onRequestFocus(); protected abstract View getVideoLoadingProgressView(); @@ -198,21 +237,4 @@ public abstract class AwContentsClient extends ContentViewClient { */ public abstract void onNewPicture(Picture picture); - //-------------------------------------------------------------------------------------------- - // Stuff that we ignore since it only makes sense for Chrome browser - //-------------------------------------------------------------------------------------------- - // - - @Override - final public boolean shouldOverrideScroll(float dx, float dy, float scrollX, float scrollY) { - return false; - } - - @Override - final public void onContextualActionBarShown() { - } - - @Override - final public void onContextualActionBarHidden() { - } } diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientShouldIgnoreNavigationTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientShouldOverrideUrlLoadingTest.java index cdcf1a3..4a1d2fe 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientShouldIgnoreNavigationTest.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/AwContentsClientShouldOverrideUrlLoadingTest.java @@ -32,7 +32,7 @@ import java.util.concurrent.Callable; /** * Tests for the WebViewClient.shouldOverrideUrlLoading() method. */ -public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { +public class AwContentsClientShouldOverrideUrlLoadingTest extends AwTestBase { private final static String ABOUT_BLANK_URL = "about:blank"; private final static String DATA_URL = "data:text/html,<div/>"; private final static String REDIRECT_TARGET_PATH = "/redirect_target.html"; @@ -44,54 +44,54 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { private static class TestAwContentsClient extends org.chromium.android_webview.test.TestAwContentsClient { - public static class ShouldIgnoreNavigationHelper extends CallbackHelper { - private String mShouldIgnoreNavigationUrl; - private String mPreviousShouldIgnoreNavigationUrl; - private boolean mShouldIgnoreNavigationReturnValue = false; - void setShouldIgnoreNavigationUrl(String url) { - mShouldIgnoreNavigationUrl = url; + public static class ShouldOverrideUrlLoadingHelper extends CallbackHelper { + private String mShouldOverrideUrlLoadingUrl; + private String mPreviousShouldOverrideUrlLoadingUrl; + private boolean mShouldOverrideUrlLoadingReturnValue = false; + void setShouldOverrideUrlLoadingUrl(String url) { + mShouldOverrideUrlLoadingUrl = url; } - void setPreviousShouldIgnoreNavigationUrl(String url) { - mPreviousShouldIgnoreNavigationUrl = url; + void setPreviousShouldOverrideUrlLoadingUrl(String url) { + mPreviousShouldOverrideUrlLoadingUrl = url; } - void setShouldIgnoreNavigationReturnValue(boolean value) { - mShouldIgnoreNavigationReturnValue = value; + void setShouldOverrideUrlLoadingReturnValue(boolean value) { + mShouldOverrideUrlLoadingReturnValue = value; } - public String getShouldIgnoreNavigationUrl() { + public String getShouldOverrideUrlLoadingUrl() { assert getCallCount() > 0; - return mShouldIgnoreNavigationUrl; + return mShouldOverrideUrlLoadingUrl; } - public String getPreviousShouldIgnoreNavigationUrl() { + public String getPreviousShouldOverrideUrlLoadingUrl() { assert getCallCount() > 1; - return mPreviousShouldIgnoreNavigationUrl; + return mPreviousShouldOverrideUrlLoadingUrl; } - public boolean getShouldIgnoreNavigationReturnValue() { - return mShouldIgnoreNavigationReturnValue; + public boolean getShouldOverrideUrlLoadingReturnValue() { + return mShouldOverrideUrlLoadingReturnValue; } public void notifyCalled(String url) { - mPreviousShouldIgnoreNavigationUrl = mShouldIgnoreNavigationUrl; - mShouldIgnoreNavigationUrl = url; + mPreviousShouldOverrideUrlLoadingUrl = mShouldOverrideUrlLoadingUrl; + mShouldOverrideUrlLoadingUrl = url; notifyCalled(); } } @Override - public boolean shouldIgnoreNavigation(String url) { - super.shouldIgnoreNavigation(url); + public boolean shouldOverrideUrlLoading(String url) { + super.shouldOverrideUrlLoading(url); boolean returnValue = - mShouldIgnoreNavigationHelper.getShouldIgnoreNavigationReturnValue(); - mShouldIgnoreNavigationHelper.notifyCalled(url); + mShouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingReturnValue(); + mShouldOverrideUrlLoadingHelper.notifyCalled(url); return returnValue; } - private ShouldIgnoreNavigationHelper mShouldIgnoreNavigationHelper; + private ShouldOverrideUrlLoadingHelper mShouldOverrideUrlLoadingHelper; public TestAwContentsClient() { - mShouldIgnoreNavigationHelper = new ShouldIgnoreNavigationHelper(); + mShouldOverrideUrlLoadingHelper = new ShouldOverrideUrlLoadingHelper(); } - public ShouldIgnoreNavigationHelper getShouldIgnoreNavigationHelper() { - return mShouldIgnoreNavigationHelper; + public ShouldOverrideUrlLoadingHelper getShouldOverrideUrlLoadingHelper() { + return mShouldOverrideUrlLoadingHelper; } } @@ -117,13 +117,13 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { } // Since this value is read on the UI thread, it's simpler to set it there too. - void setShouldIgnoreNavigationReturnValueOnUiThread( - final TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigationHelper, + void setShouldOverrideUrlLoadingReturnValueOnUiThread( + final TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideHelper, final boolean value) throws Throwable { runTestOnUiThread(new Runnable() { @Override public void run() { - shouldIgnoreNavigationHelper.setShouldIgnoreNavigationReturnValue(value); + shouldOverrideHelper.setShouldOverrideUrlLoadingReturnValue(value); } }); } @@ -194,13 +194,13 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentsClient); final AwContents awContents = testContainerView.getAwContents(); - TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigationHelper = - contentsClient.getShouldIgnoreNavigationHelper(); + TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoadingHelper = + contentsClient.getShouldOverrideUrlLoadingHelper(); loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), getHtmlForPageWithSimpleLinkTo(DATA_URL), "text/html", false); - assertEquals(0, shouldIgnoreNavigationHelper.getCallCount()); + assertEquals(0, shouldOverrideUrlLoadingHelper.getCallCount()); } private void waitForNavigationRunnableAndAssertTitleChanged(AwContents awContents, @@ -220,8 +220,8 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentsClient); final AwContents awContents = testContainerView.getAwContents(); - TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigationHelper = - contentsClient.getShouldIgnoreNavigationHelper(); + TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoadingHelper = + contentsClient.getShouldOverrideUrlLoadingHelper(); final String[] pageTitles = new String[] { "page1", "page2", "page3" }; for (String title: pageTitles) { @@ -229,7 +229,7 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { CommonResources.makeHtmlPageFrom("<title>" + title + "</title>", ""), "text/html", false); } - assertEquals(0, shouldIgnoreNavigationHelper.getCallCount()); + assertEquals(0, shouldOverrideUrlLoadingHelper.getCallCount()); waitForNavigationRunnableAndAssertTitleChanged(awContents, contentsClient.getOnPageFinishedHelper(), new Runnable() { @@ -238,7 +238,7 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { awContents.goBack(); } }); - assertEquals(0, shouldIgnoreNavigationHelper.getCallCount()); + assertEquals(0, shouldOverrideUrlLoadingHelper.getCallCount()); waitForNavigationRunnableAndAssertTitleChanged(awContents, contentsClient.getOnPageFinishedHelper(), new Runnable() { @@ -247,7 +247,7 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { awContents.goForward(); } }); - assertEquals(0, shouldIgnoreNavigationHelper.getCallCount()); + assertEquals(0, shouldOverrideUrlLoadingHelper.getCallCount()); waitForNavigationRunnableAndAssertTitleChanged(awContents, contentsClient.getOnPageFinishedHelper(), new Runnable() { @@ -256,7 +256,7 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { awContents.goBackOrForward(-2); } }); - assertEquals(0, shouldIgnoreNavigationHelper.getCallCount()); + assertEquals(0, shouldOverrideUrlLoadingHelper.getCallCount()); waitForNavigationRunnableAndAssertTitleChanged(awContents, contentsClient.getOnPageFinishedHelper(), new Runnable() { @@ -265,7 +265,7 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { awContents.goBackOrForward(1); } }); - assertEquals(0, shouldIgnoreNavigationHelper.getCallCount()); + assertEquals(0, shouldOverrideUrlLoadingHelper.getCallCount()); } @SmallTest @@ -275,10 +275,10 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentsClient); final AwContents awContents = testContainerView.getAwContents(); - TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigationHelper = - contentsClient.getShouldIgnoreNavigationHelper(); + TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoadingHelper = + contentsClient.getShouldOverrideUrlLoadingHelper(); - setShouldIgnoreNavigationReturnValueOnUiThread(shouldIgnoreNavigationHelper, true); + setShouldOverrideUrlLoadingReturnValueOnUiThread(shouldOverrideUrlLoadingHelper, true); loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), getHtmlForPageWithSimpleLinkTo(DATA_URL), "text/html", false); @@ -293,19 +293,19 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentsClient); final AwContents awContents = testContainerView.getAwContents(); - TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigationHelper = - contentsClient.getShouldIgnoreNavigationHelper(); + TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoadingHelper = + contentsClient.getShouldOverrideUrlLoadingHelper(); OnPageStartedHelper onPageStartedHelper = contentsClient.getOnPageStartedHelper(); loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), getHtmlForPageWithSimpleLinkTo(DATA_URL), "text/html", false); - final int shouldIgnoreNavigationCallCount = shouldIgnoreNavigationHelper.getCallCount(); + final int shouldOverrideUrlLoadingCallCount = shouldOverrideUrlLoadingHelper.getCallCount(); final int onPageStartedCallCount = onPageStartedHelper.getCallCount(); - setShouldIgnoreNavigationReturnValueOnUiThread(shouldIgnoreNavigationHelper, true); + setShouldOverrideUrlLoadingReturnValueOnUiThread(shouldOverrideUrlLoadingHelper, true); clickOnLinkUsingJs(awContents, contentsClient); - shouldIgnoreNavigationHelper.waitForCallback(shouldIgnoreNavigationCallCount); + shouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoadingCallCount); assertEquals(onPageStartedCallCount, onPageStartedHelper.getCallCount()); } @@ -317,23 +317,23 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentsClient); final AwContents awContents = testContainerView.getAwContents(); - final TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigationHelper = - contentsClient.getShouldIgnoreNavigationHelper(); + final TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoadingHelper = + contentsClient.getShouldOverrideUrlLoadingHelper(); OnReceivedErrorHelper onReceivedErrorHelper = contentsClient.getOnReceivedErrorHelper(); final int onReceivedErrorCallCount = onReceivedErrorHelper.getCallCount(); loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), getHtmlForPageWithSimpleLinkTo(DATA_URL), "text/html", false); - final int shouldIgnoreNavigationCallCount = shouldIgnoreNavigationHelper.getCallCount(); + final int shouldOverrideUrlLoadingCallCount = shouldOverrideUrlLoadingHelper.getCallCount(); - setShouldIgnoreNavigationReturnValueOnUiThread(shouldIgnoreNavigationHelper, true); + setShouldOverrideUrlLoadingReturnValueOnUiThread(shouldOverrideUrlLoadingHelper, true); clickOnLinkUsingJs(awContents, contentsClient); - shouldIgnoreNavigationHelper.waitForCallback(shouldIgnoreNavigationCallCount); + shouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoadingCallCount); - setShouldIgnoreNavigationReturnValueOnUiThread(shouldIgnoreNavigationHelper, false); + setShouldOverrideUrlLoadingReturnValueOnUiThread(shouldOverrideUrlLoadingHelper, false); // After we load this URL we're certain that any in-flight callbacks for the previous // navigation have been delivered. @@ -349,8 +349,8 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentsClient); final AwContents awContents = testContainerView.getAwContents(); - final TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigationHelper = - contentsClient.getShouldIgnoreNavigationHelper(); + final TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoadingHelper = + contentsClient.getShouldOverrideUrlLoadingHelper(); final String anchorLinkPath = "/anchor_link.html"; final String anchorLinkUrl = mWebServer.getResponseUrl(anchorLinkPath); @@ -359,8 +359,8 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), anchorLinkUrl); - final int shouldIgnoreNavigationCallCount = - shouldIgnoreNavigationHelper.getCallCount(); + final int shouldOverrideUrlLoadingCallCount = + shouldOverrideUrlLoadingHelper.getCallCount(); clickOnLinkUsingJs(awContents, contentsClient); @@ -368,8 +368,8 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { // navigation have been delivered. loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), ABOUT_BLANK_URL); - assertEquals(shouldIgnoreNavigationCallCount, - shouldIgnoreNavigationHelper.getCallCount()); + assertEquals(shouldOverrideUrlLoadingCallCount, + shouldOverrideUrlLoadingHelper.getCallCount()); } @SmallTest @@ -379,18 +379,18 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentsClient); final AwContents awContents = testContainerView.getAwContents(); - TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigationHelper = - contentsClient.getShouldIgnoreNavigationHelper(); + TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoadingHelper = + contentsClient.getShouldOverrideUrlLoadingHelper(); // We can't go to about:blank from here because we'd get a cross-origin error. loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), getHtmlForPageWithSimpleLinkTo(DATA_URL), "text/html", false); - int callCount = shouldIgnoreNavigationHelper.getCallCount(); + int callCount = shouldOverrideUrlLoadingHelper.getCallCount(); clickOnLinkUsingJs(awContents, contentsClient); - shouldIgnoreNavigationHelper.waitForCallback(callCount); + shouldOverrideUrlLoadingHelper.waitForCallback(callCount); } @@ -401,8 +401,8 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentsClient); final AwContents awContents = testContainerView.getAwContents(); - TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigationHelper = - contentsClient.getShouldIgnoreNavigationHelper(); + TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoadingHelper = + contentsClient.getShouldOverrideUrlLoadingHelper(); final String httpPath = "/page_with_link_to_self.html"; final String httpPathOnServer = mWebServer.getResponseUrl(httpPath); @@ -412,13 +412,13 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), httpPathOnServer); - int callCount = shouldIgnoreNavigationHelper.getCallCount(); + int callCount = shouldOverrideUrlLoadingHelper.getCallCount(); clickOnLinkUsingJs(awContents, contentsClient); - shouldIgnoreNavigationHelper.waitForCallback(callCount); + shouldOverrideUrlLoadingHelper.waitForCallback(callCount); assertEquals(httpPathOnServer, - shouldIgnoreNavigationHelper.getShouldIgnoreNavigationUrl()); + shouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl()); } @SmallTest @@ -430,18 +430,18 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { createAwTestContainerViewOnMainSync(contentsClient); final AwContents awContents = testContainerView.getAwContents(); enableJavaScriptOnUiThread(awContents); - TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigationHelper = - contentsClient.getShouldIgnoreNavigationHelper(); + TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoadingHelper = + contentsClient.getShouldOverrideUrlLoadingHelper(); final String redirectTargetUrl = createRedirectTargetPage(mWebServer); loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), getHtmlForPageWithJsAssignLinkTo(redirectTargetUrl), "text/html", false); - int callCount = shouldIgnoreNavigationHelper.getCallCount(); + int callCount = shouldOverrideUrlLoadingHelper.getCallCount(); clickOnLinkUsingJs(awContents, contentsClient); - shouldIgnoreNavigationHelper.waitForCallback(callCount); + shouldOverrideUrlLoadingHelper.waitForCallback(callCount); } @SmallTest @@ -453,16 +453,16 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { createAwTestContainerViewOnMainSync(contentsClient); final AwContents awContents = testContainerView.getAwContents(); enableJavaScriptOnUiThread(awContents); - TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigationHelper = - contentsClient.getShouldIgnoreNavigationHelper(); + TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoadingHelper = + contentsClient.getShouldOverrideUrlLoadingHelper(); final String redirectTargetUrl = createRedirectTargetPage(mWebServer); loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), getHtmlForPageWithJsReplaceLinkTo(redirectTargetUrl), "text/html", false); - int callCount = shouldIgnoreNavigationHelper.getCallCount(); + int callCount = shouldOverrideUrlLoadingHelper.getCallCount(); clickOnLinkUsingJs(awContents, contentsClient); - shouldIgnoreNavigationHelper.waitForCallback(callCount); + shouldOverrideUrlLoadingHelper.waitForCallback(callCount); } @SmallTest @@ -472,18 +472,18 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentsClient); final AwContents awContents = testContainerView.getAwContents(); - TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigationHelper = - contentsClient.getShouldIgnoreNavigationHelper(); + TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoadingHelper = + contentsClient.getShouldOverrideUrlLoadingHelper(); final String redirectTargetUrl = createRedirectTargetPage(mWebServer); loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), getHtmlForPageWithSimpleLinkTo(redirectTargetUrl), "text/html", false); - int callCount = shouldIgnoreNavigationHelper.getCallCount(); + int callCount = shouldOverrideUrlLoadingHelper.getCallCount(); clickOnLinkUsingJs(awContents, contentsClient); - shouldIgnoreNavigationHelper.waitForCallback(callCount); + shouldOverrideUrlLoadingHelper.waitForCallback(callCount); assertEquals(redirectTargetUrl, - shouldIgnoreNavigationHelper.getShouldIgnoreNavigationUrl()); + shouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl()); } @SmallTest @@ -493,8 +493,8 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentsClient); final AwContents awContents = testContainerView.getAwContents(); - final TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigationHelper = - contentsClient.getShouldIgnoreNavigationHelper(); + final TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoadingHelper = + contentsClient.getShouldOverrideUrlLoadingHelper(); final String redirectTargetUrl = createRedirectTargetPage(mWebServer); final String pageWithLinkToIgnorePath = "/page_with_link_to_ignore.html"; @@ -509,17 +509,17 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), pageWithLinkToIgnoreUrl); - setShouldIgnoreNavigationReturnValueOnUiThread(shouldIgnoreNavigationHelper, true); + setShouldOverrideUrlLoadingReturnValueOnUiThread(shouldOverrideUrlLoadingHelper, true); - int callCount = shouldIgnoreNavigationHelper.getCallCount(); + int callCount = shouldOverrideUrlLoadingHelper.getCallCount(); int onPageFinishedCallCount = contentsClient.getOnPageFinishedHelper().getCallCount(); clickOnLinkUsingJs(awContents, contentsClient); - // Some time around here true should be returned from the shouldIgnoreNavigation + // Some time around here true should be returned from the shouldOverrideUrlLoading // callback causing the navigation caused by calling clickOnLinkUsingJs to be ignored. // We validate this by checking which pages were loaded on the server. - shouldIgnoreNavigationHelper.waitForCallback(callCount); + shouldOverrideUrlLoadingHelper.waitForCallback(callCount); - setShouldIgnoreNavigationReturnValueOnUiThread(shouldIgnoreNavigationHelper, false); + setShouldOverrideUrlLoadingReturnValueOnUiThread(shouldOverrideUrlLoadingHelper, false); // We need to wait for the navigation to complete before we can initiate another load. contentsClient.getOnPageFinishedHelper().waitForCallback(onPageFinishedCallCount); @@ -541,18 +541,18 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentsClient); final AwContents awContents = testContainerView.getAwContents(); - TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigationHelper = - contentsClient.getShouldIgnoreNavigationHelper(); + TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoadingHelper = + contentsClient.getShouldOverrideUrlLoadingHelper(); loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), getHtmlForPageWithSimpleLinkTo(dataUrl), "text/html", false); - int callCount = shouldIgnoreNavigationHelper.getCallCount(); + int callCount = shouldOverrideUrlLoadingHelper.getCallCount(); clickOnLinkUsingJs(awContents, contentsClient); - shouldIgnoreNavigationHelper.waitForCallback(callCount); + shouldOverrideUrlLoadingHelper.waitForCallback(callCount); assertTrue("Expected URL that starts with 'data:' but got: <" + - shouldIgnoreNavigationHelper.getShouldIgnoreNavigationUrl() + "> instead.", - shouldIgnoreNavigationHelper.getShouldIgnoreNavigationUrl().startsWith( + shouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl() + "> instead.", + shouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl().startsWith( "data:")); } @@ -563,18 +563,18 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentsClient); final AwContents awContents = testContainerView.getAwContents(); - TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigationHelper = - contentsClient.getShouldIgnoreNavigationHelper(); + TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoadingHelper = + contentsClient.getShouldOverrideUrlLoadingHelper(); final String unsupportedSchemeUrl = "foobar://resource/1"; loadDataSync(awContents, contentsClient.getOnPageFinishedHelper(), getHtmlForPageWithSimpleLinkTo(unsupportedSchemeUrl), "text/html", false); - int callCount = shouldIgnoreNavigationHelper.getCallCount(); + int callCount = shouldOverrideUrlLoadingHelper.getCallCount(); clickOnLinkUsingJs(awContents, contentsClient); - shouldIgnoreNavigationHelper.waitForCallback(callCount); + shouldOverrideUrlLoadingHelper.waitForCallback(callCount); assertEquals(unsupportedSchemeUrl, - shouldIgnoreNavigationHelper.getShouldIgnoreNavigationUrl()); + shouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl()); } @SmallTest @@ -585,8 +585,8 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentsClient); final AwContents awContents = testContainerView.getAwContents(); - final TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigationHelper = - contentsClient.getShouldIgnoreNavigationHelper(); + final TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoadingHelper = + contentsClient.getShouldOverrideUrlLoadingHelper(); final String redirectTargetUrl = createRedirectTargetPage(mWebServer); final String postLinkUrl = addPageToTestServer(mWebServer, "/page_with_post_link.html", @@ -594,8 +594,8 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), postLinkUrl); - final int shouldIgnoreNavigationCallCount = - shouldIgnoreNavigationHelper.getCallCount(); + final int shouldOverrideUrlLoadingCallCount = + shouldOverrideUrlLoadingHelper.getCallCount(); assertEquals(0, mWebServer.getRequestCount(REDIRECT_TARGET_PATH)); clickOnLinkUsingJs(awContents, contentsClient); @@ -609,10 +609,10 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { }, WAIT_TIMEOUT_SECONDS * 1000L, CHECK_INTERVAL)); // Since the targetURL was loaded from the test server it means all processing related - // to dispatching a shouldIgnoreNavigation callback had finished and checking the call + // to dispatching a shouldOverrideUrlLoading callback had finished and checking the call // is stable. - assertEquals(shouldIgnoreNavigationCallCount, - shouldIgnoreNavigationHelper.getCallCount()); + assertEquals(shouldOverrideUrlLoadingCallCount, + shouldOverrideUrlLoadingHelper.getCallCount()); } @SmallTest @@ -622,8 +622,8 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentsClient); final AwContents awContents = testContainerView.getAwContents(); - final TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigationHelper = - contentsClient.getShouldIgnoreNavigationHelper(); + final TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoadingHelper = + contentsClient.getShouldOverrideUrlLoadingHelper(); final String iframeRedirectTargetUrl = createRedirectTargetPage(mWebServer); final String iframeRedirectUrl = @@ -632,8 +632,8 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { addPageToTestServer(mWebServer, "/iframe_intercept.html", makeHtmlPageFrom("", "<iframe src=\"" + iframeRedirectUrl + "\" />")); - final int shouldIgnoreNavigationCallCount = - shouldIgnoreNavigationHelper.getCallCount(); + final int shouldOverrideUrlLoadingCallCount = + shouldOverrideUrlLoadingHelper.getCallCount(); assertEquals(0, mWebServer.getRequestCount(REDIRECT_TARGET_PATH)); loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), pageWithIframeUrl); @@ -646,8 +646,8 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { } }, WAIT_TIMEOUT_SECONDS * 1000L, CHECK_INTERVAL)); - assertEquals(shouldIgnoreNavigationCallCount, - shouldIgnoreNavigationHelper.getCallCount()); + assertEquals(shouldOverrideUrlLoadingCallCount, + shouldOverrideUrlLoadingHelper.getCallCount()); } @SmallTest @@ -657,22 +657,22 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { final AwTestContainerView testContainerView = createAwTestContainerViewOnMainSync(contentsClient); final AwContents awContents = testContainerView.getAwContents(); - final TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigationHelper = - contentsClient.getShouldIgnoreNavigationHelper(); + final TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoadingHelper = + contentsClient.getShouldOverrideUrlLoadingHelper(); final String unsupportedSchemeUrl = "foobar://resource/1"; final String pageWithIframeUrl = addPageToTestServer(mWebServer, "/iframe_intercept.html", makeHtmlPageFrom("", "<iframe src=\"" + unsupportedSchemeUrl + "\" />")); - final int shouldIgnoreNavigationCallCount = - shouldIgnoreNavigationHelper.getCallCount(); + final int shouldOverrideUrlLoadingCallCount = + shouldOverrideUrlLoadingHelper.getCallCount(); loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), pageWithIframeUrl); - shouldIgnoreNavigationHelper.waitForCallback(shouldIgnoreNavigationCallCount); + shouldOverrideUrlLoadingHelper.waitForCallback(shouldOverrideUrlLoadingCallCount); assertEquals(unsupportedSchemeUrl, - shouldIgnoreNavigationHelper.getShouldIgnoreNavigationUrl()); + shouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl()); } /** @@ -694,14 +694,14 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { getHtmlForPageWithSimpleLinkTo(redirectUrl)); enableJavaScriptOnUiThread(awContents); - TestAwContentsClient.ShouldIgnoreNavigationHelper shouldIgnoreNavigationHelper = - contentsClient.getShouldIgnoreNavigationHelper(); - int directLoadCallCount = shouldIgnoreNavigationHelper.getCallCount(); + TestAwContentsClient.ShouldOverrideUrlLoadingHelper shouldOverrideUrlLoadingHelper = + contentsClient.getShouldOverrideUrlLoadingHelper(); + int directLoadCallCount = shouldOverrideUrlLoadingHelper.getCallCount(); loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), redirectUrl); - shouldIgnoreNavigationHelper.waitForCallback(directLoadCallCount, 1); + shouldOverrideUrlLoadingHelper.waitForCallback(directLoadCallCount, 1); assertEquals(redirectTarget, - shouldIgnoreNavigationHelper.getShouldIgnoreNavigationUrl()); + shouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl()); // There is a slight difference between navigations caused by calling load and navigations // caused by clicking on a link: @@ -710,19 +710,19 @@ public class AwContentsClientShouldIgnoreNavigationTest extends AwTestBase { // * when clicking on a link the navigation has the LINK type and has_user_gesture is // true. // Both of these should yield the same result which is what we're verifying here. - int indirectLoadCallCount = shouldIgnoreNavigationHelper.getCallCount(); + int indirectLoadCallCount = shouldOverrideUrlLoadingHelper.getCallCount(); loadUrlSync(awContents, contentsClient.getOnPageFinishedHelper(), pageWithLinkToRedirectUrl); - assertEquals(indirectLoadCallCount, shouldIgnoreNavigationHelper.getCallCount()); + assertEquals(indirectLoadCallCount, shouldOverrideUrlLoadingHelper.getCallCount()); clickOnLinkUsingJs(awContents, contentsClient); - shouldIgnoreNavigationHelper.waitForCallback(indirectLoadCallCount, 2); + shouldOverrideUrlLoadingHelper.waitForCallback(indirectLoadCallCount, 2); assertEquals(redirectTarget, - shouldIgnoreNavigationHelper.getShouldIgnoreNavigationUrl()); + shouldOverrideUrlLoadingHelper.getShouldOverrideUrlLoadingUrl()); assertEquals(redirectUrl, - shouldIgnoreNavigationHelper.getPreviousShouldIgnoreNavigationUrl()); + shouldOverrideUrlLoadingHelper.getPreviousShouldOverrideUrlLoadingUrl()); } @SmallTest diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/TestAwContentsClient.java b/android_webview/javatests/src/org/chromium/android_webview/test/TestAwContentsClient.java index 12c1f14..512184d 100644 --- a/android_webview/javatests/src/org/chromium/android_webview/test/TestAwContentsClient.java +++ b/android_webview/javatests/src/org/chromium/android_webview/test/TestAwContentsClient.java @@ -69,7 +69,7 @@ class TestAwContentsClient extends NullContentsClient { } @Override - public void onUpdateTitle(String title) { + public void onReceivedTitle(String title) { mUpdatedTitle = title; } diff --git a/android_webview/test/shell/src/org/chromium/android_webview/test/NullContentsClient.java b/android_webview/test/shell/src/org/chromium/android_webview/test/NullContentsClient.java index e3cac4a..0264089 100644 --- a/android_webview/test/shell/src/org/chromium/android_webview/test/NullContentsClient.java +++ b/android_webview/test/shell/src/org/chromium/android_webview/test/NullContentsClient.java @@ -27,7 +27,7 @@ import org.chromium.android_webview.JsResultReceiver; */ public class NullContentsClient extends AwContentsClient { @Override - public boolean shouldIgnoreNavigation(String url) { + public boolean shouldOverrideUrlLoading(String url) { return false; } @@ -53,6 +53,11 @@ public class NullContentsClient extends AwContentsClient { } @Override + public boolean shouldOverrideKeyEvent(KeyEvent event) { + return false; + } + + @Override public void onLoadResource(String url) { } @@ -157,6 +162,10 @@ public class NullContentsClient extends AwContentsClient { } @Override + public void onReceivedTitle(String title) { + } + + @Override public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) { } |