Bug 822686 - Check for null BitmapDrawable for missing jar resources. r=mfinkle a=bajaj
authorChris Peterson <cpeterson@mozilla.com>
Tue, 05 Mar 2013 12:08:43 +0000
changeset 128507 7ad686d04fa36fd0c05c010894575e1522356b4b
parent 128506 357d21b20bf022949493f9d1a5b466d58ae3577a
child 128508 dab60b543514d9129c5757b2a8dadad3fb0376cc
push id3449
push usercpeterson@mozilla.com
push dateWed, 06 Mar 2013 10:06:22 +0000
treeherdermozilla-aurora@7ad686d04fa3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle, bajaj
bugs822686
milestone21.0a2
Bug 822686 - Check for null BitmapDrawable for missing jar resources. r=mfinkle a=bajaj
mobile/android/base/Favicons.java
mobile/android/base/GeckoJarReader.java
mobile/android/base/db/BrowserProvider.java.in
--- a/mobile/android/base/Favicons.java
+++ b/mobile/android/base/Favicons.java
@@ -238,18 +238,17 @@ public class Favicons {
                     BrowserDB.updateFaviconForUrl(resolver, mPageUrl, favicon, mFaviconUrl);
                 }
             });
         }
 
         // Runs in background thread
         private Bitmap downloadFavicon(URL faviconUrl) {
             if (mFaviconUrl.startsWith("jar:jar:")) {
-                BitmapDrawable d = GeckoJarReader.getBitmapDrawable(mContext.getResources(), mFaviconUrl);
-                return d.getBitmap();
+                return GeckoJarReader.getBitmap(mContext.getResources(), mFaviconUrl);
             }
 
             URI uri;
             try {
                 uri = faviconUrl.toURI();
             } catch (URISyntaxException e) {
                 Log.d(LOGTAG, "Could not get URI for favicon");
                 return null;
--- a/mobile/android/base/GeckoJarReader.java
+++ b/mobile/android/base/GeckoJarReader.java
@@ -1,15 +1,16 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.util;
 
 import android.content.res.Resources;
+import android.graphics.Bitmap;
 import android.graphics.drawable.BitmapDrawable;
 import android.util.Log;
 
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -19,20 +20,25 @@ import java.util.Stack;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 import java.util.zip.ZipInputStream;
 
 /* Reads out of a multiple level deep jar file such as
  *  jar:jar:file:///data/app/org.mozilla.fennec.apk!/omni.ja!/chrome/chrome/content/branding/favicon32.png
  */
 public final class GeckoJarReader {
-    private static String LOGTAG = "GeckoJarReader";
+    private static final String LOGTAG = "GeckoJarReader";
 
     private GeckoJarReader() {}
 
+    public static Bitmap getBitmap(Resources resources, String url) {
+        BitmapDrawable drawable = getBitmapDrawable(resources, url);
+        return (drawable != null) ? drawable.getBitmap() : null;
+    }
+
     public static BitmapDrawable getBitmapDrawable(Resources resources, String url) {
         Stack<String> jarUrls = parseUrl(url);
         InputStream inputStream = null;
         BitmapDrawable bitmap = null;
 
         ZipFile zip = null;
         try {
             // Load the initial jar file as a zip
--- a/mobile/android/base/db/BrowserProvider.java.in
+++ b/mobile/android/base/db/BrowserProvider.java.in
@@ -1106,22 +1106,18 @@ public class BrowserProvider extends Con
                 if (faviconField == null) {
                     return null;
                 }
                 int faviconId = faviconField.getInt(null);
                 String path = mContext.getString(faviconId);
 
                 String apkPath = mContext.getPackageResourcePath();
                 File apkFile = new File(apkPath);
-                BitmapDrawable bitmapDrawable = GeckoJarReader.getBitmapDrawable(mContext.getResources(),
-                                                                                 "jar:jar:" + apkFile.toURI() + "!/omni.ja!/" + path);
-                if (bitmapDrawable == null) {
-                    return null;
-                }
-                return bitmapDrawable.getBitmap();
+                String bitmapPath = "jar:jar:" + apkFile.toURI() + "!/omni.ja!/" + path;
+                return GeckoJarReader.getBitmap(mContext.getResources(), bitmapPath);
             } catch (java.lang.IllegalAccessException ex) {
                 Log.e(LOGTAG, "[Path] Can't create favicon " + name, ex);
             } catch (java.lang.NoSuchFieldException ex) {
                 Log.e(LOGTAG, "[Path] Can't create favicon " + name, ex);
             }
             return null;
         }