下面列出了android.webkit.WebView#getCertificate ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void onPageFinished(WebView view, final String url) {
SslCertificate certificate = view.getCertificate();
if (!TextUtils.isEmpty(restoredUrl)) {
if (restoredUrl.equals(url) && certificate == null) {
// We just restored the previous state. Let's re-use the certificate we restored.
// The reason for that is that WebView doesn't restore the certificate itself.
// Without restoring the certificate manually we'd lose the certificate when
// switching tabs or restoring a previous session for other reasons.
certificate = restoredCertificate;
} else {
// The URL has changed since we restored the last state. Let's just clear all
// restored data because we do not need it anymore.
restoredUrl = null;
restoredCertificate = null;
}
}
if (callback != null) {
callback.onPageFinished(certificate != null);
// The URL which is supplied in onPageFinished() could be fake (see #301), but webview's
// URL is always correct _except_ for error pages
final String viewURL = view.getUrl();
if (!UrlUtils.isInternalErrorURL(viewURL) && viewURL != null) {
callback.onURLChanged(viewURL);
}
}
super.onPageFinished(view, url);
// evaluateJavascript(view,
// "(function() {" +
//
// CLEAR_VISITED_CSS +
//
// "})();");
}
void saveState(WebView view, Bundle bundle) {
final SslCertificate certificate = view.getCertificate();
if (certificate != null) {
bundle.putString(STATE_KEY_URL, view.getUrl());
bundle.putBundle(STATE_KEY_CERTIFICATE, SslCertificate.saveState(certificate));
}
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (mainView.isCurrentTab()) {
isLoading = false;
if (view != null && view.getTitle().equals("No Connection")) {
((MainActivity) MainActivity.getMainActivity()).mSearchView.setText(view.getTitle());
} else if (view != null){
((MainActivity) MainActivity.getMainActivity()).mSearchView.setText(view.getUrl());
}
if (view != null)
MainActivity.sslCertificate = view.getCertificate();
}
try {
if (UserPreferences.getBoolean("instagram_downloads", false) && url != null && url.contains("instagram.com")) {
CSSInjection.injectInstaTheme(SimplicityApplication.getContextOfApplication(), view);
}
if (UserPreferences.getBoolean("facebook_photos", false) && view != null && url != null && url.contains("facebook.com")) {
CSSInjection.injectPhotos(view);
}
if (UserPreferences.getBoolean("dark_mode_web", false)) {
CSSInjection.injectDarkMode(SimplicityApplication.getContextOfApplication(), view);
}
//MainActivity.colorLightWhite();
} catch (NullPointerException i) {
i.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onPageFinished(WebView view, final String url) {
SslCertificate certificate = view.getCertificate();
shouldReadURL = true;
if (!TextUtils.isEmpty(restoredUrl)) {
if (restoredUrl.equals(url) && certificate == null) {
// We just restored the previous state. Let's re-use the certificate we restored.
// The reason for that is that WebView doesn't restore the certificate itself.
// Without restoring the certificate manually we'd lose the certificate when
// switching tabs or restoring a previous session for other reasons.
certificate = restoredCertificate;
} else {
// The URL has changed since we restored the last state. Let's just clear all
// restored data because we do not need it anymore.
restoredUrl = null;
restoredCertificate = null;
}
}
if (callback != null) {
// The page is secure when the url is a localized content or when the certificate isn't null
final boolean isSecure = certificate != null || UrlUtils.isLocalizedContent(view.getUrl());
callback.onPageFinished(isSecure);
String host = null;
try {
host = new URI(url).getHost();
} catch (URISyntaxException e) {
e.printStackTrace();
}
callback.onSecurityChanged(isSecure, host, (certificate != null) ? certificate.getIssuedBy().getOName() : null);
// The URL which is supplied in onPageFinished() could be fake (see #301), but webview's
// URL is always correct _except_ for error pages
final String viewURL = view.getUrl();
if (!UrlUtils.isInternalErrorURL(viewURL) && viewURL != null) {
callback.onURLChanged(viewURL);
}
}
super.onPageFinished(view, url);
view.evaluateJavascript(
"(function() {" +
CLEAR_VISITED_CSS +
"})();",
null);
}