2362N/A * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * Applet panel class. The panel manages and manipulates the 0N/A * applet as it is being loaded. It forks a separate thread in a new 0N/A * thread group to call the applet's init(), start(), stop(), and 0N/A * destroy() methods. 0N/A * @author Arthur van Hoff 0N/A * The applet (if loaded). 0N/A * Applet will allow initialization. Should be 0N/A * set to false if loading a serialized applet 0N/A * that was pickled in the init=true state. 0N/A * The classloader for the applet. 0N/A /* applet event ids */ 0N/A /* send to the parent to force relayout */ 0N/A /* sent to a (distant) parent to indicate that the applet is being 0N/A * loaded or as completed loading 0N/A * The current status. One of: 0N/A * The thread for the applet. 0N/A * The initial applet size. 0N/A * The current applet size. 0N/A * The thread to use during applet loading 0N/A * Flag to indicate that a loading has been cancelled 0N/A /* abstract classes */ 0N/A * Creates a thread to run the applet. This method is called 0N/A * each time an applet is loaded and reloaded. 0N/A // Create a thread group for the applet, and start a new 0N/A // thread to load the applet. 0N/A // 4668479: Option to turn off codebase lookup in AppletClassLoader 0N/A // during resource requests. [stanley.ho] 0N/A // set the context class loader for this thread 0N/A * Construct an applet viewer and start the applet. 0N/A // Get the width (if any) 0N/A // Get the height (if any) 0N/A // Turn on the error flag and let TagAppletPanel 0N/A // do the right thing. 0N/A * Dispatch event to the listeners.. 0N/A //System.out.println("SEND= " + id); 0N/A * Send an event. Queue it for execution by the handler thread. 0N/A synchronized(
this) {
0N/A //System.out.println("SEND0= " + id); 0N/A // AppletClassLoader.release() must be called by a Thread 0N/A // not within the applet's ThreadGroup 0N/A * Get an event from the queue. 0N/A * This kludge is specific to get over AccessControlException thrown during 0N/A * Applet.stop() or destroy() when static thread is suspended. Set a flag 0N/A * in AppletClassLoader to indicate that an 0N/A * AccessControlException for RuntimePermission "modifyThread" or 0N/A * "modifyThreadGroup" had occurred. 0N/A * Execute applet events. 0N/A * Here is the state transition diagram 0N/A * Note: (XXX) is the action 0N/A * APPLET_XXX is the state 0N/A * (applet code loaded) --> APPLET_LOAD -- (applet init called)--> APPLET_INIT -- ( 0N/A * applet start called) --> APPLET_START -- (applet stop called) -->APPLET_STOP --(applet 0N/A * destroyed called) --> APPLET_DESTROY -->(applet gets disposed) --> 0N/A * APPLET_DISPOSE -->.... 0N/A * In the legacy lifecycle model. The applet gets loaded, inited and started. So it stays 0N/A * in the APPLET_START state unless the applet goes away(refresh page or leave the page). 0N/A * So the applet stop method called and the applet enters APPLET_STOP state. Then if the applet 0N/A * is revisited, it will call applet start method and enter the APPLET_START state and stay there. 0N/A * In the modern lifecycle model. When the applet first time visited, it is same as legacy lifecycle 0N/A * model. However, when the applet page goes away. It calls applet stop method and enters APPLET_STOP 0N/A * state and then applet destroyed method gets called and enters APPLET_DESTROY state. 0N/A * This code is also called by AppletViewer. In AppletViewer "Restart" menu, the applet is jump from 0N/A * APPLET_STOP to APPLET_DESTROY and to APPLET_INIT . 0N/A * Also, the applet can jump from APPLET_INIT state to APPLET_DESTROY (in Netscape/Mozilla case). 0N/A * Same as APPLET_LOAD to 0N/A * APPLET_DISPOSE since all of this are triggered by browser. 0N/A // if we are in the loader thread, cause 0N/A // loading to occur. We may exit this with 0N/A // status being APPLET_DISPOSE, APPLET_ERROR, 0N/A //showAppletStatus("EVENT = " + evt.getID()); 0N/A // This complexity allows loading of applets to be 0N/A // interruptable. The actual thread loading runs 0N/A // in a separate thread, so it can be interrupted 0N/A // without harming the applet thread. 0N/A // So that we don't have to worry about 0N/A // concurrency issues, the main applet thread waits 0N/A // until the loader thread terminates. 0N/A // (one way or another). 0N/A // REMIND: do we want a name? 0N/A //System.out.println("------------------- loading applet"); 0N/A // we get to go to sleep while this runs 0N/A // REMIND: issue an error -- this case should never 0N/A // AppletViewer "Restart" will jump from destroy method to 0N/A // init, that is why we need to check status w/ APPLET_DESTROY 0N/A //Need the default(fallback) font to be created in this AppContext 0N/A // Validate the applet in event dispatch thread 0N/A // to avoid deadlock. 0N/A // Validate and show the applet in event dispatch thread 0N/A // to avoid deadlock. 5704N/A // Fix for BugTraq ID 4041703. 5704N/A // Set the default focus for an applet. 0N/A // Hide the applet in event dispatch thread 0N/A // to avoid deadlock. 0N/A // During Applet.stop(), any AccessControlException on an involved Class remains in 0N/A // the "memory" of the AppletClassLoader. If the same instance of the ClassLoader is 0N/A // reused, the same exception will occur during class loading. Set the AppletClassLoader's 0N/A // exceptionStatusSet flag to allow recognition of what had happened 0N/A // when reusing AppletClassLoader object. 0N/A // rethrow exception to be handled as it normally would be. 0N/A // During Applet.destroy(), any AccessControlException on an involved Class remains in 0N/A // the "memory" of the AppletClassLoader. If the same instance of the ClassLoader is 0N/A // reused, the same exception will occur during class loading. Set the AppletClassLoader's 0N/A // exceptionStatusSet flag to allow recognition of what had happened 0N/A // when reusing AppletClassLoader object. 0N/A // rethrow exception to be handled as it normally would be. 0N/A * Gets most recent focus owner component associated with the given window. 0N/A * It does that without calling Window.getMostRecentFocusOwner since it 0N/A * provides its own logic contradicting with setDefautlFocus. Instead, it 0N/A * calls KeyboardFocusManager directly. 0N/A // Must never happen 0N/A // Meth refers static method 0N/A // Must never happen 0N/A // Will get here if exception was thrown or meth is null 0N/A * Fix for BugTraq ID 4041703. 0N/A * Set the focus to a reasonable default for an Applet. 0N/A // EmbeddedFrame might have focus before the applet was added. 0N/A // Thus after its activation the most recent focus owner will be 0N/A // restored. We need the applet's initial focusabled component to 0N/A * Load the applet into memory. 0N/A * Runs in a seperate (and interruptible) thread from the rest of the 0N/A * applet event processing so that it can be gracefully interrupted from 0N/A * things like HotJava. 0N/A // REMIND -- might be cool to visually indicate loading here -- 0N/A // maybe do animation? 0N/A // Create a class loader 0N/A // Load the archives if present. 0N/A // REMIND - this probably should be done in a separate thread, 0N/A // or at least the additional archives (epll). 0N/A // setup applet AppContext 0N/A // this must be called before loadJarFiles 0N/A // sbb -- I added a return here 0N/A // notify that loading is no longer going on 0N/A // Fixed #4508194: NullPointerException thrown during 0N/A // quick page switch 0N/A // Stick it in the frame 0N/A // serName is not null; 0N/A // Determine the JDK level that the applet targets. 0N/A // This is critical for enabling certain backward 0N/A // compatibility switch if an applet is a JDK 1.1 0N/A // applet. [stanley.ho] 0N/A // REMIND: This may not be exactly the right thing: the 0N/A // status is set by the stop button and not necessarily 0N/A // Load the archives if present. 0N/A // REMIND - this probably should be done in a separate thread, 0N/A // or at least the additional archives (epll). 0N/A * Request that the loading of the applet be stopped. 0N/A // REMIND: fill in the body 0N/A //System.out.println("Interrupting applet loader thread: " + loaderThread); 0N/A * Return true when the applet has been started. 0N/A * Is called when the applet wants to be resized. 0N/A * Status line. Called by the AppletPanel to provide 0N/A * feedback on the Applet's state. 0N/A * Called by the AppletPanel to print to the log. 0N/A * Called by the AppletPanel to provide 0N/A * feedback when an exception has happened. 0N/A * Get caching key for classloader cache 0N/A * Fixed #4501142: Classlaoder sharing policy doesn't 0N/A * take "archive" into account. This will be overridden 0N/A * by Java Plug-in. [stanleyh] 0N/A * Flush a class loader. 0N/A * Flush all class loaders. 0N/A * This method actually creates an AppletClassLoader. 0N/A * It can be override by subclasses (such as the Plug-in) 0N/A * to provide different classloaders. 0N/A * Get a class loader. Create in a restricted context 0N/A /* Should the creation of the classloader be 0N/A * within the class synchronized block? Since 0N/A * this class is used by the plugin, take care 0N/A * to avoid deadlocks, or specialize 0N/A * AppletPanel within the plugin. It may take 0N/A * an arbitrary amount of time to create a 0N/A * class loader (involving getting Jar files 0N/A * etc.) and may block unrelated applets from 0N/A * finishing createAppletThread (due to the 0N/A * class synchronization). If 0N/A * createAppletThread does not finish quickly, 0N/A * the applet cannot process other messages, 0N/A * particularly messages such as destroy 0N/A * (which timeout when called from the browser). 0N/A * get the context for the AppletClassLoader we are creating. 0N/A * the context is granted permission to create the class loader, 0N/A * connnect to the codebase, and whatever else the policy grants 0N/A //XXX: this is needed to be able to create the classloader itself! 0N/A // Fixed #4754451: Applet can have methods running on main 0N/A // thread event queue. 0N/A // The cause of this bug is that the frame of the applet 0N/A // is created in main thread group. Thus, when certain 0N/A // dispatched through the wrong event dispatch thread. 0N/A // To fix this, we rearrange the AppContext with the frame, 0N/A // so the proper event queue will be looked up. 0N/A // Swing also maintains a Frame list for the AppContext, 0N/A // so we will have to rearrange it as well. 0N/A // Check if frame's AppContext has already been set properly 0N/A // Synchronization on Window.class is needed for locking the 0N/A // critical section of the window list in AppContext. 0N/A // Remove frame from the Window list in wrong AppContext 0N/A // Lookup current frame's AppContext 0N/A // Remove frame from wrong AppContext 0N/A // Put the frame into the applet's AppContext map 0N/A // Insert frame into the Window list in the applet's AppContext map 0N/A // use the same weakRef here as it is used elsewhere 0N/A // Flag to indicate if applet is targeted for JDK 1.1. 0N/A // Flag to indicate if applet is targeted for JDK 1.2. 0N/A * Determine JDK level of an applet. 0N/A // To determine the JDK level of an applet, the 0N/A // most reliable way is to check the major version 0N/A // of the applet class file. 0N/A // synchronized on applet class object, so calling from 0N/A // different instances of the same applet will be 0N/A // Determine if the JDK level of an applet has been 0N/A // if applet JDK level has been checked before, retrieve 0N/A // value and return. 0N/A // first convert any '.' to '/' 0N/A // Read the first 8 bytes of the class file 0N/A // return if the header is not read in entirely 0N/A // for some reasons. 0N/A // Check major version in class file header 0N/A // Major version in class file is as follows: 0N/A // Store applet JDK level in AppContext for later lookup, 0N/A // e.g. page switch. 0N/A * Return true if applet is targeted to JDK 1.1. 0N/A * Return true if applet is targeted to JDK1.2. 0N/A * Read short from byte array. 0N/A return ((
int)b) &
0xFF;