Back out e64522db8661 (bug 863288) for robocop-1 hangs

This commit is contained in:
Phil Ringnalda 2013-04-23 20:52:59 -07:00
Родитель 0dc878f0f5
Коммит 3ca1d22661
9 изменённых файлов: 36 добавлений и 67 удалений

Просмотреть файл

@ -7,7 +7,6 @@ package org.mozilla.gecko;
import org.mozilla.gecko.db.BrowserContract.Combined; import org.mozilla.gecko.db.BrowserContract.Combined;
import org.mozilla.gecko.db.BrowserDB; import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.gfx.BitmapUtils;
import org.mozilla.gecko.util.GamepadUtils; import org.mozilla.gecko.util.GamepadUtils;
import org.mozilla.gecko.util.StringUtils; import org.mozilla.gecko.util.StringUtils;
import org.mozilla.gecko.util.ThreadUtils; import org.mozilla.gecko.util.ThreadUtils;
@ -20,6 +19,7 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
@ -677,9 +677,8 @@ public class AwesomeBar extends GeckoActivity
} }
Bitmap bitmap = null; Bitmap bitmap = null;
if (b != null) { if (b != null)
bitmap = BitmapUtils.decodeByteArray(b); bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
}
String shortcutTitle = TextUtils.isEmpty(title) ? url.replaceAll("^([a-z]+://)?(www\\.)?", "") : title; String shortcutTitle = TextUtils.isEmpty(title) ? url.replaceAll("^([a-z]+://)?(www\\.)?", "") : title;
GeckoAppShell.createShortcut(shortcutTitle, url, bitmap, ""); GeckoAppShell.createShortcut(shortcutTitle, url, bitmap, "");

Просмотреть файл

@ -7,7 +7,6 @@ package org.mozilla.gecko;
import org.mozilla.gecko.background.announcements.AnnouncementsBroadcastService; import org.mozilla.gecko.background.announcements.AnnouncementsBroadcastService;
import org.mozilla.gecko.db.BrowserDB; import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.gfx.BitmapUtils;
import org.mozilla.gecko.gfx.Layer; import org.mozilla.gecko.gfx.Layer;
import org.mozilla.gecko.gfx.LayerView; import org.mozilla.gecko.gfx.LayerView;
import org.mozilla.gecko.gfx.PanZoomController; import org.mozilla.gecko.gfx.PanZoomController;
@ -1157,10 +1156,10 @@ abstract public class GeckoApp
if (isDataURI) { if (isDataURI) {
int dataStart = aSrc.indexOf(','); int dataStart = aSrc.indexOf(',');
byte[] buf = Base64.decode(aSrc.substring(dataStart+1), Base64.DEFAULT); byte[] buf = Base64.decode(aSrc.substring(dataStart+1), Base64.DEFAULT);
BitmapUtils.decodeByteArray(buf, options); BitmapFactory.decodeByteArray(buf, 0, buf.length, options);
options.inSampleSize = getBitmapSampleSize(options, idealWidth, idealHeight); options.inSampleSize = getBitmapSampleSize(options, idealWidth, idealHeight);
options.inJustDecodeBounds = false; options.inJustDecodeBounds = false;
image = BitmapUtils.decodeByteArray(buf, options); image = BitmapFactory.decodeByteArray(buf, 0, buf.length, options);
} else { } else {
int byteRead; int byteRead;
byte[] buf = new byte[4192]; byte[] buf = new byte[4192];
@ -1175,10 +1174,10 @@ abstract public class GeckoApp
os.write(buf, 0, byteRead); os.write(buf, 0, byteRead);
} }
byte[] imgBuffer = os.toByteArray(); byte[] imgBuffer = os.toByteArray();
BitmapUtils.decodeByteArray(imgBuffer, options); BitmapFactory.decodeByteArray(imgBuffer, 0, imgBuffer.length, options);
options.inSampleSize = getBitmapSampleSize(options, idealWidth, idealHeight); options.inSampleSize = getBitmapSampleSize(options, idealWidth, idealHeight);
options.inJustDecodeBounds = false; options.inJustDecodeBounds = false;
image = BitmapUtils.decodeByteArray(imgBuffer, options); image = BitmapFactory.decodeByteArray(imgBuffer, 0, imgBuffer.length, options);
} }
if(image != null) { if(image != null) {
mgr.setBitmap(image); mgr.setBitmap(image);
@ -1187,7 +1186,7 @@ abstract public class GeckoApp
return false; return false;
} }
} catch(OutOfMemoryError ome) { } catch(OutOfMemoryError ome) {
Log.e(LOGTAG, "Out of Memory when converting to byte array", ome); Log.e(LOGTAG, "Out of Memmory when coverting to byte array", ome);
return false; return false;
} catch(IOException ioe) { } catch(IOException ioe) {
Log.e(LOGTAG, "I/O Exception while setting wallpaper", ioe); Log.e(LOGTAG, "I/O Exception while setting wallpaper", ioe);

Просмотреть файл

@ -6,11 +6,11 @@
package org.mozilla.gecko; package org.mozilla.gecko;
import org.mozilla.gecko.db.BrowserDB; import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.gfx.BitmapUtils;
import org.mozilla.gecko.gfx.IntSize; import org.mozilla.gecko.gfx.IntSize;
import org.mozilla.gecko.mozglue.DirectBufferAllocator; import org.mozilla.gecko.mozglue.DirectBufferAllocator;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log; import android.util.Log;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -187,14 +187,18 @@ public final class ThumbnailHelper {
} }
private void setTabThumbnail(Tab tab, Bitmap bitmap, byte[] compressed) { private void setTabThumbnail(Tab tab, Bitmap bitmap, byte[] compressed) {
if (bitmap == null) { try {
if (compressed == null) { if (bitmap == null) {
Log.w(LOGTAG, "setTabThumbnail: one of bitmap or compressed must be non-null!"); if (compressed == null) {
return; Log.w(LOGTAG, "setTabThumbnail: one of bitmap or compressed must be non-null!");
return;
}
bitmap = BitmapFactory.decodeByteArray(compressed, 0, compressed.length);
} }
bitmap = BitmapUtils.decodeByteArray(compressed); tab.updateThumbnail(bitmap);
} catch (OutOfMemoryError ome) {
Log.w(LOGTAG, "setTabThumbnail: decoding byte array of length " + compressed.length + " ran out of memory");
} }
tab.updateThumbnail(bitmap);
} }
private boolean shouldUpdateThumbnail(Tab tab) { private boolean shouldUpdateThumbnail(Tab tab) {

Просмотреть файл

@ -24,6 +24,7 @@ import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Handler; import android.os.Handler;
@ -897,8 +898,8 @@ public class AllPagesTab extends AwesomeBarTab implements GeckoEventListener {
if (b == null) if (b == null)
continue; continue;
Bitmap favicon = BitmapUtils.decodeByteArray(b); Bitmap favicon = BitmapFactory.decodeByteArray(b, 0, b.length);
if (favicon == null) if (favicon == null || favicon.getWidth() <= 0 || favicon.getHeight() <= 0)
continue; continue;
favicon = Favicons.getInstance().scaleImage(favicon); favicon = Favicons.getInstance().scaleImage(favicon);

Просмотреть файл

@ -7,13 +7,13 @@ package org.mozilla.gecko;
import org.mozilla.gecko.AwesomeBar.ContextMenuSubject; import org.mozilla.gecko.AwesomeBar.ContextMenuSubject;
import org.mozilla.gecko.db.BrowserDB.URLColumns; import org.mozilla.gecko.db.BrowserDB.URLColumns;
import org.mozilla.gecko.gfx.BitmapUtils;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
@ -91,8 +91,8 @@ abstract public class AwesomeBarTab {
byte[] b = cursor.getBlob(cursor.getColumnIndexOrThrow(URLColumns.FAVICON)); byte[] b = cursor.getBlob(cursor.getColumnIndexOrThrow(URLColumns.FAVICON));
Bitmap favicon = null; Bitmap favicon = null;
if (b != null) { if (b != null) {
Bitmap bitmap = BitmapUtils.decodeByteArray(b); Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
if (bitmap != null) { if (bitmap != null && bitmap.getWidth() > 0 && bitmap.getHeight() > 0) {
favicon = Favicons.getInstance().scaleImage(bitmap); favicon = Favicons.getInstance().scaleImage(bitmap);
} }
} }

Просмотреть файл

@ -9,7 +9,6 @@ import org.mozilla.gecko.AwesomeBar.ContextMenuSubject;
import org.mozilla.gecko.db.BrowserContract.Combined; import org.mozilla.gecko.db.BrowserContract.Combined;
import org.mozilla.gecko.db.BrowserDB; import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.db.BrowserDB.URLColumns; import org.mozilla.gecko.db.BrowserDB.URLColumns;
import org.mozilla.gecko.gfx.BitmapUtils;
import org.mozilla.gecko.util.GamepadUtils; import org.mozilla.gecko.util.GamepadUtils;
import org.mozilla.gecko.util.ThreadUtils; import org.mozilla.gecko.util.ThreadUtils;
@ -20,6 +19,7 @@ import android.content.res.Resources;
import android.database.ContentObserver; import android.database.ContentObserver;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
@ -27,6 +27,7 @@ import android.util.Pair;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -192,8 +193,8 @@ public class HistoryTab extends AwesomeBarTab {
Bitmap favicon = null; Bitmap favicon = null;
if (b != null) { if (b != null) {
Bitmap bitmap = BitmapUtils.decodeByteArray(b); Bitmap bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
if (bitmap != null) { if (bitmap != null && bitmap.getWidth() > 0 && bitmap.getHeight() > 0) {
favicon = Favicons.getInstance().scaleImage(bitmap); favicon = Favicons.getInstance().scaleImage(bitmap);
} }
} }

Просмотреть файл

@ -14,7 +14,6 @@ import org.mozilla.gecko.db.BrowserContract.History;
import org.mozilla.gecko.db.BrowserContract.SyncColumns; import org.mozilla.gecko.db.BrowserContract.SyncColumns;
import org.mozilla.gecko.db.BrowserContract.Thumbnails; import org.mozilla.gecko.db.BrowserContract.Thumbnails;
import org.mozilla.gecko.db.BrowserContract.URLColumns; import org.mozilla.gecko.db.BrowserContract.URLColumns;
import org.mozilla.gecko.gfx.BitmapUtils;
import android.content.ContentProviderOperation; import android.content.ContentProviderOperation;
import android.content.ContentResolver; import android.content.ContentResolver;
@ -23,6 +22,7 @@ import android.database.ContentObserver;
import android.database.Cursor; import android.database.Cursor;
import android.database.CursorWrapper; import android.database.CursorWrapper;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.net.Uri; import android.net.Uri;
import android.provider.Browser; import android.provider.Browser;
@ -707,13 +707,14 @@ public class LocalBrowserDB implements BrowserDB.BrowserDBIface {
} }
int faviconIndex = c.getColumnIndexOrThrow(Combined.FAVICON); int faviconIndex = c.getColumnIndexOrThrow(Combined.FAVICON);
byte[] b = c.getBlob(faviconIndex); byte[] b = c.getBlob(faviconIndex);
c.close(); c.close();
if (b == null) if (b == null)
return null; return null;
return BitmapUtils.decodeByteArray(b); return BitmapFactory.decodeByteArray(b, 0, b.length);
} }
@Override @Override

Просмотреть файл

@ -14,42 +14,6 @@ import android.util.Log;
public final class BitmapUtils { public final class BitmapUtils {
private static final String LOGTAG = "GeckoBitmapUtils"; private static final String LOGTAG = "GeckoBitmapUtils";
private BitmapUtils() {}
public static Bitmap decodeByteArray(byte[] bytes) {
return decodeByteArray(bytes, null);
}
public static Bitmap decodeByteArray(byte[] bytes, BitmapFactory.Options options) {
if (bytes.length <= 0) {
throw new IllegalArgumentException("bytes.length " + bytes.length
+ " must be a positive number");
}
Bitmap bitmap = null;
try {
bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options);
} catch (OutOfMemoryError e) {
Log.e(LOGTAG, "decodeByteArray(bytes.length=" + bytes.length
+ ", options= " + options + ") OOM!", e);
return null;
}
if (bitmap == null) {
Log.w(LOGTAG, "decodeByteArray() returning null because BitmapFactory returned null");
return null;
}
if (bitmap.getWidth() <= 0 || bitmap.getHeight() <= 0) {
Log.w(LOGTAG, "decodeByteArray() returning null because BitmapFactory returned "
+ "a bitmap with dimensions " + bitmap.getWidth()
+ "x" + bitmap.getHeight());
return null;
}
return bitmap;
}
public static int getDominantColor(Bitmap source) { public static int getDominantColor(Bitmap source) {
return getDominantColor(source, true); return getDominantColor(source, true);
} }
@ -110,7 +74,7 @@ public final class BitmapUtils {
String base64 = dataURI.substring(dataURI.indexOf(',') + 1); String base64 = dataURI.substring(dataURI.indexOf(',') + 1);
try { try {
byte[] raw = Base64.decode(base64, Base64.DEFAULT); byte[] raw = Base64.decode(base64, Base64.DEFAULT);
return BitmapUtils.decodeByteArray(raw); return BitmapFactory.decodeByteArray(raw, 0, raw.length);
} catch (Exception e) { } catch (Exception e) {
Log.e(LOGTAG, "exception decoding bitmap from data URI: " + dataURI, e); Log.e(LOGTAG, "exception decoding bitmap from data URI: " + dataURI, e);
} }

Просмотреть файл

@ -15,7 +15,6 @@ import org.mozilla.gecko.db.BrowserContract.Thumbnails;
import org.mozilla.gecko.db.BrowserDB; import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.db.BrowserDB.TopSitesCursorWrapper; import org.mozilla.gecko.db.BrowserDB.TopSitesCursorWrapper;
import org.mozilla.gecko.db.BrowserDB.URLColumns; import org.mozilla.gecko.db.BrowserDB.URLColumns;
import org.mozilla.gecko.gfx.BitmapUtils;
import org.mozilla.gecko.util.ActivityResultHandler; import org.mozilla.gecko.util.ActivityResultHandler;
import org.mozilla.gecko.util.ThreadUtils; import org.mozilla.gecko.util.ThreadUtils;
import org.mozilla.gecko.util.UiAsyncTask; import org.mozilla.gecko.util.UiAsyncTask;
@ -26,6 +25,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Path; import android.graphics.Path;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
@ -316,7 +316,7 @@ public class TopSitesView extends GridView {
if (b == null) if (b == null)
continue; continue;
Bitmap thumbnail = BitmapUtils.decodeByteArray(b); Bitmap thumbnail = BitmapFactory.decodeByteArray(b, 0, b.length);
if (thumbnail == null) if (thumbnail == null)
continue; continue;
@ -656,7 +656,7 @@ public class TopSitesView extends GridView {
final byte[] b = c.getBlob(c.getColumnIndexOrThrow(Thumbnails.DATA)); final byte[] b = c.getBlob(c.getColumnIndexOrThrow(Thumbnails.DATA));
Bitmap bitmap = null; Bitmap bitmap = null;
if (b != null) { if (b != null) {
bitmap = BitmapUtils.decodeByteArray(b); bitmap = BitmapFactory.decodeByteArray(b, 0, b.length);
} }
c.close(); c.close();