Thibault Lenclos 4 years ago
parent
commit
3c3f58a88d
No account linked to committer's email address

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

@@ -11,6 +11,7 @@ import android.graphics.Bitmap;
11 11
 import android.graphics.Color;
12 12
 import android.Manifest;
13 13
 import android.net.Uri;
14
+import android.net.http.SslError;
14 15
 import android.os.Build;
15 16
 import android.os.Environment;
16 17
 import androidx.annotation.RequiresApi;
@@ -27,6 +28,7 @@ import android.webkit.DownloadListener;
27 28
 import android.webkit.GeolocationPermissions;
28 29
 import android.webkit.JavascriptInterface;
29 30
 import android.webkit.PermissionRequest;
31
+import android.webkit.SslErrorHandler;
30 32
 import android.webkit.URLUtil;
31 33
 import android.webkit.ValueCallback;
32 34
 import android.webkit.WebChromeClient;
@@ -135,6 +137,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
135 137
   protected boolean mAllowsFullscreenVideo = false;
136 138
   protected @Nullable String mUserAgent = null;
137 139
   protected @Nullable String mUserAgentWithApplicationName = null;
140
+  public static boolean mignoreSslErrors = false;
138 141
 
139 142
   public RNCWebViewManager() {
140 143
     mWebViewConfig = new WebViewConfig() {
@@ -529,6 +532,11 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
529 532
     ((RNCWebView) view).setHasScrollEvent(hasScrollEvent);
530 533
   }
531 534
 
535
+  @ReactProp(name = "ignoreSslErrors")
536
+  public void setIgnoreSslErrors(WebView view, @Nullable Boolean ignoreSslErrors) {
537
+    mignoreSslErrors = ignoreSslErrors != null && ignoreSslErrors;
538
+  }
539
+
532 540
   @Override
533 541
   protected void addEventEmitters(ThemedReactContext reactContext, WebView view) {
534 542
     // Do not register default touch emitter and let WebView implementation handle touches
@@ -715,6 +723,15 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
715 723
     protected @Nullable
716 724
     ReadableArray mUrlPrefixesForDefaultIntent;
717 725
 
726
+    @Override
727
+    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
728
+      if (BuildConfig.DEBUG && mignoreSslErrors) {
729
+        handler.proceed();
730
+      }
731
+
732
+      super.onReceivedSslError(view, handler, error);
733
+    }
734
+
718 735
     @Override
719 736
     public void onPageFinished(WebView webView, String url) {
720 737
       super.onPageFinished(webView, url);

+ 10
- 0
docs/Reference.md View File

@@ -1091,6 +1091,16 @@ Example:
1091 1091
 
1092 1092
 `<WebView textZoom={100} />`
1093 1093
 
1094
+### `ignoreSslErrors`
1095
+
1096
+Ignore Ssl errors encountered in the webview. 
1097
+
1098
+Works only in debug mode.
1099
+
1100
+| Type    | Required | Platform |
1101
+| ------- | -------- | -------- |
1102
+| boolean | No       | Android      |
1103
+
1094 1104
 ## Methods
1095 1105
 
1096 1106
 ### `extraNativeComponentConfig()`

+ 1
- 0
src/WebView.android.tsx View File

@@ -54,6 +54,7 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
54 54
     cacheEnabled: true,
55 55
     androidHardwareAccelerationDisabled: false,
56 56
     originWhitelist: defaultOriginWhitelist,
57
+    ignoreSslErrors: false,
57 58
   };
58 59
 
59 60
   static isFileUploadSupported = async () => {

+ 5
- 0
src/WebViewTypes.ts View File

@@ -751,6 +751,11 @@ export interface AndroidWebViewProps extends WebViewSharedProps {
751 751
    * Sets ability to open fullscreen videos on Android devices.
752 752
    */
753 753
   allowsFullscreenVideo?: boolean;
754
+
755
+  /**
756
+   * Ignore Ssl errors.
757
+   */
758
+  ignoreSslErrors?: boolean;
754 759
 }
755 760
 
756 761
 export interface WebViewSharedProps extends ViewProps {