提交 655050a6 编写于 作者: P prr

8174098: Better image fetching

Reviewed-by: serb, vadim, skoivu
上级 e311e59a
...@@ -29,6 +29,10 @@ import java.lang.ref.WeakReference; ...@@ -29,6 +29,10 @@ import java.lang.ref.WeakReference;
import java.awt.Image; import java.awt.Image;
import java.awt.image.ImageObserver; import java.awt.image.ImageObserver;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
public abstract class ImageWatched { public abstract class ImageWatched {
public static Link endlink = new Link(); public static Link endlink = new Link();
...@@ -85,16 +89,26 @@ public abstract class ImageWatched { ...@@ -85,16 +89,26 @@ public abstract class ImageWatched {
} }
} }
static class AccWeakReference<T> extends WeakReference<T> {
private final AccessControlContext acc;
AccWeakReference(T ref) {
super(ref);
acc = AccessController.getContext();
}
}
/* /*
* Standard Link implementation to manage a Weak Reference * Standard Link implementation to manage a Weak Reference
* to an ImageObserver. * to an ImageObserver.
*/ */
public static class WeakLink extends Link { public static class WeakLink extends Link {
private WeakReference<ImageObserver> myref; private final AccWeakReference<ImageObserver> myref;
private Link next; private Link next;
public WeakLink(ImageObserver obs, Link next) { public WeakLink(ImageObserver obs, Link next) {
myref = new WeakReference<ImageObserver>(obs); myref = new AccWeakReference<ImageObserver>(obs);
this.next = next; this.next = next;
} }
...@@ -120,6 +134,19 @@ public abstract class ImageWatched { ...@@ -120,6 +134,19 @@ public abstract class ImageWatched {
return this; return this;
} }
private static boolean update(ImageObserver iw, AccessControlContext acc,
Image img, int info,
int x, int y, int w, int h) {
if (acc != null || System.getSecurityManager() != null) {
return AccessController.doPrivileged(
(PrivilegedAction<Boolean>) () -> {
return iw.imageUpdate(img, info, x, y, w, h);
}, acc);
}
return false;
}
public boolean newInfo(Image img, int info, public boolean newInfo(Image img, int info,
int x, int y, int w, int h) int x, int y, int w, int h)
{ {
...@@ -129,7 +156,7 @@ public abstract class ImageWatched { ...@@ -129,7 +156,7 @@ public abstract class ImageWatched {
if (myiw == null) { if (myiw == null) {
// My referent is null so we must prune in a second pass. // My referent is null so we must prune in a second pass.
ret = true; ret = true;
} else if (myiw.imageUpdate(img, info, x, y, w, h) == false) { } else if (update(myiw, myref.acc, img, info, x, y, w, h) == false) {
// My referent has lost interest so clear it and ask // My referent has lost interest so clear it and ask
// for a pruning pass to remove it later. // for a pruning pass to remove it later.
myref.clear(); myref.clear();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册