7186952: Improve clipboard access
Reviewed-by: serb, ahgross
This commit is contained in:
parent
b9b5963522
commit
6ddbe35ee2
@ -109,12 +109,6 @@ public class TextComponent extends Component implements Accessible {
|
|||||||
// the background color of non-editable TextComponents.
|
// the background color of non-editable TextComponents.
|
||||||
boolean backgroundSetByClientCode = false;
|
boolean backgroundSetByClientCode = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* True if this <code>TextComponent</code> has access
|
|
||||||
* to the System clipboard.
|
|
||||||
*/
|
|
||||||
transient private boolean canAccessClipboard;
|
|
||||||
|
|
||||||
transient protected TextListener textListener;
|
transient protected TextListener textListener;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -139,7 +133,6 @@ public class TextComponent extends Component implements Accessible {
|
|||||||
GraphicsEnvironment.checkHeadless();
|
GraphicsEnvironment.checkHeadless();
|
||||||
this.text = (text != null) ? text : "";
|
this.text = (text != null) ? text : "";
|
||||||
setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
|
setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
|
||||||
checkSystemClipboardAccess();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enableInputMethodsIfNecessary() {
|
private void enableInputMethodsIfNecessary() {
|
||||||
@ -734,17 +727,14 @@ public class TextComponent extends Component implements Accessible {
|
|||||||
/**
|
/**
|
||||||
* Assigns a valid value to the canAccessClipboard instance variable.
|
* Assigns a valid value to the canAccessClipboard instance variable.
|
||||||
*/
|
*/
|
||||||
private void checkSystemClipboardAccess() {
|
private boolean canAccessClipboard() {
|
||||||
canAccessClipboard = true;
|
|
||||||
SecurityManager sm = System.getSecurityManager();
|
SecurityManager sm = System.getSecurityManager();
|
||||||
if (sm != null) {
|
if (sm == null) return true;
|
||||||
try {
|
try {
|
||||||
sm.checkSystemClipboardAccess();
|
sm.checkSystemClipboardAccess();
|
||||||
}
|
return true;
|
||||||
catch (SecurityException e) {
|
} catch (SecurityException e) {}
|
||||||
canAccessClipboard = false;
|
return false;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -827,7 +817,6 @@ public class TextComponent extends Component implements Accessible {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
enableInputMethodsIfNecessary();
|
enableInputMethodsIfNecessary();
|
||||||
checkSystemClipboardAccess();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,14 +53,12 @@ struct EnableEditingStruct {
|
|||||||
* AwtTextComponent fields
|
* AwtTextComponent fields
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* java.awt.TextComponent fields */
|
|
||||||
jfieldID AwtTextComponent::canAccessClipboardID;
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
* AwtTextComponent methods
|
* AwtTextComponent methods
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
jmethodID AwtTextComponent::canAccessClipboardMID;
|
||||||
|
|
||||||
AwtTextComponent::AwtTextComponent() {
|
AwtTextComponent::AwtTextComponent() {
|
||||||
m_synthetic = FALSE;
|
m_synthetic = FALSE;
|
||||||
m_lStartPos = -1;
|
m_lStartPos = -1;
|
||||||
@ -367,8 +365,7 @@ AwtTextComponent::WmPaste()
|
|||||||
}
|
}
|
||||||
jobject target = GetTarget(env);
|
jobject target = GetTarget(env);
|
||||||
jboolean canAccessClipboard =
|
jboolean canAccessClipboard =
|
||||||
env->GetBooleanField(target,
|
env->CallBooleanMethod (target, AwtTextComponent::canAccessClipboardMID);
|
||||||
AwtTextComponent::canAccessClipboardID);
|
|
||||||
env->DeleteLocalRef(target);
|
env->DeleteLocalRef(target);
|
||||||
return (canAccessClipboard) ? mrDoDefault : mrConsume;
|
return (canAccessClipboard) ? mrDoDefault : mrConsume;
|
||||||
}
|
}
|
||||||
@ -854,12 +851,13 @@ Java_sun_awt_windows_WTextComponentPeer_initIDs(JNIEnv *env, jclass cls)
|
|||||||
{
|
{
|
||||||
TRY;
|
TRY;
|
||||||
|
|
||||||
cls = env->FindClass("java/awt/TextComponent");
|
jclass textComponentClassID = env->FindClass("java/awt/TextComponent");
|
||||||
if (cls != NULL) {
|
AwtTextComponent::canAccessClipboardMID =
|
||||||
AwtTextComponent::canAccessClipboardID =
|
env->GetMethodID(textComponentClassID,
|
||||||
env->GetFieldID(cls, "canAccessClipboard", "Z");
|
"canAccessClipboard", "()Z");
|
||||||
DASSERT(AwtTextComponent::canAccessClipboardID != NULL);
|
env->DeleteLocalRef(textComponentClassID);
|
||||||
}
|
|
||||||
|
DASSERT(AwtTextComponent::canAccessClipboardMID != NULL);
|
||||||
|
|
||||||
CATCH_BAD_ALLOC;
|
CATCH_BAD_ALLOC;
|
||||||
}
|
}
|
||||||
|
@ -42,8 +42,7 @@
|
|||||||
|
|
||||||
class AwtTextComponent : public AwtComponent {
|
class AwtTextComponent : public AwtComponent {
|
||||||
public:
|
public:
|
||||||
/* java.awt.TextComponent canAccessClipboard field ID */
|
static jmethodID canAccessClipboardMID;
|
||||||
static jfieldID canAccessClipboardID;
|
|
||||||
|
|
||||||
AwtTextComponent();
|
AwtTextComponent();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user