소스 검색

Update RNCWebViewManager.java

Clarify comments and add warning on blocked subresource
Alesandro Ortiz 4 년 전
부모
커밋
2390ecd8a6
No account linked to committer's email address
1개의 변경된 파일4개의 추가작업 그리고 1개의 파일을 삭제
  1. 4
    1
      android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java

+ 4
- 1
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java 파일 보기

@@ -17,6 +17,7 @@ import android.os.Environment;
17 17
 import androidx.annotation.RequiresApi;
18 18
 import androidx.core.content.ContextCompat;
19 19
 import android.text.TextUtils;
20
+import android.util.Log;
20 21
 import android.view.Gravity;
21 22
 import android.view.View;
22 23
 import android.view.ViewGroup;
@@ -801,8 +802,9 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
801 802
 
802 803
     @Override
803 804
     public void onReceivedSslError(final WebView webView, final SslErrorHandler handler, final SslError error) {
805
+        // onReceivedSslError is called for most requests, per Android docs: https://developer.android.com/reference/android/webkit/WebViewClient#onReceivedSslError(android.webkit.WebView,%2520android.webkit.SslErrorHandler,%2520android.net.http.SslError)
804 806
         // WebView.getUrl() will return the top-level window URL.
805
-        // If a top-level navigation triggers this error handler, the top-level URL will be the failing URL (not the current URL).
807
+        // If a top-level navigation triggers this error handler, the top-level URL will be the failing URL (not the URL of the currently-rendered page).
806 808
         // This is desired behavior. We later use these values to determine whether the request is a top-level navigation or a subresource request.
807 809
         String topWindowUrl = webView.getUrl();
808 810
         String failingUrl = error.getUrl();
@@ -814,6 +816,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
814 816
 
815 817
         if (!topWindowUrl.equalsIgnoreCase(failingUrl)) {
816 818
           // If error is not due to top-level navigation, then do not call onReceivedError()
819
+          Log.w("RNCWebViewManager", "Resource blocked from loading due to SSL error. Blocked URL: "+failingUrl);
817 820
           return;
818 821
         }
819 822