Bug 931918 - Part 1: don't store JAR-sourced icons in the DB. r=bnicholson

This commit is contained in:
Richard Newman 2013-10-31 10:35:16 -07:00
Родитель 6edd6350a8
Коммит 9152bcc80c
1 изменённых файлов: 34 добавлений и 5 удалений

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

@ -159,13 +159,34 @@ public class LoadFaviconTask extends UiAsyncTask<Void, Void, Bitmap> {
return response; return response;
} }
// Runs in background thread /**
private Bitmap downloadFavicon(URI targetFaviconURI) { * Retrieve the specified favicon from the JAR, returning null if it's not
if (mFaviconUrl.startsWith("jar:jar:")) { * a JAR URI.
return GeckoJarReader.getBitmap(sContext.getResources(), mFaviconUrl); */
private static Bitmap fetchJARFavicon(String uri) {
if (uri == null) {
return null;
}
if (uri.startsWith("jar:jar:")) {
Log.d(LOGTAG, "Fetching favicon from JAR.");
return GeckoJarReader.getBitmap(sContext.getResources(), uri);
}
return null;
} }
// only get favicons for HTTP/HTTPS // Runs in background thread.
private Bitmap downloadFavicon(URI targetFaviconURI) {
if (targetFaviconURI == null) {
return null;
}
final String uriString = targetFaviconURI.toString();
Bitmap image = fetchJARFavicon(uriString);
if (image != null) {
return image;
}
// Only get favicons for HTTP/HTTPS.
String scheme = targetFaviconURI.getScheme(); String scheme = targetFaviconURI.getScheme();
if (!"http".equals(scheme) && !"https".equals(scheme)) { if (!"http".equals(scheme) && !"https".equals(scheme)) {
return null; return null;
@ -173,7 +194,6 @@ public class LoadFaviconTask extends UiAsyncTask<Void, Void, Bitmap> {
// skia decoder sometimes returns null; workaround is to use BufferedHttpEntity // skia decoder sometimes returns null; workaround is to use BufferedHttpEntity
// http://groups.google.com/group/android-developers/browse_thread/thread/171b8bf35dbbed96/c3ec5f45436ceec8?lnk=raot // http://groups.google.com/group/android-developers/browse_thread/thread/171b8bf35dbbed96/c3ec5f45436ceec8?lnk=raot
Bitmap image = null;
try { try {
// Try the URL we were given. // Try the URL we were given.
HttpResponse response = tryDownload(targetFaviconURI); HttpResponse response = tryDownload(targetFaviconURI);
@ -285,11 +305,20 @@ public class LoadFaviconTask extends UiAsyncTask<Void, Void, Bitmap> {
return null; return null;
} }
// Let's see if it's in a JAR.
image = fetchJARFavicon(mFaviconUrl);
if (image != null) {
// We don't want to put this into the DB.
return image;
}
try { try {
image = downloadFavicon(new URI(mFaviconUrl)); image = downloadFavicon(new URI(mFaviconUrl));
} catch (URISyntaxException e) { } catch (URISyntaxException e) {
Log.e(LOGTAG, "The provided favicon URL is not valid"); Log.e(LOGTAG, "The provided favicon URL is not valid");
return null; return null;
} catch (Exception e) {
Log.e(LOGTAG, "Couldn't download favicon.", e);
} }
// If we're not already trying the default URL, try it now. // If we're not already trying the default URL, try it now.