Bug 884848 - Provide a way to get unscaled favicons from the Java favicon service. r=margaret DONTBUILD

This commit is contained in:
Wes Johnston 2013-07-02 10:11:48 -07:00
parent cd941d3e8e
commit 6c0ee7e931
3 changed files with 26 additions and 15 deletions

View File

@ -631,12 +631,20 @@ abstract public class BrowserApp extends GeckoApp
case R.id.add_to_launcher: {
Tab tab = Tabs.getInstance().getSelectedTab();
if (tab != null) {
String url = tab.getURL();
String title = tab.getDisplayTitle();
Bitmap favicon = tab.getFavicon();
if (url != null && title != null) {
GeckoAppShell.createShortcut(title, url, url, favicon == null ? null : favicon, "");
final String url = tab.getURL();
final String title = tab.getDisplayTitle();
if (url == null || title == null) {
return true;
}
Favicons favicons = Favicons.getInstance();
favicons.loadFavicon(url, tab.getFaviconURL(), 0,
new Favicons.OnFaviconLoadedListener() {
@Override
public void onFaviconLoaded(String url, Bitmap favicon) {
GeckoAppShell.createShortcut(title, url, url, favicon == null ? null : favicon, "");
}
});
}
return true;
}
@ -1249,7 +1257,8 @@ abstract public class BrowserApp extends GeckoApp
private void loadFavicon(final Tab tab) {
maybeCancelFaviconLoad(tab);
long id = Favicons.getInstance().loadFavicon(tab.getURL(), tab.getFaviconURL(), !tab.isPrivate(),
int flags = Favicons.FLAG_SCALE | (tab.isPrivate() ? 0 : Favicons.FLAG_PERSIST);
long id = Favicons.getInstance().loadFavicon(tab.getURL(), tab.getFaviconURL(), flags,
new Favicons.OnFaviconLoadedListener() {
@Override

View File

@ -40,6 +40,8 @@ public class Favicons {
public static final long NOT_LOADING = 0;
public static final long FAILED_EXPIRY_NEVER = -1;
public static final int FLAG_PERSIST = 1;
public static final int FLAG_SCALE = 2;
private static int sFaviconSmallSize = -1;
private static int sFaviconLargeSize = -1;
@ -106,7 +108,7 @@ public class Favicons {
return BrowserDB.getFaviconUrlForHistoryUrl(mContext.getContentResolver(), pageUrl);
}
public long loadFavicon(String pageUrl, String faviconUrl, boolean persist,
public long loadFavicon(String pageUrl, String faviconUrl, int flags,
OnFaviconLoadedListener listener) {
// Handle the case where page url is empty
@ -128,7 +130,7 @@ public class Favicons {
return -1;
}
LoadFaviconTask task = new LoadFaviconTask(ThreadUtils.getBackgroundHandler(), pageUrl, faviconUrl, persist, listener);
LoadFaviconTask task = new LoadFaviconTask(ThreadUtils.getBackgroundHandler(), pageUrl, faviconUrl, flags, listener);
long taskId = task.getId();
mLoadTasks.put(taskId, task);
@ -253,10 +255,10 @@ public class Favicons {
private String mPageUrl;
private String mFaviconUrl;
private OnFaviconLoadedListener mListener;
private boolean mPersist;
private int mFlags;
public LoadFaviconTask(Handler backgroundThreadHandler,
String pageUrl, String faviconUrl, boolean persist,
String pageUrl, String faviconUrl, int flags,
OnFaviconLoadedListener listener) {
super(backgroundThreadHandler);
@ -267,7 +269,7 @@ public class Favicons {
mPageUrl = pageUrl;
mFaviconUrl = faviconUrl;
mListener = listener;
mPersist = persist;
mFlags = flags;
}
// Runs in background thread
@ -278,7 +280,7 @@ public class Favicons {
// Runs in background thread
private void saveFaviconToDb(final Bitmap favicon) {
if (!mPersist) {
if ((mFlags & FLAG_PERSIST) == 0) {
return;
}
@ -377,7 +379,7 @@ public class Favicons {
if (storedFaviconUrl != null && storedFaviconUrl.equals(mFaviconUrl)) {
image = loadFaviconFromDb();
if (image != null && image.getWidth() > 0 && image.getHeight() > 0)
return scaleImage(image);
return ((mFlags & FLAG_SCALE) != 0) ? scaleImage(image) : image;
}
if (isCancelled())
@ -387,7 +389,7 @@ public class Favicons {
if (image != null && image.getWidth() > 0 && image.getHeight() > 0) {
saveFaviconToDb(image);
image = scaleImage(image);
image = ((mFlags & FLAG_SCALE) != 0) ? scaleImage(image) : image;
} else {
image = null;
}

View File

@ -222,7 +222,7 @@ public class AddonsSection extends AboutHomeSection {
row.setOnKeyListener(GamepadUtils.getClickDispatcher());
Favicons favicons = Favicons.getInstance();
favicons.loadFavicon(pageUrl, iconUrl, true,
favicons.loadFavicon(pageUrl, iconUrl, Favicons.FLAG_PERSIST | Favicons.FLAG_SCALE,
new Favicons.OnFaviconLoadedListener() {
@Override
public void onFaviconLoaded(String url, Bitmap favicon) {