зеркало из https://github.com/mozilla/gecko-dev.git
Add support for selectively filtering Java classes' visibility to JS
This commit is contained in:
Родитель
562b4ecb1b
Коммит
716b905e30
|
@ -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);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче