/**
* Shadow - Anonymous web browser for Android devices
* Copyright (C) 2009 Connell Gauld
*
* Thanks to University of Cambridge,
* Alastair Beresford and Andrew Rice
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package uk.ac.cam.cl.dtg.android.tor.Shadow;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.http.client.ClientProtocolException;
import uk.ac.cam.cl.dtg.android.tor.TorProxyLib.ITorProxyControl;
import uk.ac.cam.cl.dtg.android.tor.TorProxyLib.TorProxyLib;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.SearchManager;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.graphics.drawable.PaintDrawable;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.preference.PreferenceManager;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.webkit.PluginData;
import android.webkit.UrlInterceptHandler;
import android.webkit.UrlInterceptRegistry;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.CacheManager.CacheResult;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
/**
* The main browser activity
* @author Connell Gauld
*
*/
public class Shadow extends Activity implements UrlInterceptHandler,
OnClickListener {
// TorProxy service
private ITorProxyControl mControlService = null;
private final IntentFilter torStatusFilter = new IntentFilter(
TorProxyLib.STATUS_CHANGE_INTENT);
private AnonProxy mAnonProxy = null;
// UI elements
private ShadowWebView mWebView = null;
private LinearLayout mNoTorLayout = null;
private LinearLayout mWebLayout = null;
private Button mStartTor = null;
private LinearLayout mCookieIcon = null;
private TextView mTorStatus = null;
// Misc
private Drawable mGenericFavicon = null;
private boolean mInLoad = false;
private Menu mMenu = null;
private boolean mLastIsTorActive = true;
private CookieManager mCookieManager = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set up title bar of window
this.requestWindowFeature(Window.FEATURE_LEFT_ICON);
this.requestWindowFeature(Window.FEATURE_RIGHT_ICON);
this.requestWindowFeature(Window.FEATURE_PROGRESS);
this.requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
// Allow search to start by just typing
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
setContentView(R.layout.main);
// Register to capture all URLs in the WebView
UrlInterceptRegistry.registerHandler(this);
mCookieManager = CookieManager.getInstance(this);
mAnonProxy = new AnonProxy();
// Grab UI elements
mWebView = (ShadowWebView) findViewById(R.id.WebView);
mNoTorLayout = (LinearLayout) findViewById(R.id.NoTorLayout);
mWebLayout = (LinearLayout) findViewById(R.id.WebLayout);
mStartTor = (Button) findViewById(R.id.StartTor);
mCookieIcon = (LinearLayout) findViewById(R.id.CookieIcon);
mTorStatus = (TextView) findViewById(R.id.torStatus);
// Set up UI elements
mStartTor.setOnClickListener(this);
mWebView.setWebViewClient(mWebViewClient);
mWebView.setWebChromeClient(mWebViewChrome);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.getSettings().setLoadsImagesAutomatically(true);
mWebView.setBlockedCookiesView(mCookieIcon);
mCookieIcon.setOnClickListener(this);
// Misc
mGenericFavicon = getResources().getDrawable(
R.drawable.app_web_browser_sm);
// TODO - properly handle initial Intents
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(this);
String starturl = prefs.getString(getString(R.string.pref_homepage),
getString(R.string.default_homepage));
mCookieManager.setBehaviour(prefs.getString("pref_cookiebehaviour",
"whitelist"));
Intent i = getIntent();
if (i != null) {
if (Intent.ACTION_VIEW.equals(i.getAction())) {
onNewIntent(i);
return;
}
}
loadUrl(starturl);
}
// Service connection to TorProxy service
private ServiceConnection mSvcConn = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mControlService = ITorProxyControl.Stub.asInterface(service);
updateTorStatus();
}
@Override
public void onServiceDisconnected(ComponentName name) {
mControlService = null;
updateTorStatus();
}
};
/*
* Set the title bar icon to the supplied bitmap. Yoinked from the Android
* browser
*/
private void setFavicon(Bitmap icon) {
Drawable[] array = new Drawable[2];
PaintDrawable p = new PaintDrawable(Color.WHITE);
p.setCornerRadius(3f);
array[0] = p;
if (icon == null) {
array[1] = mGenericFavicon;
} else {
array[1] = new BitmapDrawable(icon);
}
LayerDrawable d = new LayerDrawable(array);
d.setLayerInset(1, 2, 2, 2, 2);
getWindow().setFeatureDrawable(Window.FEATURE_LEFT_ICON, d);
}
/**
* Yoinked from android source
*
* @param url
* @return
*/
private static String buildTitleUrl(String url) {
String titleUrl = null;
if (url != null) {
try {
// parse the url string
URL urlObj = new URL(url);
if (urlObj != null) {
titleUrl = "";
String protocol = urlObj.getProtocol();
String host = urlObj.getHost();
if (host != null && 0 < host.length()) {
titleUrl = host;
if (protocol != null) {
// if a secure site, add an "https://" prefix!
if (protocol.equalsIgnoreCase("https")) {
titleUrl = protocol + "://" + host;
}
}
}
}
} catch (MalformedURLException e) {
}
}
return titleUrl;
}
static final Pattern ACCEPTED_URI_SCHEMA = Pattern.compile("(?i)"
+ // switch on case insensitive matching
"("
+ // begin group for schema
"(?:http|https|file):\\/\\/"
+ "|(?:data|about|content|javascript):" + ")" + "(.*)");
private String smartUrlFilter(String url) {
String inUrl = url.trim();
boolean hasSpace = inUrl.indexOf(' ') != -1;
Matcher matcher = ACCEPTED_URI_SCHEMA.matcher(inUrl);
if (matcher.matches()) {
if (hasSpace) {
inUrl = inUrl.replace(" ", "%20");
}
// force scheme to lowercase
String scheme = matcher.group(1);
String lcScheme = scheme.toLowerCase();
if (!lcScheme.equals(scheme)) {
return lcScheme + matche
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Android TorProxy和Shadow开源项目.zip项目安卓应用源码下载Android TorProxy和Shadow开源项目.zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发项目技术参考
资源推荐
资源详情
资源评论
收起资源包目录
Android TorProxy和Shadow开源项目.zip项目安卓应用源码下载 (244个子文件)
all-wcprops 3KB
all-wcprops 1KB
all-wcprops 1011B
all-wcprops 1010B
all-wcprops 704B
all-wcprops 641B
all-wcprops 583B
all-wcprops 583B
all-wcprops 482B
all-wcprops 474B
all-wcprops 474B
all-wcprops 462B
all-wcprops 365B
all-wcprops 285B
all-wcprops 250B
all-wcprops 222B
all-wcprops 133B
all-wcprops 126B
all-wcprops 126B
all-wcprops 122B
all-wcprops 122B
all-wcprops 114B
all-wcprops 114B
all-wcprops 110B
all-wcprops 110B
all-wcprops 107B
all-wcprops 107B
all-wcprops 105B
all-wcprops 105B
all-wcprops 103B
all-wcprops 103B
all-wcprops 100B
all-wcprops 100B
all-wcprops 100B
all-wcprops 99B
all-wcprops 97B
all-wcprops 97B
all-wcprops 97B
all-wcprops 97B
all-wcprops 86B
resources.ap_ 46KB
resources.ap_ 27KB
TorProxy.apk 970KB
Shadow.apk 83KB
.classpath 434B
.classpath 339B
COPYING 18KB
classes.dex 1.91MB
classes.dex 72KB
entries 3KB
entries 2KB
entries 1KB
entries 1KB
entries 1KB
entries 896B
entries 879B
entries 705B
entries 698B
entries 687B
entries 669B
entries 617B
entries 541B
entries 407B
entries 391B
entries 376B
entries 291B
entries 286B
entries 271B
entries 271B
entries 265B
entries 264B
entries 264B
entries 262B
entries 260B
entries 260B
entries 252B
entries 252B
entries 252B
entries 248B
entries 248B
entries 247B
entries 245B
entries 245B
entries 241B
entries 241B
entries 241B
entries 238B
entries 237B
entries 229B
home 2KB
error.htm 3KB
about.htm 2KB
about.htm 2KB
unknownhosterror.htm 2KB
sslerror.htm 2KB
Shadow.java 20KB
SSLSocketFactory.java 15KB
AnonProxy.java 10KB
PostProcessor.java 8KB
CookieManager.java 7KB
共 244 条
- 1
- 2
- 3
资源评论
yxkfw
- 粉丝: 81
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- YOLO-yolo资源
- 适用于 Java 项目的 Squash 客户端库 .zip
- 适用于 Java 的 Chef 食谱.zip
- Simulink仿真快速入门与实践基础教程
- js-leetcode题解之179-largest-number.js
- js-leetcode题解之174-dungeon-game.js
- Matlab工具箱使用与实践基础教程
- js-leetcode题解之173-binary-search-tree-iterator.js
- js-leetcode题解之172-factorial-trailing-zeroes.js
- js-leetcode题解之171-excel-sheet-column-number.js
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功