home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2003 January / maximum-cd-2003-01.iso / Software / Apps / OperawithJava / ow32enen700b1j.exe / OPERA.JAR / opera / PluginClassLoader.class (.txt) < prev    next >
Encoding:
Java Class File  |  2002-11-07  |  4.7 KB  |  137 lines

  1. package opera;
  2.  
  3. import java.io.File;
  4. import java.io.FilePermission;
  5. import java.net.SocketPermission;
  6. import java.net.URL;
  7. import java.net.URLClassLoader;
  8. import java.security.AccessController;
  9. import java.security.AllPermission;
  10. import java.security.CodeSource;
  11. import java.security.PermissionCollection;
  12. import java.util.PropertyPermission;
  13.  
  14. public class PluginClassLoader extends URLClassLoader {
  15.    private static RuntimePermission usePolicyPermission = new RuntimePermission("usePolicy");
  16.    private static PropertyPermission browserReadPerm = new PropertyPermission("browser", "read");
  17.    private static PropertyPermission browserVerReadPerm = new PropertyPermission("browser.version", "read");
  18.    private URL codeBase;
  19.    String key;
  20.    private AppContextAdapter appContext = null;
  21.    private ThreadGroup threadGroup = null;
  22.    private int usageCount = 0;
  23.  
  24.    String getKey() {
  25.       return this.key;
  26.    }
  27.  
  28.    public PluginClassLoader(URL var1, String var2) {
  29.       super(new URL[0], ClassLoader.getSystemClassLoader());
  30.       this.codeBase = var1;
  31.       this.key = var2;
  32.    }
  33.  
  34.    public void addJar(URL var1) {
  35.       this.addURL(var1);
  36.    }
  37.  
  38.    ThreadGroup getThreadGroup() {
  39.       try {
  40.          if (this.threadGroup == null || this.threadGroup.isDestroyed()) {
  41.             this.threadGroup = new ThreadGroup(this.codeBase + "-threadGroup");
  42.             this.threadGroup.setMaxPriority(4);
  43.             AppContextCreator var1 = new AppContextCreator(this.threadGroup);
  44.             var1.setContextClassLoader(this);
  45.             Object var2 = var1.syncObject;
  46.             synchronized(var2) {
  47.                var1.start();
  48.  
  49.                try {
  50.                   var1.syncObject.wait();
  51.                } catch (InterruptedException var5) {
  52.                }
  53.  
  54.                this.appContext = var1.appContext;
  55.             }
  56.  
  57.             Object var8 = null;
  58.          }
  59.       } catch (Exception var7) {
  60.          var7.printStackTrace(System.err);
  61.       }
  62.  
  63.       return this.threadGroup;
  64.    }
  65.  
  66.    protected int getUsageCount() {
  67.       return this.usageCount;
  68.    }
  69.  
  70.    protected void grab() {
  71.       ++this.usageCount;
  72.       this.getThreadGroup();
  73.    }
  74.  
  75.    protected void release() {
  76.       if (this.usageCount > 1) {
  77.          --this.usageCount;
  78.       } else {
  79.          if (this.appContext != null) {
  80.             try {
  81.                this.appContext.dispose();
  82.             } catch (IllegalThreadStateException var2) {
  83.                var2.printStackTrace(System.err);
  84.             }
  85.          }
  86.  
  87.          this.usageCount = 0;
  88.          this.appContext = null;
  89.          this.threadGroup = null;
  90.          PluginPanel.cacheClassLoader(this);
  91.       }
  92.  
  93.    }
  94.  
  95.    public AppContextAdapter getAppContext() {
  96.       return this.appContext;
  97.    }
  98.  
  99.    public PermissionCollection getPermissions(CodeSource var1) {
  100.       PermissionCollection var2 = super.getPermissions(var1);
  101.       URL var3 = var1.getLocation();
  102.       if (var3.getProtocol().equals("file")) {
  103.          String var4 = var3.getFile().replace('/', File.separatorChar);
  104.          if (!var4.endsWith(File.separator)) {
  105.             int var5 = var4.lastIndexOf(File.separatorChar);
  106.             if (var5 != -1) {
  107.                var4 = var4.substring(0, var5 + 1) + "-";
  108.                var2.add(new FilePermission(var4, "read"));
  109.             }
  110.          }
  111.  
  112.          var2.add(new SocketPermission("localhost", "connect,accept"));
  113.          AccessController.doPrivileged(new 1(this, var2));
  114.          if (this.codeBase.getProtocol().equals("file")) {
  115.             String var7 = this.codeBase.getFile().replace('/', File.separatorChar);
  116.             if (var7.endsWith(File.separator)) {
  117.                var7 = var7 + "-";
  118.             }
  119.  
  120.             var2.add(new FilePermission(var7, "read"));
  121.          }
  122.       }
  123.  
  124.       var2.add(browserReadPerm);
  125.       var2.add(browserVerReadPerm);
  126.       if (var1.getCertificates() != null && !var2.implies(usePolicyPermission) && this.allPermissionsGranted(var1)) {
  127.          var2.add(new AllPermission());
  128.       }
  129.  
  130.       return var2;
  131.    }
  132.  
  133.    boolean allPermissionsGranted(CodeSource var1) {
  134.       return System.getProperty("browser.opera.useCertificateHandler").equals("true") ? CertificateHandler.checkCertificates(var1) : false;
  135.    }
  136. }
  137.