diff --git a/js/rhino/org/mozilla/javascript/ImporterTopLevel.java b/js/rhino/org/mozilla/javascript/ImporterTopLevel.java index 45c297ef0516..6994c2c709d0 100644 --- a/js/rhino/org/mozilla/javascript/ImporterTopLevel.java +++ b/js/rhino/org/mozilla/javascript/ImporterTopLevel.java @@ -16,6 +16,8 @@ * Reserved. */ +// API class + package org.mozilla.javascript; import java.util.Vector; diff --git a/js/rhino/org/mozilla/javascript/NativeJavaPackage.java b/js/rhino/org/mozilla/javascript/NativeJavaPackage.java index 240224441879..bf71836817b0 100644 --- a/js/rhino/org/mozilla/javascript/NativeJavaPackage.java +++ b/js/rhino/org/mozilla/javascript/NativeJavaPackage.java @@ -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); diff --git a/js/rhino/org/mozilla/javascript/SecuritySupport.java b/js/rhino/org/mozilla/javascript/SecuritySupport.java index 8c643287bfdf..98be62f3e8d6 100644 --- a/js/rhino/org/mozilla/javascript/SecuritySupport.java +++ b/js/rhino/org/mozilla/javascript/SecuritySupport.java @@ -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. + *

+ * 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); } diff --git a/js/rhino/src/org/mozilla/javascript/ImporterTopLevel.java b/js/rhino/src/org/mozilla/javascript/ImporterTopLevel.java index 45c297ef0516..6994c2c709d0 100644 --- a/js/rhino/src/org/mozilla/javascript/ImporterTopLevel.java +++ b/js/rhino/src/org/mozilla/javascript/ImporterTopLevel.java @@ -16,6 +16,8 @@ * Reserved. */ +// API class + package org.mozilla.javascript; import java.util.Vector; diff --git a/js/rhino/src/org/mozilla/javascript/NativeJavaPackage.java b/js/rhino/src/org/mozilla/javascript/NativeJavaPackage.java index 240224441879..bf71836817b0 100644 --- a/js/rhino/src/org/mozilla/javascript/NativeJavaPackage.java +++ b/js/rhino/src/org/mozilla/javascript/NativeJavaPackage.java @@ -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); diff --git a/js/rhino/src/org/mozilla/javascript/SecuritySupport.java b/js/rhino/src/org/mozilla/javascript/SecuritySupport.java index 8c643287bfdf..98be62f3e8d6 100644 --- a/js/rhino/src/org/mozilla/javascript/SecuritySupport.java +++ b/js/rhino/src/org/mozilla/javascript/SecuritySupport.java @@ -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. + *

+ * 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); }