HI,
I'd like to discuss the calling method for page loading & page finished on WebView.
For a page loading, chromium uses UI main thread to run 2 important callbacks in order to notify WebView that page loading timing change.
1. onPageStarted (notify page is staring to load)
- InterceptNavigationDelegate::ShouldIgnoreNavigation --> AwContents$InterceptNavigationDelegateImpl.shouldIgnoreNavigation -->post a message(async call) do to WebViewContentsClientAdapter.onPageStarted
2. onPageFinished (notify page loading done)
- WebContentsObserverProxy.didFinishLoad --> blocking call WebViewContentsClientAdapter.onPageFinished
Because it’s a async call to run WebViewContentsClientAdapter.onPageStarted, it dose not gurantee that WebViewContentsClientAdapter.onPageStarted executing before WebViewContentsClientAdapter.onPageFinished.
Sometimes, page loading callback is out of order, like this issue.
In order to consistent callback sequence, onPageStartedd and onPageFinished should BOTH are blocking or BOTH are async call. How about changing to use post message (async call) to trigger onPageFinished?
Thanks you.
Example:
/android_webview/java/src/org/chromium/android_webview/AwWebContentObserver.java
@Override
public void didFinishLoad(long frameId, String validatedUrl, boolean isMainFrame) {
AwContentsClient client = mAwContentsClient.get();
if (client == null) return;
String unreachableWebDataUrl = AwContentsStatics.getUnreachableWebDataUrl();
boolean isErrorUrl =
unreachableWebDataUrl != null && unreachableWebDataUrl.equals(validatedUrl);
if (isMainFrame && !isErrorUrl) {
//
//client.onPageFinished(validatedUrl);
//
client.getCallbackHelper().postOnPageFinished(validatedUrl);
}
}