diff options
Diffstat (limited to 'src/com/android/browser/DownloadTouchIcon.java')
| -rw-r--r-- | src/com/android/browser/DownloadTouchIcon.java | 80 |
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(); } } } |
