Bug 1070092: Support favicon data URIs r=rnewman
--- 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;