Skip to content

Commit 685f692

Browse files
# Conflicts: # web3lib/src/main/java/coming/web3/Web3ViewClient.java
2 parents 62b22db + 08dfa71 commit 685f692

4 files changed

Lines changed: 48 additions & 158 deletions

File tree

web3lib/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ afterEvaluate {
1111
from components.release
1212
groupId = 'com.comingchat.web3'
1313
artifactId = 'web3'
14-
version = '1.0.3'
14+
version = '1.0.6'
1515
}
1616
}
1717
}
@@ -67,4 +67,4 @@ dependencies {
6767

6868
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
6969
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
70-
}
70+
}

web3lib/src/main/java/coming/web3/Web3View.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package coming.web3;
22

33
import android.annotation.SuppressLint;
4+
import android.app.AlertDialog;
45
import android.content.Context;
6+
import android.content.DialogInterface;
57
import android.content.res.Resources;
8+
import android.net.http.SslError;
69
import android.os.Build;
710
import android.util.AttributeSet;
811
import android.util.Log;
12+
import android.webkit.SslErrorHandler;
913
import android.webkit.WebChromeClient;
1014
import android.webkit.WebResourceRequest;
1115
import android.webkit.WebResourceResponse;
@@ -86,7 +90,7 @@ public void setWebViewClient(WebViewClient client) {
8690
@SuppressLint("SetJavaScriptEnabled")
8791
private void init() {
8892
jsInjectorClient = new JsInjectorClient(getContext());
89-
webViewClient = new Web3ViewClient(jsInjectorClient, new UrlHandlerManager());
93+
webViewClient = new Web3ViewClient(getContext(),jsInjectorClient, new UrlHandlerManager());
9094
WebSettings webSettings = super.getSettings();
9195
webSettings.setJavaScriptEnabled(true);
9296
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);

web3lib/src/main/java/coming/web3/Web3ViewClient.java

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import static android.os.Build.VERSION_CODES.N;
55

66
import android.net.Uri;
7+
import android.app.AlertDialog;
8+
import android.content.Context;
9+
import android.content.DialogInterface;
710
import android.net.http.SslError;
811
import android.text.TextUtils;
912
import android.util.Base64;
@@ -24,10 +27,12 @@ public class Web3ViewClient extends WebViewClient {
2427

2528
private final JsInjectorClient jsInjectorClient;
2629
private final UrlHandlerManager urlHandlerManager;
30+
private final Context context;
2731

2832
private boolean isInjected;
2933

30-
public Web3ViewClient(JsInjectorClient jsInjectorClient, UrlHandlerManager urlHandlerManager) {
34+
public Web3ViewClient(Context context,JsInjectorClient jsInjectorClient, UrlHandlerManager urlHandlerManager) {
35+
this.context = context;
3136
this.jsInjectorClient = jsInjectorClient;
3237
this.urlHandlerManager = urlHandlerManager;
3338
}
@@ -145,8 +150,41 @@ private void injectScriptFile(WebView view) {
145150
}
146151

147152
@Override
148-
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
149-
handler.proceed();
153+
public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
154+
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
155+
String message = "SSL Certificate error.";
156+
switch (error.getPrimaryError()) {
157+
case SslError.SSL_UNTRUSTED:
158+
message = "The certificate authority is not trusted.";
159+
break;
160+
case SslError.SSL_EXPIRED:
161+
message = "The certificate has expired.";
162+
break;
163+
case SslError.SSL_IDMISMATCH:
164+
message = "The certificate Hostname mismatch.";
165+
break;
166+
case SslError.SSL_NOTYETVALID:
167+
message = "The certificate is not yet valid.";
168+
break;
169+
}
170+
message += " Do you want to continue anyway?";
171+
172+
builder.setTitle("SSL Certificate Error");
173+
builder.setMessage(message);
174+
builder.setPositiveButton("continue", new DialogInterface.OnClickListener() {
175+
@Override
176+
public void onClick(DialogInterface dialog, int which) {
177+
handler.proceed();
178+
}
179+
});
180+
builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
181+
@Override
182+
public void onClick(DialogInterface dialog, int which) {
183+
handler.cancel();
184+
}
185+
});
186+
final AlertDialog dialog = builder.create();
187+
dialog.show();
150188
}
151189

152190
public void onReload() {

web3lib/src/main/java/coming/web3/widget/AWalletAlertDialog.java

Lines changed: 0 additions & 152 deletions
This file was deleted.

0 commit comments

Comments
 (0)