use of android.webkit.SslErrorHandler in project habpanelviewer by vbier.
the class ClientWebView method initialize.
synchronized void initialize(final IConnectionListener cl) {
setWebChromeClient(new WebChromeClient() {
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
if (consoleMessage.message().contains("SSE error, closing EventSource")) {
cl.disconnected();
}
return super.onConsoleMessage(consoleMessage);
}
});
setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (isHabPanelUrl(url)) {
evaluateJavascript("angular.element(document.body).scope().$root.kioskMode", s -> {
mKioskMode = Boolean.parseBoolean(s);
Log.d(TAG, "HABPanel page loaded. kioskMode=" + mKioskMode);
});
}
}
@Override
public void onReceivedSslError(WebView view, final SslErrorHandler handler, final SslError error) {
Log.d(TAG, "onReceivedSslError: " + error.getUrl());
SslCertificate cert = error.getCertificate();
if (ConnectionUtil.isTrusted(error.getCertificate())) {
Log.d(TAG, "certificate is trusted: " + error.getUrl());
handler.proceed();
return;
}
String h;
try {
URL url = new URL(error.getUrl());
h = url.getHost();
} catch (MalformedURLException e) {
h = getContext().getString(R.string.unknownHost);
}
final String host = h;
String r = getContext().getString(R.string.notValid);
switch(error.getPrimaryError()) {
case SslError.SSL_DATE_INVALID:
r = getContext().getString(R.string.invalidDate);
break;
case SslError.SSL_EXPIRED:
r = getContext().getString(R.string.expired);
break;
case SslError.SSL_IDMISMATCH:
r = getContext().getString(R.string.hostnameMismatch);
break;
case SslError.SSL_NOTYETVALID:
r = getContext().getString(R.string.notYetValid);
break;
case SslError.SSL_UNTRUSTED:
r = getContext().getString(R.string.untrusted);
break;
}
final String reason = r;
String c = getContext().getString(R.string.issuedBy) + cert.getIssuedBy().getDName() + "<br/>";
c += getContext().getString(R.string.issuedTo) + cert.getIssuedTo().getDName() + "<br/>";
c += getContext().getString(R.string.validFrom) + SimpleDateFormat.getDateInstance().format(cert.getValidNotBeforeDate()) + "<br/>";
c += getContext().getString(R.string.validUntil) + SimpleDateFormat.getDateInstance().format(cert.getValidNotAfterDate()) + "<br/>";
final String certInfo = c;
new AlertDialog.Builder(ClientWebView.this.getContext()).setTitle(getContext().getString(R.string.certInvalid)).setMessage(getContext().getString(R.string.sslCert) + "https://" + host + " " + reason + ".\n\n" + certInfo.replaceAll("<br/>", "\n") + "\n" + getContext().getString(R.string.storeSecurityException)).setIcon(android.R.drawable.ic_dialog_alert).setPositiveButton(android.R.string.yes, (dialog, whichButton) -> {
try {
ConnectionUtil.addCertificate(error.getCertificate());
} catch (Exception e) {
e.printStackTrace();
}
handler.proceed();
}).setNegativeButton(android.R.string.no, (dialog, whichButton) -> loadData("<html><body><h1>" + getContext().getString(R.string.certInvalid) + "</h1><h2>" + getContext().getString(R.string.sslCert) + "https://" + host + " " + reason + ".</h2>" + certInfo + "</body></html>", "text/html", "UTF-8")).show();
}
@Override
public void onReceivedHttpAuthRequest(WebView view, final HttpAuthHandler handler, final String host, final String realm) {
AlertDialog.Builder dialog = new AlertDialog.Builder(getContext()).setCancelable(false).setTitle(R.string.login_required).setMessage(getContext().getString(R.string.host_realm, host, realm)).setView(R.layout.dialog_login).setPositiveButton(R.string.okay, (dialog12, id) -> {
EditText userT = ((AlertDialog) dialog12).findViewById(R.id.username);
EditText passT = ((AlertDialog) dialog12).findViewById(R.id.password);
handler.proceed(userT.getText().toString(), passT.getText().toString());
}).setNegativeButton(R.string.cancel, (dialog1, which) -> handler.cancel());
final AlertDialog alert = dialog.create();
alert.show();
}
});
setOnTouchListener((v, event) -> (event.getAction() == MotionEvent.ACTION_MOVE && mDraggingPrevented));
CookieManager.getInstance().setAcceptCookie(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
CookieManager.getInstance().setAcceptThirdPartyCookies(this, true);
}
WebSettings webSettings = getSettings();
webSettings.setDomStorageEnabled(true);
final IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
getContext().registerReceiver(mNetworkReceiver, intentFilter);
}
use of android.webkit.SslErrorHandler in project IbookerEditorAndroid by zrunker.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ibookerEditorView = findViewById(R.id.ibookereditorview);
ibookerEditorView.setIEEditViewBackgroundColor(Color.parseColor("#DDDDDD")).setIEEditViewIbookerEdHint("书客编辑器").setIbookerEditorImgPreviewListener(new IbookerEditorWebView.IbookerEditorImgPreviewListener() {
@Override
public void onIbookerEditorImgPreview(String currentPath, int position, ArrayList<String> imgAllPathList) {
Toast.makeText(MainActivity.this, currentPath + "===" + position + "===" + imgAllPathList.toString(), Toast.LENGTH_LONG).show();
Intent intent = new Intent(MainActivity.this, ImgVPagerActivity.class);
intent.putExtra("currentPath", currentPath);
intent.putExtra("position", position);
intent.putStringArrayListExtra("imgAllPathList", imgAllPathList);
startActivity(intent);
}
}).setIbookerEditorWebViewUrlLoadingListener(new IbookerEditorWebView.IbookerEditorWebViewUrlLoadingListener() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
return true;
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(request.getUrl().toString()));
startActivity(intent);
}
return true;
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
}
@Override
public void onPageFinished(WebView view, String url) {
}
});
ibookerEditorView.getIbookerEditorVpView().getEditView().getIbookerEd().setText("[链接描述](http://ips.ifeng.com/video19.ifeng.com/video09/2018/09/28/p2749834-102-998769-221938.mp4?ifsign=1&vid=2f24cc82-9236-4289-adcc-5e34ae569cc8&uid=1516537011039_hyemhv7718&from=weMedia_pc&pver=weMediaHTML5Player_v1.0.0&sver=&se=%E9%A3%9E%E7%A2%9F%E8%AF%B4&cat=8622&ptype=8622&platform=pc&sourceType=h5&dt=1538135880000&gid=SLTFYWYkO4jp&sign=16536514b3d291920ac6253872661e9c&tm=1538206173419)\n" + " " + "\"This come from string. You can insert inline formula:\" +\n" + " \" \\\\(ax^2 + bx + c = 0\\\\) \" +\n" + " \"or displayed formula: $$\\\\sum_{i=0}^n i^2 = \\\\frac{(n^2+n)(2n+1)}{6}$$\";" + "### 书客编辑器\n***\n书客编辑器从这里开始,我们的每一次开始,都那么小心翼翼,这一次如果可以的话不妨就现在开始试试。\n\n书客编辑器,简易,高效。轻轻松松记录你的每一刻。\n>书客编辑器不仅仅是为了“还好”而设计\n\n“还好”,那就意味着产品不够好;“很好”,那就意味着还需要努力;产品目标只为“最好”。\n```\nWish you every day to be beautiful.\n```\n书客编辑器期待你的加入!!!\n\n![书客编辑器](http://editor.ibooker.cc/resources/images-logos/ic_launcher_96.png)\n![书客创作](http://www.ibookerfile.cc/upload/images/acontents/1_1519218464761acontentimage.jpg)");
}
use of android.webkit.SslErrorHandler in project WeexErosFramework by bmfe.
the class BMWebView method initWebView.
private void initWebView(WebView wv) {
WebSettings settings = wv.getSettings();
settings.setJavaScriptEnabled(true);
settings.setAppCacheEnabled(true);
settings.setUseWideViewPort(true);
settings.setDomStorageEnabled(true);
settings.setSupportZoom(false);
settings.setBuiltInZoomControls(false);
wv.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
WXLogUtils.v("tag", "onPageOverride " + url);
return true;
}
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
WXLogUtils.v("tag", "onPageStarted " + url);
if (BMWebView.this.mOnPageListener != null) {
BMWebView.this.mOnPageListener.onPageStart(url);
}
}
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
WXLogUtils.v("tag", "onPageFinished " + url);
if (BMWebView.this.mOnPageListener != null) {
BMWebView.this.mOnPageListener.onPageFinish(url, view.canGoBack(), view.canGoForward());
}
}
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
if (BMWebView.this.mOnErrorListener != null) {
BMWebView.this.mOnErrorListener.onError("error", "page error");
}
}
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
super.onReceivedHttpError(view, request, errorResponse);
if (BMWebView.this.mOnErrorListener != null) {
BMWebView.this.mOnErrorListener.onError("error", "http error");
}
}
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
super.onReceivedSslError(view, handler, error);
if (BMWebView.this.mOnErrorListener != null) {
BMWebView.this.mOnErrorListener.onError("error", "ssl error");
}
}
});
wv.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
BMWebView.this.showWebView(newProgress == 100);
BMWebView.this.showProgressBar(newProgress != 100);
WXLogUtils.v("tag", "onPageProgressChanged " + newProgress);
}
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
if (BMWebView.this.mOnPageListener != null) {
BMWebView.this.mOnPageListener.onReceivedTitle(view.getTitle());
}
}
});
}
use of android.webkit.SslErrorHandler in project WeexErosFramework by bmfe.
the class BMWXWebView method initWebView.
private void initWebView(WebView wv) {
WebSettings settings = wv.getSettings();
settings.setAppCacheEnabled(true);
settings.setUseWideViewPort(true);
settings.setDomStorageEnabled(true);
settings.setSupportZoom(false);
settings.setBuiltInZoomControls(false);
addWebJavascriptInterface(wv);
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
WXLogUtils.v("tag", "onPageOverride " + url);
return true;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
WXLogUtils.v("tag", "onPageStarted " + url);
if (mOnPageListener != null) {
mOnPageListener.onPageStart(url);
}
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
WXLogUtils.v("tag", "onPageFinished " + url);
if (mOnPageListener != null) {
mOnPageListener.onPageFinish(url, view.canGoBack(), view.canGoForward());
}
}
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
if (mOnErrorListener != null) {
// mOnErrorListener.onError("error", "page error code:" + error.getErrorCode() + ", desc:" + error.getDescription() + ", url:" + request.getUrl());
mOnErrorListener.onError("error", "page error");
}
}
@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
super.onReceivedHttpError(view, request, errorResponse);
if (mOnErrorListener != null) {
mOnErrorListener.onError("error", "http error");
}
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
super.onReceivedSslError(view, handler, error);
if (mOnErrorListener != null) {
mOnErrorListener.onError("error", "ssl error");
}
}
});
wv.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
showWebView(newProgress == 100);
showProgressBar(newProgress != 100);
WXLogUtils.v("tag", "onPageProgressChanged " + newProgress);
}
@Override
public void onReceivedTitle(WebView view, String title) {
super.onReceivedTitle(view, title);
if (mOnPageListener != null) {
mOnPageListener.onReceivedTitle(view.getTitle());
}
}
@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
mContentHeight = Integer.parseInt(message);
mContentHeight = mContentHeight / (WXViewUtils.defaultPixelScaleFactor(getView().getContext()) * 2);
Map<String, String> params = new HashMap<>();
params.put("contentHeight", mContentHeight + "");
if (mWXWeb != null) {
mWXWeb.fireEvent("bmPageFinish", params);
}
result.confirm();
return true;
}
});
}
use of android.webkit.SslErrorHandler in project android-app-common-tasks by multidots.
the class OAuthActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.asn_activity_oauth);
final String paramUrlToLoad = getIntent().getStringExtra(PARAM_URL_TO_LOAD);
final String paramCallback = getIntent().getStringExtra(PARAM_CALLBACK);
if (TextUtils.isEmpty(paramUrlToLoad)) {
throw new IllegalArgumentException("required PARAM_URL_TO_LOAD");
}
if (TextUtils.isEmpty(paramCallback)) {
throw new IllegalArgumentException("required PARAM_CALLBACK");
}
WebView webView = (WebView) findViewById(R.id.web_view);
final View progressContainer = findViewById(R.id.progress_container);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
progressContainer.setVisibility(View.VISIBLE);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
progressContainer.setVisibility(View.GONE);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.contains(paramCallback)) {
Intent intent = new Intent();
intent.setData(Uri.parse(url));
setResult(RESULT_OK, intent);
finish();
return true;
}
return super.shouldOverrideUrlLoading(view, url);
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
Intent intent = new Intent();
intent.setAction(description);
setResult(RESULT_CANCELED, intent);
finish();
}
});
webView.loadUrl(paramUrlToLoad);
}
Aggregations