Bug 931918 - Part 1: Don't store JAR-sourced icons in the DB. r=bnicholson, a=bajaj
authorRichard Newman <rnewman@mozilla.com>
Thu, 31 Oct 2013 10:35:16 -0700
changeset 166381 aee9feb9c9bb0c6ba220c84b5162f7a852d4ab06
parent 166380 d0c8aba6bfb047597329cd0051433d4f1a524072
child 166382 9e54369efcb059e0bc9b293d2b7a8c21685d448c
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnicholson, bajaj
bugs931918
milestone27.0a2
Bug 931918 - Part 1: Don't store JAR-sourced icons in the DB. r=bnicholson, a=bajaj
mobile/android/base/favicons/LoadFaviconTask.java
--- a/mobile/android/base/favicons/LoadFaviconTask.java
+++ b/mobile/android/base/favicons/LoadFaviconTask.java
@@ -154,31 +154,51 @@ public class LoadFaviconTask extends UiA
 
             if (status >= 400) {
                 return null;
             }
         }
         return response;
     }
 
-    // Runs in background thread
+    /**
+     * Retrieve the specified favicon from the JAR, returning null if it's not
+     * a JAR URI.
+     */
+    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;
+    }
+
+    // Runs in background thread.
     private Bitmap downloadFavicon(URI targetFaviconURI) {
-        if (mFaviconUrl.startsWith("jar:jar:")) {
-            return GeckoJarReader.getBitmap(sContext.getResources(), mFaviconUrl);
+        if (targetFaviconURI == null) {
+            return null;
         }
 
-        // only get favicons for HTTP/HTTPS
+        final String uriString = targetFaviconURI.toString();
+        Bitmap image = fetchJARFavicon(uriString);
+        if (image != null) {
+            return image;
+        }
+
+        // Only get favicons for HTTP/HTTPS.
         String scheme = targetFaviconURI.getScheme();
         if (!"http".equals(scheme) && !"https".equals(scheme)) {
             return null;
         }
 
         // skia decoder sometimes returns null; workaround is to use BufferedHttpEntity
         // http://groups.google.com/group/android-developers/browse_thread/thread/171b8bf35dbbed96/c3ec5f45436ceec8?lnk=raot
-        Bitmap image = null;
         try {
             // Try the URL we were given.
             HttpResponse response = tryDownload(targetFaviconURI);
             if (response == null) {
                 return null;
             }
 
             HttpEntity entity = response.getEntity();
@@ -280,21 +300,30 @@ public class LoadFaviconTask extends UiA
         if (image != null && image.getWidth() > 0 && image.getHeight() > 0) {
             return image;
         }
 
         if (mOnlyFromLocal || isCancelled()) {
             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 {
             image = downloadFavicon(new URI(mFaviconUrl));
         } catch (URISyntaxException e) {
             Log.e(LOGTAG, "The provided favicon URL is not valid");
             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 (image == null && !isUsingDefaultURL) {
             try {
                 image = downloadFavicon(new URI(Favicons.guessDefaultFaviconURL(mPageUrl)));
             } catch (URISyntaxException e){
                 // Not interesting. It was an educated guess, anyway.