home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 November / PCO1197.ISO / FilesBBS / WIN95 / NET_COM / N32E403.EXE / nav40l.z / java40.jar / netscape / applet / AppletClassLoader.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-09-04  |  12.9 KB  |  806 lines

  1. package netscape.applet;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.io.FileOutputStream;
  6. import java.io.IOException;
  7. import java.io.InputStream;
  8. import java.net.MalformedURLException;
  9. import java.net.URL;
  10. import java.net.URLConnection;
  11. import java.util.Enumeration;
  12. import java.util.Hashtable;
  13. import java.util.Vector;
  14. import java.util.zip.ZipEntry;
  15. import java.util.zip.ZipFile;
  16. import netscape.misc.WeakLink;
  17. import netscape.security.AppletSecurity;
  18. import netscape.security.AppletSecurityException;
  19. import netscape.security.Principal;
  20. import netscape.security.PrivilegeManager;
  21. import netscape.security.Target;
  22.  
  23. public class AppletClassLoader extends ClassLoader {
  24.    URL codeBaseURL;
  25.    URL archiveURL;
  26.    MozillaAppletContext context;
  27.    static boolean wantTiming;
  28.    long loaderTime;
  29.    String scriptOrigin;
  30.    boolean isReusable;
  31.    Principal codeBasePrincipal;
  32.    Principal[] matchPrincipalAry;
  33.    public static final String MANIFEST_FILENAME = "META-INF/manifest.mf";
  34.    private String archiveFile;
  35.    private boolean capturedArchive;
  36.    private int nativeArchive;
  37.    private int nativeZig;
  38.    byte[] inputBuf;
  39.    static Vector classloaders = new Vector(10);
  40.    private static boolean capturingClasses;
  41.    private static final boolean MARIMBA_ENABLED = true;
  42.    private CastanetChannelInfo channelInfo;
  43.    private Hashtable codebaseEnv;
  44.  
  45.    String grabArchiveFile() throws IOException {
  46.       String var1 = this.archiveURL.getFile();
  47.       if (!var1.endsWith(".jar") && !var1.endsWith(".zip")) {
  48.          return null;
  49.       } else {
  50.          String var2;
  51.          if (capturingClasses) {
  52.             int var3 = var1.lastIndexOf(47);
  53.             String var4 = var1.substring(var3 + 1);
  54.             var2 = this.getCaptureDir() + "/" + var4;
  55.          } else {
  56.             var2 = this.getTempName();
  57.             if (var2 == null) {
  58.                return null;
  59.             }
  60.          }
  61.  
  62.          SecurityManager.enablePrivilege("UniversalFileAccess");
  63.          SecurityManager.enablePrivilege("UniversalConnect");
  64.          FileOutputStream var14 = new FileOutputStream(var2);
  65.          long var15 = 0L;
  66.          if (wantTiming) {
  67.             var15 = System.currentTimeMillis();
  68.          }
  69.  
  70.          InputStream var6 = null;
  71.  
  72.          try {
  73.             URLConnection var9 = this.archiveURL.openConnection();
  74.             var9.setAllowUserInteraction(false);
  75.             var6 = var9.getInputStream();
  76.             if (this.inputBuf == null) {
  77.                this.inputBuf = new byte[4096];
  78.             }
  79.  
  80.             Thread var11 = Thread.currentThread();
  81.  
  82.             int var10;
  83.             while((var10 = var6.read(this.inputBuf)) >= 0 && !var11.isInterrupted()) {
  84.                var14.write(this.inputBuf, 0, var10);
  85.             }
  86.  
  87.             if (var11.isInterrupted()) {
  88.                throw new IOException("interrupted: " + this);
  89.             }
  90.          } finally {
  91.             if (var6 != null) {
  92.                var6.close();
  93.             }
  94.  
  95.             if (var14 != null) {
  96.                var14.close();
  97.             }
  98.  
  99.          }
  100.  
  101.          SecurityManager.revertPrivilege();
  102.          if (wantTiming) {
  103.             long var7 = System.currentTimeMillis();
  104.             long var16 = var7 - var15;
  105.             this.loaderTime += var16;
  106.             System.err.println("# Archive download time: " + this.archiveURL + ": " + var16 + " (total = " + this.loaderTime + ")");
  107.          }
  108.  
  109.          if (capturingClasses) {
  110.             System.err.println("#\tCaptured archive " + var2);
  111.             this.capturedArchive = true;
  112.          } else if (this.context != null && MozillaAppletContext.debug >= 2) {
  113.             System.err.println("# Loading classes from downloaded archive file: " + this.archiveURL);
  114.          }
  115.  
  116.          return var2;
  117.       }
  118.    }
  119.  
  120.    native String getTempName();
  121.  
  122.    private native int openArchive0(String var1) throws IOException;
  123.  
  124.    private native byte[] loadFromArchive0(int var1, String var2) throws IOException;
  125.  
  126.    private native void closeArchive0(int var1) throws IOException;
  127.  
  128.    void openArchive() {
  129.       try {
  130.          this.archiveFile = this.grabArchiveFile();
  131.          if (this.archiveFile == null) {
  132.             return;
  133.          }
  134.  
  135.          this.nativeArchive = this.openArchive0(this.archiveFile);
  136.          if (this.nativeArchive != 0) {
  137.             this.nativeZig = this.setupZignature();
  138.             if (this.nativeZig != 0) {
  139.                if (!this.loadManifest(this.nativeArchive, this.nativeZig, this.codeBaseURL.getFile()) || this.loadSignatures(this.nativeArchive, this.nativeZig, this.codeBaseURL.getFile()) <= 0) {
  140.                   this.nativeZig = 0;
  141.                }
  142.  
  143.                return;
  144.             }
  145.          }
  146.       } catch (IOException var2) {
  147.          ((Throwable)var2).printStackTrace();
  148.          System.err.println("# Unable to load archive " + this.archiveURL + ": " + var2);
  149.          this.nativeZig = 0;
  150.       }
  151.  
  152.    }
  153.  
  154.    byte[] loadFromArchive(String var1) throws IOException {
  155.       return this.nativeArchive != 0 ? this.loadFromArchive0(this.nativeArchive, var1) : null;
  156.    }
  157.  
  158.    void closeArchive() {
  159.       if (this.nativeArchive != 0) {
  160.          try {
  161.             this.closeArchive0(this.nativeArchive);
  162.             if (this.context != null && MozillaAppletContext.debug >= 5) {
  163.                System.err.println("# Closed downloaded archive: " + this.archiveURL);
  164.             }
  165.          } catch (IOException var3) {
  166.             if (this.context != null && MozillaAppletContext.debug >= 5) {
  167.                System.err.println("# Failed to close downloaded archive: " + this.archiveURL);
  168.             }
  169.          }
  170.  
  171.          this.nativeArchive = 0;
  172.          if (!this.capturedArchive) {
  173.             File var1 = new File(this.archiveFile);
  174.             SecurityManager.enablePrivilege("UniversalFileRead");
  175.             SecurityManager.enablePrivilege("UniversalFileDelete");
  176.             boolean var2 = var1.delete();
  177.             SecurityManager.revertPrivilege();
  178.             if (this.context != null && MozillaAppletContext.debug >= 5) {
  179.                if (var2) {
  180.                   System.err.println("# Deleted downloaded archive: " + this.archiveFile);
  181.                   return;
  182.                }
  183.  
  184.                System.err.println("# Failed to delete downloaded archive: " + this.archiveFile);
  185.             }
  186.          }
  187.       }
  188.  
  189.    }
  190.  
  191.    static synchronized AppletClassLoader getClassLoader(MozillaAppletContext var0, URL var1, URL var2, String var3, boolean var4) {
  192.       boolean var5 = false;
  193.       AppletClassLoader var6 = null;
  194.       SecurityManager.enablePrivilege("UniversalConnect");
  195.  
  196.       for(int var8 = 0; var8 < classloaders.size(); ++var8) {
  197.          WeakLink var9 = (WeakLink)classloaders.elementAt(var8);
  198.          AppletClassLoader var10 = (AppletClassLoader)var9.get();
  199.          if (var10 == null) {
  200.             var5 = true;
  201.          } else {
  202.             String var11 = var1.getFile();
  203.             int var12 = var11.lastIndexOf(47);
  204.             URL var7 = var1;
  205.             if (var12 > 0 && var12 < var11.length() - 1) {
  206.                try {
  207.                   var7 = new URL(var1, var11.substring(0, var12 + 1));
  208.                } catch (MalformedURLException var13) {
  209.                }
  210.             }
  211.  
  212.             if (var7.equals(var10.codeBaseURL)) {
  213.                label89: {
  214.                   boolean var10000;
  215.                   if (var2 == null) {
  216.                      if (var10.archiveURL == null) {
  217.                         break label89;
  218.                      }
  219.  
  220.                      var10000 = false;
  221.                   } else {
  222.                      var10000 = var2.equals(var10.archiveURL);
  223.                   }
  224.  
  225.                   if (!var10000) {
  226.                      continue;
  227.                   }
  228.                }
  229.  
  230.                label81: {
  231.                   boolean var16;
  232.                   if (var3 == null) {
  233.                      if (var10.scriptOrigin == null) {
  234.                         break label81;
  235.                      }
  236.  
  237.                      var16 = false;
  238.                   } else {
  239.                      var16 = var3.equals(var10.scriptOrigin);
  240.                   }
  241.  
  242.                   if (!var16) {
  243.                      continue;
  244.                   }
  245.                }
  246.  
  247.                if ((var3 == null || var0 == var10.context) && var10.isReusable) {
  248.                   if (!var4) {
  249.                      var6 = var10;
  250.                      if (MozillaAppletContext.debug >= 8) {
  251.                         System.err.println("#   reusing class loader " + var10 + "\n" + "#\tcontext = " + var0 + "\n" + "#\tcodebase = " + var7 + "\n" + "#\tarchive = " + var2 + "\n" + "#\tscriptOrigin = " + var3);
  252.                      }
  253.                      break;
  254.                   }
  255.  
  256.                   if (MozillaAppletContext.debug >= 8) {
  257.                      System.err.println("#   preventing reuse of " + var10);
  258.                   }
  259.  
  260.                   var10.isReusable = false;
  261.                }
  262.             }
  263.          }
  264.       }
  265.  
  266.       SecurityManager.revertPrivilege();
  267.       if (var6 == null) {
  268.          var6 = new AppletClassLoader(var0, var1, var2);
  269.          var6.scriptOrigin = var3;
  270.          classloaders.addElement(new WeakLink(var6));
  271.       }
  272.  
  273.       if (var5) {
  274.          for(int var14 = classloaders.size() - 1; var14 >= 0; --var14) {
  275.             WeakLink var15 = (WeakLink)classloaders.elementAt(var14);
  276.             if (var15.get() == null) {
  277.                classloaders.removeElementAt(var14);
  278.             }
  279.  
  280.             if (MozillaAppletContext.debug >= 8) {
  281.                System.err.println("#   classloader was removed");
  282.             }
  283.          }
  284.       }
  285.  
  286.       return var6;
  287.    }
  288.  
  289.    AppletClassLoader(MozillaAppletContext var1, URL var2, URL var3) {
  290.       this.capturedArchive = false;
  291.       this.scriptOrigin = null;
  292.       this.isReusable = true;
  293.       this.codeBasePrincipal = new Principal(var2);
  294.       String var4 = var2.getFile();
  295.       int var5 = var4.lastIndexOf(47);
  296.       if (var5 > 0 && var5 < var4.length() - 1) {
  297.          try {
  298.             var2 = new URL(var2, var4.substring(0, var5 + 1));
  299.          } catch (MalformedURLException var6) {
  300.          }
  301.       }
  302.  
  303.       this.codeBaseURL = var2;
  304.       this.archiveURL = var3;
  305.       this.context = var1;
  306.       if (MozillaAppletContext.debug > 5) {
  307.          System.err.println("#   new class loader " + this + "\n" + "#\tcontext = " + var1 + "\n" + "#\tcodebase = " + var2 + "\n" + "#\tarchive = " + var3);
  308.       }
  309.  
  310.       if (this.archiveURL != null) {
  311.          this.openArchive();
  312.       }
  313.  
  314.    }
  315.  
  316.    void close() {
  317.       if (this.archiveURL != null) {
  318.          this.closeArchive();
  319.       }
  320.  
  321.       if (this.channelInfo != null) {
  322.          this.channelInfo.closeZips();
  323.       }
  324.  
  325.    }
  326.  
  327.    protected void finalize() {
  328.       this.close();
  329.       if (MozillaAppletContext.debug >= 8) {
  330.          System.err.println("# finalized: " + this);
  331.       }
  332.  
  333.    }
  334.  
  335.    protected AppletClassLoader(URL var1) {
  336.       this((MozillaAppletContext)null, var1, (URL)null);
  337.    }
  338.  
  339.    String getScriptOrigin() {
  340.       return this.scriptOrigin;
  341.    }
  342.  
  343.    public URL getCodeBase() {
  344.       return this.codeBaseURL;
  345.    }
  346.  
  347.    private Class loadClass(String var1, URL var2, String var3) throws IOException {
  348.       SecurityManager.enablePrivilege("UniversalConnect");
  349.       byte[] var4 = var2.getData();
  350.       SecurityManager.revertPrivilege();
  351.       if (capturingClasses) {
  352.          this.captureClassFile(var1, var4);
  353.       }
  354.  
  355.       return ((ClassLoader)this).defineClass(var1, var4, 0, var4.length, this.nativeZig, var3);
  356.    }
  357.  
  358.    public Class loadClass(String var1) throws ClassNotFoundException {
  359.       return this.loadClass(var1, true);
  360.    }
  361.  
  362.    protected final Class loadClass(String var1, boolean var2) throws ClassNotFoundException {
  363.       Class var3;
  364.       if (wantTiming) {
  365.          long var4 = System.currentTimeMillis();
  366.          var3 = this.loadClass1(var1, var2);
  367.          long var6 = System.currentTimeMillis();
  368.          long var8 = var6 - var4;
  369.          this.loaderTime += var8;
  370.          System.err.println("# Class load time: " + var1 + ": " + var8 + " (total = " + this.loaderTime + ")");
  371.       } else {
  372.          var3 = this.loadClass1(var1, var2);
  373.       }
  374.  
  375.       return var3;
  376.    }
  377.  
  378.    private Class loadClass1(String var1, boolean var2) throws ClassNotFoundException {
  379.       Class var3 = ((ClassLoader)this).findLoadedClass(var1);
  380.       if (var3 == null) {
  381.          SecurityManager var4 = System.getSecurityManager();
  382.          if (var4 != null) {
  383.             int var5 = var1.lastIndexOf(46);
  384.             if (var5 >= 0) {
  385.                var4.checkPackageAccess(var1.substring(0, var5));
  386.             }
  387.          }
  388.  
  389.          try {
  390.             return ((ClassLoader)this).findSystemClass(var1);
  391.          } catch (NoClassDefFoundError var8) {
  392.             if (this.channelInfo == null) {
  393.                throw var8;
  394.             }
  395.          } catch (ClassNotFoundException var9) {
  396.          }
  397.  
  398.          var3 = this.findClass(var1);
  399.       }
  400.  
  401.       if (var3 == null) {
  402.          throw new ClassNotFoundException(var1);
  403.       } else {
  404.          if (this.nativeArchive != 0) {
  405.             System.getSecurityManager().checkURLConnect(this.codeBaseURL, this.archiveURL);
  406.          }
  407.  
  408.          if (var2) {
  409.             try {
  410.                ((ClassLoader)this).resolveClass(var3);
  411.             } catch (NoClassDefFoundError var6) {
  412.                if (this.channelInfo == null) {
  413.                   throw var6;
  414.                }
  415.  
  416.                throw new ClassNotFoundException(var1);
  417.             } catch (UnknownError var7) {
  418.                if (this.channelInfo == null) {
  419.                   throw var7;
  420.                }
  421.  
  422.                throw new ClassNotFoundException(var1);
  423.             }
  424.          }
  425.  
  426.          return var3;
  427.       }
  428.    }
  429.  
  430.    private synchronized Class findClass(String var1) throws ClassNotFoundException {
  431.       boolean var2 = true;
  432.       Class var3 = ((ClassLoader)this).findLoadedClass(var1);
  433.       if (var3 != null) {
  434.          return var3;
  435.       } else {
  436.          if (MozillaAppletContext.debug >= 2) {
  437.             System.err.println("# Loading class " + var1);
  438.          }
  439.  
  440.          SecurityManager var4 = System.getSecurityManager();
  441.          if (var4 != null) {
  442.             int var5 = var1.lastIndexOf(46);
  443.             if (var5 >= 0) {
  444.                var4.checkPackageDefinition(var1.substring(0, var5));
  445.             }
  446.          }
  447.  
  448.          String var14 = var1.replace('.', '/') + ".class";
  449.          if (this.nativeArchive != 0) {
  450.             try {
  451.                byte[] var6 = this.loadFromArchive(var14);
  452.                if (var6 != null) {
  453.                   var3 = ((ClassLoader)this).defineClass(var1, var6, 0, var6.length, this.nativeZig, var14);
  454.                   if (var3 != null && this.context != null && MozillaAppletContext.debug >= 2) {
  455.                      System.err.println("# Loaded " + var14 + " from " + this.archiveURL);
  456.                   }
  457.  
  458.                   var2 = false;
  459.                }
  460.             } catch (IOException var12) {
  461.                if (MozillaAppletContext.debug >= 2) {
  462.                   System.err.println("# Failed to load " + var14 + " from " + this.archiveURL);
  463.                }
  464.             }
  465.          }
  466.  
  467.          if (var3 == null) {
  468.             URL var15;
  469.             try {
  470.                var15 = new URL(this.codeBaseURL, var14);
  471.             } catch (MalformedURLException var9) {
  472.                throw new ClassNotFoundException(var1);
  473.             }
  474.  
  475.             if (this.context != null && MozillaAppletContext.debug >= 5) {
  476.                System.err.println("# Fetching " + var15);
  477.             }
  478.  
  479.             try {
  480.                var3 = this.loadClass(var1, var15, var14);
  481.                var2 = false;
  482.             } catch (IOException var10) {
  483.                if (this.channelInfo != null) {
  484.                   try {
  485.                      var3 = this.marimbaLoad(var1);
  486.                      var2 = false;
  487.                   } catch (IOException var8) {
  488.                   }
  489.                }
  490.  
  491.                if (var3 == null) {
  492.                   throw new ClassNotFoundException(var1);
  493.                }
  494.             } catch (SecurityException var11) {
  495.                if (this.context != null && MozillaAppletContext.debug >= 5) {
  496.                   System.err.println("# Exception while loading " + var14 + " from downloaded archive " + var15.toString() + "\n#   Exception: " + ((Throwable)var11).toString());
  497.                }
  498.  
  499.                throw var11;
  500.             }
  501.          }
  502.  
  503.          if (!var1.equals(var3.getName())) {
  504.             Class var16 = var3;
  505.             Object var13 = null;
  506.             throw new ClassFormatError(var1 + " != " + var16.getName());
  507.          } else {
  508.             if (!var2) {
  509.                this.setPrincipalAry(var3, var14);
  510.             }
  511.  
  512.             return var3;
  513.          }
  514.       }
  515.    }
  516.  
  517.    static boolean getCaptureClassFiles() {
  518.       return capturingClasses;
  519.    }
  520.  
  521.    static void setCaptureClassFiles(boolean var0) {
  522.       capturingClasses = var0;
  523.    }
  524.  
  525.    String getCaptureDir() throws IOException {
  526.       String var1 = this.codeBaseURL.toString();
  527.       if (var1.startsWith("http://")) {
  528.          var1 = var1.substring(7);
  529.       }
  530.  
  531.       if (var1.endsWith("/")) {
  532.          var1 = var1.substring(0, var1.length() - 1);
  533.       }
  534.  
  535.       var1 = var1.replace('/', '_').replace(':', '_');
  536.       SecurityManager.enablePrivilege("UniversalFileRead");
  537.       SecurityManager.enablePrivilege("UniversalFileWrite");
  538.       File var2 = new File(var1);
  539.       if ((!var2.exists() || !var2.isDirectory()) && !var2.mkdir()) {
  540.          throw new IOException(var2 + " is not a directory");
  541.       } else {
  542.          return var1;
  543.       }
  544.    }
  545.  
  546.    void captureClassFile(String var1, byte[] var2) {
  547.       try {
  548.          String var3 = this.getCaptureDir();
  549.          SecurityManager.enablePrivilege("UniversalFileRead");
  550.          SecurityManager.enablePrivilege("UniversalFileWrite");
  551.  
  552.          File var6;
  553.          do {
  554.             int var4 = var1.indexOf(46);
  555.             if (var4 == -1) {
  556.                File var9 = new File(var3 + "/" + var1 + ".class");
  557.                FileOutputStream var10 = new FileOutputStream(var9);
  558.                var10.write(var2, 0, var2.length);
  559.                System.err.println("#\tCaptured class " + var9);
  560.                var10.close();
  561.                return;
  562.             }
  563.  
  564.             String var5 = var1.substring(0, var4);
  565.             var1 = var1.substring(var4 + 1);
  566.             var3 = var3 + "/" + var5;
  567.             var6 = new File(var3);
  568.          } while(var6.exists() && var6.isDirectory() || var6.mkdir());
  569.  
  570.          throw new IOException("Can't create " + var6);
  571.       } catch (SecurityException var7) {
  572.          System.err.println("#\tCan't capture class: " + var7);
  573.       } catch (IOException var8) {
  574.          System.err.println("#\tCan't capture class: " + var8);
  575.       }
  576.    }
  577.  
  578.    byte[] getResource(URL var1) {
  579.       byte[] var2 = null;
  580.       String var3 = var1.getFile();
  581.       String var4 = this.codeBaseURL.getFile();
  582.       if (!var3.startsWith(var4)) {
  583.          return null;
  584.       } else {
  585.          String var5 = var3.substring(var4.length());
  586.  
  587.          try {
  588.             var2 = this.loadFromArchive(var5);
  589.             if (var2 != null && this.context != null && MozillaAppletContext.debug >= 5) {
  590.                System.err.println("# Loaded " + var5 + " from " + this.archiveURL);
  591.             }
  592.          } catch (IOException var6) {
  593.             if (MozillaAppletContext.debug >= 5) {
  594.                System.err.println("# Failed to load " + var5 + " from " + this.archiveURL);
  595.             }
  596.          }
  597.  
  598.          return var2;
  599.       }
  600.    }
  601.  
  602.    private boolean setPrincipalAry(Class var1, String var2) {
  603.       Object var3 = null;
  604.       int var4 = 1;
  605.       Object[] var5 = getCertificates(this.nativeZig, var1, var2);
  606.       if (var5 != null) {
  607.          var4 += var5.length;
  608.       }
  609.  
  610.       Principal[] var12 = new Principal[var4];
  611.  
  612.       for(int var6 = var4 - 1; var6-- > 0; var12[var6] = new Principal(14, (byte[])var5[var6], var1)) {
  613.       }
  614.  
  615.       var12[var4 - 1] = this.codeBasePrincipal;
  616.  
  617.       try {
  618.          if (this.matchPrincipalAry != null) {
  619.             PrivilegeManager var9 = AppletSecurity.getPrivilegeManager();
  620.             if (var9 != null && var9.comparePrincipalArray(var12, this.matchPrincipalAry) == 1) {
  621.                var12 = new Principal[]{this.codeBasePrincipal};
  622.                throw new AppletSecurityException("mismatch of principals");
  623.             }
  624.          }
  625.       } finally {
  626.          this.setPrincipals(var1, var12);
  627.       }
  628.  
  629.       return true;
  630.    }
  631.  
  632.    public boolean checkMatchPrincipalAlways(int var1) {
  633.       PrivilegeManager var5 = AppletSecurity.getPrivilegeManager();
  634.       if (var5 == null) {
  635.          return true;
  636.       } else {
  637.          this.matchPrincipalAry = var5.getClassPrincipalsFromStack(var1 + 1);
  638.          Enumeration var2 = ((ClassLoader)this).getClassNames();
  639.  
  640.          while(var2.hasMoreElements()) {
  641.             String var4 = (String)var2.nextElement();
  642.             Class var3 = ((ClassLoader)this).findLoadedClass(var4);
  643.             if (var3 != null && !var5.checkMatchPrincipal(var3, var1 + 1)) {
  644.                return false;
  645.             }
  646.          }
  647.  
  648.          return true;
  649.       }
  650.    }
  651.  
  652.    private native int setupZignature();
  653.  
  654.    private native int destroyZignature(int var1);
  655.  
  656.    private native boolean loadManifest(int var1, int var2, String var3);
  657.  
  658.    private native int loadSignatures(int var1, int var2, String var3);
  659.  
  660.    private native boolean verifySignature(int var1, Class var2, String var3);
  661.  
  662.    private static native Object[] getCertificates(int var0, Class var1, String var2);
  663.  
  664.    private native void setPrincipals(Class var1, Principal[] var2);
  665.  
  666.    public AppletClassLoader(URL var1, CastanetChannelInfo var2) {
  667.       this((MozillaAppletContext)null, var1, (URL)null);
  668.       this.channelInfo = var2;
  669.    }
  670.  
  671.    public Class classFromBytes(byte[] var1, String var2) {
  672.       if (this.channelInfo == null) {
  673.          return null;
  674.       } else {
  675.          Class var3 = ((ClassLoader)this).findLoadedClass(var2);
  676.          if (var3 != null) {
  677.             return var3;
  678.          } else {
  679.             try {
  680.                var3 = ((ClassLoader)this).findSystemClass(var2);
  681.                if (var3 != null) {
  682.                   return var3;
  683.                }
  684.             } catch (NoClassDefFoundError var8) {
  685.             } catch (ClassNotFoundException var9) {
  686.             }
  687.  
  688.             SecurityManager var4 = System.getSecurityManager();
  689.             if (var4 != null) {
  690.                int var5 = var2.lastIndexOf(46);
  691.                if (var5 >= 0) {
  692.                   var4.checkPackageDefinition(var2.substring(0, var5));
  693.                }
  694.             }
  695.  
  696.             PrivilegeManager var12 = PrivilegeManager.getPrivilegeManager();
  697.             if (var12 != null) {
  698.                Target var6 = Target.findTarget("MarimbaInternalTarget");
  699.                if (var6 == null) {
  700.                   throw new AppletSecurityException("classFromBytes call denied");
  701.                }
  702.  
  703.                var12.checkPrivilegeEnabled(var6);
  704.             }
  705.  
  706.             try {
  707.                var3 = ((ClassLoader)this).defineClass(var2, var1, 0, var1.length);
  708.                return var3;
  709.             } catch (NoClassDefFoundError var7) {
  710.                return null;
  711.             }
  712.          }
  713.       }
  714.    }
  715.  
  716.    private Class marimbaLoad(String var1) throws IOException, ClassNotFoundException {
  717.       if (this.channelInfo == null) {
  718.          return null;
  719.       } else {
  720.          Class var2 = null;
  721.          int var3 = this.channelInfo.getPathlen();
  722.          if (var3 != 0) {
  723.             String var4 = var1.replace('.', '/') + ".class";
  724.  
  725.             for(int var5 = 0; var5 < var3; ++var5) {
  726.                URL var6 = this.channelInfo.getURL(var5);
  727.                if (var6 != null) {
  728.                   try {
  729.                      var2 = this.loadClass(var1, new URL(var6, var4), var4);
  730.                      if (var2 != null) {
  731.                         return var2;
  732.                      }
  733.                   } catch (NoClassDefFoundError var14) {
  734.                   } catch (MalformedURLException var15) {
  735.                   } catch (FileNotFoundException var16) {
  736.                   }
  737.                }
  738.  
  739.                ZipFile var7 = this.channelInfo.getZip(var5);
  740.                if (var7 != null) {
  741.                   ZipEntry var8 = var7.getEntry(var4);
  742.                   if (var8 != null) {
  743.                      int var9 = (int)var8.getSize();
  744.                      byte[] var10 = new byte[var9];
  745.                      InputStream var11 = var7.getInputStream(var8);
  746.  
  747.                      for(int var12 = 0; var12 < var9; var12 += var11.read(var10, var12, var9 - var12)) {
  748.                      }
  749.  
  750.                      var11.close();
  751.  
  752.                      try {
  753.                         var2 = ((ClassLoader)this).defineClass(var1, var10, 0, var10.length);
  754.                      } catch (NoClassDefFoundError var13) {
  755.                      }
  756.  
  757.                      if (var2 != null) {
  758.                         return var2;
  759.                      }
  760.                   }
  761.                }
  762.             }
  763.          }
  764.  
  765.          return null;
  766.       }
  767.    }
  768.  
  769.    public boolean marimbaCheckRead(String var1, boolean var2) {
  770.       return this.channelInfo != null ? this.channelInfo.checkRead(var1, var2) : false;
  771.    }
  772.  
  773.    public boolean marimbaCheckWrite(String var1, boolean var2) {
  774.       return this.channelInfo != null ? this.channelInfo.checkWrite(var1, var2) : false;
  775.    }
  776.  
  777.    public String marimbaGetHost() {
  778.       return this.channelInfo != null ? this.channelInfo.getHost() : null;
  779.    }
  780.  
  781.    boolean marimbaCheckThreadGroup(ThreadGroup var1) {
  782.       return this.channelInfo == null ? false : this.channelInfo.checkThreadGroup(var1);
  783.    }
  784.  
  785.    void marimbaCheckTopLevelWindow(Object var1) {
  786.       if (this.channelInfo != null) {
  787.          this.channelInfo.checkTopLevelWindow(var1);
  788.       }
  789.    }
  790.  
  791.    Hashtable getCodebaseEnv() {
  792.       if (this.codebaseEnv == null) {
  793.          this.initCodebaseEnv();
  794.       }
  795.  
  796.       return this.codebaseEnv;
  797.    }
  798.  
  799.    synchronized void initCodebaseEnv() {
  800.       if (this.codebaseEnv == null) {
  801.          this.codebaseEnv = new Hashtable();
  802.       }
  803.  
  804.    }
  805. }
  806.