Bug 822686 - Check for null BitmapDrawable for missing jar resources. r=mfinkle
authorChris Peterson <cpeterson@mozilla.com>
Tue, 05 Mar 2013 12:08:43 +0000
changeset 123815 4afd31d13e7f841a0526faee767a864fa99e29c1
parent 123814 9d6d7796e2849189b996576939b48497528087eb
child 123816 99d71c24a5df4bfcc9f0bfcd187d7e57f5e4f22e
push id24397
push userryanvm@gmail.com
push dateTue, 05 Mar 2013 15:24:36 +0000
treeherdermozilla-central@c95439870e05 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs822686
milestone22.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 822686 - Check for null BitmapDrawable for missing jar resources. r=mfinkle
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
@@ -236,18 +236,17 @@ public class Favicons {
 
             ContentResolver resolver = mContext.getContentResolver();
             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
@@ -1126,22 +1126,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;
         }