Browse Source

Add config to ignore Ssl errors on Android

Thibault 4 years ago
parent
commit
ec2aac1d7d

+ 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 (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);

+ 8
- 0
docs/Reference.md View File

@@ -1091,6 +1091,14 @@ Example:
1091 1091
 
1092 1092
 `<WebView textZoom={100} />`
1093 1093
 
1094
+### `ignoreSslErrors`
1095
+
1096
+Ignore Ssl errors encountered in the webview. 
1097
+
1098
+| Type    | Required | Platform |
1099
+| ------- | -------- | -------- |
1100
+| boolean | No       | Android      |
1101
+
1094 1102
 ## Methods
1095 1103
 
1096 1104
 ### `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

@@ -590,6 +590,11 @@ export interface AndroidWebViewProps extends WebViewSharedProps {
590 590
    * Sets ability to open fullscreen videos on Android devices.
591 591
    */
592 592
   allowsFullscreenVideo?: boolean;
593
+
594
+  /**
595
+   * Ignore Ssl errors.
596
+   */
597
+  ignoreSslErrors?: boolean;
593 598
 }
594 599
 
595 600
 export interface WebViewSharedProps extends ViewProps {