2011-11-18 18:28:17 +00:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
2012-05-21 11:12:37 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-11-18 18:28:17 +00:00
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
2012-07-28 00:53:54 +00:00
|
|
|
import org.mozilla.gecko.db.BrowserDB;
|
2013-05-06 20:13:59 +00:00
|
|
|
import org.mozilla.gecko.gfx.BitmapUtils;
|
2012-08-02 01:58:23 +00:00
|
|
|
import org.mozilla.gecko.util.GeckoJarReader;
|
2013-03-15 10:52:53 +00:00
|
|
|
import org.mozilla.gecko.util.ThreadUtils;
|
|
|
|
import org.mozilla.gecko.util.UiAsyncTask;
|
2012-07-28 00:53:54 +00:00
|
|
|
|
|
|
|
import org.apache.http.HttpEntity;
|
2013-04-08 13:39:49 +00:00
|
|
|
import org.apache.http.HttpResponse;
|
2012-07-28 00:53:54 +00:00
|
|
|
import org.apache.http.client.methods.HttpGet;
|
|
|
|
import org.apache.http.entity.BufferedHttpEntity;
|
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
import android.content.ContentResolver;
|
|
|
|
import android.content.Context;
|
2012-10-31 12:34:32 +00:00
|
|
|
import android.graphics.Bitmap;
|
2012-06-10 23:44:50 +00:00
|
|
|
import android.net.http.AndroidHttpClient;
|
2013-02-19 21:14:37 +00:00
|
|
|
import android.os.Handler;
|
2012-11-14 12:10:01 +00:00
|
|
|
import android.support.v4.util.LruCache;
|
2011-11-18 18:28:17 +00:00
|
|
|
import android.util.Log;
|
|
|
|
|
2012-03-22 18:11:49 +00:00
|
|
|
import java.io.InputStream;
|
2011-11-18 18:28:17 +00:00
|
|
|
import java.net.MalformedURLException;
|
2012-06-10 23:44:50 +00:00
|
|
|
import java.net.URI;
|
|
|
|
import java.net.URISyntaxException;
|
2012-07-28 00:53:54 +00:00
|
|
|
import java.net.URL;
|
2012-06-10 23:44:50 +00:00
|
|
|
import java.util.Collections;
|
2011-11-18 18:28:17 +00:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
|
|
|
|
2012-07-18 00:54:54 +00:00
|
|
|
public class Favicons {
|
2011-11-18 18:28:17 +00:00
|
|
|
private static final String LOGTAG = "GeckoFavicons";
|
|
|
|
|
|
|
|
public static final long NOT_LOADING = 0;
|
2013-04-08 13:39:49 +00:00
|
|
|
public static final long FAILED_EXPIRY_NEVER = -1;
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2013-01-28 22:52:05 +00:00
|
|
|
private static int sFaviconSmallSize = -1;
|
|
|
|
private static int sFaviconLargeSize = -1;
|
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
private Map<Long,LoadFaviconTask> mLoadTasks;
|
|
|
|
private long mNextFaviconLoadId;
|
2012-11-05 11:42:25 +00:00
|
|
|
private LruCache<String, Bitmap> mFaviconsCache;
|
2013-04-08 13:39:49 +00:00
|
|
|
private LruCache<String, Long> mFailedCache;
|
2013-05-06 20:13:59 +00:00
|
|
|
private LruCache<String, Integer> mColorCache;
|
2013-05-24 16:21:01 +00:00
|
|
|
private static final String USER_AGENT = GeckoAppShell.getGeckoInterface().getDefaultUAString();
|
2012-06-10 23:44:50 +00:00
|
|
|
private AndroidHttpClient mHttpClient;
|
2011-11-18 18:28:17 +00:00
|
|
|
|
|
|
|
public interface OnFaviconLoadedListener {
|
2012-11-05 11:42:25 +00:00
|
|
|
public void onFaviconLoaded(String url, Bitmap favicon);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2012-12-03 08:59:17 +00:00
|
|
|
public Favicons() {
|
2011-11-18 18:28:17 +00:00
|
|
|
Log.d(LOGTAG, "Creating Favicons instance");
|
|
|
|
|
2012-06-10 23:44:50 +00:00
|
|
|
mLoadTasks = Collections.synchronizedMap(new HashMap<Long,LoadFaviconTask>());
|
2011-11-18 18:28:17 +00:00
|
|
|
mNextFaviconLoadId = 0;
|
2012-10-31 12:34:32 +00:00
|
|
|
|
|
|
|
// Create a favicon memory cache that have up to 1mb of size
|
2012-11-05 11:42:25 +00:00
|
|
|
mFaviconsCache = new LruCache<String, Bitmap>(1024 * 1024) {
|
2012-10-31 12:34:32 +00:00
|
|
|
@Override
|
2012-11-05 11:42:25 +00:00
|
|
|
protected int sizeOf(String url, Bitmap image) {
|
|
|
|
return image.getRowBytes() * image.getHeight();
|
2012-10-31 12:34:32 +00:00
|
|
|
}
|
|
|
|
};
|
2013-04-08 13:39:49 +00:00
|
|
|
|
|
|
|
// Create a failed favicon memory cache that has up to 64 entries
|
|
|
|
mFailedCache = new LruCache<String, Long>(64);
|
2013-05-06 20:13:59 +00:00
|
|
|
|
|
|
|
// Create a cache to store favicon dominant colors
|
|
|
|
mColorCache = new LruCache<String, Integer>(256);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2012-06-10 23:44:50 +00:00
|
|
|
private synchronized AndroidHttpClient getHttpClient() {
|
|
|
|
if (mHttpClient != null)
|
|
|
|
return mHttpClient;
|
|
|
|
|
|
|
|
mHttpClient = AndroidHttpClient.newInstance(USER_AGENT);
|
|
|
|
return mHttpClient;
|
|
|
|
}
|
|
|
|
|
2012-11-05 11:42:25 +00:00
|
|
|
private void dispatchResult(final String pageUrl, final Bitmap image,
|
2012-10-31 12:34:32 +00:00
|
|
|
final OnFaviconLoadedListener listener) {
|
|
|
|
if (pageUrl != null && image != null)
|
|
|
|
putFaviconInMemCache(pageUrl, image);
|
|
|
|
|
|
|
|
// We want to always run the listener on UI thread
|
2013-03-15 10:52:53 +00:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-27 05:48:00 +00:00
|
|
|
@Override
|
2012-10-31 12:34:32 +00:00
|
|
|
public void run() {
|
|
|
|
if (listener != null)
|
|
|
|
listener.onFaviconLoaded(pageUrl, image);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-07-26 22:08:50 +00:00
|
|
|
public String getFaviconUrlForPageUrl(String pageUrl) {
|
2012-11-13 18:56:58 +00:00
|
|
|
return BrowserDB.getFaviconUrlForHistoryUrl(mContext.getContentResolver(), pageUrl);
|
2012-07-26 22:08:50 +00:00
|
|
|
}
|
|
|
|
|
2012-10-09 18:26:33 +00:00
|
|
|
public long loadFavicon(String pageUrl, String faviconUrl, boolean persist,
|
2011-11-18 18:28:17 +00:00
|
|
|
OnFaviconLoadedListener listener) {
|
|
|
|
|
|
|
|
// Handle the case where page url is empty
|
|
|
|
if (pageUrl == null || pageUrl.length() == 0) {
|
2012-10-31 12:34:32 +00:00
|
|
|
dispatchResult(null, null, listener);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-04-08 13:39:49 +00:00
|
|
|
// Check if favicon has failed
|
|
|
|
if (isFailedFavicon(pageUrl)) {
|
|
|
|
dispatchResult(pageUrl, null, listener);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-10-31 12:34:32 +00:00
|
|
|
// Check if favicon is mem cached
|
2012-11-05 11:42:25 +00:00
|
|
|
Bitmap image = getFaviconFromMemCache(pageUrl);
|
2012-10-31 12:34:32 +00:00
|
|
|
if (image != null) {
|
|
|
|
dispatchResult(pageUrl, image, listener);
|
|
|
|
return -1;
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2013-03-15 10:52:53 +00:00
|
|
|
LoadFaviconTask task = new LoadFaviconTask(ThreadUtils.getBackgroundHandler(), pageUrl, faviconUrl, persist, listener);
|
2011-11-18 18:28:17 +00:00
|
|
|
|
|
|
|
long taskId = task.getId();
|
|
|
|
mLoadTasks.put(taskId, task);
|
|
|
|
|
|
|
|
task.execute();
|
|
|
|
|
|
|
|
return taskId;
|
|
|
|
}
|
|
|
|
|
2012-11-05 11:42:25 +00:00
|
|
|
public Bitmap getFaviconFromMemCache(String pageUrl) {
|
2012-10-31 12:34:32 +00:00
|
|
|
return mFaviconsCache.get(pageUrl);
|
|
|
|
}
|
|
|
|
|
2012-11-05 11:42:25 +00:00
|
|
|
public void putFaviconInMemCache(String pageUrl, Bitmap image) {
|
2012-10-31 12:34:32 +00:00
|
|
|
mFaviconsCache.put(pageUrl, image);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void clearMemCache() {
|
|
|
|
mFaviconsCache.evictAll();
|
|
|
|
}
|
|
|
|
|
2013-04-08 13:39:49 +00:00
|
|
|
public boolean isFailedFavicon(String pageUrl) {
|
|
|
|
Long fetchTime = mFailedCache.get(pageUrl);
|
|
|
|
if (fetchTime == null)
|
|
|
|
return false;
|
|
|
|
// We don't have any other rules yet.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void putFaviconInFailedCache(String pageUrl, long fetchTime) {
|
|
|
|
mFailedCache.put(pageUrl, fetchTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void clearFailedCache() {
|
|
|
|
mFailedCache.evictAll();
|
|
|
|
}
|
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
public boolean cancelFaviconLoad(long taskId) {
|
|
|
|
Log.d(LOGTAG, "Requesting cancelation of favicon load (" + taskId + ")");
|
|
|
|
|
2012-06-10 23:44:50 +00:00
|
|
|
boolean cancelled = false;
|
|
|
|
synchronized (mLoadTasks) {
|
|
|
|
if (!mLoadTasks.containsKey(taskId))
|
|
|
|
return false;
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2012-06-10 23:44:50 +00:00
|
|
|
Log.d(LOGTAG, "Cancelling favicon load (" + taskId + ")");
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2012-06-10 23:44:50 +00:00
|
|
|
LoadFaviconTask task = mLoadTasks.get(taskId);
|
|
|
|
cancelled = task.cancel(false);
|
|
|
|
}
|
|
|
|
return cancelled;
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void close() {
|
|
|
|
Log.d(LOGTAG, "Closing Favicons database");
|
|
|
|
|
|
|
|
// Cancel any pending tasks
|
2012-06-10 23:44:50 +00:00
|
|
|
synchronized (mLoadTasks) {
|
|
|
|
Set<Long> taskIds = mLoadTasks.keySet();
|
|
|
|
Iterator<Long> iter = taskIds.iterator();
|
|
|
|
while (iter.hasNext()) {
|
|
|
|
long taskId = iter.next();
|
|
|
|
cancelFaviconLoad(taskId);
|
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
2012-06-10 23:44:50 +00:00
|
|
|
if (mHttpClient != null)
|
|
|
|
mHttpClient.close();
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
2012-12-03 08:59:17 +00:00
|
|
|
private static class FaviconsInstanceHolder {
|
|
|
|
private static final Favicons INSTANCE = new Favicons();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Favicons getInstance() {
|
|
|
|
return Favicons.FaviconsInstanceHolder.INSTANCE;
|
|
|
|
}
|
|
|
|
|
2013-01-28 22:52:05 +00:00
|
|
|
public boolean isLargeFavicon(Bitmap image) {
|
|
|
|
return image.getWidth() > sFaviconSmallSize || image.getHeight() > sFaviconSmallSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Bitmap scaleImage(Bitmap image) {
|
|
|
|
// If the icon is larger than 16px, scale it to sFaviconLargeSize.
|
|
|
|
// Otherwise, scale it to sFaviconSmallSize.
|
|
|
|
if (isLargeFavicon(image)) {
|
|
|
|
image = Bitmap.createScaledBitmap(image, sFaviconLargeSize, sFaviconLargeSize, false);
|
|
|
|
} else {
|
|
|
|
image = Bitmap.createScaledBitmap(image, sFaviconSmallSize, sFaviconSmallSize, false);
|
|
|
|
}
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
2013-05-06 20:13:59 +00:00
|
|
|
public int getFaviconColor(Bitmap image, String key) {
|
|
|
|
Integer color = mColorCache.get(key);
|
|
|
|
if (color != null) {
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
color = BitmapUtils.getDominantColor(image);
|
|
|
|
mColorCache.put(key, color);
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2012-12-03 08:59:17 +00:00
|
|
|
public void attachToContext(Context context) {
|
|
|
|
mContext = context;
|
2013-01-28 22:52:05 +00:00
|
|
|
if (sFaviconSmallSize < 0) {
|
2013-05-28 15:48:27 +00:00
|
|
|
sFaviconSmallSize = Math.round(mContext.getResources().getDimension(R.dimen.favicon_size_small));
|
2013-01-28 22:52:05 +00:00
|
|
|
}
|
|
|
|
if (sFaviconLargeSize < 0) {
|
2013-05-28 15:48:27 +00:00
|
|
|
sFaviconLargeSize = Math.round(mContext.getResources().getDimension(R.dimen.favicon_size_large));
|
2013-01-28 22:52:05 +00:00
|
|
|
}
|
2012-12-03 08:59:17 +00:00
|
|
|
}
|
|
|
|
|
2013-02-21 20:01:09 +00:00
|
|
|
private class LoadFaviconTask extends UiAsyncTask<Void, Void, Bitmap> {
|
2011-11-18 18:28:17 +00:00
|
|
|
private long mId;
|
|
|
|
private String mPageUrl;
|
|
|
|
private String mFaviconUrl;
|
|
|
|
private OnFaviconLoadedListener mListener;
|
2012-10-09 18:26:33 +00:00
|
|
|
private boolean mPersist;
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2013-02-25 23:15:49 +00:00
|
|
|
public LoadFaviconTask(Handler backgroundThreadHandler,
|
2013-02-19 21:14:37 +00:00
|
|
|
String pageUrl, String faviconUrl, boolean persist,
|
|
|
|
OnFaviconLoadedListener listener) {
|
2013-02-25 23:15:49 +00:00
|
|
|
super(backgroundThreadHandler);
|
2013-02-19 21:14:37 +00:00
|
|
|
|
2012-01-24 16:52:26 +00:00
|
|
|
synchronized(this) {
|
|
|
|
mId = ++mNextFaviconLoadId;
|
|
|
|
}
|
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
mPageUrl = pageUrl;
|
|
|
|
mFaviconUrl = faviconUrl;
|
|
|
|
mListener = listener;
|
2012-10-09 18:26:33 +00:00
|
|
|
mPersist = persist;
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Runs in background thread
|
2012-11-05 11:42:25 +00:00
|
|
|
private Bitmap loadFaviconFromDb() {
|
2011-11-18 18:28:17 +00:00
|
|
|
ContentResolver resolver = mContext.getContentResolver();
|
2012-11-05 11:42:25 +00:00
|
|
|
return BrowserDB.getFaviconForUrl(resolver, mPageUrl);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Runs in background thread
|
2012-12-22 05:27:41 +00:00
|
|
|
private void saveFaviconToDb(final Bitmap favicon) {
|
2012-10-09 18:26:33 +00:00
|
|
|
if (!mPersist) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-19 21:14:37 +00:00
|
|
|
ContentResolver resolver = mContext.getContentResolver();
|
|
|
|
BrowserDB.updateFaviconForUrl(resolver, mPageUrl, favicon, mFaviconUrl);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Runs in background thread
|
2012-11-05 11:42:25 +00:00
|
|
|
private Bitmap downloadFavicon(URL faviconUrl) {
|
2012-03-24 00:07:10 +00:00
|
|
|
if (mFaviconUrl.startsWith("jar:jar:")) {
|
2013-03-05 12:08:43 +00:00
|
|
|
return GeckoJarReader.getBitmap(mContext.getResources(), mFaviconUrl);
|
2012-03-24 00:07:10 +00:00
|
|
|
}
|
|
|
|
|
2012-06-10 23:44:50 +00:00
|
|
|
URI uri;
|
|
|
|
try {
|
|
|
|
uri = faviconUrl.toURI();
|
|
|
|
} catch (URISyntaxException e) {
|
2012-09-09 01:40:58 +00:00
|
|
|
Log.d(LOGTAG, "Could not get URI for favicon");
|
2012-06-10 23:44:50 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// only get favicons for HTTP/HTTPS
|
|
|
|
String scheme = uri.getScheme();
|
|
|
|
if (!"http".equals(scheme) && !"https".equals(scheme))
|
|
|
|
return null;
|
|
|
|
|
2012-03-28 18:14:19 +00:00
|
|
|
// skia decoder sometimes returns null; workaround is to use BufferedHttpEntity
|
|
|
|
// http://groups.google.com/group/android-developers/browse_thread/thread/171b8bf35dbbed96/c3ec5f45436ceec8?lnk=raot
|
2012-11-05 11:42:25 +00:00
|
|
|
Bitmap image = null;
|
2011-11-18 18:28:17 +00:00
|
|
|
try {
|
2012-03-28 18:14:19 +00:00
|
|
|
HttpGet request = new HttpGet(faviconUrl.toURI());
|
2013-04-08 13:39:49 +00:00
|
|
|
HttpResponse response = getHttpClient().execute(request);
|
|
|
|
if (response == null)
|
|
|
|
return null;
|
|
|
|
if (response.getStatusLine() != null) {
|
|
|
|
// Was the response a failure?
|
|
|
|
int status = response.getStatusLine().getStatusCode();
|
|
|
|
if (status >= 400) {
|
|
|
|
putFaviconInFailedCache(mPageUrl, FAILED_EXPIRY_NEVER);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
HttpEntity entity = response.getEntity();
|
|
|
|
if (entity == null)
|
|
|
|
return null;
|
|
|
|
if (entity.getContentType() != null) {
|
|
|
|
// Is the content type valid? Might be a captive portal.
|
|
|
|
String contentType = entity.getContentType().getValue();
|
|
|
|
if (contentType.indexOf("image") == -1)
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-03-28 18:14:19 +00:00
|
|
|
BufferedHttpEntity bufferedEntity = new BufferedHttpEntity(entity);
|
2012-06-10 23:44:50 +00:00
|
|
|
InputStream contentStream = bufferedEntity.getContent();
|
2013-05-08 01:29:48 +00:00
|
|
|
image = BitmapUtils.decodeStream(contentStream);
|
|
|
|
contentStream.close();
|
2011-11-18 18:28:17 +00:00
|
|
|
} catch (Exception e) {
|
2012-03-24 00:07:10 +00:00
|
|
|
Log.e(LOGTAG, "Error reading favicon", e);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-05 11:42:25 +00:00
|
|
|
protected Bitmap doInBackground(Void... unused) {
|
|
|
|
Bitmap image = null;
|
2011-11-18 18:28:17 +00:00
|
|
|
|
|
|
|
if (isCancelled())
|
|
|
|
return null;
|
|
|
|
|
|
|
|
URL faviconUrl = null;
|
|
|
|
|
|
|
|
// Handle the case of malformed favicon URL
|
|
|
|
try {
|
|
|
|
// If favicon is empty, fallback to default favicon URI
|
|
|
|
if (mFaviconUrl == null || mFaviconUrl.length() == 0) {
|
2011-12-08 13:56:45 +00:00
|
|
|
// Handle the case of malformed URL
|
|
|
|
URL pageUrl = null;
|
2012-03-24 00:38:49 +00:00
|
|
|
pageUrl = new URL(mPageUrl);
|
2011-12-08 13:56:45 +00:00
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
faviconUrl = new URL(pageUrl.getProtocol(), pageUrl.getAuthority(), "/favicon.ico");
|
|
|
|
mFaviconUrl = faviconUrl.toString();
|
|
|
|
} else {
|
|
|
|
faviconUrl = new URL(mFaviconUrl);
|
|
|
|
}
|
|
|
|
} catch (MalformedURLException e) {
|
2012-09-09 01:40:58 +00:00
|
|
|
Log.d(LOGTAG, "The provided favicon URL is not valid");
|
2011-11-18 18:28:17 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isCancelled())
|
|
|
|
return null;
|
|
|
|
|
2012-11-13 18:56:58 +00:00
|
|
|
String storedFaviconUrl = getFaviconUrlForPageUrl(mPageUrl);
|
2011-11-18 18:28:17 +00:00
|
|
|
if (storedFaviconUrl != null && storedFaviconUrl.equals(mFaviconUrl)) {
|
|
|
|
image = loadFaviconFromDb();
|
2013-02-04 19:08:10 +00:00
|
|
|
if (image != null && image.getWidth() > 0 && image.getHeight() > 0)
|
2013-01-28 22:52:05 +00:00
|
|
|
return scaleImage(image);
|
2012-04-03 00:36:13 +00:00
|
|
|
}
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2012-04-03 00:36:13 +00:00
|
|
|
if (isCancelled())
|
|
|
|
return null;
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2012-04-03 00:36:13 +00:00
|
|
|
image = downloadFavicon(faviconUrl);
|
2011-11-18 18:28:17 +00:00
|
|
|
|
2012-12-03 08:59:17 +00:00
|
|
|
if (image != null && image.getWidth() > 0 && image.getHeight() > 0) {
|
2012-03-24 00:07:10 +00:00
|
|
|
saveFaviconToDb(image);
|
2013-01-28 22:52:05 +00:00
|
|
|
image = scaleImage(image);
|
2012-12-03 08:59:17 +00:00
|
|
|
} else {
|
|
|
|
image = null;
|
2012-03-24 00:07:10 +00:00
|
|
|
}
|
|
|
|
|
2011-11-18 18:28:17 +00:00
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-11-05 11:42:25 +00:00
|
|
|
protected void onPostExecute(final Bitmap image) {
|
2011-11-18 18:28:17 +00:00
|
|
|
mLoadTasks.remove(mId);
|
2012-10-31 12:34:32 +00:00
|
|
|
dispatchResult(mPageUrl, image, mListener);
|
2011-11-18 18:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCancelled() {
|
|
|
|
mLoadTasks.remove(mId);
|
|
|
|
|
|
|
|
// Note that we don't call the listener callback if the
|
|
|
|
// favicon load is cancelled.
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getId() {
|
|
|
|
return mId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|