trcoffman 4 years ago
parent
commit
ad1df56ab9
No account linked to committer's email address

+ 26
- 0
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java View File

194
 
194
 
195
     webView.setDownloadListener(new DownloadListener() {
195
     webView.setDownloadListener(new DownloadListener() {
196
       public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
196
       public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
197
+        webView.setIgnoreErrFailedForThisURL(url);
198
+
197
         RNCWebViewModule module = getModule(reactContext);
199
         RNCWebViewModule module = getModule(reactContext);
198
 
200
 
199
         DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
201
         DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
713
     protected boolean mLastLoadFailed = false;
715
     protected boolean mLastLoadFailed = false;
714
     protected @Nullable
716
     protected @Nullable
715
     ReadableArray mUrlPrefixesForDefaultIntent;
717
     ReadableArray mUrlPrefixesForDefaultIntent;
718
+    protected @Nullable String ignoreErrFailedForThisURL = null;
719
+
720
+    public void setIgnoreErrFailedForThisURL(@Nullable String url) {
721
+      ignoreErrFailedForThisURL = url;
722
+    }
716
 
723
 
717
     @Override
724
     @Override
718
     public void onPageFinished(WebView webView, String url) {
725
     public void onPageFinished(WebView webView, String url) {
764
       int errorCode,
771
       int errorCode,
765
       String description,
772
       String description,
766
       String failingUrl) {
773
       String failingUrl) {
774
+
775
+      if (ignoreErrFailedForThisURL != null
776
+          && failingUrl.equals(ignoreErrFailedForThisURL)
777
+          && errorCode == -1
778
+          && description.equals("net::ERR_FAILED")) {
779
+
780
+        // This is a workaround for a bug in the WebView.
781
+        // See these chromium issues for more context:
782
+        // https://bugs.chromium.org/p/chromium/issues/detail?id=1023678
783
+        // https://bugs.chromium.org/p/chromium/issues/detail?id=1050635
784
+        // This entire commit should be reverted once this bug is resolved in chromium.
785
+        setIgnoreErrFailedForThisURL(null);
786
+        return;
787
+      }
788
+
767
       super.onReceivedError(webView, errorCode, description, failingUrl);
789
       super.onReceivedError(webView, errorCode, description, failingUrl);
768
       mLastLoadFailed = true;
790
       mLastLoadFailed = true;
769
 
791
 
987
       super(reactContext);
1009
       super(reactContext);
988
     }
1010
     }
989
 
1011
 
1012
+    public void setIgnoreErrFailedForThisURL(String url) {
1013
+      mRNCWebViewClient.setIgnoreErrFailedForThisURL(url);
1014
+    }
1015
+
990
     public void setSendContentSizeChangeEvents(boolean sendContentSizeChangeEvents) {
1016
     public void setSendContentSizeChangeEvents(boolean sendContentSizeChangeEvents) {
991
       this.sendContentSizeChangeEvents = sendContentSizeChangeEvents;
1017
       this.sendContentSizeChangeEvents = sendContentSizeChangeEvents;
992
     }
1018
     }