|
@@ -18,6 +18,7 @@ import android.os.Environment;
|
18
|
18
|
import androidx.annotation.RequiresApi;
|
19
|
19
|
import androidx.core.content.ContextCompat;
|
20
|
20
|
import android.text.TextUtils;
|
|
21
|
+import android.util.Log;
|
21
|
22
|
import android.view.Gravity;
|
22
|
23
|
import android.view.View;
|
23
|
24
|
import android.view.ViewGroup;
|
|
@@ -28,6 +29,7 @@ import android.webkit.CookieManager;
|
28
|
29
|
import android.webkit.DownloadListener;
|
29
|
30
|
import android.webkit.GeolocationPermissions;
|
30
|
31
|
import android.webkit.JavascriptInterface;
|
|
32
|
+import android.webkit.RenderProcessGoneDetail;
|
31
|
33
|
import android.webkit.SslErrorHandler;
|
32
|
34
|
import android.webkit.PermissionRequest;
|
33
|
35
|
import android.webkit.URLUtil;
|
|
@@ -70,6 +72,7 @@ import com.reactnativecommunity.webview.events.TopLoadingProgressEvent;
|
70
|
72
|
import com.reactnativecommunity.webview.events.TopLoadingStartEvent;
|
71
|
73
|
import com.reactnativecommunity.webview.events.TopMessageEvent;
|
72
|
74
|
import com.reactnativecommunity.webview.events.TopShouldStartLoadWithRequestEvent;
|
|
75
|
+import com.reactnativecommunity.webview.events.TopRenderProcessGoneEvent;
|
73
|
76
|
|
74
|
77
|
import org.json.JSONException;
|
75
|
78
|
import org.json.JSONObject;
|
|
@@ -580,6 +583,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
580
|
583
|
export.put(TopShouldStartLoadWithRequestEvent.EVENT_NAME, MapBuilder.of("registrationName", "onShouldStartLoadWithRequest"));
|
581
|
584
|
export.put(ScrollEventType.getJSEventName(ScrollEventType.SCROLL), MapBuilder.of("registrationName", "onScroll"));
|
582
|
585
|
export.put(TopHttpErrorEvent.EVENT_NAME, MapBuilder.of("registrationName", "onHttpError"));
|
|
586
|
+ export.put(TopRenderProcessGoneEvent.EVENT_NAME, MapBuilder.of("registrationName", "onRenderProcessGone"));
|
583
|
587
|
return export;
|
584
|
588
|
}
|
585
|
589
|
|
|
@@ -776,7 +780,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
776
|
780
|
mLastLoadFailed = false;
|
777
|
781
|
|
778
|
782
|
RNCWebView reactWebView = (RNCWebView) webView;
|
779
|
|
- reactWebView.callInjectedJavaScriptBeforeContentLoaded();
|
|
783
|
+ reactWebView.callInjectedJavaScriptBeforeContentLoaded();
|
780
|
784
|
|
781
|
785
|
dispatchEvent(
|
782
|
786
|
webView,
|
|
@@ -833,11 +837,11 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
833
|
837
|
case SslError.SSL_UNTRUSTED:
|
834
|
838
|
description = "The certificate authority is not trusted";
|
835
|
839
|
break;
|
836
|
|
- default:
|
|
840
|
+ default:
|
837
|
841
|
description = "Unknown SSL Error";
|
838
|
842
|
break;
|
839
|
843
|
}
|
840
|
|
-
|
|
844
|
+
|
841
|
845
|
description = descriptionPrefix + description;
|
842
|
846
|
|
843
|
847
|
this.onReceivedError(
|
|
@@ -847,7 +851,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
847
|
851
|
failingUrl
|
848
|
852
|
);
|
849
|
853
|
}
|
850
|
|
-
|
|
854
|
+
|
851
|
855
|
@Override
|
852
|
856
|
public void onReceivedError(
|
853
|
857
|
WebView webView,
|
|
@@ -904,6 +908,41 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
904
|
908
|
}
|
905
|
909
|
}
|
906
|
910
|
|
|
911
|
+ @TargetApi(Build.VERSION_CODES.O)
|
|
912
|
+ @Override
|
|
913
|
+ public boolean onRenderProcessGone(WebView webView, RenderProcessGoneDetail detail) {
|
|
914
|
+ // WebViewClient.onRenderProcessGone was added in O.
|
|
915
|
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
|
916
|
+ return false;
|
|
917
|
+ }
|
|
918
|
+ super.onRenderProcessGone(webView, detail);
|
|
919
|
+
|
|
920
|
+ if(detail.didCrash()){
|
|
921
|
+ Log.e("RNCWebViewManager", "The WebView rendering process crashed.");
|
|
922
|
+ }
|
|
923
|
+ else{
|
|
924
|
+ Log.w("RNCWebViewManager", "The WebView rendering process was killed by the system.");
|
|
925
|
+ }
|
|
926
|
+
|
|
927
|
+ // if webView is null, we cannot return any event
|
|
928
|
+ // since the view is already dead/disposed
|
|
929
|
+ // still prevent the app crash by returning true.
|
|
930
|
+ if(webView == null){
|
|
931
|
+ return true;
|
|
932
|
+ }
|
|
933
|
+
|
|
934
|
+ WritableMap event = createWebViewEvent(webView, webView.getUrl());
|
|
935
|
+ event.putBoolean("didCrash", detail.didCrash());
|
|
936
|
+
|
|
937
|
+ dispatchEvent(
|
|
938
|
+ webView,
|
|
939
|
+ new TopRenderProcessGoneEvent(webView.getId(), event)
|
|
940
|
+ );
|
|
941
|
+
|
|
942
|
+ // returning false would crash the app.
|
|
943
|
+ return true;
|
|
944
|
+ }
|
|
945
|
+
|
907
|
946
|
protected void emitFinishEvent(WebView webView, String url) {
|
908
|
947
|
dispatchEvent(
|
909
|
948
|
webView,
|