Mercurial > hg > openjdk > jdk6 > jdk
changeset 916:a9dd5d0f04d5 jdk6-b32
8042582: Test java/awt/KeyboardFocusmanager/ChangeKFMTest/ChangeKFMTest.html fails on Windows x64
Reviewed-by: pchelko, ant
author | anashaty |
---|---|
date | Tue, 13 May 2014 15:41:23 +0400 |
parents | 809b9cc623c7 |
children | ea62d623879a |
files | src/share/classes/java/awt/KeyboardFocusManager.java |
diffstat | 1 files changed, 44 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/classes/java/awt/KeyboardFocusManager.java Mon May 19 18:31:48 2014 +0400 +++ b/src/share/classes/java/awt/KeyboardFocusManager.java Tue May 13 15:41:23 2014 +0400 @@ -232,15 +232,7 @@ public static void setCurrentKeyboardFocusManager( KeyboardFocusManager newManager) throws SecurityException { - SecurityManager security = System.getSecurityManager(); - if (security != null) { - if (replaceKeyboardFocusManagerPermission == null) { - replaceKeyboardFocusManagerPermission = - new AWTPermission("replaceKeyboardFocusManager"); - } - security. - checkPermission(replaceKeyboardFocusManagerPermission); - } + checkReplaceKFMPermission(); KeyboardFocusManager oldManager = null; @@ -495,7 +487,7 @@ */ protected Component getGlobalFocusOwner() throws SecurityException { synchronized (KeyboardFocusManager.class) { - checkCurrentKFMSecurity(); + checkKFMSecurity(); return focusOwner; } } @@ -530,7 +522,7 @@ if (focusOwner == null || focusOwner.isFocusable()) { synchronized (KeyboardFocusManager.class) { - checkCurrentKFMSecurity(); + checkKFMSecurity(); oldFocusOwner = getFocusOwner(); try { @@ -581,7 +573,7 @@ */ public void clearGlobalFocusOwner() { synchronized (KeyboardFocusManager.class) { - checkCurrentKFMSecurity(); + checkKFMSecurity(); } if (!GraphicsEnvironment.isHeadless()) { @@ -663,7 +655,7 @@ throws SecurityException { synchronized (KeyboardFocusManager.class) { - checkCurrentKFMSecurity(); + checkKFMSecurity(); return permanentFocusOwner; } } @@ -700,7 +692,7 @@ if (permanentFocusOwner == null || permanentFocusOwner.isFocusable()) { synchronized (KeyboardFocusManager.class) { - checkCurrentKFMSecurity(); + checkKFMSecurity(); oldPermanentFocusOwner = getPermanentFocusOwner(); try { @@ -766,7 +758,7 @@ */ protected Window getGlobalFocusedWindow() throws SecurityException { synchronized (KeyboardFocusManager.class) { - checkCurrentKFMSecurity(); + checkKFMSecurity(); return focusedWindow; } } @@ -798,7 +790,7 @@ if (focusedWindow == null || focusedWindow.isFocusableWindow()) { synchronized (KeyboardFocusManager.class) { - checkCurrentKFMSecurity(); + checkKFMSecurity(); oldFocusedWindow = getFocusedWindow(); try { @@ -865,7 +857,7 @@ */ protected Window getGlobalActiveWindow() throws SecurityException { synchronized (KeyboardFocusManager.class) { - checkCurrentKFMSecurity(); + checkKFMSecurity(); return activeWindow; } } @@ -895,7 +887,7 @@ protected void setGlobalActiveWindow(Window activeWindow) { Window oldActiveWindow; synchronized (KeyboardFocusManager.class) { - checkCurrentKFMSecurity(); + checkKFMSecurity(); oldActiveWindow = getActiveWindow(); if (focusLog.isLoggable(Level.FINER)) { focusLog.log(Level.FINER, "Setting global active window to " + activeWindow + ", old active " + oldActiveWindow); @@ -1190,7 +1182,7 @@ throws SecurityException { synchronized (KeyboardFocusManager.class) { - checkCurrentKFMSecurity(); + checkKFMSecurity(); return currentFocusCycleRoot; } } @@ -1215,7 +1207,7 @@ Container oldFocusCycleRoot; synchronized (KeyboardFocusManager.class) { - checkCurrentKFMSecurity(); + checkKFMSecurity(); oldFocusCycleRoot = getCurrentFocusCycleRoot(); currentFocusCycleRoot = newFocusCycleRoot; } @@ -3106,13 +3098,36 @@ } } - private void checkCurrentKFMSecurity() { - if (this != getCurrentKeyboardFocusManager()) { - if (focusLog.isLoggable(Level.FINER)) { - focusLog.finer("This manager is " + this + - ", current is " + getCurrentKeyboardFocusManager()); - } - throw new SecurityException(notPrivileged); - } - } + private static void checkReplaceKFMPermission() + throws SecurityException + { + SecurityManager security = System.getSecurityManager(); + if (security != null) { + if (replaceKeyboardFocusManagerPermission == null) { + replaceKeyboardFocusManagerPermission = + new AWTPermission("replaceKeyboardFocusManager"); + } + security. + checkPermission(replaceKeyboardFocusManagerPermission); + } + } + + // Checks if this KeyboardFocusManager instance is the current KFM, + // or otherwise checks if the calling thread has "replaceKeyboardFocusManager" + // permission. Here's the reasoning to do so: + // + // A system KFM instance (which is the current KFM by default) may have no + // "replaceKFM" permission when a client code is on the call stack beneath, + // but still it should be able to execute the methods protected by this check + // due to the system KFM is trusted (and so it does like "privileged"). + // + // If this KFM instance is not the current KFM but the client code has all + // permissions we can't throw SecurityException because it would contradict + // the security concepts. In this case the trusted client code is responsible + // for calling the secured methods from KFM instance which is not current. + private void checkKFMSecurity() { + if (this != getCurrentKeyboardFocusManager()) { + checkReplaceKFMPermission(); + } + } }