fix(Android): Workaround for chromium bugs 1023678 and 1050635. (#1221)
There is a bug in the WebView that causes a spurious call to onReceivedError whenever you download a file. This commit is a workaround for that bug. The idea here is to try and detect these spurious errors and drop them before they cause problems. This commit should be reverted once those chromium bugs are fixed.
This commit is contained in:
parent
c6ad1f9ed0
commit
5d88af44fa
|
@ -197,6 +197,8 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||||
|
|
||||||
webView.setDownloadListener(new DownloadListener() {
|
webView.setDownloadListener(new DownloadListener() {
|
||||||
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
|
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
|
||||||
|
webView.setIgnoreErrFailedForThisURL(url);
|
||||||
|
|
||||||
RNCWebViewModule module = getModule(reactContext);
|
RNCWebViewModule module = getModule(reactContext);
|
||||||
|
|
||||||
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
|
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
|
||||||
|
@ -721,6 +723,11 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||||
protected boolean mLastLoadFailed = false;
|
protected boolean mLastLoadFailed = false;
|
||||||
protected @Nullable
|
protected @Nullable
|
||||||
ReadableArray mUrlPrefixesForDefaultIntent;
|
ReadableArray mUrlPrefixesForDefaultIntent;
|
||||||
|
protected @Nullable String ignoreErrFailedForThisURL = null;
|
||||||
|
|
||||||
|
public void setIgnoreErrFailedForThisURL(@Nullable String url) {
|
||||||
|
ignoreErrFailedForThisURL = url;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPageFinished(WebView webView, String url) {
|
public void onPageFinished(WebView webView, String url) {
|
||||||
|
@ -772,6 +779,21 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||||
int errorCode,
|
int errorCode,
|
||||||
String description,
|
String description,
|
||||||
String failingUrl) {
|
String failingUrl) {
|
||||||
|
|
||||||
|
if (ignoreErrFailedForThisURL != null
|
||||||
|
&& failingUrl.equals(ignoreErrFailedForThisURL)
|
||||||
|
&& errorCode == -1
|
||||||
|
&& description.equals("net::ERR_FAILED")) {
|
||||||
|
|
||||||
|
// This is a workaround for a bug in the WebView.
|
||||||
|
// See these chromium issues for more context:
|
||||||
|
// https://bugs.chromium.org/p/chromium/issues/detail?id=1023678
|
||||||
|
// https://bugs.chromium.org/p/chromium/issues/detail?id=1050635
|
||||||
|
// This entire commit should be reverted once this bug is resolved in chromium.
|
||||||
|
setIgnoreErrFailedForThisURL(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
super.onReceivedError(webView, errorCode, description, failingUrl);
|
super.onReceivedError(webView, errorCode, description, failingUrl);
|
||||||
mLastLoadFailed = true;
|
mLastLoadFailed = true;
|
||||||
|
|
||||||
|
@ -999,6 +1021,10 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||||
super(reactContext);
|
super(reactContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setIgnoreErrFailedForThisURL(String url) {
|
||||||
|
mRNCWebViewClient.setIgnoreErrFailedForThisURL(url);
|
||||||
|
}
|
||||||
|
|
||||||
public void setSendContentSizeChangeEvents(boolean sendContentSizeChangeEvents) {
|
public void setSendContentSizeChangeEvents(boolean sendContentSizeChangeEvents) {
|
||||||
this.sendContentSizeChangeEvents = sendContentSizeChangeEvents;
|
this.sendContentSizeChangeEvents = sendContentSizeChangeEvents;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue