@Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { /* * in theory this should be checked to make sure it's not null but if there is some failure * in the association then usage of webViewProxy should trigger a NPE to make sure the issue * is not ignored */ KrollProxy webViewProxy = this.webView.getProxy(); KrollDict data = new KrollDict(); data.put(TiC.ERROR_PROPERTY_CODE, error.getPrimaryError()); webView.getProxy().fireSyncEvent(TiC.EVENT_SSL_ERROR, data); boolean ignoreSslError = false; try { ignoreSslError = webViewProxy.getProperties().optBoolean(TiC.PROPERTY_WEBVIEW_IGNORE_SSL_ERROR, false); } catch(IllegalArgumentException e) { Log.e(TAG, TiC.PROPERTY_WEBVIEW_IGNORE_SSL_ERROR + " property does not contain a boolean value, ignoring"); } if (ignoreSslError == true) { Log.w(TAG, "ran into SSL error but ignoring..."); handler.proceed(); } else { Log.e(TAG, "SSL error occurred: " + error.toString()); handler.cancel(); } }
/** * Notify the host application that an SSL error occurred while loading a resource. * The host application must call either handler.cancel() or handler.proceed(). * Note that the decision may be retained for use in response to future SSL errors. * The default behavior is to cancel the load. * * @param view The WebView that is initiating the callback. * @param handler An SslErrorHandler object that will handle the user's response. * @param error The SSL error object. */ @TargetApi(8) @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { final String packageName = parentEngine.cordova.getActivity().getPackageName(); final PackageManager pm = parentEngine.cordova.getActivity().getPackageManager(); ApplicationInfo appInfo; try { appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA); if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) { // debug = true handler.proceed(); return; } else { // debug = false super.onReceivedSslError(view, handler, error); } } catch (NameNotFoundException e) { // When it doubt, lock it out! super.onReceivedSslError(view, handler, error); } }
private void preSetting(){ //加载服务器上的页面 mWebView.getSettings().setJavaScriptEnabled(true); mWebView.getSettings().setBlockNetworkImage(false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mWebView.getSettings().setMixedContentMode( WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE); } mWebView.setWebViewClient(new WebViewClient() { @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { // TODO Auto-generated method stub // handler.cancel();// Android默认的处理方式 handler.proceed();// 接受所有网站的证书 // handleMessage(Message msg);// 进行其他处理 } }); //加载本地中的html //myWebView.loadUrl("file:///android_asset/www/test2.html"); //加上下面这段代码可以使网页中的链接不以浏览器的方式打开 mWebView.setWebViewClient(new WebViewClient()); //允许使用javascript mWebView.getSettings().setJavaScriptEnabled(true); }
@Override protected void initView() { String name = getIntent().getStringExtra("name"); String url = getIntent().getStringExtra("url"); //设置沉浸式状态栏 setStatus(); iv_search.setVisibility(View.VISIBLE); //设置沉浸式状态栏背景 bar_layout.setBackgroundResource(R.color.black_alpha_5); title_text.setText(name); wv.setWebViewClient(new WebViewClient() { @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { super.onReceivedSslError(view, handler, error); handler.proceed(); } }); wv.getSettings().setJavaScriptEnabled(true); wv.loadUrl(url); }
private WebViewClient c() { Object obj = 1; Object obj2 = null; try { if (WebViewClient.class.getMethod("onReceivedSslError", new Class[]{WebView.class, SslErrorHandler.class, SslError.class}) == null) { obj = null; } obj2 = obj; } catch (NoSuchMethodException e) { } catch (IllegalArgumentException e2) { } if (obj2 != null) { Log.i(a, "has method onReceivedSslError : "); return new q(this); } Log.i(a, "has no method onReceivedSslError : "); return new a(); }
/** * Notify the host application that an SSL error occurred while loading a resource. * The host application must call either handler.cancel() or handler.proceed(). * Note that the decision may be retained for use in response to future SSL errors. * The default behavior is to cancel the load. * * @param view The WebView that is initiating the callback. * @param handler An SslErrorHandler object that will handle the user's response. * @param error The SSL error object. */ @TargetApi(8) @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { final String packageName = this.cordova.getActivity().getPackageName(); final PackageManager pm = this.cordova.getActivity().getPackageManager(); ApplicationInfo appInfo; try { appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA); if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) { // debug = true handler.proceed(); return; } else { // debug = false super.onReceivedSslError(view, handler, error); } } catch (NameNotFoundException e) { // When it doubt, lock it out! super.onReceivedSslError(view, handler, error); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_load_url); webview = (WebView) findViewById(R.id.webview); webview.loadUrl("https://www.sawerly.com/beta/cms/3/en"); webview.getSettings().setUseWideViewPort(true); webview.getSettings().setJavaScriptEnabled(true); // webview.measure(100,100); webview.setWebViewClient(new WebViewClient(){ @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { super.onReceivedSslError(view, handler, error); handler.proceed(); } }); // webview.setWebChromeClient(new WebChromeClient()); }
@Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { handler.cancel(); // WebView can try to load the favicon for a bad page when you set a new URL. If we then // loadErrorPage() again, WebView tries to load the favicon again. We end up in onReceivedSSlError() // again, and we get an infinite loop of reloads (we also erroneously show the favicon URL // in the toolbar, but that's less noticeable). Hence we check whether this error is from // the desired page, or a page resource: if (error.getUrl().equals(currentPageURL)) { TelemetryWrapper.sslErrorEvent(true, error); ErrorPage.loadErrorPage(view, error.getUrl(), WebViewClient.ERROR_FAILED_SSL_HANDSHAKE); } else { TelemetryWrapper.sslErrorEvent(false, error); } }
/** * Show untrusted cert dialog */ public void showUntrustedCertDialog( X509Certificate x509Certificate, SslError error, SslErrorHandler handler ) { // Show a dialog with the certificate info SslUntrustedCertDialog dialog; if (x509Certificate == null) { dialog = SslUntrustedCertDialog.newInstanceForEmptySslError(error, handler); } else { dialog = SslUntrustedCertDialog. newInstanceForFullSslError(x509Certificate, error, handler); } FragmentManager fm = getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.addToBackStack(null); dialog.show(ft, UNTRUSTED_CERT_DIALOG_TAG); }
public static SslUntrustedCertDialog newInstanceForFullSslError(X509Certificate cert, SslError error, SslErrorHandler handler) { if (cert == null) { throw new IllegalArgumentException("Trying to create instance with parameter cert == null"); } if (error == null) { throw new IllegalArgumentException("Trying to create instance with parameter error == null"); } if (handler == null) { throw new IllegalArgumentException("Trying to create instance with parameter handler == null"); } SslUntrustedCertDialog dialog = new SslUntrustedCertDialog(); dialog.m509Certificate = cert; dialog.mHandler = handler; dialog.mErrorViewAdapter = new SslErrorViewAdapter(error); dialog.mCertificateViewAdapter = new X509CertificateViewAdapter(cert); return dialog; }