I have an activity that does OAuth authentication by intercepting the redirect url once it show up in the webview. However, the onPageFinished function is somehow called twi
I'm looking into an event where m.yotube.com triggers two onPageFinished events but it does not seem like caused by redirection to me. After some studies I found that there is one extra onPageFinished triggered by didFinishNavigation before the one triggered by didStopLoading which other pages also receives.
See also:
https://chromium.googlesource.com/chromium/src.git/+/master/android_webview/java/src/org/chromium/android_webview/AwWebContentsObserver.java
@Override
public void didFinishNavigation(final String url, boolean isInMainFrame, boolean isErrorPage,
boolean hasCommitted, boolean isSameDocument, boolean isFragmentNavigation,
Integer pageTransition, int errorCode, String errorDescription, int httpStatusCode) {
...
if (client != null && isFragmentNavigation) {
client.getCallbackHelper().postOnPageFinished(url);
}
}
@Override
public void didStopLoading(String validatedUrl) {
if (validatedUrl.length() == 0) validatedUrl = ContentUrlConstants.ABOUT_BLANK_DISPLAY_URL;
AwContentsClient client = getClientIfNeedToFireCallback(validatedUrl);
if (client != null && validatedUrl.equals(mLastDidFinishLoadUrl)) {
client.getCallbackHelper().postOnPageFinished(validatedUrl);
mLastDidFinishLoadUrl = null;
}
}
Another instance I receive extra onPageFinished calls (even before onPageStarted!) is when I utilize webview.restoreState() in Fragments. it fires two onPageFinished events when trying to resume last viewed page.