|
|
|
|
868
|
|
868
|
|
869
|
@Override
|
869
|
@Override
|
870
|
public void onReceivedSslError(final WebView webView, final SslErrorHandler handler, final SslError error) {
|
870
|
public void onReceivedSslError(final WebView webView, final SslErrorHandler handler, final SslError error) {
|
|
|
871
|
+ // 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)
|
|
|
872
|
+ // WebView.getUrl() will return the top-level window URL.
|
|
|
873
|
+ // 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).
|
|
|
874
|
+ // This is desired behavior. We later use these values to determine whether the request is a top-level navigation or a subresource request.
|
|
|
875
|
+ String topWindowUrl = webView.getUrl();
|
|
|
876
|
+ String failingUrl = error.getUrl();
|
|
|
877
|
+
|
|
|
878
|
+ // Cancel request after obtaining top-level URL.
|
|
|
879
|
+ // If request is cancelled before obtaining top-level URL, undesired behavior may occur.
|
|
|
880
|
+ // Undesired behavior: Return value of WebView.getUrl() may be the current URL instead of the failing URL.
|
871
|
handler.cancel();
|
881
|
handler.cancel();
|
872
|
|
882
|
|
|
|
883
|
+ if (!topWindowUrl.equalsIgnoreCase(failingUrl)) {
|
|
|
884
|
+ // If error is not due to top-level navigation, then do not call onReceivedError()
|
|
|
885
|
+ Log.w("RNCWebViewManager", "Resource blocked from loading due to SSL error. Blocked URL: "+failingUrl);
|
|
|
886
|
+ return;
|
|
|
887
|
+ }
|
|
|
888
|
+
|
873
|
int code = error.getPrimaryError();
|
889
|
int code = error.getPrimaryError();
|
874
|
- String failingUrl = error.getUrl();
|
|
|
875
|
String description = "";
|
890
|
String description = "";
|
876
|
String descriptionPrefix = "SSL error: ";
|
891
|
String descriptionPrefix = "SSL error: ";
|
877
|
|
892
|
|