Java Code Examples for android.webkit.WebView#getCertificate()

The following examples show how to use android.webkit.WebView#getCertificate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FocusWebViewClient.java    From firefox-echo-show with Mozilla Public License 2.0 5 votes vote down vote up
@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 +
//
//                "})();");
    }
 
Example 2
Source File: FocusWebViewClient.java    From focus-android with Mozilla Public License 2.0 5 votes vote down vote up
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));
    }
}
 
Example 3
Source File: SimplicityWebViewClient.java    From SimplicityBrowser with MIT License 5 votes vote down vote up
@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();
    }
}
 
Example 4
Source File: FocusWebViewClient.java    From focus-android with Mozilla Public License 2.0 4 votes vote down vote up
@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);
}