Restrict plugins to a fixed size surface after exceeding a pixel threshold.
fixes bug: http://b/issue?id=2428737
Change-Id: I8d8f2c591ac8539a345e0167b05bec8539f34535
diff --git a/core/java/android/webkit/ViewManager.java b/core/java/android/webkit/ViewManager.java
index 47e7791..02f452b 100644
--- a/core/java/android/webkit/ViewManager.java
+++ b/core/java/android/webkit/ViewManager.java
@@ -16,6 +16,7 @@
package android.webkit;
+import android.view.SurfaceView;
import android.view.View;
import android.widget.AbsoluteLayout;
@@ -27,6 +28,9 @@
private boolean mHidden;
private boolean mReadyToDraw;
+ // Threshold at which a surface is prevented from further increasing in size
+ private static final int MAX_SURFACE_THRESHOLD = 1000000;
+
class ChildView {
int x;
int y;
@@ -34,6 +38,11 @@
int height;
View mView; // generic view to show
+ /* set to true if the view is a surface and it has exceeded the pixel
+ threshold specified in MAX_SURFACE_THRESHOLD.
+ */
+ boolean isFixedSize = false;
+
ChildView() {
}
@@ -49,15 +58,15 @@
return;
}
setBounds(x, y, width, height);
- final AbsoluteLayout.LayoutParams lp =
- new AbsoluteLayout.LayoutParams(ctvD(width), ctvD(height),
- ctvX(x), ctvY(y));
+
mWebView.mPrivateHandler.post(new Runnable() {
public void run() {
// This method may be called multiple times. If the view is
// already attached, just set the new LayoutParams,
// otherwise attach the view and add it to the list of
// children.
+ AbsoluteLayout.LayoutParams lp = computeLayout(ChildView.this);
+
if (mView.getParent() != null) {
mView.setLayoutParams(lp);
} else {
@@ -67,7 +76,7 @@
});
}
- void attachViewOnUIThread(AbsoluteLayout.LayoutParams lp) {
+ private void attachViewOnUIThread(AbsoluteLayout.LayoutParams lp) {
mWebView.addView(mView, lp);
mChildren.add(this);
if (!mReadyToDraw) {
@@ -86,7 +95,7 @@
});
}
- void removeViewOnUIThread() {
+ private void removeViewOnUIThread() {
mWebView.removeView(mView);
mChildren.remove(this);
}
@@ -125,16 +134,37 @@
return mWebView.contentToViewY(val);
}
- void scaleAll() {
- for (ChildView v : mChildren) {
- View view = v.mView;
- AbsoluteLayout.LayoutParams lp =
- (AbsoluteLayout.LayoutParams) view.getLayoutParams();
+ /**
+ * This should only be called from the UI thread.
+ */
+ private AbsoluteLayout.LayoutParams computeLayout(ChildView v) {
+
+ // if the surface has exceed a predefined threshold then fix the size
+ // of the surface.
+ if (!v.isFixedSize && (v.width * v.height) > MAX_SURFACE_THRESHOLD
+ && v.mView instanceof SurfaceView) {
+ ((SurfaceView)v.mView).getHolder().setFixedSize(v.width, v.height);
+ v.isFixedSize = true;
+ }
+
+ AbsoluteLayout.LayoutParams lp =
+ (AbsoluteLayout.LayoutParams) v.mView.getLayoutParams();
+
+ if (lp == null)
+ lp = new AbsoluteLayout.LayoutParams(ctvD(v.width), ctvD(v.height),
+ ctvX(v.x), ctvY(v.y));
+ else {
lp.width = ctvD(v.width);
lp.height = ctvD(v.height);
lp.x = ctvX(v.x);
lp.y = ctvY(v.y);
- view.setLayoutParams(lp);
+ }
+ return lp;
+ }
+
+ void scaleAll() {
+ for (ChildView v : mChildren) {
+ v.mView.setLayoutParams(computeLayout(v));
}
}