7186952: Improve clipboard access
authordenis
Mon, 26 Nov 2012 20:49:54 +0400
changeset 16097 6277cf02aeac
parent 16096 a4397a7163e3
child 16098 9001e536ab4e
7186952: Improve clipboard access Reviewed-by: serb, ahgross
jdk/src/share/classes/java/awt/TextComponent.java
jdk/src/windows/native/sun/windows/awt_TextComponent.cpp
jdk/src/windows/native/sun/windows/awt_TextComponent.h
--- a/jdk/src/share/classes/java/awt/TextComponent.java	Tue Nov 20 11:46:42 2012 +0400
+++ b/jdk/src/share/classes/java/awt/TextComponent.java	Mon Nov 26 20:49:54 2012 +0400
@@ -109,12 +109,6 @@
     // the background color of non-editable TextComponents.
     boolean backgroundSetByClientCode = false;
 
-    /**
-     * True if this <code>TextComponent</code> has access
-     * to the System clipboard.
-     */
-    transient private boolean canAccessClipboard;
-
     transient protected TextListener textListener;
 
     /*
@@ -139,7 +133,6 @@
         GraphicsEnvironment.checkHeadless();
         this.text = (text != null) ? text : "";
         setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
-        checkSystemClipboardAccess();
     }
 
     private void enableInputMethodsIfNecessary() {
@@ -734,17 +727,14 @@
     /**
      * Assigns a valid value to the canAccessClipboard instance variable.
      */
-    private void checkSystemClipboardAccess() {
-        canAccessClipboard = true;
+    private boolean canAccessClipboard() {
         SecurityManager sm = System.getSecurityManager();
-        if (sm != null) {
-            try {
-                sm.checkSystemClipboardAccess();
-            }
-            catch (SecurityException e) {
-                canAccessClipboard = false;
-            }
-        }
+        if (sm == null) return true;
+        try {
+            sm.checkSystemClipboardAccess();
+            return true;
+        } catch (SecurityException e) {}
+        return false;
     }
 
     /*
@@ -827,7 +817,6 @@
             }
         }
         enableInputMethodsIfNecessary();
-        checkSystemClipboardAccess();
     }
 
 
--- a/jdk/src/windows/native/sun/windows/awt_TextComponent.cpp	Tue Nov 20 11:46:42 2012 +0400
+++ b/jdk/src/windows/native/sun/windows/awt_TextComponent.cpp	Mon Nov 26 20:49:54 2012 +0400
@@ -53,14 +53,12 @@
  * AwtTextComponent fields
  */
 
-/* java.awt.TextComponent fields */
-jfieldID AwtTextComponent::canAccessClipboardID;
-
-
 /************************************************************************
  * AwtTextComponent methods
  */
 
+jmethodID AwtTextComponent::canAccessClipboardMID;
+
 AwtTextComponent::AwtTextComponent() {
     m_synthetic = FALSE;
     m_lStartPos = -1;
@@ -367,8 +365,7 @@
         }
         jobject target = GetTarget(env);
         jboolean canAccessClipboard =
-            env->GetBooleanField(target,
-                                 AwtTextComponent::canAccessClipboardID);
+            env->CallBooleanMethod (target, AwtTextComponent::canAccessClipboardMID);
         env->DeleteLocalRef(target);
         return (canAccessClipboard) ? mrDoDefault : mrConsume;
     }
@@ -854,12 +851,13 @@
 {
     TRY;
 
-    cls = env->FindClass("java/awt/TextComponent");
-    if (cls != NULL) {
-        AwtTextComponent::canAccessClipboardID =
-            env->GetFieldID(cls, "canAccessClipboard", "Z");
-        DASSERT(AwtTextComponent::canAccessClipboardID != NULL);
-    }
+    jclass textComponentClassID = env->FindClass("java/awt/TextComponent");
+    AwtTextComponent::canAccessClipboardMID =
+        env->GetMethodID(textComponentClassID,
+        "canAccessClipboard", "()Z");
+    env->DeleteLocalRef(textComponentClassID);
+
+    DASSERT(AwtTextComponent::canAccessClipboardMID != NULL);
 
     CATCH_BAD_ALLOC;
 }
--- a/jdk/src/windows/native/sun/windows/awt_TextComponent.h	Tue Nov 20 11:46:42 2012 +0400
+++ b/jdk/src/windows/native/sun/windows/awt_TextComponent.h	Mon Nov 26 20:49:54 2012 +0400
@@ -42,8 +42,7 @@
 
 class AwtTextComponent : public AwtComponent {
 public:
-    /* java.awt.TextComponent canAccessClipboard field ID */
-    static jfieldID canAccessClipboardID;
+    static jmethodID canAccessClipboardMID;
 
     AwtTextComponent();