home *** CD-ROM | disk | FTP | other *** search
- package com.ms.applet;
-
- import com.ms.awt.image.ByteArrayImageSource;
- import com.ms.com.ComLib;
- import com.ms.net.wininet.URLUtils;
- import com.ms.net.wininet.WininetStreamHandlerFactory;
- import java.applet.Applet;
- import java.applet.AppletContext;
- import java.applet.AppletStub;
- import java.applet.AudioClip;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Event;
- import java.awt.Frame;
- import java.awt.Image;
- import java.awt.Toolkit;
- import java.awt.Window;
- import java.awt.image.ImageProducer;
- import java.io.BufferedOutputStream;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.PrintStream;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.net.URLConnection;
- import java.util.Enumeration;
- import java.util.Hashtable;
- import java.util.Properties;
- import java.util.Vector;
- import sun.awt.image.URLImageSource;
-
- public class BrowserAppletFrame extends Frame implements AppletStub, Runnable, IJavaObjectLoader2 {
- int hwnd;
- Hashtable atts;
- URL documentURL;
- URL baseURL;
- Applet applet;
- AppletBaseClassLoader loader;
- int status;
- int pdispApplet;
- Thread handler;
- Dimension appletSize = new Dimension(0, 0);
- public static final int APPLET_DISPOSE = 0;
- public static final int APPLET_LOAD = 1;
- public static final int APPLET_INIT = 2;
- public static final int APPLET_START = 3;
- public static final int APPLET_STOP = 4;
- public static final int APPLET_DESTROY = 5;
- static final int WM_USER = 1024;
- static final int HOSTFRAME_SHOWSTATUS = 1025;
- static final int HOSTFRAME_REPAINTSTATUS = 1026;
- static final int HOSTFRAME_SHOWDOCUMENT = 1027;
- static final int HOSTFRAME_SETDOWNLOADSTATE = 1028;
- static final int STATUS_INITED = 256;
- static final int STATUS_STARTED = 257;
- static final int STATUS_STOPPED = 258;
- static final int STATUS_DESTROYED = 259;
- static final int STATUS_OPENING_CLASS = 260;
- static final int STATUS_OPENING_CABINET = 261;
- Event queue;
- static Vector frames = new Vector();
- private static Vector classloaders = new Vector();
- private static int oldloadersCount;
- private static final int CLASSLOADER_KEEP_ALIVE_COUNT = 3;
- private BrowserAppletContext appletContext;
- Hashtable audioHash = new Hashtable();
- Hashtable imgHash = new Hashtable();
- static boolean isFirstTimeInited;
- IJavaObjectLoaderHost jolHost;
-
- public static native int getAppletDispatch(Applet var0);
-
- public static native void releaseAppletDispatch(int var0);
-
- public int deliverJavaObjectDispatch() {
- return this.pdispApplet != 0 && this.status == 3 ? this.pdispApplet : 0;
- }
-
- public void loadParameter(String var1, String var2) {
- if (this.atts == null) {
- this.atts = new Hashtable();
- }
-
- var2 = var2.trim();
- int var4 = 0;
- int var5 = var2.length();
- char[] var6 = new char[var5];
-
- for(int var3 = 0; var3 < var5; ++var3) {
- char var7 = var2.charAt(var3);
- if (var7 >= ' ') {
- var6[var4++] = var7;
- }
- }
-
- var2 = new String(var6, 0, var4);
- this.atts.put(var1.toLowerCase(), var2);
- }
-
- String massageURLSpec(String var1) {
- if (!var1.startsWith("http:")) {
- String var2 = URLUtils.canonicalizeURL(var1, 805306368);
- if (var2 != null) {
- var1 = var2;
- }
- }
-
- if (var1.startsWith("file:")) {
- int var3 = var1.length();
-
- int var5;
- for(var5 = 5; var5 < var3 && var1.charAt(var5) == '/'; ++var5) {
- }
-
- if (var5 < 8) {
- var1 = "file:///" + var1.substring(var5);
- }
- }
-
- if (var1.startsWith("file:///\\\\")) {
- var1 = "file:///\\\\" + var1.substring(10).replace('\\', '/');
- } else {
- var1 = var1.replace('\\', '/');
- }
-
- return var1;
- }
-
- public void init(String var1, int var2, IJavaObjectLoaderHost var3) {
- firstTimeInit();
- this.jolHost = var3;
- this.hwnd = var2;
-
- try {
- ComLib.declareMessagePumpThread();
- } catch (Throwable var10) {
- }
-
- try {
- this.documentURL = new URL(this.massageURLSpec(var1));
- } catch (MalformedURLException var9) {
- }
-
- String var4 = this.getParameter("codebase");
- if (var4 != null) {
- if (!var4.endsWith("/")) {
- var4 = var4 + "/";
- }
-
- try {
- this.baseURL = new URL(this.massageURLSpec(var4));
- } catch (MalformedURLException var8) {
- }
- }
-
- if (this.baseURL == null) {
- this.baseURL = this.documentURL;
- }
-
- ((Component)this).setBackground(Color.lightGray);
-
- try {
- this.appletSize.width = Integer.valueOf(this.getParameter("width"));
- } catch (Exception var7) {
- }
-
- try {
- this.appletSize.height = Integer.valueOf(this.getParameter("height"));
- } catch (Exception var6) {
- }
-
- ((Component)this).resize(this.appletSize);
- String var5 = "applet-" + this.getParameter("code");
- this.handler = new Thread(new AppletThreadGroup("group " + var5), this, "thread " + var5);
- this.handler.start();
- }
-
- public void resizeApplet(int var1, int var2) {
- if (var1 != this.appletSize.width || var2 != this.appletSize.height) {
- this.appletSize.width = var1;
- this.appletSize.height = var2;
- ((Component)this).resize(this.appletSize);
- }
-
- }
-
- public void sendEvent(int var1) {
- this.queueEvent(new Event((Object)null, var1, (Object)null));
- }
-
- protected synchronized void queueEvent(Event var1) {
- if (this.queue == null) {
- var1.target = this.queue;
- this.queue = var1;
- this.notifyAll();
- } else {
- Event var2;
- for(var2 = this.queue; var2.target != null; var2 = (Event)var2.target) {
- }
-
- var2.target = var1;
- }
- }
-
- synchronized Event getNextEvent() throws InterruptedException {
- while(this.queue == null) {
- this.wait();
- }
-
- Event var1 = this.queue;
- this.queue = (Event)this.queue.target;
- var1.target = this;
- return var1;
- }
-
- public void run() {
- frames.addElement(this);
-
- try {
- int var3 = Thread.currentThread().getPriority();
- Thread.currentThread().setPriority(var3 + 1);
- ((Window)this).show();
-
- while(true) {
- Event var4;
- try {
- var4 = this.getNextEvent();
- } catch (InterruptedException var49) {
- return;
- }
-
- try {
- switch (var4.id) {
- case 0:
- if (this.status == 1) {
- this.status = 0;
- ((Container)this).remove(this.applet);
- return;
- }
- break;
- case 1:
- if (this.status != 0) {
- break;
- }
-
- this.loader = this.getClassLoader();
- String var5 = this.getParameter("code");
- if (var5.endsWith(".class")) {
- var5 = var5.substring(0, var5.length() - 6).replace('/', '.');
- }
-
- if (var5.endsWith(".java")) {
- var5 = var5.substring(0, var5.length() - 5).replace('/', '.');
- }
-
- try {
- try {
- this.setDownloadState(true);
- this.applet = (Applet)this.loader.loadClass(var5).newInstance();
- } finally {
- this.setDownloadState(false);
- }
-
- this.pdispApplet = getAppletDispatch(this.applet);
- } catch (ClassNotFoundException var50) {
- this.showAppletStatus("load: class " + var5 + " not found");
- this.showAppletException(var50);
- break;
- } catch (InstantiationException var51) {
- this.showAppletStatus("load: " + var5 + " can't be instantiated");
- this.showAppletException(var51);
- break;
- } catch (IllegalAccessException var52) {
- this.showAppletStatus("load: " + var5 + " is not public or has no public constructor");
- this.showAppletException(var52);
- break;
- } catch (Exception var53) {
- this.showAppletStatus("exception: " + var53);
- this.showAppletException(var53);
- break;
- } catch (ThreadDeath var54) {
- this.showAppletStatus("killed");
- return;
- } catch (Error var55) {
- this.showAppletStatus("error: " + var55);
- this.showAppletException(var55);
- break;
- }
-
- this.applet.setStub(this);
- this.applet.hide();
- ((Container)this).add("Center", this.applet);
- this.status = 1;
- this.showAppletStatus(256);
- ((Container)this).validate();
- break;
- case 2:
- if (this.status == 1) {
- try {
- this.setDownloadState(true);
- this.applet.resize(this.appletSize);
- this.applet.init();
- ((Container)this).validate();
- } finally {
- this.setDownloadState(false);
- }
-
- this.status = 2;
- this.showAppletStatus(256);
- }
- break;
- case 3:
- if (this.status == 2) {
- this.applet.resize(this.appletSize);
- this.applet.start();
- ((Container)this).validate();
- this.applet.show();
- this.status = 3;
- this.showAppletStatus(257);
- }
- break;
- case 4:
- if (this.status == 3) {
- this.status = 2;
- this.applet.hide();
- this.applet.stop();
- this.showAppletStatus(258);
- }
- break;
- case 5:
- if (this.status == 2) {
- this.status = 1;
- this.applet.destroy();
- this.showAppletStatus(259);
- }
- }
- } catch (Exception var56) {
- this.showAppletStatus("exception: " + var56);
- this.showAppletException(var56);
- } catch (ThreadDeath var57) {
- this.showAppletStatus("killed");
- return;
- } catch (Error var58) {
- this.showAppletStatus("error: " + var58);
- this.showAppletException(var58);
- }
- }
- } finally {
- frames.removeElement(this);
- releaseClassLoader(this.getCodeBase());
- releaseAppletDispatch(this.pdispApplet);
- ((Frame)this).dispose();
- this.jolHost = null;
- }
- }
-
- public boolean isActive() {
- return this.status == 3;
- }
-
- protected void showAppletStatus(String var1) {
- this.jolHost.showStatus(var1);
- }
-
- protected void showAppletStatus(int var1) {
- this.jolHost.showSystemStatus(var1, false, (String)null);
- }
-
- protected void showLoaderStatus(int var1, String var2) {
- this.jolHost.showSystemStatus(var1, true, var2);
- }
-
- protected void setDownloadState(boolean var1) {
- this.jolHost.setDownloadState(var1);
- }
-
- protected void showAppletException(Throwable var1) {
- var1.printStackTrace();
- }
-
- AppletBaseClassLoader getClassLoader() throws MalformedURLException {
- String var2 = this.getParameter("cabbase");
- Object var3 = null;
- URL var14;
- if (var2 == null) {
- var14 = this.getCodeBase();
- } else {
- var14 = new URL(this.getCodeBase(), var2);
- }
-
- Vector var4 = classloaders;
- synchronized(var4){}
-
- try {
- int var7 = classloaders.size();
-
- for(int var6 = 0; var6 < var7; ++var6) {
- ClassLoaderEntry var1 = (ClassLoaderEntry)classloaders.elementAt(var6);
- if (var14.equals(var1.codebase)) {
- if (var1.countRefs == 0) {
- --oldloadersCount;
- }
-
- ++var1.countRefs;
- AppletBaseClassLoader var8 = var1.loader;
- return var8;
- }
- }
-
- Object var15;
- if (var2 == null) {
- var15 = new AppletClassLoader(var14);
- } else {
- var15 = new CabClassLoader(var14, this.getCodeBase());
- }
-
- try {
- ((AppletBaseClassLoader)var15).setSecureState(this.documentURL.getProtocol(), var14.getProtocol());
- } catch (Throwable var11) {
- }
-
- ClassLoaderEntry var13 = new ClassLoaderEntry(var14, (AppletBaseClassLoader)var15);
- classloaders.addElement(var13);
- return var13.loader;
- } catch (Throwable var12) {
- throw var12;
- }
- }
-
- static synchronized void releaseClassLoader(URL var0) {
- int var2 = classloaders.size();
-
- for(int var1 = 0; var1 < var2; ++var1) {
- ClassLoaderEntry var3 = (ClassLoaderEntry)classloaders.elementAt(var1);
- if (var0.equals(var3.codebase)) {
- --var3.countRefs;
- classloaders.removeElementAt(var1);
- classloaders.addElement(var3);
- if (var3.countRefs == 0) {
- ++oldloadersCount;
- }
-
- while(oldloadersCount >= 3) {
- for(int var5 = 0; var5 < var2; ++var5) {
- ClassLoaderEntry var4 = (ClassLoaderEntry)classloaders.elementAt(var5);
- if (var4.countRefs == 0) {
- classloaders.removeElementAt(var5);
- --oldloadersCount;
- break;
- }
- }
- }
-
- return;
- }
- }
-
- }
-
- public URL getDocumentBase() {
- return this.documentURL;
- }
-
- public URL getCodeBase() {
- return this.baseURL;
- }
-
- public String getParameter(String var1) {
- return (String)this.atts.get(var1.toLowerCase());
- }
-
- public AppletContext getAppletContext() {
- if (this.appletContext == null) {
- this.appletContext = new BrowserAppletContext(this);
- }
-
- return this.appletContext;
- }
-
- public void appletResize(int var1, int var2) {
- }
-
- public Applet getApplet(String var1) {
- AppletSecurity var2 = (AppletSecurity)System.getSecurityManager();
- var1 = var1.toLowerCase();
- Enumeration var3 = frames.elements();
-
- while(var3.hasMoreElements()) {
- BrowserAppletFrame var4 = (BrowserAppletFrame)var3.nextElement();
- String var5 = var4.getParameter("name");
- if (var5 != null) {
- var5 = var5.toLowerCase();
- }
-
- if (var1.equals(var5) && var4.getDocumentBase().equals(this.getDocumentBase())) {
- try {
- var2.checkConnect(this.getCodeBase().getHost(), var4.getCodeBase().getHost());
- return var4.applet;
- } catch (SecurityException var6) {
- }
- }
- }
-
- return null;
- }
-
- public Enumeration getApplets() {
- AppletSecurity var1 = (AppletSecurity)System.getSecurityManager();
- Vector var2 = new Vector();
- Enumeration var3 = frames.elements();
-
- while(var3.hasMoreElements()) {
- BrowserAppletFrame var4 = (BrowserAppletFrame)var3.nextElement();
- if (var4.getDocumentBase().equals(this.getDocumentBase())) {
- try {
- var1.checkConnect(this.getCodeBase().getHost(), var4.getCodeBase().getHost());
- var2.addElement(var4.applet);
- } catch (SecurityException var5) {
- }
- }
- }
-
- return var2.elements();
- }
-
- byte[] getDataFileFromLoader(URL var1) {
- String var2 = this.baseURL.toString();
- String var3 = var1.toString();
- Object var4 = null;
- if (var2.length() == var3.length()) {
- return null;
- } else if (var3.startsWith(var2)) {
- String var5 = var3.substring(var2.length());
- return this.loader.getDataItem(var5);
- } else {
- return null;
- }
- }
-
- synchronized AudioClip getAudioClipFromCache(URL var1) {
- System.getSecurityManager().checkConnect(var1.getHost(), var1.getPort());
- Object var2 = (AudioClip)this.audioHash.get(var1);
- if (var2 != null) {
- return (AudioClip)var2;
- } else {
- if (this.loader.isDataStore()) {
- byte[] var3 = this.getDataFileFromLoader(var1);
- if (var3 != null) {
- var2 = new AppletAudioClip(var1, var3);
- }
- }
-
- if (var2 == null) {
- var2 = new AppletAudioClip(var1);
- }
-
- this.audioHash.put(var1, var2);
- return (AudioClip)var2;
- }
- }
-
- synchronized Image getImageFromHash(URL var1) {
- System.getSecurityManager().checkConnect(var1.getHost(), var1.getPort());
- Image var2 = (Image)this.imgHash.get(var1);
- if (var2 != null) {
- return var2;
- } else {
- Object var3 = null;
-
- try {
- try {
- if (this.loader.isDataStore()) {
- var3 = new ByteArrayImageSource(var1.toString(), this.getDataFileFromLoader(var1));
- }
- } catch (Exception var5) {
- }
-
- if (var3 == null) {
- URLConnection var4 = var1.openConnection();
- var4.setUseCaches(true);
- var3 = new URLImageSource(var1, var4);
- }
-
- if (var3 != null) {
- var2 = Toolkit.getDefaultToolkit().createImage((ImageProducer)var3);
- this.imgHash.put(var1, var2);
- }
- } catch (Exception var6) {
- }
-
- return var2;
- }
- }
-
- static synchronized void firstTimeInit() {
- if (!isFirstTimeInited) {
- isFirstTimeInited = true;
-
- try {
- URL.setURLStreamHandlerFactory(new WininetStreamHandlerFactory());
- } catch (Exception var3) {
- }
-
- if ("true".equalsIgnoreCase(System.getProperty("com.ms.applet.enable.logging"))) {
- try {
- String var0 = System.getProperty("java.home");
- PrintStream var1 = new PrintStream(new BufferedOutputStream(new FileOutputStream(new File(var0, "javalog.txt"))), true);
- System.out = var1;
- System.err = var1;
- } catch (Exception var2) {
- }
- }
-
- Properties var4 = new Properties(System.getProperties());
- ((Hashtable)var4).put("package.restrict.definition.java", "true");
- ((Hashtable)var4).put("package.restrict.definition.sun", "true");
- ((Hashtable)var4).put("package.restrict.definition.com.ms", "true");
- ((Hashtable)var4).put("java.version.applet", "true");
- ((Hashtable)var4).put("java.vendor.applet", "true");
- ((Hashtable)var4).put("java.vendor.url.applet", "true");
- ((Hashtable)var4).put("java.class.version.applet", "true");
- ((Hashtable)var4).put("os.name.applet", "true");
- ((Hashtable)var4).put("os.version.applet", "true");
- ((Hashtable)var4).put("os.arch.applet", "true");
- ((Hashtable)var4).put("file.separator.applet", "true");
- ((Hashtable)var4).put("path.separator.applet", "true");
- ((Hashtable)var4).put("line.separator.applet", "true");
- ((Hashtable)var4).put("browser.applet", "true");
- System.setProperties(var4);
- if (System.getSecurityManager() == null) {
- System.setSecurityManager(new AppletSecurity());
- }
-
- }
- }
-
- public IJavaObjectLoaderHost getLoaderHost() {
- return this.jolHost;
- }
- }
-