home *** CD-ROM | disk | FTP | other *** search
- package opera;
-
- import java.io.File;
- import java.io.FilePermission;
- import java.net.SocketPermission;
- import java.net.URL;
- import java.net.URLClassLoader;
- import java.security.AccessController;
- import java.security.AllPermission;
- import java.security.CodeSource;
- import java.security.PermissionCollection;
- import java.util.PropertyPermission;
-
- public class PluginClassLoader extends URLClassLoader {
- private static RuntimePermission usePolicyPermission = new RuntimePermission("usePolicy");
- private static PropertyPermission browserReadPerm = new PropertyPermission("browser", "read");
- private static PropertyPermission browserVerReadPerm = new PropertyPermission("browser.version", "read");
- private URL codeBase;
- String key;
- private AppContextAdapter appContext = null;
- private ThreadGroup threadGroup = null;
- private int usageCount = 0;
-
- String getKey() {
- return this.key;
- }
-
- public PluginClassLoader(URL var1, String var2) {
- super(new URL[0], ClassLoader.getSystemClassLoader());
- this.codeBase = var1;
- this.key = var2;
- }
-
- public void addJar(URL var1) {
- this.addURL(var1);
- }
-
- ThreadGroup getThreadGroup() {
- try {
- if (this.threadGroup == null || this.threadGroup.isDestroyed()) {
- this.threadGroup = new ThreadGroup(this.codeBase + "-threadGroup");
- this.threadGroup.setMaxPriority(4);
- AppContextCreator var1 = new AppContextCreator(this.threadGroup);
- var1.setContextClassLoader(this);
- Object var2 = var1.syncObject;
- synchronized(var2) {
- var1.start();
-
- try {
- var1.syncObject.wait();
- } catch (InterruptedException var5) {
- }
-
- this.appContext = var1.appContext;
- }
-
- Object var8 = null;
- }
- } catch (Exception var7) {
- var7.printStackTrace(System.err);
- }
-
- return this.threadGroup;
- }
-
- protected int getUsageCount() {
- return this.usageCount;
- }
-
- protected void grab() {
- ++this.usageCount;
- this.getThreadGroup();
- }
-
- protected void release() {
- if (this.usageCount > 1) {
- --this.usageCount;
- } else {
- if (this.appContext != null) {
- try {
- this.appContext.dispose();
- } catch (IllegalThreadStateException var2) {
- var2.printStackTrace(System.err);
- }
- }
-
- this.usageCount = 0;
- this.appContext = null;
- this.threadGroup = null;
- PluginPanel.cacheClassLoader(this);
- }
-
- }
-
- public AppContextAdapter getAppContext() {
- return this.appContext;
- }
-
- public PermissionCollection getPermissions(CodeSource var1) {
- PermissionCollection var2 = super.getPermissions(var1);
- URL var3 = var1.getLocation();
- if (var3.getProtocol().equals("file")) {
- String var4 = var3.getFile().replace('/', File.separatorChar);
- if (!var4.endsWith(File.separator)) {
- int var5 = var4.lastIndexOf(File.separatorChar);
- if (var5 != -1) {
- var4 = var4.substring(0, var5 + 1) + "-";
- var2.add(new FilePermission(var4, "read"));
- }
- }
-
- var2.add(new SocketPermission("localhost", "connect,accept"));
- AccessController.doPrivileged(new 1(this, var2));
- if (this.codeBase.getProtocol().equals("file")) {
- String var7 = this.codeBase.getFile().replace('/', File.separatorChar);
- if (var7.endsWith(File.separator)) {
- var7 = var7 + "-";
- }
-
- var2.add(new FilePermission(var7, "read"));
- }
- }
-
- var2.add(browserReadPerm);
- var2.add(browserVerReadPerm);
- if (var1.getCertificates() != null && !var2.implies(usePolicyPermission) && this.allPermissionsGranted(var1)) {
- var2.add(new AllPermission());
- }
-
- return var2;
- }
-
- boolean allPermissionsGranted(CodeSource var1) {
- return System.getProperty("browser.opera.useCertificateHandler").equals("true") ? CertificateHandler.checkCertificates(var1) : false;
- }
- }
-