|
|
|
@ -4,10 +4,22 @@
@@ -4,10 +4,22 @@
|
|
|
|
|
|
|
|
|
|
package acr.browser.lightning; |
|
|
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
|
import java.io.File; |
|
|
|
|
import java.io.FileNotFoundException; |
|
|
|
|
import java.io.FileOutputStream; |
|
|
|
|
import java.io.FileWriter; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.net.URISyntaxException; |
|
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint; |
|
|
|
|
import android.app.Activity; |
|
|
|
|
import android.app.AlertDialog; |
|
|
|
|
import android.content.*; |
|
|
|
|
import android.content.ActivityNotFoundException; |
|
|
|
|
import android.content.Context; |
|
|
|
|
import android.content.DialogInterface; |
|
|
|
|
import android.content.Intent; |
|
|
|
|
import android.content.SharedPreferences; |
|
|
|
|
import android.graphics.Bitmap; |
|
|
|
|
import android.graphics.BitmapFactory; |
|
|
|
|
import android.graphics.ColorMatrix; |
|
|
|
@ -26,16 +38,21 @@ import android.view.GestureDetector.SimpleOnGestureListener;
@@ -26,16 +38,21 @@ import android.view.GestureDetector.SimpleOnGestureListener;
|
|
|
|
|
import android.view.MotionEvent; |
|
|
|
|
import android.view.View; |
|
|
|
|
import android.view.View.OnTouchListener; |
|
|
|
|
import android.webkit.*; |
|
|
|
|
import android.webkit.CookieManager; |
|
|
|
|
import android.webkit.GeolocationPermissions; |
|
|
|
|
import android.webkit.HttpAuthHandler; |
|
|
|
|
import android.webkit.SslErrorHandler; |
|
|
|
|
import android.webkit.ValueCallback; |
|
|
|
|
import android.webkit.WebChromeClient; |
|
|
|
|
import android.webkit.WebResourceRequest; |
|
|
|
|
import android.webkit.WebResourceResponse; |
|
|
|
|
import android.webkit.WebSettings; |
|
|
|
|
import android.webkit.WebSettings.LayoutAlgorithm; |
|
|
|
|
import android.webkit.WebSettings.PluginState; |
|
|
|
|
import android.webkit.WebView; |
|
|
|
|
import android.webkit.WebViewClient; |
|
|
|
|
import android.widget.EditText; |
|
|
|
|
import android.widget.LinearLayout; |
|
|
|
|
import org.apache.http.util.ByteArrayBuffer; |
|
|
|
|
|
|
|
|
|
import java.io.*; |
|
|
|
|
import java.net.*; |
|
|
|
|
|
|
|
|
|
public class LightningView { |
|
|
|
|
|
|
|
|
@ -648,108 +665,7 @@ public class LightningView {
@@ -648,108 +665,7 @@ public class LightningView {
|
|
|
|
|
ByteArrayInputStream EMPTY = new ByteArrayInputStream("".getBytes()); |
|
|
|
|
return new WebResourceResponse("text/plain", "utf-8", EMPTY); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
boolean useProxy = mPreferences.getBoolean(PreferenceConstants.USE_PROXY, false); |
|
|
|
|
boolean mDoLeakHardening = false; |
|
|
|
|
|
|
|
|
|
if (!useProxy) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!mDoLeakHardening) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// now we are going to proxy!
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
URL uURl = new URL(url); |
|
|
|
|
|
|
|
|
|
Proxy proxy = null; |
|
|
|
|
|
|
|
|
|
String host = mPreferences.getString(PreferenceConstants.USE_PROXY_HOST, |
|
|
|
|
"localhost"); |
|
|
|
|
int port = mPreferences.getInt(PreferenceConstants.USE_PROXY_PORT, 8118); |
|
|
|
|
proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port)); |
|
|
|
|
|
|
|
|
|
HttpURLConnection.setFollowRedirects(true); |
|
|
|
|
HttpURLConnection conn = (HttpURLConnection) uURl.openConnection(proxy); |
|
|
|
|
conn.setInstanceFollowRedirects(true); |
|
|
|
|
conn.setRequestProperty("User-Agent", mSettings.getUserAgentString()); |
|
|
|
|
|
|
|
|
|
// conn.setRequestProperty("Transfer-Encoding", "chunked");
|
|
|
|
|
// conn.setUseCaches(false);
|
|
|
|
|
|
|
|
|
|
final int bufferSize = 1024 * 32; |
|
|
|
|
conn.setChunkedStreamingMode(bufferSize); |
|
|
|
|
|
|
|
|
|
String cType = conn.getContentType(); |
|
|
|
|
String cEnc = conn.getContentEncoding(); |
|
|
|
|
int connLen = conn.getContentLength(); |
|
|
|
|
|
|
|
|
|
if (cType != null) { |
|
|
|
|
String[] ctArray = cType.split(";"); |
|
|
|
|
cType = ctArray[0].trim(); |
|
|
|
|
|
|
|
|
|
if (cEnc == null && ctArray.length > 1) { |
|
|
|
|
cEnc = ctArray[1]; |
|
|
|
|
if (cEnc.indexOf('=') != -1) { |
|
|
|
|
cEnc = cEnc.split("=")[1].trim(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (connLen <= 0) { |
|
|
|
|
connLen = 2048; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (cType != null && cType.startsWith("text")) { |
|
|
|
|
InputStream fStream; |
|
|
|
|
|
|
|
|
|
BufferedInputStream bis = new BufferedInputStream(conn.getInputStream()); |
|
|
|
|
ByteArrayBuffer baf = new ByteArrayBuffer(connLen); |
|
|
|
|
int read; |
|
|
|
|
int bufSize = 2048; |
|
|
|
|
byte[] buffer = new byte[bufSize]; |
|
|
|
|
while (true) { |
|
|
|
|
read = bis.read(buffer); |
|
|
|
|
if (read == -1) { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
baf.append(buffer, 0, read); |
|
|
|
|
} |
|
|
|
|
byte[] plainText = baf.toByteArray(); |
|
|
|
|
|
|
|
|
|
fStream = new ByteArrayInputStream(plainText); |
|
|
|
|
|
|
|
|
|
fStream = new ReplacingInputStream(new ByteArrayInputStream(plainText), |
|
|
|
|
"poster=".getBytes(), "foo=".getBytes()); |
|
|
|
|
fStream = new ReplacingInputStream(fStream, "Poster=".getBytes(), |
|
|
|
|
"foo=".getBytes()); |
|
|
|
|
fStream = new ReplacingInputStream(fStream, "Poster=".getBytes(), |
|
|
|
|
"foo=".getBytes()); |
|
|
|
|
fStream = new ReplacingInputStream(fStream, ".poster".getBytes(), |
|
|
|
|
".foo".getBytes()); |
|
|
|
|
fStream = new ReplacingInputStream(fStream, "\"poster\"".getBytes(), |
|
|
|
|
"\"foo\"".getBytes()); |
|
|
|
|
|
|
|
|
|
return new WebResourceResponse(cType, cEnc, fStream); |
|
|
|
|
}/** |
|
|
|
|
* else if (mDoLeakHardening) { WebResourceResponse response = |
|
|
|
|
* new WebResourceResponse( cType, cEnc, conn.getInputStream()); |
|
|
|
|
* |
|
|
|
|
* return response; |
|
|
|
|
* |
|
|
|
|
* } |
|
|
|
|
*/ |
|
|
|
|
else { |
|
|
|
|
return null; // let webkit handle it
|
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
Log.e(Constants.TAG, "Error filtering stream", e); |
|
|
|
|
ByteArrayInputStream EMPTY = new ByteArrayInputStream("".getBytes()); |
|
|
|
|
return new WebResourceResponse("text/plain", "utf-8", EMPTY); |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|