--- a/jdk/src/share/classes/sun/awt/EmbeddedFrame.java Tue Jul 31 21:01:56 2012 +0400
+++ b/jdk/src/share/classes/sun/awt/EmbeddedFrame.java Thu Aug 30 13:11:23 2012 -0700
@@ -29,12 +29,6 @@
import java.awt.event.*;
import java.awt.image.*;
import java.awt.peer.*;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Modifier;
-import java.lang.reflect.Field;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
import java.util.Set;
@@ -66,8 +60,6 @@
implements KeyEventDispatcher, PropertyChangeListener {
private boolean isCursorAllowed = true;
- private static Field fieldPeer;
- private static Field currentCycleRoot;
private boolean supportsXEmbed = false;
private KeyboardFocusManager appletKFM;
// JDK 1.1 compatibility
@@ -213,39 +205,8 @@
*/
public boolean dispatchKeyEvent(KeyEvent e) {
- // We can't guarantee that this is called on the same AppContext as EmbeddedFrame
- // belongs to. That's why we can't use public methods to find current focus cycle
- // root. Instead, we access KFM's private field directly.
- if (currentCycleRoot == null) {
- currentCycleRoot = AccessController.doPrivileged(new PrivilegedAction<Field>() {
- public Field run() {
- try {
- Field unaccessibleRoot = KeyboardFocusManager.class.
- getDeclaredField("currentFocusCycleRoot");
- if (unaccessibleRoot != null) {
- unaccessibleRoot.setAccessible(true);
- }
- return unaccessibleRoot;
- } catch (NoSuchFieldException e1) {
- assert false;
- } catch (SecurityException e2) {
- assert false;
- }
- return null;
- }
- });
- }
-
- Container currentRoot = null;
- if (currentCycleRoot != null) {
- try {
- // The field is static, so we can pass null to Field.get() as the argument.
- currentRoot = (Container)currentCycleRoot.get(null);
- } catch (IllegalAccessException e3) {
- // This is impossible: currentCycleRoot would be null if setAccessible failed.
- assert false;
- }
- }
+ Container currentRoot = AWTAccessor.getKeyboardFocusManagerAccessor()
+ .getCurrentFocusCycleRoot();
// if we are not in EmbeddedFrame's cycle, we should not try to leave.
if (this != currentRoot) {
@@ -389,32 +350,8 @@
@SuppressWarnings("deprecation")
protected void setPeer(final ComponentPeer p){
- if (fieldPeer == null) {
- fieldPeer = AccessController.doPrivileged(new PrivilegedAction<Field>() {
- public Field run() {
- try {
- Field lnkPeer = Component.class.getDeclaredField("peer");
- if (lnkPeer != null) {
- lnkPeer.setAccessible(true);
- }
- return lnkPeer;
- } catch (NoSuchFieldException e) {
- assert false;
- } catch (SecurityException e) {
- assert false;
- }
- return null;
- }//run
- });
- }
- try{
- if (fieldPeer != null){
- fieldPeer.set(EmbeddedFrame.this, p);
- }
- } catch (IllegalAccessException e) {
- assert false;
- }
- }; //setPeer method ends
+ AWTAccessor.getComponentAccessor().setPeer(EmbeddedFrame.this, p);
+ };
/**
* Synthesize native message to activate or deactivate EmbeddedFrame window