Skip to content

Commit

Permalink
Wait for redirects before showing main webview
Browse files Browse the repository at this point in the history
The onPageFinished callback fires when a page is redirected to another
one. We can detect if a new page load is started before the previous
page is finished, and wait for that new page load to finish.

https://phabricator.endlessm.com/T34576
  • Loading branch information
dylanmccall committed Mar 21, 2023
1 parent b3c326e commit a4de463
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -221,22 +221,27 @@ public boolean shouldOverrideUrlLoading(WebView view, String url) {
mWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
mWebView.getSettings().setMediaPlaybackRequiresUserGesture(false);
mWebView.setWebViewClient(new WebViewClient() {
boolean isRedirected = false;

@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
isRedirected = false;
}

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
isRedirected = true;
return tryOpenExternalLink(url);
}

@Override
public void onPageFinished(WebView view, String url) {
Log.i(TAG, "MainPythonWebViewClient onPageFinished");
if (isRedirected) {
return;
}

Log.v(TAG, "MainPythonWebViewClient loading finished");
displayMainWebView();
// FIXME: We should use postVisualStateCallback here...
// mWebView.postVisualStateCallback(123, new WebView.VisualStateCallback() {
// @Override
// public void onComplete(long requestId) {
// displayMainWebView();
// }
// });
}
});
mWebViewSwitcher.addView(mWebView, 1);
Expand Down

0 comments on commit a4de463

Please sign in to comment.