Bug 1070092: Support favicon data URIs r=rnewman
authorChris Kitching <chriskitching@linux.com>
Fri, 19 Sep 2014 17:20:45 -0700
changeset 231969 dbc507f70c905cbed39dd4af03cf5e429084d725
parent 231968 309d2134b5174cde690a3571eb5c9918c990cb76
child 231970 4b3d816c21fdd965b174791c6b58790c70d4399d
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs1070092
milestone35.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 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;