merged fix: Prevent Android java.lang.NullPointerException in InAppWebViewCl…
This commit is contained in:
parent
cad913f279
commit
596a228a05
|
@ -39,6 +39,7 @@
|
||||||
- Merged "Android fix leaking MethodChannel through anonymous class" [#1201](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1201) (thanks to [emakar](https://github.com/emakar))
|
- Merged "Android fix leaking MethodChannel through anonymous class" [#1201](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1201) (thanks to [emakar](https://github.com/emakar))
|
||||||
- Merged "Fix RangeError: Maximum call stack size exceeded" [#1208](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1208) (thanks to [liasica](https://github.com/liasica))
|
- Merged "Fix RangeError: Maximum call stack size exceeded" [#1208](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1208) (thanks to [liasica](https://github.com/liasica))
|
||||||
- Merged "fix: try to open with Chrome if default browser app does not support custom tabs" [#1233](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1233) (thanks to [addie9000](https://github.com/addie9000))
|
- Merged "fix: try to open with Chrome if default browser app does not support custom tabs" [#1233](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1233) (thanks to [addie9000](https://github.com/addie9000))
|
||||||
|
- Merged "fix: Prevent Android java.lang.NullPointerException in InAppWebViewCl…" [#1237](https://github.com/pichillilorenzo/flutter_inappwebview/pull/1237) (thanks to [kamilpowalowski](https://github.com/kamilpowalowski))
|
||||||
|
|
||||||
## 5.4.4+3
|
## 5.4.4+3
|
||||||
|
|
||||||
|
|
|
@ -343,22 +343,20 @@ public class InAppWebViewClient extends WebViewClient {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceivedHttpAuthRequest(final WebView view, final HttpAuthHandler handler, final String host, final String realm) {
|
public void onReceivedHttpAuthRequest(final WebView view, final HttpAuthHandler handler, final String host, final String realm) {
|
||||||
URI uri;
|
final String url = view.getUrl();
|
||||||
try {
|
String protocol = "https";
|
||||||
uri = new URI(view.getUrl());
|
int port = 0;
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
|
|
||||||
credentialsProposed = null;
|
if (url != null) {
|
||||||
previousAuthRequestFailureCount = 0;
|
try {
|
||||||
|
URI uri = new URI(url);
|
||||||
handler.cancel();
|
protocol = uri.getScheme();
|
||||||
return;
|
port = uri.getPort();
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final String protocol = uri.getScheme();
|
|
||||||
final int port = uri.getPort();
|
|
||||||
|
|
||||||
previousAuthRequestFailureCount++;
|
previousAuthRequestFailureCount++;
|
||||||
|
|
||||||
if (credentialsProposed == null)
|
if (credentialsProposed == null)
|
||||||
|
@ -373,6 +371,8 @@ public class InAppWebViewClient extends WebViewClient {
|
||||||
HttpAuthenticationChallenge challenge = new HttpAuthenticationChallenge(protectionSpace, previousAuthRequestFailureCount, credentialProposed);
|
HttpAuthenticationChallenge challenge = new HttpAuthenticationChallenge(protectionSpace, previousAuthRequestFailureCount, credentialProposed);
|
||||||
|
|
||||||
final InAppWebView webView = (InAppWebView) view;
|
final InAppWebView webView = (InAppWebView) view;
|
||||||
|
final String finalProtocol = protocol;
|
||||||
|
final int finalPort = port;
|
||||||
final WebViewChannelDelegate.ReceivedHttpAuthRequestCallback callback = new WebViewChannelDelegate.ReceivedHttpAuthRequestCallback() {
|
final WebViewChannelDelegate.ReceivedHttpAuthRequestCallback callback = new WebViewChannelDelegate.ReceivedHttpAuthRequestCallback() {
|
||||||
@Override
|
@Override
|
||||||
public boolean nonNullSuccess(@NonNull HttpAuthResponse response) {
|
public boolean nonNullSuccess(@NonNull HttpAuthResponse response) {
|
||||||
|
@ -385,7 +385,7 @@ public class InAppWebViewClient extends WebViewClient {
|
||||||
boolean permanentPersistence = response.isPermanentPersistence();
|
boolean permanentPersistence = response.isPermanentPersistence();
|
||||||
if (permanentPersistence) {
|
if (permanentPersistence) {
|
||||||
CredentialDatabase.getInstance(view.getContext())
|
CredentialDatabase.getInstance(view.getContext())
|
||||||
.setHttpAuthCredential(host, protocol, realm, port, username, password);
|
.setHttpAuthCredential(host, finalProtocol, realm, finalPort, username, password);
|
||||||
}
|
}
|
||||||
handler.proceed(username, password);
|
handler.proceed(username, password);
|
||||||
break;
|
break;
|
||||||
|
@ -433,19 +433,20 @@ public class InAppWebViewClient extends WebViewClient {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError sslError) {
|
public void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError sslError) {
|
||||||
URI uri;
|
final String url = sslError.getUrl();
|
||||||
|
String host = "";
|
||||||
|
String protocol = "https";
|
||||||
|
int port = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
uri = new URI(sslError.getUrl());
|
URI uri = new URI(url);
|
||||||
|
host = uri.getHost();
|
||||||
|
protocol = uri.getScheme();
|
||||||
|
port = uri.getPort();
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
handler.cancel();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final String host = uri.getHost();
|
|
||||||
final String protocol = uri.getScheme();
|
|
||||||
final int port = uri.getPort();
|
|
||||||
|
|
||||||
URLProtectionSpace protectionSpace = new URLProtectionSpace(host, protocol, null, port, sslError.getCertificate(), sslError);
|
URLProtectionSpace protectionSpace = new URLProtectionSpace(host, protocol, null, port, sslError.getCertificate(), sslError);
|
||||||
ServerTrustChallenge challenge = new ServerTrustChallenge(protectionSpace);
|
ServerTrustChallenge challenge = new ServerTrustChallenge(protectionSpace);
|
||||||
|
|
||||||
|
@ -492,19 +493,20 @@ public class InAppWebViewClient extends WebViewClient {
|
||||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||||
@Override
|
@Override
|
||||||
public void onReceivedClientCertRequest(final WebView view, final ClientCertRequest request) {
|
public void onReceivedClientCertRequest(final WebView view, final ClientCertRequest request) {
|
||||||
URI uri;
|
final String url = view.getUrl();
|
||||||
try {
|
|
||||||
uri = new URI(view.getUrl());
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
request.cancel();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final String host = request.getHost();
|
final String host = request.getHost();
|
||||||
final String protocol = uri.getScheme();
|
String protocol = "https";
|
||||||
final int port = request.getPort();
|
final int port = request.getPort();
|
||||||
|
|
||||||
|
if (url != null) {
|
||||||
|
try {
|
||||||
|
URI uri = new URI(url);
|
||||||
|
protocol = uri.getScheme();
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
URLProtectionSpace protectionSpace = new URLProtectionSpace(host, protocol, null, port, view.getCertificate(), null);
|
URLProtectionSpace protectionSpace = new URLProtectionSpace(host, protocol, null, port, view.getCertificate(), null);
|
||||||
ClientCertChallenge challenge = new ClientCertChallenge(protectionSpace, request.getPrincipals(), request.getKeyTypes());
|
ClientCertChallenge challenge = new ClientCertChallenge(protectionSpace, request.getPrincipals(), request.getKeyTypes());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue