Java Code Examples for com.tencent.smtt.sdk.WebView#getUrl()

The following examples show how to use com.tencent.smtt.sdk.WebView#getUrl() . 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: WebViewFragment.java    From Dainty with Apache License 2.0 6 votes vote down vote up
private void blockAds(WebView view) {
    String tags = view.getUrl();
    //noinspection MismatchedQueryAndUpdateOfStringBuilder
    StringBuilder sb = new StringBuilder();
    sb.append("javascript: ");
    String[] allTag = tags.split(",");
    for (String tag : allTag) {
        String adTag = tag;
        if (adTag.trim().length() > 0) {
            adTag = adTag.trim();
            if (adTag.contains("#")) {
                adTag = adTag.substring(adTag.indexOf("#") + 1);
                sb.append("document.getElementById(\'").append(adTag).append("\').remove();");

            } else if (adTag.contains(".")) {
                adTag = adTag.substring(adTag.indexOf(".") + 1);
                sb.append("var esc=document.getElementsByClassName(\'").append(adTag).append("\');for (var i = esc.length - 1; i >= 0; i--){esc[i].remove();};");

            } else {
                sb.append("var esc=document.getElementsByTagName(\'").append(adTag).append("\');for (var i = esc.length - 1; i >= 0; i--){esc[i].remove();};");
            }
        }
    }
}
 
Example 2
Source File: WebViewCacheWrapper.java    From YCWebView with Apache License 2.0 5 votes vote down vote up
@Override
public void loadUrl(WebView webView, String url) {
    if (!isValidUrl(url)) {
        return;
    }
    webView.loadUrl(url);
    mReferer = webView.getUrl();
    mOrigin = getOriginUrl(mReferer);
    mUserAgent = webView.getSettings().getUserAgentString();
}
 
Example 3
Source File: WebViewCacheWrapper.java    From YCWebView with Apache License 2.0 5 votes vote down vote up
@Override
public void loadUrl(WebView webView, String url, Map<String, String> additionalHttpHeaders) {
    if (!isValidUrl(url)) {
        return;
    }
    webView.loadUrl(url, additionalHttpHeaders);
    mReferer = webView.getUrl();
    mOrigin = getOriginUrl(mReferer);
    mUserAgent = webView.getSettings().getUserAgentString();
}
 
Example 4
Source File: RNX5WebViewManager.java    From react-native-x5 with MIT License 4 votes vote down vote up
@ReactProp(name = "source")
public void setSource(WebView view, @Nullable ReadableMap source) {
    if (source != null) {
        if (source.hasKey("html")) {
            String html = source.getString("html");
            if (source.hasKey("baseUrl")) {
                view.loadDataWithBaseURL(
                        source.getString("baseUrl"), html, HTML_MIME_TYPE, HTML_ENCODING, null);
            } else {
                view.loadData(html, HTML_MIME_TYPE, HTML_ENCODING);
            }
            return;
        }
        if (source.hasKey("uri")) {
            String url = source.getString("uri");
            String previousUrl = view.getUrl();
            if (previousUrl != null && previousUrl.equals(url)) {
                return;
            }
            if (source.hasKey("method")) {
                String method = source.getString("method");
                if (method.equals(HTTP_METHOD_POST)) {
                    byte[] postData = null;
                    if (source.hasKey("body")) {
                        String body = source.getString("body");
                        try {
                            postData = body.getBytes("UTF-8");
                        } catch (UnsupportedEncodingException e) {
                            postData = body.getBytes();
                        }
                    }
                    if (postData == null) {
                        postData = new byte[0];
                    }
                    view.postUrl(url, postData);
                    return;
                }
            }
            HashMap<String, String> headerMap = new HashMap<>();
            if (source.hasKey("headers")) {
                ReadableMap headers = source.getMap("headers");
                ReadableMapKeySetIterator iter = headers.keySetIterator();
                while (iter.hasNextKey()) {
                    String key = iter.nextKey();
                    if ("user-agent".equals(key.toLowerCase(Locale.ENGLISH))) {
                        if (view.getSettings() != null) {
                            view.getSettings().setUserAgentString(headers.getString(key));
                        }
                    } else {
                        headerMap.put(key, headers.getString(key));
                    }
                }
            }
            view.loadUrl(url, headerMap);
            return;
        }
    }
    view.loadUrl(BLANK_URL);
}