Bug 701839 - Wrong favicon displayed when both default location and link exists [r=mfinkle]

This commit is contained in:
Brian Nicholson 2011-11-17 12:57:27 -08:00
Родитель 590801a6c6
Коммит a0e49ffb51
1 изменённых файлов: 31 добавлений и 2 удалений

Просмотреть файл

@ -52,9 +52,12 @@ import android.os.AsyncTask;
import android.provider.Browser; import android.provider.Browser;
import android.util.Log; import android.util.Log;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.HashMap; import java.util.HashMap;
@ -244,13 +247,39 @@ public class Favicons {
Log.d(LOGTAG, "Downloading favicon for URL = " + mPageUrl + Log.d(LOGTAG, "Downloading favicon for URL = " + mPageUrl +
" with favicon URL = " + mFaviconUrl); " with favicon URL = " + mFaviconUrl);
// due to android bug 6066, we must download the entire image before using it
// http://code.google.com/p/android/issues/detail?id=6066
HttpURLConnection urlConnection = null;
BufferedInputStream contentStream = null;
ByteArrayInputStream byteStream = null;
BitmapDrawable image = null; BitmapDrawable image = null;
try { try {
InputStream is = (InputStream) faviconUrl.getContent(); urlConnection = (HttpURLConnection) faviconUrl.openConnection();
image = (BitmapDrawable) Drawable.createFromStream(is, "src"); int length = urlConnection.getContentLength();
contentStream = new BufferedInputStream(urlConnection.getInputStream(), length);
byte[] bytes = new byte[length];
int pos = 0;
int offset = 0;
while ((pos = contentStream.read(bytes, offset, length - offset)) > 0)
offset += pos;
if (length == offset) {
byteStream = new ByteArrayInputStream(bytes);
image = (BitmapDrawable) Drawable.createFromStream(byteStream, "src");
}
} catch (IOException e) { } catch (IOException e) {
Log.d(LOGTAG, "Error downloading favicon: " + e); Log.d(LOGTAG, "Error downloading favicon: " + e);
} finally {
if (urlConnection != null)
urlConnection.disconnect();
try {
if (contentStream != null)
contentStream.close();
if (byteStream != null)
byteStream.close();
} catch (IOException e) {
Log.d(LOGTAG, "error closing favicon stream");
}
} }
if (image != null) { if (image != null) {