From 6c0ee7e931ce531ca51e2acbc6ef85f164407b8a Mon Sep 17 00:00:00 2001 From: Wes Johnston Date: Tue, 2 Jul 2013 10:11:48 -0700 Subject: [PATCH] Bug 884848 - Provide a way to get unscaled favicons from the Java favicon service. r=margaret DONTBUILD --- mobile/android/base/BrowserApp.java | 21 +++++++++++++------ mobile/android/base/Favicons.java | 18 +++++++++------- mobile/android/base/widget/AddonsSection.java | 2 +- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/mobile/android/base/BrowserApp.java b/mobile/android/base/BrowserApp.java index 8879e6ff027..2f89eddaabc 100644 --- a/mobile/android/base/BrowserApp.java +++ b/mobile/android/base/BrowserApp.java @@ -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 diff --git a/mobile/android/base/Favicons.java b/mobile/android/base/Favicons.java index 41a1109e1f9..473580cfd12 100644 --- a/mobile/android/base/Favicons.java +++ b/mobile/android/base/Favicons.java @@ -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; } diff --git a/mobile/android/base/widget/AddonsSection.java b/mobile/android/base/widget/AddonsSection.java index c2998121965..217c1ad29b0 100644 --- a/mobile/android/base/widget/AddonsSection.java +++ b/mobile/android/base/widget/AddonsSection.java @@ -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) {