Bug 884848 - Provide a way to get unscaled favicons from the Java favicon service. r=margaret DONTBUILD
authorWes Johnston <wjohnston@mozilla.com>
Tue, 02 Jul 2013 10:11:48 -0700
changeset 137175 341910d20d7b
parent 137174 13a04f575b99
child 137176 1e575c695425
push id30425
push userwjohnston@mozilla.com
push date2013-07-02 17:12 +0000
treeherdermozilla-inbound@341910d20d7b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs884848
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 884848 - Provide a way to get unscaled favicons from the Java favicon service. r=margaret DONTBUILD
mobile/android/base/BrowserApp.java
mobile/android/base/Favicons.java
mobile/android/base/widget/AddonsSection.java
--- a/mobile/android/base/BrowserApp.java
+++ b/mobile/android/base/BrowserApp.java
@@ -626,22 +626,30 @@ abstract public class BrowserApp extends
                         Clipboard.setText(url);
                     }
                 }
                 return true;
             }
             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;
             }
         }
         return false;
     }
 
     public boolean showAwesomebar(AwesomeBar.Target aTarget) {
@@ -1244,17 +1252,18 @@ abstract public class BrowserApp extends
         outState.putBoolean(STATE_DYNAMIC_TOOLBAR_ENABLED, mDynamicToolbarEnabled);
         outState.putInt(STATE_ABOUT_HOME_TOP_PADDING, mAboutHome.getTopPadding());
     }
 
     /* Favicon methods */
     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
             public void onFaviconLoaded(String pageUrl, Bitmap favicon) {
                 // Leave favicon UI untouched if we failed to load the image
                 // for some reason.
                 if (favicon == null)
                     return;
--- a/mobile/android/base/Favicons.java
+++ b/mobile/android/base/Favicons.java
@@ -35,16 +35,18 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
 public class Favicons {
     private static final String LOGTAG = "GeckoFavicons";
 
     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;
 
     private Context mContext;
 
     private Map<Long,LoadFaviconTask> mLoadTasks;
     private long mNextFaviconLoadId;
@@ -101,17 +103,17 @@ public class Favicons {
             }
         });
     }
 
     public String getFaviconUrlForPageUrl(String pageUrl) {
         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
         if (pageUrl == null || pageUrl.length() == 0) {
             dispatchResult(null, null, listener);
             return -1;
         }
 
@@ -123,17 +125,17 @@ public class Favicons {
 
         // Check if favicon is mem cached
         Bitmap image = getFaviconFromMemCache(pageUrl);
         if (image != null) {
             dispatchResult(pageUrl, image, listener);
             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);
 
         task.execute();
 
         return taskId;
     }
@@ -248,42 +250,42 @@ public class Favicons {
         }
     }
 
     private class LoadFaviconTask extends UiAsyncTask<Void, Void, Bitmap> {
         private long mId;
         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);
 
             synchronized(this) {
                 mId = ++mNextFaviconLoadId;
             }
 
             mPageUrl = pageUrl;
             mFaviconUrl = faviconUrl;
             mListener = listener;
-            mPersist = persist;
+            mFlags = flags;
         }
 
         // Runs in background thread
         private Bitmap loadFaviconFromDb() {
             ContentResolver resolver = mContext.getContentResolver();
             return BrowserDB.getFaviconForUrl(resolver, mPageUrl);
         }
 
         // Runs in background thread
         private void saveFaviconToDb(final Bitmap favicon) {
-            if (!mPersist) {
+            if ((mFlags & FLAG_PERSIST) == 0) {
                 return;
             }
 
             ContentResolver resolver = mContext.getContentResolver();
             BrowserDB.updateFaviconForUrl(resolver, mPageUrl, favicon, mFaviconUrl);
         }
 
         // Runs in background thread
@@ -372,27 +374,27 @@ public class Favicons {
 
             if (isCancelled())
                 return null;
 
             String storedFaviconUrl = getFaviconUrlForPageUrl(mPageUrl);
             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())
                 return null;
 
             image = downloadFavicon(faviconUrl);
 
             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;
             }
 
             return image;
         }
 
         @Override
--- a/mobile/android/base/widget/AddonsSection.java
+++ b/mobile/android/base/widget/AddonsSection.java
@@ -217,17 +217,17 @@ public class AddonsSection extends About
             public void onClick(View v) {
                 if (mUriLoadListener != null)
                     mUriLoadListener.onAboutHomeUriLoad(addonUrl);
             }
         });
         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) {
                 if (favicon != null) {
                     Drawable drawable = new BitmapDrawable(favicon);
                     drawable.setBounds(sIconBounds);
                     row.setCompoundDrawables(drawable, null, null, null);
                 }