summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/DownloadTouchIcon.java
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2014-10-27 17:21:20 +0000
committerNarayan Kamath <narayan@google.com>2014-10-27 17:23:52 +0000
commit30ce2c541e4957b16cdbb3cce3a12494571d0254 (patch)
treecda3522247711276364b911e50e4ae9e3d958b64 /src/com/android/browser/DownloadTouchIcon.java
parentfe4083510dc773911651456f150bf5432f81a6c0 (diff)
downloadpackages_apps_Browser-30ce2c541e4957b16cdbb3cce3a12494571d0254.tar.gz
packages_apps_Browser-30ce2c541e4957b16cdbb3cce3a12494571d0254.tar.bz2
packages_apps_Browser-30ce2c541e4957b16cdbb3cce3a12494571d0254.zip
Rewrite calls to Proxy.getPreferredHttpHost
Use java.net.URLConnection which is the only maintained method of making http requests from java. These were the last calls to getPreferredHttpHost and that hidden API will now be deleted. Change-Id: I97e022507ba656f627754af4e889f4812314ea90
Diffstat (limited to 'src/com/android/browser/DownloadTouchIcon.java')
-rw-r--r--src/com/android/browser/DownloadTouchIcon.java80
1 files changed, 31 insertions, 49 deletions
diff --git a/src/com/android/browser/DownloadTouchIcon.java b/src/com/android/browser/DownloadTouchIcon.java
index ba299b6d6..2d12cc76a 100644
--- a/src/com/android/browser/DownloadTouchIcon.java
+++ b/src/com/android/browser/DownloadTouchIcon.java
@@ -16,12 +16,9 @@
package com.android.browser;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpHost;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.params.HttpClientParams;
-import org.apache.http.conn.params.ConnRouteParams;
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
import android.content.ContentResolver;
import android.content.ContentValues;
@@ -29,8 +26,6 @@ import android.content.Context;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
-import android.net.Proxy;
-import android.net.http.AndroidHttpClient;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Message;
@@ -50,7 +45,6 @@ class DownloadTouchIcon extends AsyncTask<String, Void, Void> {
private final String mUserAgent; // Sites may serve a different icon to different UAs
private Message mMessage;
- private final Context mContext;
/* package */ Tab mTab;
/**
@@ -58,9 +52,8 @@ class DownloadTouchIcon extends AsyncTask<String, Void, Void> {
* the originalUrl so we take account of redirects. Used when the user
* bookmarks a page from outside the bookmarks activity.
*/
- public DownloadTouchIcon(Tab tab, Context ctx, ContentResolver cr, WebView view) {
+ public DownloadTouchIcon(Tab tab, ContentResolver cr, WebView view) {
mTab = tab;
- mContext = ctx.getApplicationContext();
mContentResolver = cr;
// Store these in case they change.
mOriginalUrl = view.getOriginalUrl();
@@ -75,9 +68,8 @@ class DownloadTouchIcon extends AsyncTask<String, Void, Void> {
* TODO: Would be nice to set the user agent here so that there is no
* potential for the three different ctors here to return different icons.
*/
- public DownloadTouchIcon(Context ctx, ContentResolver cr, String url) {
+ public DownloadTouchIcon(ContentResolver cr, String url) {
mTab = null;
- mContext = ctx.getApplicationContext();
mContentResolver = cr;
mOriginalUrl = null;
mUrl = url;
@@ -89,9 +81,8 @@ class DownloadTouchIcon extends AsyncTask<String, Void, Void> {
* the passed Message's data bundle with the key
* {@link BrowserContract.Bookmarks#TOUCH_ICON} and then send the message.
*/
- public DownloadTouchIcon(Context context, Message msg, String userAgent) {
+ public DownloadTouchIcon(Message msg, String userAgent) {
mMessage = msg;
- mContext = context.getApplicationContext();
mContentResolver = null;
mOriginalUrl = null;
mUrl = null;
@@ -107,48 +98,39 @@ class DownloadTouchIcon extends AsyncTask<String, Void, Void> {
boolean inDatabase = mCursor != null && mCursor.getCount() > 0;
- String url = values[0];
-
if (inDatabase || mMessage != null) {
- AndroidHttpClient client = null;
- HttpGet request = null;
-
+ HttpURLConnection connection = null;
try {
- client = AndroidHttpClient.newInstance(mUserAgent);
- HttpHost httpHost = Proxy.getPreferredHttpHost(mContext, url);
- if (httpHost != null) {
- ConnRouteParams.setDefaultProxy(client.getParams(), httpHost);
+ URL url = new URL(values[0]);
+ connection = (HttpURLConnection) url.openConnection();
+ if (mUserAgent != null) {
+ connection.addRequestProperty("User-Agent", mUserAgent);
}
- request = new HttpGet(url);
-
- // Follow redirects
- HttpClientParams.setRedirecting(client.getParams(), true);
-
- HttpResponse response = client.execute(request);
- if (response.getStatusLine().getStatusCode() == 200) {
- HttpEntity entity = response.getEntity();
- if (entity != null) {
- InputStream content = entity.getContent();
- if (content != null) {
- Bitmap icon = BitmapFactory.decodeStream(
- content, null, null);
- if (inDatabase) {
- storeIcon(icon);
- } else if (mMessage != null) {
- Bundle b = mMessage.getData();
- b.putParcelable(BrowserContract.Bookmarks.TOUCH_ICON, icon);
- }
+ if (connection.getResponseCode() == 200) {
+ InputStream content = connection.getInputStream();
+ Bitmap icon = null;
+ try {
+ icon = BitmapFactory.decodeStream(
+ content, null, null);
+ } finally {
+ try {
+ content.close();
+ } catch (IOException ignored) {
}
}
+
+ if (inDatabase) {
+ storeIcon(icon);
+ } else if (mMessage != null) {
+ Bundle b = mMessage.getData();
+ b.putParcelable(BrowserContract.Bookmarks.TOUCH_ICON, icon);
+ }
}
- } catch (Exception ex) {
- if (request != null) {
- request.abort();
- }
+ } catch (IOException ignored) {
} finally {
- if (client != null) {
- client.close();
+ if (connection != null) {
+ connection.disconnect();
}
}
}