Add support for selectively filtering Java classes' visibility to JS

This commit is contained in:
norris%netscape.com 1999-06-18 21:35:35 +00:00
Родитель 562b4ecb1b
Коммит 716b905e30
6 изменённых файлов: 38 добавлений и 0 удалений

Просмотреть файл

@ -16,6 +16,8 @@
* Reserved.
*/
// API class
package org.mozilla.javascript;
import java.util.Vector;

Просмотреть файл

@ -135,8 +135,12 @@ public class NativeJavaPackage extends ScriptableObject {
String newPackage = packageName.length() == 0
? id
: packageName + "." + id;
Context cx = Context.getContext();
SecuritySupport ss = cx.getSecuritySupport();
Scriptable newValue;
try {
if (ss != null && !ss.visibleToScripts(newPackage))
throw new ClassNotFoundException();
Class newClass = Class.forName(newPackage);
newValue = NativeJavaClass.wrap(getTopLevelScope(this), newClass);
newValue.setParentScope(this);

Просмотреть файл

@ -90,4 +90,17 @@ public interface SecuritySupport {
* @return a security context object previously passed to defineClass
*/
public Object getSecurityDomain(Class cl);
/**
* Return true iff the Java class with the given name should be exposed
* to scripts.
* <p>
* An embedding may filter which Java classes are exposed through
* LiveConnect to JavaScript scripts.
* @param fullClassName the full name of the class (including the package
* name, with '.' as a delimiter). For example the
* standard string class is "java.lang.String"
* @return whether or not to reveal this class to scripts
*/
public boolean visibleToScripts(String fullClassName);
}

Просмотреть файл

@ -16,6 +16,8 @@
* Reserved.
*/
// API class
package org.mozilla.javascript;
import java.util.Vector;

Просмотреть файл

@ -135,8 +135,12 @@ public class NativeJavaPackage extends ScriptableObject {
String newPackage = packageName.length() == 0
? id
: packageName + "." + id;
Context cx = Context.getContext();
SecuritySupport ss = cx.getSecuritySupport();
Scriptable newValue;
try {
if (ss != null && !ss.visibleToScripts(newPackage))
throw new ClassNotFoundException();
Class newClass = Class.forName(newPackage);
newValue = NativeJavaClass.wrap(getTopLevelScope(this), newClass);
newValue.setParentScope(this);

Просмотреть файл

@ -90,4 +90,17 @@ public interface SecuritySupport {
* @return a security context object previously passed to defineClass
*/
public Object getSecurityDomain(Class cl);
/**
* Return true iff the Java class with the given name should be exposed
* to scripts.
* <p>
* An embedding may filter which Java classes are exposed through
* LiveConnect to JavaScript scripts.
* @param fullClassName the full name of the class (including the package
* name, with '.' as a delimiter). For example the
* standard string class is "java.lang.String"
* @return whether or not to reveal this class to scripts
*/
public boolean visibleToScripts(String fullClassName);
}