Line
Link Here
|
0 |
-- /dev/null |
0 |
++ icedtea-web/netx/sun/applet/AppletImageRef.java |
Line 0
Link Here
|
0 |
-- icedtea-web.orig/configure.ac |
1 |
/* |
|
|
2 |
* Copyright (c) 1995, 2014, Oracle and/or its affiliates. All rights reserved. |
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
5 |
* This code is free software; you can redistribute it and/or modify it |
6 |
* under the terms of the GNU General Public License version 2 only, as |
7 |
* published by the Free Software Foundation. Oracle designates this |
8 |
* particular file as subject to the "Classpath" exception as provided |
9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
15 |
* accompanied this code). |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License version |
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
* |
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
23 |
* questions. |
24 |
*/ |
25 |
|
26 |
package sun.applet; |
27 |
|
28 |
import java.awt.Toolkit; |
29 |
import java.awt.Image; |
30 |
import java.lang.ref.SoftReference; |
31 |
import sun.awt.image.URLImageSource; |
32 |
import java.net.URL; |
33 |
|
34 |
@Deprecated(since = "9") |
35 |
class AppletImageRef { |
36 |
private SoftReference<Image> soft = null; |
37 |
|
38 |
URL url; |
39 |
|
40 |
/** |
41 |
* Returns a pointer to the object referenced by this Ref. If the object |
42 |
* has been thrown away by the garbage collector, it will be |
43 |
* reconstituted. This method does everything necessary to ensure that the garbage |
44 |
* collector throws things away in Least Recently Used(LRU) order. Applications should |
45 |
* never override this method. The get() method effectively caches calls to |
46 |
* reconstitute(). |
47 |
*/ |
48 |
public synchronized Image get() { |
49 |
Image t = check(); |
50 |
if (t == null) { |
51 |
t = reconstitute(); |
52 |
setThing(t); |
53 |
} |
54 |
return t; |
55 |
} |
56 |
|
57 |
/** |
58 |
* Create the Ref |
59 |
*/ |
60 |
AppletImageRef(URL url) { |
61 |
this.url = url; |
62 |
} |
63 |
|
64 |
/** |
65 |
* Flushes the cached object. Forces the next invocation of get() to |
66 |
* invoke reconstitute(). |
67 |
*/ |
68 |
public synchronized void flush() { |
69 |
SoftReference<Image> s = soft; |
70 |
if (s != null) s.clear(); |
71 |
soft = null; |
72 |
} |
73 |
|
74 |
/** |
75 |
* Sets the thing to the specified object. |
76 |
* @param thing the specified object |
77 |
*/ |
78 |
public synchronized void setThing(Image thing) { |
79 |
flush(); |
80 |
soft = new SoftReference<>(thing); |
81 |
} |
82 |
|
83 |
/** |
84 |
* Checks to see what object is being pointed at by this Ref and returns it. |
85 |
*/ |
86 |
public synchronized Image check() { |
87 |
SoftReference<Image> s = soft; |
88 |
if (s == null) return null; |
89 |
return s.get(); |
90 |
} |
91 |
|
92 |
/** |
93 |
* Reconsitute the image. Only called when the ref has been flushed. |
94 |
*/ |
95 |
public Image reconstitute() { |
96 |
Image img = Toolkit.getDefaultToolkit().createImage(new URLImageSource(url)); |
97 |
return img; |
98 |
} |
99 |
} |
|
|
100 |
++ icedtea-web/configure.ac |
Lines 122-130
Link Here
|
122 |
fi |
122 |
fi |
123 |
IT_CHECK_FOR_CLASS(COM_SUN_JNDI_TOOLKIT_URL_URLUTIL, [com.sun.jndi.toolkit.url.UrlUtil], [some.pkg], [$JAVA_NAMING]) |
123 |
IT_CHECK_FOR_CLASS(COM_SUN_JNDI_TOOLKIT_URL_URLUTIL, [com.sun.jndi.toolkit.url.UrlUtil], [some.pkg], [$JAVA_NAMING]) |
124 |
IT_CHECK_FOR_CLASS(SUN_NET_WWW_PROTOCOL_HTTP_HANDLER, [sun.net.www.protocol.http.Handler], [some.pkg], [$JAVA_BASE]) |
124 |
IT_CHECK_FOR_CLASS(SUN_NET_WWW_PROTOCOL_HTTP_HANDLER, [sun.net.www.protocol.http.Handler], [some.pkg], [$JAVA_BASE]) |
125 |
IT_CHECK_FOR_CLASS(SUN_APPLET_APPLETIMAGEREF, [sun.applet.AppletImageRef], [sun.applet], [$JAVA_DESKTOP]) |
125 |
dnl IT_CHECK_FOR_CLASS(SUN_APPLET_APPLETIMAGEREF, [sun.applet.AppletImageRef], [sun.applet], [$JAVA_DESKTOP]) |
126 |
|
126 |
|
127 |
IT_CHECK_FOR_SUN_APPLET_ACCESSIBILITY |
127 |
dnl IT_CHECK_FOR_SUN_APPLET_ACCESSIBILITY |
128 |
IT_CHECK_GLIB_VERSION |
128 |
IT_CHECK_GLIB_VERSION |
129 |
IT_CHECK_XULRUNNER_MIMEDESCRIPTION_CONSTCHAR |
129 |
IT_CHECK_XULRUNNER_MIMEDESCRIPTION_CONSTCHAR |
130 |
IT_CHECK_XULRUNNER_REQUIRES_C11 |
130 |
IT_CHECK_XULRUNNER_REQUIRES_C11 |
131 |
-- /dev/null |
131 |
++ icedtea-web/netx/sun/applet/AppletViewerPanel.java |
Line 0
Link Here
|
0 |
-- /dev/null |
1 |
/* |
|
|
2 |
* Copyright (c) 1995, 2005, Oracle and/or its affiliates. All rights reserved. |
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
5 |
* This code is free software; you can redistribute it and/or modify it |
6 |
* under the terms of the GNU General Public License version 2 only, as |
7 |
* published by the Free Software Foundation. Oracle designates this |
8 |
* particular file as subject to the "Classpath" exception as provided |
9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
15 |
* accompanied this code). |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License version |
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
* |
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
23 |
* questions. |
24 |
*/ |
25 |
|
26 |
package sun.applet; |
27 |
|
28 |
import java.util.*; |
29 |
import java.io.*; |
30 |
import java.net.URL; |
31 |
import java.net.MalformedURLException; |
32 |
import java.awt.*; |
33 |
import java.applet.*; |
34 |
|
35 |
|
36 |
/** |
37 |
* Sample applet panel class. The panel manages and manipulates the |
38 |
* applet as it is being loaded. It forks a seperate thread in a new |
39 |
* thread group to call the applet's init(), start(), stop(), and |
40 |
* destroy() methods. |
41 |
* |
42 |
* @author Arthur van Hoff |
43 |
* |
44 |
* @deprecated The Applet API is deprecated. See the |
45 |
* <a href="../../java/applet/package-summary.html"> java.applet package |
46 |
* documentation</a> for further information. |
47 |
*/ |
48 |
@Deprecated(since = "9") |
49 |
class AppletViewerPanel extends AppletPanel { |
50 |
|
51 |
/* Are we debugging? */ |
52 |
static boolean debug = false; |
53 |
|
54 |
/** |
55 |
* The document url. |
56 |
*/ |
57 |
URL documentURL; |
58 |
|
59 |
/** |
60 |
* The base url. |
61 |
*/ |
62 |
URL baseURL; |
63 |
|
64 |
/** |
65 |
* The attributes of the applet. |
66 |
*/ |
67 |
Hashtable<String, String> atts; |
68 |
|
69 |
/* |
70 |
* JDK 1.1 serialVersionUID |
71 |
*/ |
72 |
private static final long serialVersionUID = 8890989370785545619L; |
73 |
|
74 |
/** |
75 |
* Construct an applet viewer and start the applet. |
76 |
*/ |
77 |
AppletViewerPanel(URL documentURL, Hashtable<String, String> atts) { |
78 |
this.documentURL = documentURL; |
79 |
this.atts = atts; |
80 |
|
81 |
String att = getParameter("codebase"); |
82 |
if (att != null) { |
83 |
if (!att.endsWith("/")) { |
84 |
att += "/"; |
85 |
} |
86 |
try { |
87 |
baseURL = new URL(documentURL, att); |
88 |
} catch (MalformedURLException e) { |
89 |
} |
90 |
} |
91 |
if (baseURL == null) { |
92 |
String file = documentURL.getFile(); |
93 |
int i = file.lastIndexOf('/'); |
94 |
if (i >= 0 && i < file.length() - 1) { |
95 |
try { |
96 |
baseURL = new URL(documentURL, file.substring(0, i + 1)); |
97 |
} catch (MalformedURLException e) { |
98 |
} |
99 |
} |
100 |
} |
101 |
|
102 |
// when all is said & done, baseURL shouldn't be null |
103 |
if (baseURL == null) |
104 |
baseURL = documentURL; |
105 |
|
106 |
|
107 |
} |
108 |
|
109 |
/** |
110 |
* Get an applet parameter. |
111 |
*/ |
112 |
public String getParameter(String name) { |
113 |
return atts.get(name.toLowerCase()); |
114 |
} |
115 |
|
116 |
/** |
117 |
* Get the document url. |
118 |
*/ |
119 |
public URL getDocumentBase() { |
120 |
return documentURL; |
121 |
|
122 |
} |
123 |
|
124 |
/** |
125 |
* Get the base url. |
126 |
*/ |
127 |
public URL getCodeBase() { |
128 |
return baseURL; |
129 |
} |
130 |
|
131 |
/** |
132 |
* Get the width. |
133 |
*/ |
134 |
public int getWidth() { |
135 |
String w = getParameter("width"); |
136 |
if (w != null) { |
137 |
return Integer.valueOf(w).intValue(); |
138 |
} |
139 |
return 0; |
140 |
} |
141 |
|
142 |
|
143 |
/** |
144 |
* Get the height. |
145 |
*/ |
146 |
public int getHeight() { |
147 |
String h = getParameter("height"); |
148 |
if (h != null) { |
149 |
return Integer.valueOf(h).intValue(); |
150 |
} |
151 |
return 0; |
152 |
} |
153 |
|
154 |
/** |
155 |
* Get initial_focus |
156 |
*/ |
157 |
public boolean hasInitialFocus() |
158 |
{ |
159 |
|
160 |
// 6234219: Do not set initial focus on an applet |
161 |
// during startup if applet is targeted for |
162 |
// JDK 1.1/1.2. [stanley.ho] |
163 |
if (isJDK11Applet() || isJDK12Applet()) |
164 |
return false; |
165 |
|
166 |
String initialFocus = getParameter("initial_focus"); |
167 |
|
168 |
if (initialFocus != null) |
169 |
{ |
170 |
if (initialFocus.toLowerCase().equals("false")) |
171 |
return false; |
172 |
} |
173 |
|
174 |
return true; |
175 |
} |
176 |
|
177 |
/** |
178 |
* Get the code parameter |
179 |
*/ |
180 |
public String getCode() { |
181 |
return getParameter("code"); |
182 |
} |
183 |
|
184 |
|
185 |
/** |
186 |
* Return the list of jar files if specified. |
187 |
* Otherwise return null. |
188 |
*/ |
189 |
public String getJarFiles() { |
190 |
return getParameter("archive"); |
191 |
} |
192 |
|
193 |
/** |
194 |
* Return the value of the object param |
195 |
*/ |
196 |
public String getSerializedObject() { |
197 |
return getParameter("object");// another name? |
198 |
} |
199 |
|
200 |
|
201 |
/** |
202 |
* Get the applet context. For now this is |
203 |
* also implemented by the AppletPanel class. |
204 |
*/ |
205 |
@SuppressWarnings("deprecation") |
206 |
public AppletContext getAppletContext() { |
207 |
return (AppletContext)getParent(); |
208 |
} |
209 |
|
210 |
static void debug(String s) { |
211 |
if(debug) |
212 |
System.err.println("AppletViewerPanel:::" + s); |
213 |
} |
214 |
|
215 |
static void debug(String s, Throwable t) { |
216 |
if(debug) { |
217 |
t.printStackTrace(); |
218 |
debug(s); |
219 |
} |
220 |
} |
221 |
} |
|
|
222 |
++ icedtea-web/netx/sun/applet/AppletPanel.java |
Line 0
Link Here
|
0 |
-- /dev/null |
1 |
/* |
|
|
2 |
* Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved. |
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
5 |
* This code is free software; you can redistribute it and/or modify it |
6 |
* under the terms of the GNU General Public License version 2 only, as |
7 |
* published by the Free Software Foundation. Oracle designates this |
8 |
* particular file as subject to the "Classpath" exception as provided |
9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
15 |
* accompanied this code). |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License version |
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
* |
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
23 |
* questions. |
24 |
*/ |
25 |
|
26 |
package sun.applet; |
27 |
|
28 |
import java.applet.*; |
29 |
import java.awt.*; |
30 |
import java.awt.event.*; |
31 |
import java.io.*; |
32 |
import java.lang.ref.WeakReference; |
33 |
import java.lang.reflect.InvocationTargetException; |
34 |
import java.lang.reflect.Method; |
35 |
import java.net.JarURLConnection; |
36 |
import java.net.SocketPermission; |
37 |
import java.net.URL; |
38 |
import java.security.*; |
39 |
import java.util.*; |
40 |
import java.util.Locale; |
41 |
import java.util.concurrent.LinkedBlockingQueue; |
42 |
import sun.awt.AWTAccessor; |
43 |
import sun.awt.AppContext; |
44 |
import sun.awt.EmbeddedFrame; |
45 |
import sun.awt.SunToolkit; |
46 |
import sun.security.util.SecurityConstants; |
47 |
|
48 |
/** |
49 |
* Applet panel class. The panel manages and manipulates the |
50 |
* applet as it is being loaded. It forks a separate thread in a new |
51 |
* thread group to call the applet's init(), start(), stop(), and |
52 |
* destroy() methods. |
53 |
* |
54 |
* @deprecated The Applet API is deprecated. See the |
55 |
* <a href="../../java/applet/package-summary.html"> java.applet package |
56 |
* documentation</a> for further information. |
57 |
* |
58 |
* @author Arthur van Hoff |
59 |
*/ |
60 |
@SuppressWarnings({"serial"}) // JDK implementation class |
61 |
@Deprecated(since = "9") |
62 |
public |
63 |
abstract class AppletPanel extends Panel implements AppletStub, Runnable { |
64 |
|
65 |
/** |
66 |
* The applet (if loaded). |
67 |
*/ |
68 |
Applet applet; |
69 |
|
70 |
|
71 |
/** |
72 |
* The classloader for the applet. |
73 |
*/ |
74 |
protected AppletClassLoader loader; |
75 |
|
76 |
/* applet event ids */ |
77 |
public static final int APPLET_DISPOSE = 0; |
78 |
public static final int APPLET_LOAD = 1; |
79 |
public static final int APPLET_INIT = 2; |
80 |
public static final int APPLET_START = 3; |
81 |
public static final int APPLET_STOP = 4; |
82 |
public static final int APPLET_DESTROY = 5; |
83 |
public static final int APPLET_QUIT = 6; |
84 |
public static final int APPLET_ERROR = 7; |
85 |
|
86 |
/* send to the parent to force relayout */ |
87 |
public static final int APPLET_RESIZE = 51234; |
88 |
|
89 |
/* sent to a (distant) parent to indicate that the applet is being |
90 |
* loaded or as completed loading |
91 |
*/ |
92 |
public static final int APPLET_LOADING = 51235; |
93 |
public static final int APPLET_LOADING_COMPLETED = 51236; |
94 |
|
95 |
/** |
96 |
* The current status. One of: |
97 |
* APPLET_DISPOSE, |
98 |
* APPLET_LOAD, |
99 |
* APPLET_INIT, |
100 |
* APPLET_START, |
101 |
* APPLET_STOP, |
102 |
* APPLET_DESTROY, |
103 |
* APPLET_ERROR. |
104 |
*/ |
105 |
protected int status; |
106 |
|
107 |
/** |
108 |
* The thread for the applet. |
109 |
*/ |
110 |
protected Thread handler; |
111 |
|
112 |
|
113 |
/** |
114 |
* The initial applet size. |
115 |
*/ |
116 |
Dimension defaultAppletSize = new Dimension(10, 10); |
117 |
|
118 |
/** |
119 |
* The current applet size. |
120 |
*/ |
121 |
Dimension currentAppletSize = new Dimension(10, 10); |
122 |
|
123 |
/** |
124 |
* The thread to use during applet loading |
125 |
*/ |
126 |
|
127 |
Thread loaderThread = null; |
128 |
|
129 |
/** |
130 |
* Flag to indicate that a loading has been cancelled |
131 |
*/ |
132 |
boolean loadAbortRequest = false; |
133 |
|
134 |
/* abstract classes */ |
135 |
protected abstract String getCode(); |
136 |
protected abstract String getJarFiles(); |
137 |
|
138 |
@Override |
139 |
public abstract int getWidth(); |
140 |
@Override |
141 |
public abstract int getHeight(); |
142 |
public abstract boolean hasInitialFocus(); |
143 |
|
144 |
private static int threadGroupNumber = 0; |
145 |
|
146 |
protected void setupAppletAppContext() { |
147 |
// do nothing |
148 |
} |
149 |
|
150 |
/* |
151 |
* Creates a thread to run the applet. This method is called |
152 |
* each time an applet is loaded and reloaded. |
153 |
*/ |
154 |
synchronized void createAppletThread() { |
155 |
// Create a thread group for the applet, and start a new |
156 |
// thread to load the applet. |
157 |
String nm = "applet-" + getCode(); |
158 |
loader = getClassLoader(getCodeBase(), getClassLoaderCacheKey()); |
159 |
loader.grab(); // Keep this puppy around! |
160 |
|
161 |
// 4668479: Option to turn off codebase lookup in AppletClassLoader |
162 |
// during resource requests. [stanley.ho] |
163 |
String param = getParameter("codebase_lookup"); |
164 |
|
165 |
if (param != null && param.equals("false")) |
166 |
loader.setCodebaseLookup(false); |
167 |
else |
168 |
loader.setCodebaseLookup(true); |
169 |
|
170 |
|
171 |
ThreadGroup appletGroup = loader.getThreadGroup(); |
172 |
handler = new Thread(appletGroup, this, "thread " + nm, 0, false); |
173 |
// set the context class loader for this thread |
174 |
AccessController.doPrivileged(new PrivilegedAction<Object>() { |
175 |
@Override |
176 |
public Object run() { |
177 |
handler.setContextClassLoader(loader); |
178 |
return null; |
179 |
} |
180 |
}); |
181 |
handler.start(); |
182 |
} |
183 |
|
184 |
void joinAppletThread() throws InterruptedException { |
185 |
if (handler != null) { |
186 |
handler.join(); |
187 |
handler = null; |
188 |
} |
189 |
} |
190 |
|
191 |
void release() { |
192 |
if (loader != null) { |
193 |
loader.release(); |
194 |
loader = null; |
195 |
} |
196 |
} |
197 |
|
198 |
/** |
199 |
* Construct an applet viewer and start the applet. |
200 |
*/ |
201 |
public void init() { |
202 |
try { |
203 |
// Get the width (if any) |
204 |
defaultAppletSize.width = getWidth(); |
205 |
currentAppletSize.width = defaultAppletSize.width; |
206 |
|
207 |
// Get the height (if any) |
208 |
defaultAppletSize.height = getHeight(); |
209 |
currentAppletSize.height = defaultAppletSize.height; |
210 |
|
211 |
} catch (NumberFormatException e) { |
212 |
// Turn on the error flag and let TagAppletPanel |
213 |
// do the right thing. |
214 |
status = APPLET_ERROR; |
215 |
showAppletStatus("badattribute.exception"); |
216 |
showAppletLog("badattribute.exception"); |
217 |
showAppletException(e); |
218 |
} |
219 |
|
220 |
setLayout(new BorderLayout()); |
221 |
|
222 |
createAppletThread(); |
223 |
} |
224 |
|
225 |
/** |
226 |
* Minimum size |
227 |
*/ |
228 |
@Override |
229 |
@SuppressWarnings("deprecation") |
230 |
public Dimension minimumSize() { |
231 |
return new Dimension(defaultAppletSize.width, |
232 |
defaultAppletSize.height); |
233 |
} |
234 |
|
235 |
/** |
236 |
* Preferred size |
237 |
*/ |
238 |
@Override |
239 |
@SuppressWarnings("deprecation") |
240 |
public Dimension preferredSize() { |
241 |
return new Dimension(currentAppletSize.width, |
242 |
currentAppletSize.height); |
243 |
} |
244 |
|
245 |
private AppletListener listeners; |
246 |
|
247 |
/** |
248 |
* AppletEvent Queue |
249 |
*/ |
250 |
private LinkedBlockingQueue<Integer> queue = null; |
251 |
|
252 |
public synchronized void addAppletListener(AppletListener l) { |
253 |
listeners = AppletEventMulticaster.add(listeners, l); |
254 |
} |
255 |
|
256 |
public synchronized void removeAppletListener(AppletListener l) { |
257 |
listeners = AppletEventMulticaster.remove(listeners, l); |
258 |
} |
259 |
|
260 |
/** |
261 |
* Dispatch event to the listeners.. |
262 |
*/ |
263 |
public void dispatchAppletEvent(int id, Object argument) { |
264 |
//System.out.println("SEND= " + id); |
265 |
if (listeners != null) { |
266 |
AppletEvent evt = new AppletEvent(this, id, argument); |
267 |
listeners.appletStateChanged(evt); |
268 |
} |
269 |
} |
270 |
|
271 |
/** |
272 |
* Send an event. Queue it for execution by the handler thread. |
273 |
*/ |
274 |
public void sendEvent(int id) { |
275 |
synchronized(this) { |
276 |
if (queue == null) { |
277 |
//System.out.println("SEND0= " + id); |
278 |
queue = new LinkedBlockingQueue<>(); |
279 |
} |
280 |
boolean inserted = queue.add(id); |
281 |
notifyAll(); |
282 |
} |
283 |
if (id == APPLET_QUIT) { |
284 |
try { |
285 |
joinAppletThread(); // Let the applet event handler exit |
286 |
} catch (InterruptedException e) { |
287 |
} |
288 |
|
289 |
// AppletClassLoader.release() must be called by a Thread |
290 |
// not within the applet's ThreadGroup |
291 |
if (loader == null) |
292 |
loader = getClassLoader(getCodeBase(), getClassLoaderCacheKey()); |
293 |
release(); |
294 |
} |
295 |
} |
296 |
|
297 |
/** |
298 |
* Get an event from the queue. |
299 |
*/ |
300 |
synchronized AppletEvent getNextEvent() throws InterruptedException { |
301 |
while (queue == null || queue.isEmpty()) { |
302 |
wait(); |
303 |
} |
304 |
int eventId = queue.take(); |
305 |
return new AppletEvent(this, eventId, null); |
306 |
} |
307 |
|
308 |
boolean emptyEventQueue() { |
309 |
if ((queue == null) || (queue.isEmpty())) |
310 |
return true; |
311 |
else |
312 |
return false; |
313 |
} |
314 |
|
315 |
/** |
316 |
* This kludge is specific to get over AccessControlException thrown during |
317 |
* Applet.stop() or destroy() when static thread is suspended. Set a flag |
318 |
* in AppletClassLoader to indicate that an |
319 |
* AccessControlException for RuntimePermission "modifyThread" or |
320 |
* "modifyThreadGroup" had occurred. |
321 |
*/ |
322 |
private void setExceptionStatus(AccessControlException e) { |
323 |
Permission p = e.getPermission(); |
324 |
if (p instanceof RuntimePermission) { |
325 |
if (p.getName().startsWith("modifyThread")) { |
326 |
if (loader == null) |
327 |
loader = getClassLoader(getCodeBase(), getClassLoaderCacheKey()); |
328 |
loader.setExceptionStatus(); |
329 |
} |
330 |
} |
331 |
} |
332 |
|
333 |
/** |
334 |
* Execute applet events. |
335 |
* Here is the state transition diagram |
336 |
* |
337 |
* <pre>{@literal |
338 |
* Note: (XXX) is the action |
339 |
* APPLET_XXX is the state |
340 |
* (applet code loaded) --> APPLET_LOAD -- (applet init called)--> APPLET_INIT -- |
341 |
* (applet start called) --> APPLET_START -- (applet stop called) --> APPLET_STOP -- |
342 |
* (applet destroyed called) --> APPLET_DESTROY --> (applet gets disposed) --> |
343 |
* APPLET_DISPOSE --> ... |
344 |
* }</pre> |
345 |
* |
346 |
* In the legacy lifecycle model. The applet gets loaded, inited and started. So it stays |
347 |
* in the APPLET_START state unless the applet goes away(refresh page or leave the page). |
348 |
* So the applet stop method called and the applet enters APPLET_STOP state. Then if the applet |
349 |
* is revisited, it will call applet start method and enter the APPLET_START state and stay there. |
350 |
* |
351 |
* In the modern lifecycle model. When the applet first time visited, it is same as legacy lifecycle |
352 |
* model. However, when the applet page goes away. It calls applet stop method and enters APPLET_STOP |
353 |
* state and then applet destroyed method gets called and enters APPLET_DESTROY state. |
354 |
* |
355 |
* This code is also called by AppletViewer. In AppletViewer "Restart" menu, the applet is jump from |
356 |
* APPLET_STOP to APPLET_DESTROY and to APPLET_INIT . |
357 |
* |
358 |
* Also, the applet can jump from APPLET_INIT state to APPLET_DESTROY (in Netscape/Mozilla case). |
359 |
* Same as APPLET_LOAD to |
360 |
* APPLET_DISPOSE since all of this are triggered by browser. |
361 |
* |
362 |
*/ |
363 |
@Override |
364 |
public void run() { |
365 |
|
366 |
Thread curThread = Thread.currentThread(); |
367 |
if (curThread == loaderThread) { |
368 |
// if we are in the loader thread, cause |
369 |
// loading to occur. We may exit this with |
370 |
// status being APPLET_DISPOSE, APPLET_ERROR, |
371 |
// or APPLET_LOAD |
372 |
runLoader(); |
373 |
return; |
374 |
} |
375 |
|
376 |
boolean disposed = false; |
377 |
while (!disposed && !curThread.isInterrupted()) { |
378 |
AppletEvent evt; |
379 |
try { |
380 |
evt = getNextEvent(); |
381 |
} catch (InterruptedException e) { |
382 |
showAppletStatus("bail"); |
383 |
return; |
384 |
} |
385 |
|
386 |
//showAppletStatus("EVENT = " + evt.getID()); |
387 |
try { |
388 |
switch (evt.getID()) { |
389 |
case APPLET_LOAD: |
390 |
if (!okToLoad()) { |
391 |
break; |
392 |
} |
393 |
// This complexity allows loading of applets to be |
394 |
// interruptable. The actual thread loading runs |
395 |
// in a separate thread, so it can be interrupted |
396 |
// without harming the applet thread. |
397 |
// So that we don't have to worry about |
398 |
// concurrency issues, the main applet thread waits |
399 |
// until the loader thread terminates. |
400 |
// (one way or another). |
401 |
if (loaderThread == null) { |
402 |
setLoaderThread(new Thread(null, this, |
403 |
"AppletLoader", 0, false)); |
404 |
loaderThread.start(); |
405 |
// we get to go to sleep while this runs |
406 |
loaderThread.join(); |
407 |
setLoaderThread(null); |
408 |
} else { |
409 |
// REMIND: issue an error -- this case should never |
410 |
// occur. |
411 |
} |
412 |
break; |
413 |
|
414 |
case APPLET_INIT: |
415 |
// AppletViewer "Restart" will jump from destroy method to |
416 |
// init, that is why we need to check status w/ APPLET_DESTROY |
417 |
if (status != APPLET_LOAD && status != APPLET_DESTROY) { |
418 |
showAppletStatus("notloaded"); |
419 |
break; |
420 |
} |
421 |
applet.resize(defaultAppletSize); |
422 |
|
423 |
applet.init(); |
424 |
|
425 |
//Need the default(fallback) font to be created in this AppContext |
426 |
Font f = getFont(); |
427 |
if (f == null || |
428 |
"dialog".equals(f.getFamily().toLowerCase(Locale.ENGLISH)) && |
429 |
f.getSize() == 12 && f.getStyle() == Font.PLAIN) { |
430 |
setFont(new Font(Font.DIALOG, Font.PLAIN, 12)); |
431 |
} |
432 |
|
433 |
// Validate the applet in event dispatch thread |
434 |
// to avoid deadlock. |
435 |
try { |
436 |
final AppletPanel p = this; |
437 |
Runnable r = new Runnable() { |
438 |
@Override |
439 |
public void run() { |
440 |
p.validate(); |
441 |
} |
442 |
}; |
443 |
AWTAccessor.getEventQueueAccessor().invokeAndWait(applet, r); |
444 |
} |
445 |
catch(InterruptedException ie) { |
446 |
} |
447 |
catch(InvocationTargetException ite) { |
448 |
} |
449 |
|
450 |
status = APPLET_INIT; |
451 |
showAppletStatus("inited"); |
452 |
break; |
453 |
|
454 |
case APPLET_START: |
455 |
{ |
456 |
if (status != APPLET_INIT && status != APPLET_STOP) { |
457 |
showAppletStatus("notinited"); |
458 |
break; |
459 |
} |
460 |
applet.resize(currentAppletSize); |
461 |
applet.start(); |
462 |
|
463 |
// Validate and show the applet in event dispatch thread |
464 |
// to avoid deadlock. |
465 |
try { |
466 |
final AppletPanel p = this; |
467 |
final Applet a = applet; |
468 |
Runnable r = new Runnable() { |
469 |
@Override |
470 |
public void run() { |
471 |
p.validate(); |
472 |
a.setVisible(true); |
473 |
|
474 |
// Fix for BugTraq ID 4041703. |
475 |
// Set the default focus for an applet. |
476 |
if (hasInitialFocus()) { |
477 |
setDefaultFocus(); |
478 |
} |
479 |
} |
480 |
}; |
481 |
AWTAccessor.getEventQueueAccessor().invokeAndWait(applet, r); |
482 |
} |
483 |
catch(InterruptedException ie) { |
484 |
} |
485 |
catch(InvocationTargetException ite) { |
486 |
} |
487 |
|
488 |
status = APPLET_START; |
489 |
showAppletStatus("started"); |
490 |
break; |
491 |
} |
492 |
|
493 |
case APPLET_STOP: |
494 |
if (status != APPLET_START) { |
495 |
showAppletStatus("notstarted"); |
496 |
break; |
497 |
} |
498 |
status = APPLET_STOP; |
499 |
|
500 |
// Hide the applet in event dispatch thread |
501 |
// to avoid deadlock. |
502 |
try { |
503 |
final Applet a = applet; |
504 |
Runnable r = new Runnable() { |
505 |
@Override |
506 |
public void run() { |
507 |
a.setVisible(false); |
508 |
} |
509 |
}; |
510 |
AWTAccessor.getEventQueueAccessor().invokeAndWait(applet, r); |
511 |
} |
512 |
catch(InterruptedException ie) { |
513 |
} |
514 |
catch(InvocationTargetException ite) { |
515 |
} |
516 |
|
517 |
|
518 |
// During Applet.stop(), any AccessControlException on an involved Class remains in |
519 |
// the "memory" of the AppletClassLoader. If the same instance of the ClassLoader is |
520 |
// reused, the same exception will occur during class loading. Set the AppletClassLoader's |
521 |
// exceptionStatusSet flag to allow recognition of what had happened |
522 |
// when reusing AppletClassLoader object. |
523 |
try { |
524 |
applet.stop(); |
525 |
} catch (java.security.AccessControlException e) { |
526 |
setExceptionStatus(e); |
527 |
// rethrow exception to be handled as it normally would be. |
528 |
throw e; |
529 |
} |
530 |
showAppletStatus("stopped"); |
531 |
break; |
532 |
|
533 |
case APPLET_DESTROY: |
534 |
if (status != APPLET_STOP && status != APPLET_INIT) { |
535 |
showAppletStatus("notstopped"); |
536 |
break; |
537 |
} |
538 |
status = APPLET_DESTROY; |
539 |
|
540 |
// During Applet.destroy(), any AccessControlException on an involved Class remains in |
541 |
// the "memory" of the AppletClassLoader. If the same instance of the ClassLoader is |
542 |
// reused, the same exception will occur during class loading. Set the AppletClassLoader's |
543 |
// exceptionStatusSet flag to allow recognition of what had happened |
544 |
// when reusing AppletClassLoader object. |
545 |
try { |
546 |
applet.destroy(); |
547 |
} catch (java.security.AccessControlException e) { |
548 |
setExceptionStatus(e); |
549 |
// rethrow exception to be handled as it normally would be. |
550 |
throw e; |
551 |
} |
552 |
showAppletStatus("destroyed"); |
553 |
break; |
554 |
|
555 |
case APPLET_DISPOSE: |
556 |
if (status != APPLET_DESTROY && status != APPLET_LOAD) { |
557 |
showAppletStatus("notdestroyed"); |
558 |
break; |
559 |
} |
560 |
status = APPLET_DISPOSE; |
561 |
|
562 |
try { |
563 |
final Applet a = applet; |
564 |
Runnable r = new Runnable() { |
565 |
@Override |
566 |
public void run() { |
567 |
remove(a); |
568 |
} |
569 |
}; |
570 |
AWTAccessor.getEventQueueAccessor().invokeAndWait(applet, r); |
571 |
} |
572 |
catch(InterruptedException ie) |
573 |
{ |
574 |
} |
575 |
catch(InvocationTargetException ite) |
576 |
{ |
577 |
} |
578 |
applet = null; |
579 |
showAppletStatus("disposed"); |
580 |
disposed = true; |
581 |
break; |
582 |
|
583 |
case APPLET_QUIT: |
584 |
return; |
585 |
} |
586 |
} catch (Exception e) { |
587 |
status = APPLET_ERROR; |
588 |
if (e.getMessage() != null) { |
589 |
showAppletStatus("exception2", e.getClass().getName(), |
590 |
e.getMessage()); |
591 |
} else { |
592 |
showAppletStatus("exception", e.getClass().getName()); |
593 |
} |
594 |
showAppletException(e); |
595 |
} catch (ThreadDeath e) { |
596 |
showAppletStatus("death"); |
597 |
return; |
598 |
} catch (Error e) { |
599 |
status = APPLET_ERROR; |
600 |
if (e.getMessage() != null) { |
601 |
showAppletStatus("error2", e.getClass().getName(), |
602 |
e.getMessage()); |
603 |
} else { |
604 |
showAppletStatus("error", e.getClass().getName()); |
605 |
} |
606 |
showAppletException(e); |
607 |
} |
608 |
clearLoadAbortRequest(); |
609 |
} |
610 |
} |
611 |
|
612 |
/** |
613 |
* Gets most recent focus owner component associated with the given window. |
614 |
* It does that without calling Window.getMostRecentFocusOwner since it |
615 |
* provides its own logic contradicting with setDefautlFocus. Instead, it |
616 |
* calls KeyboardFocusManager directly. |
617 |
*/ |
618 |
private Component getMostRecentFocusOwnerForWindow(Window w) { |
619 |
return AWTAccessor.getKeyboardFocusManagerAccessor() |
620 |
.getMostRecentFocusOwner(w); |
621 |
} |
622 |
|
623 |
/* |
624 |
* Fix for BugTraq ID 4041703. |
625 |
* Set the focus to a reasonable default for an Applet. |
626 |
*/ |
627 |
private void setDefaultFocus() { |
628 |
Component toFocus = null; |
629 |
Container parent = getParent(); |
630 |
|
631 |
if(parent != null) { |
632 |
if (parent instanceof Window) { |
633 |
toFocus = getMostRecentFocusOwnerForWindow((Window)parent); |
634 |
if (toFocus == parent || toFocus == null) { |
635 |
toFocus = parent.getFocusTraversalPolicy(). |
636 |
getInitialComponent((Window)parent); |
637 |
} |
638 |
} else if (parent.isFocusCycleRoot()) { |
639 |
toFocus = parent.getFocusTraversalPolicy(). |
640 |
getDefaultComponent(parent); |
641 |
} |
642 |
} |
643 |
|
644 |
if (toFocus != null) { |
645 |
if (parent instanceof EmbeddedFrame) { |
646 |
((EmbeddedFrame) parent).synthesizeWindowActivation(true); |
647 |
} |
648 |
// EmbeddedFrame might have focus before the applet was added. |
649 |
// Thus after its activation the most recent focus owner will be |
650 |
// restored. We need the applet's initial focusabled component to |
651 |
// be focused here. |
652 |
toFocus.requestFocusInWindow(); |
653 |
} |
654 |
} |
655 |
|
656 |
/** |
657 |
* Load the applet into memory. |
658 |
* Runs in a seperate (and interruptible) thread from the rest of the |
659 |
* applet event processing so that it can be gracefully interrupted from |
660 |
* things like HotJava. |
661 |
*/ |
662 |
@SuppressWarnings("deprecation") |
663 |
private void runLoader() { |
664 |
if (status != APPLET_DISPOSE) { |
665 |
showAppletStatus("notdisposed"); |
666 |
return; |
667 |
} |
668 |
|
669 |
dispatchAppletEvent(APPLET_LOADING, null); |
670 |
|
671 |
// REMIND -- might be cool to visually indicate loading here -- |
672 |
// maybe do animation? |
673 |
status = APPLET_LOAD; |
674 |
|
675 |
// Create a class loader |
676 |
loader = getClassLoader(getCodeBase(), getClassLoaderCacheKey()); |
677 |
|
678 |
// Load the archives if present. |
679 |
// REMIND - this probably should be done in a separate thread, |
680 |
// or at least the additional archives (epll). |
681 |
|
682 |
String code = getCode(); |
683 |
|
684 |
// setup applet AppContext |
685 |
// this must be called before loadJarFiles |
686 |
setupAppletAppContext(); |
687 |
|
688 |
try { |
689 |
loadJarFiles(loader); |
690 |
applet = createApplet(loader); |
691 |
} catch (ClassNotFoundException e) { |
692 |
status = APPLET_ERROR; |
693 |
showAppletStatus("notfound", code); |
694 |
showAppletLog("notfound", code); |
695 |
showAppletException(e); |
696 |
return; |
697 |
} catch (InstantiationException e) { |
698 |
status = APPLET_ERROR; |
699 |
showAppletStatus("nocreate", code); |
700 |
showAppletLog("nocreate", code); |
701 |
showAppletException(e); |
702 |
return; |
703 |
} catch (IllegalAccessException e) { |
704 |
status = APPLET_ERROR; |
705 |
showAppletStatus("noconstruct", code); |
706 |
showAppletLog("noconstruct", code); |
707 |
showAppletException(e); |
708 |
// sbb -- I added a return here |
709 |
return; |
710 |
} catch (Exception e) { |
711 |
status = APPLET_ERROR; |
712 |
showAppletStatus("exception", e.getMessage()); |
713 |
showAppletException(e); |
714 |
return; |
715 |
} catch (ThreadDeath e) { |
716 |
status = APPLET_ERROR; |
717 |
showAppletStatus("death"); |
718 |
return; |
719 |
} catch (Error e) { |
720 |
status = APPLET_ERROR; |
721 |
showAppletStatus("error", e.getMessage()); |
722 |
showAppletException(e); |
723 |
return; |
724 |
} finally { |
725 |
// notify that loading is no longer going on |
726 |
dispatchAppletEvent(APPLET_LOADING_COMPLETED, null); |
727 |
} |
728 |
|
729 |
// Fixed #4508194: NullPointerException thrown during |
730 |
// quick page switch |
731 |
// |
732 |
if (applet != null) |
733 |
{ |
734 |
// Stick it in the frame |
735 |
applet.setStub(this); |
736 |
applet.hide(); |
737 |
add("Center", applet); |
738 |
showAppletStatus("loaded"); |
739 |
validate(); |
740 |
} |
741 |
} |
742 |
|
743 |
protected Applet createApplet(final AppletClassLoader loader) throws ClassNotFoundException, |
744 |
IllegalAccessException, IOException, InstantiationException, InterruptedException { |
745 |
String code = getCode(); |
746 |
|
747 |
if (code != null) { |
748 |
applet = (Applet)loader.loadCode(code).newInstance(); |
749 |
} else { |
750 |
String msg = "nocode"; |
751 |
status = APPLET_ERROR; |
752 |
showAppletStatus(msg); |
753 |
showAppletLog(msg); |
754 |
repaint(); |
755 |
} |
756 |
|
757 |
// Determine the JDK level that the applet targets. |
758 |
// This is critical for enabling certain backward |
759 |
// compatibility switch if an applet is a JDK 1.1 |
760 |
// applet. [stanley.ho] |
761 |
findAppletJDKLevel(applet); |
762 |
|
763 |
if (Thread.interrupted()) { |
764 |
try { |
765 |
status = APPLET_DISPOSE; // APPLET_ERROR? |
766 |
applet = null; |
767 |
// REMIND: This may not be exactly the right thing: the |
768 |
// status is set by the stop button and not necessarily |
769 |
// here. |
770 |
showAppletStatus("death"); |
771 |
} finally { |
772 |
Thread.currentThread().interrupt(); // resignal interrupt |
773 |
} |
774 |
return null; |
775 |
} |
776 |
return applet; |
777 |
} |
778 |
|
779 |
protected void loadJarFiles(AppletClassLoader loader) throws IOException, |
780 |
InterruptedException { |
781 |
// Load the archives if present. |
782 |
// REMIND - this probably should be done in a separate thread, |
783 |
// or at least the additional archives (epll). |
784 |
String jarFiles = getJarFiles(); |
785 |
|
786 |
if (jarFiles != null) { |
787 |
StringTokenizer st = new StringTokenizer(jarFiles, ",", false); |
788 |
while(st.hasMoreTokens()) { |
789 |
String tok = st.nextToken().trim(); |
790 |
try { |
791 |
loader.addJar(tok); |
792 |
} catch (IllegalArgumentException e) { |
793 |
// bad archive name |
794 |
continue; |
795 |
} |
796 |
} |
797 |
} |
798 |
} |
799 |
|
800 |
/** |
801 |
* Request that the loading of the applet be stopped. |
802 |
*/ |
803 |
protected synchronized void stopLoading() { |
804 |
// REMIND: fill in the body |
805 |
if (loaderThread != null) { |
806 |
//System.out.println("Interrupting applet loader thread: " + loaderThread); |
807 |
loaderThread.interrupt(); |
808 |
} else { |
809 |
setLoadAbortRequest(); |
810 |
} |
811 |
} |
812 |
|
813 |
|
814 |
protected synchronized boolean okToLoad() { |
815 |
return !loadAbortRequest; |
816 |
} |
817 |
|
818 |
protected synchronized void clearLoadAbortRequest() { |
819 |
loadAbortRequest = false; |
820 |
} |
821 |
|
822 |
protected synchronized void setLoadAbortRequest() { |
823 |
loadAbortRequest = true; |
824 |
} |
825 |
|
826 |
|
827 |
private synchronized void setLoaderThread(Thread loaderThread) { |
828 |
this.loaderThread = loaderThread; |
829 |
} |
830 |
|
831 |
/** |
832 |
* Return true when the applet has been started. |
833 |
*/ |
834 |
@Override |
835 |
public boolean isActive() { |
836 |
return status == APPLET_START; |
837 |
} |
838 |
|
839 |
|
840 |
private EventQueue appEvtQ = null; |
841 |
/** |
842 |
* Is called when the applet wants to be resized. |
843 |
*/ |
844 |
@Override |
845 |
public void appletResize(int width, int height) { |
846 |
currentAppletSize.width = width; |
847 |
currentAppletSize.height = height; |
848 |
final Dimension currentSize = new Dimension(currentAppletSize.width, |
849 |
currentAppletSize.height); |
850 |
|
851 |
if(loader != null) { |
852 |
AppContext appCtxt = loader.getAppContext(); |
853 |
if(appCtxt != null) |
854 |
appEvtQ = (java.awt.EventQueue)appCtxt.get(AppContext.EVENT_QUEUE_KEY); |
855 |
} |
856 |
|
857 |
final AppletPanel ap = this; |
858 |
if (appEvtQ != null){ |
859 |
appEvtQ.postEvent(new InvocationEvent(Toolkit.getDefaultToolkit(), |
860 |
new Runnable() { |
861 |
@Override |
862 |
public void run() { |
863 |
if (ap != null) { |
864 |
ap.dispatchAppletEvent( |
865 |
APPLET_RESIZE, |
866 |
currentSize); |
867 |
} |
868 |
} |
869 |
})); |
870 |
} |
871 |
} |
872 |
|
873 |
@Override |
874 |
public void setBounds(int x, int y, int width, int height) { |
875 |
super.setBounds(x, y, width, height); |
876 |
currentAppletSize.width = width; |
877 |
currentAppletSize.height = height; |
878 |
} |
879 |
|
880 |
public Applet getApplet() { |
881 |
return applet; |
882 |
} |
883 |
|
884 |
/** |
885 |
* Status line. Called by the AppletPanel to provide |
886 |
* feedback on the Applet's state. |
887 |
*/ |
888 |
protected void showAppletStatus(String status) { |
889 |
getAppletContext().showStatus(amh.getMessage(status)); |
890 |
} |
891 |
|
892 |
protected void showAppletStatus(String status, Object arg) { |
893 |
getAppletContext().showStatus(amh.getMessage(status, arg)); |
894 |
} |
895 |
protected void showAppletStatus(String status, Object arg1, Object arg2) { |
896 |
getAppletContext().showStatus(amh.getMessage(status, arg1, arg2)); |
897 |
} |
898 |
|
899 |
/** |
900 |
* Called by the AppletPanel to print to the log. |
901 |
*/ |
902 |
protected void showAppletLog(String msg) { |
903 |
System.out.println(amh.getMessage(msg)); |
904 |
} |
905 |
|
906 |
protected void showAppletLog(String msg, Object arg) { |
907 |
System.out.println(amh.getMessage(msg, arg)); |
908 |
} |
909 |
|
910 |
/** |
911 |
* Called by the AppletPanel to provide |
912 |
* feedback when an exception has happened. |
913 |
*/ |
914 |
protected void showAppletException(Throwable t) { |
915 |
t.printStackTrace(); |
916 |
repaint(); |
917 |
} |
918 |
|
919 |
/** |
920 |
* Get caching key for classloader cache |
921 |
*/ |
922 |
public String getClassLoaderCacheKey() |
923 |
{ |
924 |
/** |
925 |
* Fixed #4501142: Classloader sharing policy doesn't |
926 |
* take "archive" into account. This will be overridden |
927 |
* by Java Plug-in. [stanleyh] |
928 |
*/ |
929 |
return getCodeBase().toString(); |
930 |
} |
931 |
|
932 |
/** |
933 |
* The class loaders |
934 |
*/ |
935 |
private static HashMap<String, AppletClassLoader> classloaders = new HashMap<>(); |
936 |
|
937 |
/** |
938 |
* Flush a class loader. |
939 |
*/ |
940 |
public static synchronized void flushClassLoader(String key) { |
941 |
classloaders.remove(key); |
942 |
} |
943 |
|
944 |
/** |
945 |
* Flush all class loaders. |
946 |
*/ |
947 |
public static synchronized void flushClassLoaders() { |
948 |
classloaders = new HashMap<>(); |
949 |
} |
950 |
|
951 |
/** |
952 |
* This method actually creates an AppletClassLoader. |
953 |
* |
954 |
* It can be override by subclasses (such as the Plug-in) |
955 |
* to provide different classloaders. |
956 |
*/ |
957 |
protected AppletClassLoader createClassLoader(final URL codebase) { |
958 |
return new AppletClassLoader(codebase); |
959 |
} |
960 |
|
961 |
/** |
962 |
* Get a class loader. Create in a restricted context |
963 |
*/ |
964 |
synchronized AppletClassLoader getClassLoader(final URL codebase, final String key) { |
965 |
AppletClassLoader c = classloaders.get(key); |
966 |
if (c == null) { |
967 |
AccessControlContext acc = |
968 |
getAccessControlContext(codebase); |
969 |
c = AccessController.doPrivileged( |
970 |
new PrivilegedAction<AppletClassLoader>() { |
971 |
@Override |
972 |
public AppletClassLoader run() { |
973 |
AppletClassLoader ac = createClassLoader(codebase); |
974 |
/* Should the creation of the classloader be |
975 |
* within the class synchronized block? Since |
976 |
* this class is used by the plugin, take care |
977 |
* to avoid deadlocks, or specialize |
978 |
* AppletPanel within the plugin. It may take |
979 |
* an arbitrary amount of time to create a |
980 |
* class loader (involving getting Jar files |
981 |
* etc.) and may block unrelated applets from |
982 |
* finishing createAppletThread (due to the |
983 |
* class synchronization). If |
984 |
* createAppletThread does not finish quickly, |
985 |
* the applet cannot process other messages, |
986 |
* particularly messages such as destroy |
987 |
* (which timeout when called from the browser). |
988 |
*/ |
989 |
synchronized (getClass()) { |
990 |
AppletClassLoader res = classloaders.get(key); |
991 |
if (res == null) { |
992 |
classloaders.put(key, ac); |
993 |
return ac; |
994 |
} else { |
995 |
return res; |
996 |
} |
997 |
} |
998 |
} |
999 |
},acc); |
1000 |
} |
1001 |
return c; |
1002 |
} |
1003 |
|
1004 |
/** |
1005 |
* get the context for the AppletClassLoader we are creating. |
1006 |
* the context is granted permission to create the class loader, |
1007 |
* connnect to the codebase, and whatever else the policy grants |
1008 |
* to all codebases. |
1009 |
*/ |
1010 |
private AccessControlContext getAccessControlContext(final URL codebase) { |
1011 |
|
1012 |
PermissionCollection perms = AccessController.doPrivileged( |
1013 |
new PrivilegedAction<PermissionCollection>() { |
1014 |
@Override |
1015 |
public PermissionCollection run() { |
1016 |
Policy p = java.security.Policy.getPolicy(); |
1017 |
if (p != null) { |
1018 |
return p.getPermissions(new CodeSource(null, |
1019 |
(java.security.cert.Certificate[]) null)); |
1020 |
} else { |
1021 |
return null; |
1022 |
} |
1023 |
} |
1024 |
}); |
1025 |
|
1026 |
if (perms == null) |
1027 |
perms = new Permissions(); |
1028 |
|
1029 |
//XXX: this is needed to be able to create the classloader itself! |
1030 |
|
1031 |
perms.add(SecurityConstants.CREATE_CLASSLOADER_PERMISSION); |
1032 |
|
1033 |
Permission p; |
1034 |
java.net.URLConnection urlConnection = null; |
1035 |
try { |
1036 |
urlConnection = codebase.openConnection(); |
1037 |
p = urlConnection.getPermission(); |
1038 |
} catch (java.io.IOException ioe) { |
1039 |
p = null; |
1040 |
} |
1041 |
|
1042 |
if (p != null) |
1043 |
perms.add(p); |
1044 |
|
1045 |
if (p instanceof FilePermission) { |
1046 |
|
1047 |
String path = p.getName(); |
1048 |
|
1049 |
int endIndex = path.lastIndexOf(File.separatorChar); |
1050 |
|
1051 |
if (endIndex != -1) { |
1052 |
path = path.substring(0, endIndex+1); |
1053 |
|
1054 |
if (path.endsWith(File.separator)) { |
1055 |
path += "-"; |
1056 |
} |
1057 |
perms.add(new FilePermission(path, |
1058 |
SecurityConstants.FILE_READ_ACTION)); |
1059 |
} |
1060 |
} else { |
1061 |
URL locUrl = codebase; |
1062 |
if (urlConnection instanceof JarURLConnection) { |
1063 |
locUrl = ((JarURLConnection)urlConnection).getJarFileURL(); |
1064 |
} |
1065 |
String host = locUrl.getHost(); |
1066 |
if (host != null && (host.length() > 0)) |
1067 |
perms.add(new SocketPermission(host, |
1068 |
SecurityConstants.SOCKET_CONNECT_ACCEPT_ACTION)); |
1069 |
} |
1070 |
|
1071 |
ProtectionDomain domain = |
1072 |
new ProtectionDomain(new CodeSource(codebase, |
1073 |
(java.security.cert.Certificate[]) null), perms); |
1074 |
AccessControlContext acc = |
1075 |
new AccessControlContext(new ProtectionDomain[] { domain }); |
1076 |
|
1077 |
return acc; |
1078 |
} |
1079 |
|
1080 |
public Thread getAppletHandlerThread() { |
1081 |
return handler; |
1082 |
} |
1083 |
|
1084 |
public int getAppletWidth() { |
1085 |
return currentAppletSize.width; |
1086 |
} |
1087 |
|
1088 |
public int getAppletHeight() { |
1089 |
return currentAppletSize.height; |
1090 |
} |
1091 |
|
1092 |
public static void changeFrameAppContext(Frame frame, AppContext newAppContext) |
1093 |
{ |
1094 |
// Fixed #4754451: Applet can have methods running on main |
1095 |
// thread event queue. |
1096 |
// |
1097 |
// The cause of this bug is that the frame of the applet |
1098 |
// is created in main thread group. Thus, when certain |
1099 |
// AWT/Swing events are generated, the events will be |
1100 |
// dispatched through the wrong event dispatch thread. |
1101 |
// |
1102 |
// To fix this, we rearrange the AppContext with the frame, |
1103 |
// so the proper event queue will be looked up. |
1104 |
// |
1105 |
// Swing also maintains a Frame list for the AppContext, |
1106 |
// so we will have to rearrange it as well. |
1107 |
|
1108 |
// Check if frame's AppContext has already been set properly |
1109 |
AppContext oldAppContext = SunToolkit.targetToAppContext(frame); |
1110 |
|
1111 |
if (oldAppContext == newAppContext) |
1112 |
return; |
1113 |
|
1114 |
// Synchronization on Window.class is needed for locking the |
1115 |
// critical section of the window list in AppContext. |
1116 |
synchronized (Window.class) |
1117 |
{ |
1118 |
WeakReference<Window> weakRef = null; |
1119 |
// Remove frame from the Window list in wrong AppContext |
1120 |
{ |
1121 |
// Lookup current frame's AppContext |
1122 |
@SuppressWarnings("unchecked") |
1123 |
Vector<WeakReference<Window>> windowList = |
1124 |
(Vector<WeakReference<Window>>)oldAppContext.get(Window.class); |
1125 |
if (windowList != null) { |
1126 |
for (WeakReference<Window> ref : windowList) { |
1127 |
if (ref.get() == frame) { |
1128 |
weakRef = ref; |
1129 |
break; |
1130 |
} |
1131 |
} |
1132 |
// Remove frame from wrong AppContext |
1133 |
if (weakRef != null) |
1134 |
windowList.remove(weakRef); |
1135 |
} |
1136 |
} |
1137 |
|
1138 |
// Put the frame into the applet's AppContext map |
1139 |
SunToolkit.insertTargetMapping(frame, newAppContext); |
1140 |
|
1141 |
// Insert frame into the Window list in the applet's AppContext map |
1142 |
{ |
1143 |
@SuppressWarnings("unchecked") |
1144 |
Vector<WeakReference<Window>> windowList = |
1145 |
(Vector<WeakReference<Window>>)newAppContext.get(Window.class); |
1146 |
if (windowList == null) { |
1147 |
windowList = new Vector<WeakReference<Window>>(); |
1148 |
newAppContext.put(Window.class, windowList); |
1149 |
} |
1150 |
// use the same weakRef here as it is used elsewhere |
1151 |
windowList.add(weakRef); |
1152 |
} |
1153 |
} |
1154 |
} |
1155 |
|
1156 |
// Flag to indicate if applet is targeted for JDK 1.1. |
1157 |
private boolean jdk11Applet = false; |
1158 |
|
1159 |
// Flag to indicate if applet is targeted for JDK 1.2. |
1160 |
private boolean jdk12Applet = false; |
1161 |
|
1162 |
/** |
1163 |
* Determine JDK level of an applet. |
1164 |
*/ |
1165 |
private void findAppletJDKLevel(Applet applet) |
1166 |
{ |
1167 |
// To determine the JDK level of an applet, the |
1168 |
// most reliable way is to check the major version |
1169 |
// of the applet class file. |
1170 |
|
1171 |
// synchronized on applet class object, so calling from |
1172 |
// different instances of the same applet will be |
1173 |
// serialized. |
1174 |
Class<?> appletClass = applet.getClass(); |
1175 |
|
1176 |
synchronized(appletClass) { |
1177 |
// Determine if the JDK level of an applet has been |
1178 |
// checked before. |
1179 |
Boolean jdk11Target = loader.isJDK11Target(appletClass); |
1180 |
Boolean jdk12Target = loader.isJDK12Target(appletClass); |
1181 |
|
1182 |
// if applet JDK level has been checked before, retrieve |
1183 |
// value and return. |
1184 |
if (jdk11Target != null || jdk12Target != null) { |
1185 |
jdk11Applet = (jdk11Target == null) ? false : jdk11Target.booleanValue(); |
1186 |
jdk12Applet = (jdk12Target == null) ? false : jdk12Target.booleanValue(); |
1187 |
return; |
1188 |
} |
1189 |
|
1190 |
String name = appletClass.getName(); |
1191 |
|
1192 |
// first convert any '.' to '/' |
1193 |
name = name.replace('.', '/'); |
1194 |
|
1195 |
// append .class |
1196 |
final String resourceName = name + ".class"; |
1197 |
|
1198 |
byte[] classHeader = new byte[8]; |
1199 |
|
1200 |
try (InputStream is = AccessController.doPrivileged( |
1201 |
(PrivilegedAction<InputStream>) () -> loader.getResourceAsStream(resourceName))) { |
1202 |
|
1203 |
// Read the first 8 bytes of the class file |
1204 |
int byteRead = is.read(classHeader, 0, 8); |
1205 |
|
1206 |
// return if the header is not read in entirely |
1207 |
// for some reasons. |
1208 |
if (byteRead != 8) |
1209 |
return; |
1210 |
} |
1211 |
catch (IOException e) { |
1212 |
return; |
1213 |
} |
1214 |
|
1215 |
// Check major version in class file header |
1216 |
int major_version = readShort(classHeader, 6); |
1217 |
|
1218 |
// Major version in class file is as follows: |
1219 |
// 45 - JDK 1.1 |
1220 |
// 46 - JDK 1.2 |
1221 |
// 47 - JDK 1.3 |
1222 |
// 48 - JDK 1.4 |
1223 |
// 49 - JDK 1.5 |
1224 |
if (major_version < 46) |
1225 |
jdk11Applet = true; |
1226 |
else if (major_version == 46) |
1227 |
jdk12Applet = true; |
1228 |
|
1229 |
// Store applet JDK level in AppContext for later lookup, |
1230 |
// e.g. page switch. |
1231 |
loader.setJDK11Target(appletClass, jdk11Applet); |
1232 |
loader.setJDK12Target(appletClass, jdk12Applet); |
1233 |
} |
1234 |
} |
1235 |
|
1236 |
/** |
1237 |
* Return true if applet is targeted to JDK 1.1. |
1238 |
*/ |
1239 |
protected boolean isJDK11Applet() { |
1240 |
return jdk11Applet; |
1241 |
} |
1242 |
|
1243 |
/** |
1244 |
* Return true if applet is targeted to JDK1.2. |
1245 |
*/ |
1246 |
protected boolean isJDK12Applet() { |
1247 |
return jdk12Applet; |
1248 |
} |
1249 |
|
1250 |
/** |
1251 |
* Read short from byte array. |
1252 |
*/ |
1253 |
private int readShort(byte[] b, int off) { |
1254 |
int hi = readByte(b[off]); |
1255 |
int lo = readByte(b[off + 1]); |
1256 |
return (hi << 8) | lo; |
1257 |
} |
1258 |
|
1259 |
private int readByte(byte b) { |
1260 |
return ((int)b) & 0xFF; |
1261 |
} |
1262 |
|
1263 |
|
1264 |
private static AppletMessageHandler amh = new AppletMessageHandler("appletpanel"); |
1265 |
} |
|
|
1266 |
++ icedtea-web/netx/sun/applet/AppletListener.java |
Line 0
Link Here
|
0 |
-- /dev/null |
1 |
/* |
|
|
2 |
* Copyright (c) 1997, Oracle and/or its affiliates. All rights reserved. |
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
5 |
* This code is free software; you can redistribute it and/or modify it |
6 |
* under the terms of the GNU General Public License version 2 only, as |
7 |
* published by the Free Software Foundation. Oracle designates this |
8 |
* particular file as subject to the "Classpath" exception as provided |
9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
15 |
* accompanied this code). |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License version |
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
* |
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
23 |
* questions. |
24 |
*/ |
25 |
|
26 |
package sun.applet; |
27 |
|
28 |
import java.util.EventListener; |
29 |
|
30 |
/** |
31 |
* Applet Listener interface. This interface is to be implemented |
32 |
* by objects interested in AppletEvents. |
33 |
* |
34 |
* @author Sunita Mani |
35 |
* |
36 |
* @deprecated The Applet API is deprecated. See the |
37 |
* <a href="../../java/applet/package-summary.html"> java.applet package |
38 |
* documentation</a> for further information. |
39 |
*/ |
40 |
@Deprecated(since = "9") |
41 |
public interface AppletListener extends EventListener { |
42 |
public void appletStateChanged(AppletEvent e); |
43 |
} |
|
|
44 |
++ icedtea-web/netx/sun/applet/AppletEvent.java |
Line 0
Link Here
|
0 |
-- /dev/null |
1 |
/* |
|
|
2 |
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
5 |
* This code is free software; you can redistribute it and/or modify it |
6 |
* under the terms of the GNU General Public License version 2 only, as |
7 |
* published by the Free Software Foundation. Oracle designates this |
8 |
* particular file as subject to the "Classpath" exception as provided |
9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
15 |
* accompanied this code). |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License version |
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
* |
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
23 |
* questions. |
24 |
*/ |
25 |
|
26 |
package sun.applet; |
27 |
|
28 |
import java.util.EventObject; |
29 |
|
30 |
|
31 |
/** |
32 |
* AppletEvent class. |
33 |
* |
34 |
* @author Sunita Mani |
35 |
* |
36 |
* @deprecated The Applet API is deprecated. See the |
37 |
* <a href="../../java/applet/package-summary.html"> java.applet package |
38 |
* documentation</a> for further information. |
39 |
*/ |
40 |
@SuppressWarnings("serial") // JDK-implementation class |
41 |
@Deprecated(since = "9") |
42 |
public class AppletEvent extends EventObject { |
43 |
|
44 |
private Object arg; |
45 |
private int id; |
46 |
|
47 |
|
48 |
public AppletEvent(Object source, int id, Object argument) { |
49 |
super(source); |
50 |
this.arg = argument; |
51 |
this.id = id; |
52 |
} |
53 |
|
54 |
public int getID() { |
55 |
return id; |
56 |
} |
57 |
|
58 |
public Object getArgument() { |
59 |
return arg; |
60 |
} |
61 |
|
62 |
public String toString() { |
63 |
String str = getClass().getName() + "[source=" + source + " + id="+ id; |
64 |
if (arg != null) { |
65 |
str += " + arg=" + arg; |
66 |
} |
67 |
str += " ]"; |
68 |
return str; |
69 |
} |
70 |
} |
|
|
71 |
++ icedtea-web/netx/sun/applet/AppletMessageHandler.java |
Line 0
Link Here
|
0 |
-- /dev/null |
1 |
/* |
|
|
2 |
* Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved. |
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
5 |
* This code is free software; you can redistribute it and/or modify it |
6 |
* under the terms of the GNU General Public License version 2 only, as |
7 |
* published by the Free Software Foundation. Oracle designates this |
8 |
* particular file as subject to the "Classpath" exception as provided |
9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
15 |
* accompanied this code). |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License version |
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
* |
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
23 |
* questions. |
24 |
*/ |
25 |
|
26 |
package sun.applet; |
27 |
|
28 |
import java.util.ResourceBundle; |
29 |
import java.util.MissingResourceException; |
30 |
import java.text.MessageFormat; |
31 |
|
32 |
/** |
33 |
* An hanlder of localized messages. |
34 |
* |
35 |
* @author Koji Uno |
36 |
*/ |
37 |
class AppletMessageHandler { |
38 |
private static ResourceBundle rb; |
39 |
private String baseKey = null; |
40 |
|
41 |
static { |
42 |
try { |
43 |
rb = ResourceBundle.getBundle |
44 |
("sun.applet.resources.MsgAppletViewer"); |
45 |
} catch (MissingResourceException e) { |
46 |
System.out.println(e.getMessage()); |
47 |
System.exit(1); |
48 |
} |
49 |
} |
50 |
|
51 |
AppletMessageHandler(String baseKey) { |
52 |
this.baseKey = baseKey; |
53 |
} |
54 |
|
55 |
String getMessage(String key) { |
56 |
return rb.getString(getQualifiedKey(key)); |
57 |
} |
58 |
|
59 |
String getMessage(String key, Object arg){ |
60 |
String basemsgfmt = rb.getString(getQualifiedKey(key)); |
61 |
MessageFormat msgfmt = new MessageFormat(basemsgfmt); |
62 |
Object msgobj[] = new Object[1]; |
63 |
if (arg == null) { |
64 |
arg = "null"; // mimic java.io.PrintStream.print(String) |
65 |
} |
66 |
msgobj[0] = arg; |
67 |
return msgfmt.format(msgobj); |
68 |
} |
69 |
|
70 |
String getMessage(String key, Object arg1, Object arg2) { |
71 |
String basemsgfmt = rb.getString(getQualifiedKey(key)); |
72 |
MessageFormat msgfmt = new MessageFormat(basemsgfmt); |
73 |
Object msgobj[] = new Object[2]; |
74 |
if (arg1 == null) { |
75 |
arg1 = "null"; |
76 |
} |
77 |
if (arg2 == null) { |
78 |
arg2 = "null"; |
79 |
} |
80 |
msgobj[0] = arg1; |
81 |
msgobj[1] = arg2; |
82 |
return msgfmt.format(msgobj); |
83 |
} |
84 |
|
85 |
String getMessage(String key, Object arg1, Object arg2, Object arg3) { |
86 |
String basemsgfmt = rb.getString(getQualifiedKey(key)); |
87 |
MessageFormat msgfmt = new MessageFormat(basemsgfmt); |
88 |
Object msgobj[] = new Object[3]; |
89 |
if (arg1 == null) { |
90 |
arg1 = "null"; |
91 |
} |
92 |
if (arg2 == null) { |
93 |
arg2 = "null"; |
94 |
} |
95 |
if (arg3 == null) { |
96 |
arg3 = "null"; |
97 |
} |
98 |
msgobj[0] = arg1; |
99 |
msgobj[1] = arg2; |
100 |
msgobj[2] = arg3; |
101 |
return msgfmt.format(msgobj); |
102 |
} |
103 |
|
104 |
String getMessage(String key, Object arg[]) { |
105 |
String basemsgfmt = rb.getString(getQualifiedKey(key)); |
106 |
MessageFormat msgfmt = new MessageFormat(basemsgfmt); |
107 |
return msgfmt.format(arg); |
108 |
} |
109 |
|
110 |
String getQualifiedKey(String subKey) { |
111 |
return baseKey + "." + subKey; |
112 |
} |
113 |
} |
|
|
114 |
++ icedtea-web/netx/sun/applet/AppletEventMulticaster.java |
Line 0
Link Here
|
0 |
-- icedtea-web.orig/netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java |
1 |
/* |
|
|
2 |
* Copyright (c) 1997, Oracle and/or its affiliates. All rights reserved. |
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
5 |
* This code is free software; you can redistribute it and/or modify it |
6 |
* under the terms of the GNU General Public License version 2 only, as |
7 |
* published by the Free Software Foundation. Oracle designates this |
8 |
* particular file as subject to the "Classpath" exception as provided |
9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
15 |
* accompanied this code). |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License version |
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
* |
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
23 |
* questions. |
24 |
*/ |
25 |
|
26 |
package sun.applet; |
27 |
|
28 |
import java.util.EventListener; |
29 |
import java.io.Serializable; |
30 |
import java.io.ObjectOutputStream; |
31 |
import java.io.IOException; |
32 |
|
33 |
/** |
34 |
* AppletEventMulticaster class. This class manages an immutable |
35 |
* structure consisting of a chain of AppletListeners and is |
36 |
* responsible for dispatching events to them. |
37 |
* |
38 |
* @author Sunita Mani |
39 |
* |
40 |
* @deprecated The Applet API is deprecated. See the |
41 |
* <a href="../../java/applet/package-summary.html"> java.applet package |
42 |
* documentation</a> for further information. |
43 |
*/ |
44 |
@Deprecated(since = "9") |
45 |
public class AppletEventMulticaster implements AppletListener { |
46 |
|
47 |
private final AppletListener a, b; |
48 |
|
49 |
public AppletEventMulticaster(AppletListener a, AppletListener b) { |
50 |
this.a = a; this.b = b; |
51 |
} |
52 |
|
53 |
public void appletStateChanged(AppletEvent e) { |
54 |
a.appletStateChanged(e); |
55 |
b.appletStateChanged(e); |
56 |
} |
57 |
|
58 |
/** |
59 |
* Adds Applet-listener-a with Applet-listener-b and |
60 |
* returns the resulting multicast listener. |
61 |
* @param a Applet-listener-a |
62 |
* @param b Applet-listener-b |
63 |
*/ |
64 |
public static AppletListener add(AppletListener a, AppletListener b) { |
65 |
return addInternal(a, b); |
66 |
} |
67 |
|
68 |
/** |
69 |
* Removes the old Applet-listener from Applet-listener-l and |
70 |
* returns the resulting multicast listener. |
71 |
* @param l Applet-listener-l |
72 |
* @param oldl the Applet-listener being removed |
73 |
*/ |
74 |
public static AppletListener remove(AppletListener l, AppletListener oldl) { |
75 |
return removeInternal(l, oldl); |
76 |
} |
77 |
|
78 |
/** |
79 |
* Returns the resulting multicast listener from adding listener-a |
80 |
* and listener-b together. |
81 |
* If listener-a is null, it returns listener-b; |
82 |
* If listener-b is null, it returns listener-a |
83 |
* If neither are null, then it creates and returns |
84 |
* a new AppletEventMulticaster instance which chains a with b. |
85 |
* @param a event listener-a |
86 |
* @param b event listener-b |
87 |
*/ |
88 |
private static AppletListener addInternal(AppletListener a, AppletListener b) { |
89 |
if (a == null) return b; |
90 |
if (b == null) return a; |
91 |
return new AppletEventMulticaster(a, b); |
92 |
} |
93 |
|
94 |
|
95 |
/** |
96 |
* Removes a listener from this multicaster and returns the |
97 |
* resulting multicast listener. |
98 |
* @param oldl the listener to be removed |
99 |
*/ |
100 |
protected AppletListener remove(AppletListener oldl) { |
101 |
if (oldl == a) return b; |
102 |
if (oldl == b) return a; |
103 |
AppletListener a2 = removeInternal(a, oldl); |
104 |
AppletListener b2 = removeInternal(b, oldl); |
105 |
if (a2 == a && b2 == b) { |
106 |
return this; // it's not here |
107 |
} |
108 |
return addInternal(a2, b2); |
109 |
} |
110 |
|
111 |
|
112 |
/** |
113 |
* Returns the resulting multicast listener after removing the |
114 |
* old listener from listener-l. |
115 |
* If listener-l equals the old listener OR listener-l is null, |
116 |
* returns null. |
117 |
* Else if listener-l is an instance of AppletEventMulticaster |
118 |
* then it removes the old listener from it. |
119 |
* Else, returns listener l. |
120 |
* @param l the listener being removed from |
121 |
* @param oldl the listener being removed |
122 |
*/ |
123 |
private static AppletListener removeInternal(AppletListener l, AppletListener oldl) { |
124 |
if (l == oldl || l == null) { |
125 |
return null; |
126 |
} else if (l instanceof AppletEventMulticaster) { |
127 |
return ((AppletEventMulticaster)l).remove(oldl); |
128 |
} else { |
129 |
return l; // it's not here |
130 |
} |
131 |
} |
132 |
} |
|
|
133 |
++ icedtea-web/netx/net/sourceforge/jnlp/runtime/JNLPSecurityManager.java |
Lines 338-371
Link Here
|
338 |
} |
338 |
} |
339 |
} |
339 |
} |
340 |
|
340 |
|
341 |
/** |
341 |
/** |
342 |
* Checks whether the window can be displayed without an applet |
|
|
343 |
* warning banner, and adds the window to the list of windows to |
344 |
* be disposed when the calling application exits. |
345 |
*/ |
346 |
@Override |
347 |
public boolean checkTopLevelWindow(Object window) { |
348 |
ApplicationInstance app = getApplication(); |
349 |
|
350 |
// remember window -> application mapping for focus, close on exit |
351 |
if (app != null && window instanceof Window) { |
352 |
Window w = (Window) window; |
353 |
|
354 |
OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "SM: app: " + app.getTitle() + " is adding a window: " + window + " with appContext " + AppContext.getAppContext()); |
355 |
|
356 |
weakWindows.add(w); // for mapping window -> app |
357 |
weakApplications.add(app); |
358 |
|
359 |
app.addWindow(w); |
360 |
} |
361 |
|
362 |
// todo: set awt.appletWarning to custom message |
363 |
// todo: logo on with glass pane on JFrame/JWindow? |
364 |
|
365 |
return super.checkTopLevelWindow(window); |
366 |
} |
367 |
|
368 |
/** |
369 |
* Checks whether the caller can exit the system. This method |
342 |
* Checks whether the caller can exit the system. This method |
370 |
* identifies whether the caller is a real call to Runtime.exec |
343 |
* identifies whether the caller is a real call to Runtime.exec |
371 |
* and has special behavior when returning from this method |
344 |
* and has special behavior when returning from this method |
Lines 422-480
Link Here
|
422 |
exitAllowed = false; |
395 |
exitAllowed = false; |
423 |
} |
396 |
} |
424 |
|
397 |
|
425 |
/** |
|
|
426 |
* This returns the appropriate {@link AppContext}. Hooks in AppContext |
427 |
* check if the current {@link SecurityManager} is an instance of |
428 |
* AWTSecurityManager and if so, call this method to give it a chance to |
429 |
* return the appropriate appContext based on the application that is |
430 |
* running. |
431 |
* <p> |
432 |
* This can be called from any thread (possibly a swing thread) to find out |
433 |
* the AppContext for the thread (which may correspond to a particular |
434 |
* applet). |
435 |
* </p> |
436 |
*/ |
437 |
@Override |
438 |
public AppContext getAppContext() { |
439 |
ApplicationInstance app = getApplication(); |
440 |
if (app == null) { |
441 |
/* |
442 |
* if we cannot find an application based on the code on the stack, |
443 |
* then assume it is the main application |
444 |
*/ |
445 |
return mainAppContext; |
446 |
} else { |
447 |
return app.getAppContext(); |
448 |
} |
449 |
|
450 |
} |
451 |
|
452 |
/** |
453 |
* Tests if a client can get access to the AWT event queue. This version allows |
454 |
* complete access to the EventQueue for its own AppContext-specific EventQueue. |
455 |
* |
456 |
* FIXME there are probably huge security implications for this. Eg: |
457 |
* http://hg.openjdk.java.net/jdk7/awt/jdk/rev/8022709a306d |
458 |
* |
459 |
* @exception SecurityException if the caller does not have |
460 |
* permission to accesss the AWT event queue. |
461 |
*/ |
462 |
@Override |
463 |
public void checkAwtEventQueueAccess() { |
464 |
/* |
465 |
* this is the templace of the code that should allow applets access to |
466 |
* eventqueues |
467 |
*/ |
468 |
|
469 |
// AppContext appContext = AppContext.getAppContext(); |
470 |
// ApplicationInstance instance = getApplication(); |
471 |
|
472 |
// if ((appContext == mainAppContext) && (instance != null)) { |
473 |
// If we're about to allow access to the main EventQueue, |
474 |
// and anything untrusted is on the class context stack, |
475 |
// disallow access. |
476 |
super.checkAwtEventQueueAccess(); |
477 |
// } |
478 |
} |
479 |
|
480 |
} |
398 |
} |