Browse Source

Update RNCWebViewManager.java

Clarify comments and add warning on blocked subresource
Alesandro Ortiz 4 years ago
parent
commit
2390ecd8a6
No account linked to committer's email address

+ 4
- 1
android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java View File

17
 import androidx.annotation.RequiresApi;
17
 import androidx.annotation.RequiresApi;
18
 import androidx.core.content.ContextCompat;
18
 import androidx.core.content.ContextCompat;
19
 import android.text.TextUtils;
19
 import android.text.TextUtils;
20
+import android.util.Log;
20
 import android.view.Gravity;
21
 import android.view.Gravity;
21
 import android.view.View;
22
 import android.view.View;
22
 import android.view.ViewGroup;
23
 import android.view.ViewGroup;
801
 
802
 
802
     @Override
803
     @Override
803
     public void onReceivedSslError(final WebView webView, final SslErrorHandler handler, final SslError error) {
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
         // WebView.getUrl() will return the top-level window URL.
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
         // This is desired behavior. We later use these values to determine whether the request is a top-level navigation or a subresource request.
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
         String topWindowUrl = webView.getUrl();
809
         String topWindowUrl = webView.getUrl();
808
         String failingUrl = error.getUrl();
810
         String failingUrl = error.getUrl();
814
 
816
 
815
         if (!topWindowUrl.equalsIgnoreCase(failingUrl)) {
817
         if (!topWindowUrl.equalsIgnoreCase(failingUrl)) {
816
           // If error is not due to top-level navigation, then do not call onReceivedError()
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
           return;
820
           return;
818
         }
821
         }
819
 
822