Bug 1070092: Support favicon data URIs r=rnewman
authorChris Kitching <chriskitching@linux.com>
Fri, 19 Sep 2014 17:20:45 -0700
changeset 208754 dbc507f70c905cbed39dd4af03cf5e429084d725
parent 208753 309d2134b5174cde690a3571eb5c9918c990cb76
child 208755 4b3d816c21fdd965b174791c6b58790c70d4399d
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersrnewman
bugs1070092
milestone35.0a1
Bug 1070092: Support favicon data URIs r=rnewman
mobile/android/base/favicons/LoadFaviconTask.java
mobile/android/base/favicons/decoders/FaviconDecoder.java
--- a/mobile/android/base/favicons/LoadFaviconTask.java
+++ b/mobile/android/base/favicons/LoadFaviconTask.java
@@ -314,18 +314,16 @@ public class LoadFaviconTask {
 
         // Having downloaded the image, decode it.
         return FaviconDecoder.decodeFavicon(buffer, 0, bPointer + 1);
     }
 
     // LoadFavicon tasks are performed on a unique background executor thread
     // to avoid network blocking.
     public final void execute() {
-        ThreadUtils.assertOnUiThread();
-
         try {
             Favicons.longRunningExecutor.execute(new Runnable() {
                 @Override
                 public void run() {
                     final Bitmap result = doInBackground();
 
                     ThreadUtils.getUiHandler().post(new Runnable() {
                        @Override
@@ -354,16 +352,24 @@ public class LoadFaviconTask {
         return mCancelled;
     }
 
     Bitmap doInBackground() {
         if (isCancelled()) {
             return null;
         }
 
+        // Attempt to decode the favicon URL as a data URL. We don't bother storing such URIs in
+        // the database: the cost of decoding them here probably doesn't exceed the cost of mucking
+        // about with the DB.
+        LoadFaviconResult uriBitmaps = FaviconDecoder.decodeDataURI(faviconURL);
+        if (uriBitmaps != null) {
+            return pushToCacheAndGetResult(uriBitmaps);
+        }
+
         String storedFaviconUrl;
         boolean isUsingDefaultURL = false;
 
         // Handle the case of malformed favicon URL.
         // If favicon is empty, fall back to the stored one.
         if (TextUtils.isEmpty(faviconURL)) {
             // Try to get the favicon URL from the memory cache.
             storedFaviconUrl = Favicons.getFaviconURLForPageURLFromCache(pageUrl);
--- a/mobile/android/base/favicons/decoders/FaviconDecoder.java
+++ b/mobile/android/base/favicons/decoders/FaviconDecoder.java
@@ -121,17 +121,17 @@ public class FaviconDecoder {
 
     public static LoadFaviconResult decodeDataURI(String uri) {
         if (uri == null) {
             Log.w(LOG_TAG, "Can't decode null data: URI.");
             return null;
         }
 
         if (!uri.startsWith("data:image/")) {
-            Log.w(LOG_TAG, "Can't decode non-image data: URI.");
+            // Can't decode non-image data: URI.
             return null;
         }
 
         // Otherwise, let's attack this blindly. Strictly we should be parsing.
         int offset = uri.indexOf(',') + 1;
         if (offset == 0) {
             Log.w(LOG_TAG, "No ',' in data: URI; malformed?");
             return null;