зеркало из https://github.com/mozilla/gecko-dev.git
Bug 738421 - Close up ZipReader. r=cpeterson
This commit is contained in:
Родитель
6e90e43d7b
Коммит
1c604a679f
|
@ -274,6 +274,10 @@ public class Favicons {
|
|||
Log.d(LOGTAG, "Downloading favicon for URL = " + mPageUrl +
|
||||
" with favicon URL = " + mFaviconUrl);
|
||||
|
||||
if (mFaviconUrl.startsWith("jar:jar:")) {
|
||||
return GeckoJarReader.getBitmapDrawable(mFaviconUrl);
|
||||
}
|
||||
|
||||
// due to android bug 6066, we must download the entire image before using it
|
||||
// http://code.google.com/p/android/issues/detail?id=6066
|
||||
URLConnection urlConnection = null;
|
||||
|
@ -294,8 +298,10 @@ public class Favicons {
|
|||
byteStream = new ByteArrayInputStream(bytes);
|
||||
image = (BitmapDrawable) Drawable.createFromStream(byteStream, "src");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// just close up and return null
|
||||
} catch (Exception e) {
|
||||
Log.e(LOGTAG, "Error downloading favicon", e);
|
||||
Log.e(LOGTAG, "Error reading favicon", e);
|
||||
} finally {
|
||||
if (urlConnection != null && urlConnection instanceof HttpURLConnection) {
|
||||
HttpURLConnection httpConnection = (HttpURLConnection) urlConnection;
|
||||
|
@ -312,11 +318,6 @@ public class Favicons {
|
|||
}
|
||||
}
|
||||
|
||||
if (image != null) {
|
||||
Log.d(LOGTAG, "Downloaded favicon successfully for URL = " + mPageUrl);
|
||||
saveFaviconToDb(image);
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
|
@ -373,6 +374,11 @@ public class Favicons {
|
|||
image = downloadFavicon(faviconUrl);
|
||||
}
|
||||
|
||||
if (image != null) {
|
||||
Log.d(LOGTAG, "Downloaded favicon successfully for URL = " + mPageUrl);
|
||||
saveFaviconToDb(image);
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,26 +14,60 @@ import java.util.zip.ZipEntry;
|
|||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.util.Log;
|
||||
|
||||
/* 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 class GeckoJarReader {
|
||||
static private String LOGTAG = "GeckoJarReader";
|
||||
private static String LOGTAG = "GeckoJarReader";
|
||||
|
||||
static public InputStream getStream(String url) {
|
||||
public static BitmapDrawable getBitmapDrawable(String url) {
|
||||
Stack<String> jarUrls = parseUrl(url);
|
||||
ZipInputStream inputStream = null;
|
||||
InputStream inputStream = null;
|
||||
BitmapDrawable bitmap = null;
|
||||
|
||||
ZipFile zip = null;
|
||||
try {
|
||||
// Load the initial jar file as a zip
|
||||
URL fileUrl = new URL(jarUrls.pop());
|
||||
File file = new File(fileUrl.getPath());
|
||||
zip = new ZipFile(file);
|
||||
ZipEntry entry = null;
|
||||
zip = getZipFile(jarUrls.pop());
|
||||
inputStream = getStream(zip, jarUrls);
|
||||
if (inputStream != null) {
|
||||
bitmap = new BitmapDrawable(inputStream);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
Log.e(LOGTAG, "Exception ", ex);
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch(IOException ex) {
|
||||
Log.e(LOGTAG, "Error closing stream", ex);
|
||||
}
|
||||
}
|
||||
if (zip != null) {
|
||||
try {
|
||||
zip.close();
|
||||
} catch(IOException ex) {
|
||||
Log.e(LOGTAG, "Error closing zip", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
private static ZipFile getZipFile(String url) throws IOException {
|
||||
URL fileUrl = new URL(url);
|
||||
File file = new File(fileUrl.getPath());
|
||||
return new ZipFile(file);
|
||||
}
|
||||
|
||||
private static InputStream getStream(ZipFile zip, Stack<String> jarUrls) throws IOException {
|
||||
ZipInputStream inputStream = null;
|
||||
ZipEntry entry = null;
|
||||
try {
|
||||
// loop through children jar files until we reach the innermost one
|
||||
while (jarUrls.peek() != null) {
|
||||
String fileName = jarUrls.pop();
|
||||
|
@ -59,26 +93,13 @@ public class GeckoJarReader {
|
|||
}
|
||||
}
|
||||
} catch (EmptyStackException ex) {
|
||||
Log.d(LOGTAG, "Reached Jar reader reached end of stack");
|
||||
} catch (IOException ex) {
|
||||
Log.e(LOGTAG, "Exception ", ex);
|
||||
} catch (Exception ex) {
|
||||
Log.e(LOGTAG, "Exception ", ex);
|
||||
} finally {
|
||||
if (zip != null) {
|
||||
try {
|
||||
zip.close();
|
||||
} catch(IOException ex) {
|
||||
Log.e(LOGTAG, "Error closing zip", ex);
|
||||
}
|
||||
}
|
||||
Log.d(LOGTAG, "Jar reader reached end of stack");
|
||||
}
|
||||
|
||||
return inputStream;
|
||||
}
|
||||
|
||||
/* Searches through a ZipInputStream for an entry with a given name */
|
||||
static private ZipEntry getEntryFromStream(ZipInputStream zipStream, String entryName) {
|
||||
private static ZipEntry getEntryFromStream(ZipInputStream zipStream, String entryName) {
|
||||
ZipEntry entry = null;
|
||||
|
||||
try {
|
||||
|
@ -102,11 +123,11 @@ public class GeckoJarReader {
|
|||
* omni.ja
|
||||
* chrome/chrome/content/branding/favicon32.png
|
||||
*/
|
||||
static private Stack<String> parseUrl(String url) {
|
||||
private static Stack<String> parseUrl(String url) {
|
||||
return parseUrl(url, null);
|
||||
}
|
||||
|
||||
static private Stack<String> parseUrl(String url, Stack<String> results) {
|
||||
private static Stack<String> parseUrl(String url, Stack<String> results) {
|
||||
if (results == null) {
|
||||
results = new Stack<String>();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче