7186952: Improve clipboard access

Reviewed-by: serb, ahgross
This commit is contained in:
Denis Fokin 2012-11-26 20:49:54 +04:00
parent b9b5963522
commit 6ddbe35ee2
3 changed files with 18 additions and 32 deletions

View File

@ -109,12 +109,6 @@ public class TextComponent extends Component implements Accessible {
// 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 @@ public class TextComponent extends Component implements Accessible {
GraphicsEnvironment.checkHeadless();
this.text = (text != null) ? text : "";
setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
checkSystemClipboardAccess();
}
private void enableInputMethodsIfNecessary() {
@ -734,17 +727,14 @@ public class TextComponent extends Component implements Accessible {
/**
* 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 @@ public class TextComponent extends Component implements Accessible {
}
}
enableInputMethodsIfNecessary();
checkSystemClipboardAccess();
}

View File

@ -53,14 +53,12 @@ struct EnableEditingStruct {
* 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 @@ AwtTextComponent::WmPaste()
}
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 @@ Java_sun_awt_windows_WTextComponentPeer_initIDs(JNIEnv *env, jclass cls)
{
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;
}

View File

@ -42,8 +42,7 @@
class AwtTextComponent : public AwtComponent {
public:
/* java.awt.TextComponent canAccessClipboard field ID */
static jfieldID canAccessClipboardID;
static jmethodID canAccessClipboardMID;
AwtTextComponent();