-
Notifications
You must be signed in to change notification settings - Fork 17
/
WebClientv11.java
executable file
·42 lines (36 loc) · 1.29 KB
/
WebClientv11.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.tobykurien.google_news.webviewclient;
import java.io.ByteArrayInputStream;
import com.tobykurien.google_news.GoogleNewsActivity;
import android.annotation.TargetApi;
import android.app.Activity;
import android.net.Uri;
import android.os.Build;
import android.util.Log;
import android.view.View;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
/**
* WebViewClient for Android 3.0+
*
* @author toby
*/
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class WebClientv11 extends WebClient {
public WebClientv11(GoogleNewsActivity activity, WebView wv, View pd) {
super(activity, wv, pd);
}
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
// Block 3rd party requests (i.e. scripts/iframes/etc. outside Google's domains)
// and also any unencrypted connections
if (!url.startsWith("data:") &&
(!url.startsWith("https://") ||
!isGoogleSite(Uri.parse(url)))) {
Uri uri = Uri.parse(url);
Log.d("wvc11", "Blocking " + url);
return new WebResourceResponse("text/plain", "utf-8",
new ByteArrayInputStream(("[blocked " + uri.getHost() + "]").getBytes()));
}
return super.shouldInterceptRequest(view, url);
}
}