Search in sources :

Example 1 with WPWebChromeClient

use of org.wordpress.android.util.helpers.WPWebChromeClient in project WordPress-Android by wordpress-mobile.

the class WPWebViewActivity method configureWebView.

@SuppressLint("SetJavaScriptEnabled")
@Override
protected void configureWebView() {
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setDomStorageEnabled(true);
    WebViewClient webViewClient;
    Bundle extras = getIntent().getExtras();
    // Configure the allowed URLs if available
    ArrayList<String> allowedURL = null;
    if (extras.getBoolean(DISABLE_LINKS_ON_PAGE, false)) {
        String addressToLoad = extras.getString(URL_TO_LOAD);
        String authURL = extras.getString(AUTHENTICATION_URL);
        allowedURL = new ArrayList<>();
        if (!TextUtils.isEmpty(addressToLoad)) {
            allowedURL.add(addressToLoad);
        }
        if (!TextUtils.isEmpty(authURL)) {
            allowedURL.add(authURL);
        }
        if (extras.getStringArray(ALLOWED_URLS) != null) {
            String[] urls = extras.getStringArray(ALLOWED_URLS);
            for (String currentURL : urls) {
                allowedURL.add(currentURL);
            }
        }
    }
    if (getIntent().hasExtra(LOCAL_BLOG_ID)) {
        SiteModel site = mSiteStore.getSiteByLocalId(getIntent().getIntExtra(LOCAL_BLOG_ID, -1));
        if (site == null) {
            AppLog.e(AppLog.T.UTILS, "No valid blog passed to WPWebViewActivity");
            finish();
        }
        webViewClient = new WPWebViewClient(site, mAccountStore.getAccessToken(), allowedURL);
    } else {
        webViewClient = new URLFilteredWebViewClient(allowedURL);
    }
    mWebView.setWebViewClient(webViewClient);
    mWebView.setWebChromeClient(new WPWebChromeClient(this, (ProgressBar) findViewById(R.id.progress_bar)));
}
Also used : WPWebViewClient(org.wordpress.android.util.WPWebViewClient) Bundle(android.os.Bundle) SiteModel(org.wordpress.android.fluxc.model.SiteModel) URLFilteredWebViewClient(org.wordpress.android.util.URLFilteredWebViewClient) ProgressBar(android.widget.ProgressBar) WPWebChromeClient(org.wordpress.android.util.helpers.WPWebChromeClient) WebViewClient(android.webkit.WebViewClient) WPWebViewClient(org.wordpress.android.util.WPWebViewClient) URLFilteredWebViewClient(org.wordpress.android.util.URLFilteredWebViewClient) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Bundle (android.os.Bundle)1 WebViewClient (android.webkit.WebViewClient)1 ProgressBar (android.widget.ProgressBar)1 SiteModel (org.wordpress.android.fluxc.model.SiteModel)1 URLFilteredWebViewClient (org.wordpress.android.util.URLFilteredWebViewClient)1 WPWebViewClient (org.wordpress.android.util.WPWebViewClient)1 WPWebChromeClient (org.wordpress.android.util.helpers.WPWebChromeClient)1