| Index: android_webview/java/src/org/chromium/android_webview/AwContents.java
|
| 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 bb4222c87c273f6e8a5a8a32fc91e7805fdd5e50..35760ddc6316b64578a2d55e6254e5c19cfb6e1e 100644
|
| --- a/android_webview/java/src/org/chromium/android_webview/AwContents.java
|
| +++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java
|
| @@ -195,6 +195,10 @@ public class AwContents {
|
|
|
| private AwPdfExporter mAwPdfExporter;
|
|
|
| + // This flag indicates that ShouldOverrideUrlNavigation should be posted
|
| + // through the resourcethrottle. This is only used for popup windows.
|
| + private boolean mDeferredShouldOverrideUrlLoadingIsPendingForPopup;
|
| +
|
| private static final class DestroyRunnable implements Runnable {
|
| private final long mNativeAwContents;
|
| private DestroyRunnable(long nativeAwContents) {
|
| @@ -284,62 +288,33 @@ public class AwContents {
|
| }
|
|
|
| //--------------------------------------------------------------------------------------------
|
| + // When the navigation is for a newly created WebView (i.e. a popup), intercept the navigation
|
| + // here for implementing shouldOverrideUrlLoading. This is to send the shouldOverrideUrlLoading
|
| + // callback to the correct WebViewClient that is associated with the WebView.
|
| + // Otherwise, use this delegate only to post onPageStarted messages.
|
| + //
|
| + // We are not using WebContentsObserver.didStartLoading because of stale URLs, out of order
|
| + // onPageStarted's and double onPageStarted's.
|
| + //
|
| private class InterceptNavigationDelegateImpl implements InterceptNavigationDelegate {
|
| - private String mLastLoadUrlAddress;
|
| -
|
| - public void onUrlLoadRequested(String url) {
|
| - mLastLoadUrlAddress = url;
|
| - }
|
| -
|
| @Override
|
| public boolean shouldIgnoreNavigation(NavigationParams navigationParams) {
|
| final String url = navigationParams.url;
|
| - final int transitionType = navigationParams.pageTransitionType;
|
| - final boolean isLoadUrl =
|
| - (transitionType & PageTransitionTypes.PAGE_TRANSITION_FROM_API) != 0;
|
| - final boolean isBackForward =
|
| - (transitionType & PageTransitionTypes.PAGE_TRANSITION_FORWARD_BACK) != 0;
|
| - final boolean isReload =
|
| - (transitionType & PageTransitionTypes.PAGE_TRANSITION_CORE_MASK) ==
|
| - PageTransitionTypes.PAGE_TRANSITION_RELOAD;
|
| - final boolean isRedirect = navigationParams.isRedirect;
|
| -
|
| boolean ignoreNavigation = false;
|
| -
|
| - // Any navigation from loadUrl, goBack/Forward, or reload, are considered application
|
| - // initiated and hence will not yield a shouldOverrideUrlLoading() callback.
|
| - // TODO(joth): Using PageTransitionTypes should be sufficient to determine all app
|
| - // initiated navigations, and so mLastLoadUrlAddress should be removed.
|
| - if ((isLoadUrl && !isRedirect) || isBackForward || isReload ||
|
| - mLastLoadUrlAddress != null && mLastLoadUrlAddress.equals(url)) {
|
| - // Support the case where the user clicks on a link that takes them back to the
|
| - // same page.
|
| - mLastLoadUrlAddress = null;
|
| -
|
| - // If the embedder requested the load of a certain URL via the loadUrl API, then we
|
| - // 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.shouldOverrideUrlLoading(url);
|
| + if (mDeferredShouldOverrideUrlLoadingIsPendingForPopup) {
|
| + mDeferredShouldOverrideUrlLoadingIsPendingForPopup = false;
|
| + // If this is used for all navigations in future, cases for application initiated
|
| + // load, redirect and backforward should also be filtered out.
|
| + if (!navigationParams.isPost) {
|
| + ignoreNavigation = mContentsClient.shouldOverrideUrlLoading(url);
|
| + }
|
| }
|
| -
|
| - // 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
|
| - // 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).
|
| + // 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 in order.
|
| if (!ignoreNavigation) {
|
| - // 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 in order.
|
| mContentsClient.getCallbackHelper().postOnPageStarted(url);
|
| }
|
| -
|
| return ignoreNavigation;
|
| }
|
| }
|
| @@ -618,6 +593,7 @@ public class AwContents {
|
| // Recap: supplyContentsForPopup() is called on the parent window's content, this method is
|
| // called on the popup window's content.
|
| private void receivePopupContents(int popupNativeAwContents) {
|
| + mDeferredShouldOverrideUrlLoadingIsPendingForPopup = true;
|
| // Save existing view state.
|
| final boolean wasAttached = mIsAttachedToWindow;
|
| final boolean wasViewVisible = mIsViewVisible;
|
| @@ -912,8 +888,6 @@ public class AwContents {
|
|
|
| mContentViewCore.loadUrl(params);
|
|
|
| - suppressInterceptionForThisNavigation();
|
| -
|
| // The behavior of WebViewClassic uses the populateVisitedLinks callback in WebKit.
|
| // Chromium does not use this use code path and the best emulation of this behavior to call
|
| // request visited links once on the first URL load of the WebView.
|
| @@ -923,14 +897,6 @@ public class AwContents {
|
| }
|
| }
|
|
|
| - private void suppressInterceptionForThisNavigation() {
|
| - if (mInterceptNavigationDelegate != null) {
|
| - // getUrl returns a sanitized address in the same format that will be used for
|
| - // callbacks, so it's safe to use string comparison as an equality check later on.
|
| - mInterceptNavigationDelegate.onUrlLoadRequested(mContentViewCore.getUrl());
|
| - }
|
| - }
|
| -
|
| /**
|
| * Get the URL of the current page.
|
| *
|
| @@ -1146,8 +1112,6 @@ public class AwContents {
|
| */
|
| public void goBack() {
|
| mContentViewCore.goBack();
|
| -
|
| - suppressInterceptionForThisNavigation();
|
| }
|
|
|
| /**
|
| @@ -1162,8 +1126,6 @@ public class AwContents {
|
| */
|
| public void goForward() {
|
| mContentViewCore.goForward();
|
| -
|
| - suppressInterceptionForThisNavigation();
|
| }
|
|
|
| /**
|
| @@ -1178,8 +1140,6 @@ public class AwContents {
|
| */
|
| public void goBackOrForward(int steps) {
|
| mContentViewCore.goToOffset(steps);
|
| -
|
| - suppressInterceptionForThisNavigation();
|
| }
|
|
|
| /**
|
|
|