Procházet zdrojové kódy

Add config to ignore Ssl errors on Android

Thibault před 4 roky
rodič
revize
ec2aac1d7d

+ 17
- 0
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java Zobrazit soubor

11
 import android.graphics.Color;
11
 import android.graphics.Color;
12
 import android.Manifest;
12
 import android.Manifest;
13
 import android.net.Uri;
13
 import android.net.Uri;
14
+import android.net.http.SslError;
14
 import android.os.Build;
15
 import android.os.Build;
15
 import android.os.Environment;
16
 import android.os.Environment;
16
 import androidx.annotation.RequiresApi;
17
 import androidx.annotation.RequiresApi;
27
 import android.webkit.GeolocationPermissions;
28
 import android.webkit.GeolocationPermissions;
28
 import android.webkit.JavascriptInterface;
29
 import android.webkit.JavascriptInterface;
29
 import android.webkit.PermissionRequest;
30
 import android.webkit.PermissionRequest;
31
+import android.webkit.SslErrorHandler;
30
 import android.webkit.URLUtil;
32
 import android.webkit.URLUtil;
31
 import android.webkit.ValueCallback;
33
 import android.webkit.ValueCallback;
32
 import android.webkit.WebChromeClient;
34
 import android.webkit.WebChromeClient;
135
   protected boolean mAllowsFullscreenVideo = false;
137
   protected boolean mAllowsFullscreenVideo = false;
136
   protected @Nullable String mUserAgent = null;
138
   protected @Nullable String mUserAgent = null;
137
   protected @Nullable String mUserAgentWithApplicationName = null;
139
   protected @Nullable String mUserAgentWithApplicationName = null;
140
+  public static boolean mignoreSslErrors = false;
138
 
141
 
139
   public RNCWebViewManager() {
142
   public RNCWebViewManager() {
140
     mWebViewConfig = new WebViewConfig() {
143
     mWebViewConfig = new WebViewConfig() {
529
     ((RNCWebView) view).setHasScrollEvent(hasScrollEvent);
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
   @Override
540
   @Override
533
   protected void addEventEmitters(ThemedReactContext reactContext, WebView view) {
541
   protected void addEventEmitters(ThemedReactContext reactContext, WebView view) {
534
     // Do not register default touch emitter and let WebView implementation handle touches
542
     // Do not register default touch emitter and let WebView implementation handle touches
715
     protected @Nullable
723
     protected @Nullable
716
     ReadableArray mUrlPrefixesForDefaultIntent;
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
     @Override
735
     @Override
719
     public void onPageFinished(WebView webView, String url) {
736
     public void onPageFinished(WebView webView, String url) {
720
       super.onPageFinished(webView, url);
737
       super.onPageFinished(webView, url);

+ 8
- 0
docs/Reference.md Zobrazit soubor

1091
 
1091
 
1092
 `<WebView textZoom={100} />`
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
 ## Methods
1102
 ## Methods
1095
 
1103
 
1096
 ### `extraNativeComponentConfig()`
1104
 ### `extraNativeComponentConfig()`

+ 1
- 0
src/WebView.android.tsx Zobrazit soubor

54
     cacheEnabled: true,
54
     cacheEnabled: true,
55
     androidHardwareAccelerationDisabled: false,
55
     androidHardwareAccelerationDisabled: false,
56
     originWhitelist: defaultOriginWhitelist,
56
     originWhitelist: defaultOriginWhitelist,
57
+    ignoreSslErrors: false,
57
   };
58
   };
58
 
59
 
59
   static isFileUploadSupported = async () => {
60
   static isFileUploadSupported = async () => {

+ 5
- 0
src/WebViewTypes.ts Zobrazit soubor

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