ゴール:
WebView によって行われたすべてのリクエストをオーバーライドし、自分でリクエストを行います (最終的にプロキシを設定します)。
コード:
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
if (url == null || url.trim().equals(""))
return null;
final DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getConnectionManager().closeExpiredConnections();
final HttpUriRequest httpRequest = new HttpGet(url);
try {
final HttpResponse response = httpClient.execute(httpRequest);
final Header[] headers = response.getHeaders(CONTENT_TYPE);
String mimeType = "";
String encoding = "";
if (headers != null && headers.length > 0) {
final String type = headers[0].getValue();
final int semicolonIndex = type.indexOf(';');
if (semicolonIndex != -1) {
mimeType = type.substring(0, semicolonIndex).trim();
encoding = type.substring(semicolonIndex + 1).trim();
final int equalsIndex = encoding.indexOf('=');
if (equalsIndex != -1)
encoding = encoding.substring(equalsIndex + 1).trim();
} else
mimeType = type;
}
return new WebResourceResponse(mimeType, encoding, response.getEntity().getContent());
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} finally {
httpClient.getConnectionManager().closeExpiredConnections();
}
return null;
}
リクエストはすべて問題なく処理されているように見えますが、最終的に次の 2 つの問題のいずれかでスタック トレースが表示されます。
3 15:07:28.650 E/InputDispatcher( 3981): channel '40d76268 com.secure.browser/com.secure.browser.SecureBrowserActivity (server)' ~ Consumer closed input channel or an error occurred. events=0x8
01-03 15:07:28.650 E/InputDispatcher( 3981): channel '40d76268 com.secure.browser/com.secure.browser.SecureBrowserActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
これは明らかに、オペレーティング システムがファイル記述子 (fid) を使い果たしていることを示しています。
また
01-03 15:29:36.810 I/DEBUG ( 5798): 5903cd34 ac81c0b7 /system/lib/libdvm.so
01-03 15:29:38.380 I/DEBUG ( 5798): debuggerd committing suicide to free the zombie!
01-03 15:29:38.380 I/BootReceiver( 3981): Copying /data/tombstones/tombstone_07 to DropBox
(SYSTEM_TOMBSTONE)
つまり、OS で低レベルの問題が発生していると思います。
私は3.0 +を使用しているので、機能がサポートされているはずです。
これは、JavaScript をオンにしたとき、または JavaScript を使用せずにしばらくブラウジングした後にほとんど失敗します。