23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 |
26 package netscape.javascript; |
26 package netscape.javascript; |
27 |
27 |
28 import jdk.internal.netscape.javascript.spi.JSObjectProvider; |
|
29 import java.applet.Applet; |
|
30 import java.security.AccessController; |
28 import java.security.AccessController; |
31 import java.security.PrivilegedAction; |
29 import java.security.PrivilegedAction; |
32 import java.util.Iterator; |
30 import java.util.Iterator; |
33 import java.util.ServiceLoader; |
31 import java.util.ServiceLoader; |
34 |
32 |
137 * @throws JSException when an error is reported from the browser or |
135 * @throws JSException when an error is reported from the browser or |
138 * JavaScript engine. |
136 * JavaScript engine. |
139 */ |
137 */ |
140 public abstract void setSlot(int index, Object value) throws JSException; |
138 public abstract void setSlot(int index, Object value) throws JSException; |
141 |
139 |
142 /** |
|
143 * Returns a JSObject for the window containing the given applet. This |
|
144 * method only works when the Java code is running in a browser as an |
|
145 * applet. The object returned may be used to access the HTML DOM directly. |
|
146 * |
|
147 * @param applet The applet. |
|
148 * @return JSObject representing the window containing the given applet or |
|
149 * {@code null} if we are not connected to a browser. |
|
150 * @throws JSException when an error is reported from the browser or |
|
151 * JavaScript engine or if applet is {@code null} |
|
152 * |
|
153 * @deprecated The Applet API is deprecated, no replacement. See the |
|
154 * <a href="{@docRoot}/java.desktop/java/applet/package-summary.html"> |
|
155 * java.applet package documentation</a> for further information. |
|
156 */ |
|
157 |
|
158 @Deprecated(since="9", forRemoval=true) |
|
159 @SuppressWarnings("exports") |
|
160 public static JSObject getWindow(Applet applet) throws JSException { |
|
161 return ProviderLoader.callGetWindow(applet); |
|
162 } |
|
163 |
|
164 private static class ProviderLoader { |
|
165 private static final JSObjectProvider provider; |
|
166 |
|
167 static { |
|
168 provider = AccessController.doPrivileged( |
|
169 new PrivilegedAction<>() { |
|
170 @Override |
|
171 public JSObjectProvider run() { |
|
172 Iterator<JSObjectProvider> providers = |
|
173 ServiceLoader.loadInstalled(JSObjectProvider.class).iterator(); |
|
174 if (providers.hasNext()) { |
|
175 return providers.next(); |
|
176 } |
|
177 return null; |
|
178 } |
|
179 } |
|
180 ); |
|
181 } |
|
182 |
|
183 private static JSObject callGetWindow(Applet applet) { |
|
184 if (provider != null) { |
|
185 return provider.getWindow(applet); |
|
186 } |
|
187 return null; |
|
188 } |
|
189 } |
|
190 } |
140 } |