applets reloaded: introducing the next-generation java ... · applets reloaded: introducing the...

58
Applets Reloaded: Introducing the Next-Generation JavaPlug-In Technology Kenneth Russell Sven Gothel Java SE Deployment Team Sun Microsystems, Inc. TS-6290

Upload: others

Post on 21-May-2020

22 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

Applets Reloaded:Introducing the Next-GenerationJava™ Plug-In Technology

Kenneth RussellSven GothelJava SE Deployment TeamSun Microsystems, Inc.

TS-6290

Page 2: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 2

Learn how to deploy leading-edge Java™ platform content into the web browser using the next-generation Java Plug-In technology

Page 3: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 3

Agenda

Architectural OverviewDeploying Applets using JNLPCommand Line ArgumentsJava Runtime Environment (JRE™) Version SelectionPerformance and Compatibility TipsUsing JNLP ExtensionsMaintaining Corporate IdentityJava/JavaScript™ Programming Language IntegrationManipulating the DOMAccess to Web ServicesExperimental FunctionalityThanksQ&A

Page 4: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 4

Architectural Overview

Ground-up rewrite of the support for applets in the web browserApplets are no longer executed in a Java Virtual Machine (JVM™) inside the web browserInstead, a separate JVM machine process is launched to execute the appletsBy default, only one JVM machine is launched• Same resource consumption and sharing properties as the “classic”

Java Plug-In technology

Opportunity to launch more than one JVM machine• To support per-applet command-line arguments, heap size requests,

and more

Architectural similarities to Java Web Start technology, but tighter browser integration

Page 5: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 5

Architectural Overview

HTML-Webpage

Applet 1

Applet 2

Applet 3

Page 6: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 6

Architectural Overview

Thin Server JVM

Fat Client JVM 1

Fat Client JVM 2

OS Process 1

OS Process 2

OS Process 3

Page 7: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 7

Advantages

Improved reliabilityImproved user experience• Applets launch in the background

Built-in JNLP supportPer-applet command line arguments• Heap size, Java 2D™ API acceleration options...

Improved Java/JavaScript programming language integrationImproved Windows Vista support• Signed applets now work correctly in Protected Mode Internet Explorer

Page 8: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 8

Agenda

Architectural OverviewDeploying Applets using JNLPCommand Line ArgumentsJRE Version SelectionPerformance and Compatibility TipsUsing JNLP ExtensionsMaintaining Corporate IdentityJava/JavaScript Programming Language IntegrationManipulating the DOMAccess to Web ServicesExperimental FunctionalityThanksQ&A

Page 9: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 9

Deploying Applets Using JNLP

Most significant feature in new plug-in is ability to launch applets directly from JNLP filesSame descriptor used by Java Web Start softwareMore powerful than classic “archive”, “code”, “cache_archive” parametersProvides access to advanced JNLP extensions previously available only to Java Web Start software applications*• *Small set was previously available, with restrictions; these

restrictions have now been removed

Provides access to the JNLP APIs from applets• PersistenceService, DownloadService

Provides control over heap size, command-line arguments, JRE version selection, and auto-download• Same capabilities as Java Web Start software for applications

Page 10: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 10

Basic JNLP Example

<applet width=”500” height=”500”> <param name=”jnlp_href” value=”my_applet.jnlp”></applet>

Page 11: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 11

Basic JNLP Example

<?xml version=”1.0” encoding=”UTF-8”?><jnlp href=”my_applet.jnlp”> <information> <title=”My Applet”> <vendor>My Company, Inc.</vendor> <offline-allowed /> </information> <resources> <j2se version=”1.4+” href=”http://java.sun.com/products/autodl/j2se” /> <jar href=”my_jar_1.jar” main=”true” /> <jar href=”my_jar_2.jar” /> </resources> <applet-desc name=”My Applet” main-class=”com.mycompany.MyApplet” width=”1” height=”1” /></jnlp>

Page 12: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 12

Discussion

Basically behaves exactly like an application started with Java Web Start softwarejnlp_href parameter bridges between the web page and the JNLP description of the appletSupports only the <applet-desc> JNLP tag• Does not make sense to launch applications

Applet tag and JNLP file have overlapping mechanisms for specifying things like the width and heightWill discuss interpretation of duplicate parameters

Page 13: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 13

Referencing Resources

New capability to reference your resources with relative pathsAllows migration of content from server to server and place to placeBest practice:• Do not specify a codebase in your JNLP tag• Let the Java Plug-In technology supply it automatically

Page 14: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 14

Applet-Desc Tag

<?xml version=”1.0” encoding=”UTF-8”?><jnlp href=”my_applet.jnlp”> <information> <title=”My Applet”> <vendor>My Company, Inc.</vendor> <offline-allowed /> </information> <resources> <j2se version=”1.4+” href=”http://java.sun.com/products/autodl/j2se” /> <jar href=”my_jar_1.jar” main=”true” /> <jar href=”my_jar_2.jar” /> </resources> <applet-desc name=”My Applet” main-class=”com.mycompany.MyApplet” width=”1” height=”1” /></jnlp>

Page 15: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 15

Applet-Desc Tag

width and height are ignored• Browser always overrides because it knows best how big the applet

needs to be• Relative width and height supported in applet tag (i.e., “50%”)

main-class parameter always used• code parameter from applet tag is ignored

• Enables backward compatibility mechanisms (described later)

Page 16: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 16

Information Tag

<?xml version=”1.0” encoding=”UTF-8”?><jnlp href=”my_applet.jnlp”> <information> <title=”My Applet”> <vendor>My Company, Inc.</vendor> <offline-allowed /> </information> <resources> <j2se version=”1.4+” href=”http://java.sun.com/products/autodl/j2se” /> <jar href=”my_jar_1.jar” main=”true” /> <jar href=”my_jar_2.jar” /> </resources> <applet-desc name=”My Applet” main-class=”com.mycompany.MyApplet” width=”1” height=”1” /></jnlp>

Page 17: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 17

Information Tag

Keep in mind that the information tag is required

Page 18: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 18

Resources Tag

<?xml version=”1.0” encoding=”UTF-8”?><jnlp href=”my_applet.jnlp”> <information> <title=”My Applet”> <vendor>My Company, Inc.</vendor> <offline-allowed /> </information> <resources> <j2se version=”1.4+” href=”http://java.sun.com/products/autodl/j2se” /> <jar href=”my_jar_1.jar” main=”true” /> <jar href=”my_jar_2.jar” /> </resources> <applet-desc name=”My Applet” main-class=”com.mycompany.MyApplet” width=”1” height=”1” /></jnlp>

Page 19: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 19

Resources Tag

Note requirement of main jar specification per JNLP specDifferent than old-style applets where archive parameter simply specified a list of jars

Page 20: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 20

Agenda

Architectural OverviewDeploying Applets using JNLPCommand Line ArgumentsJRE Version SelectionPerformance and Compatibility TipsUsing JNLP ExtensionsMaintaining Corporate IdentityJava/JavaScript Programming Language IntegrationManipulating the DOMAccess to Web ServicesExperimental FunctionalityThanksQ&A

Page 21: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 21

Command Line Arguments

<?xml version=”1.0” encoding=”UTF-8”?><jnlp href=”my_applet.jnlp”> ... <resources> <j2se version=”1.4+” href=”http://java.sun.com/products/autodl/j2se” max-heap-size=”128m” java-vm-args=”-verbose:gc” /> <property name=”sun.java2d.opengl” value=”true” /> ... </resources> ...</jnlp>

Page 22: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 22

Command Line Arguments

Low-level command line arguments may be specified for each applet• System properties• Maximum heap size• JVM machine arguments

Plug-In launches a new JVM machine instance when necessary• When no existing instance satisfies the command-line argument request

System still runs multiple applets per JVM machine instanceSharing algorithm is deliberately loosely specified• Can get arbitrarily complicated• Might require revision later• Consult the release notes

Page 23: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 23

Command Line Arguments

An applet may force itself into its own JVM machine instance separate from all other applets

<param name=”separate_jvm” value=”true” />

Useful when migrating certain kinds of desktop applications to work in the web browser• Signed applets which have global networking state

Page 24: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 24

Command Line Arguments

Java Web Start software has a notion of “secure” command line arguments• System properties and JVM machine arguments

Java Plug-In reuses the same definitions• Consult release notes and Java Web Start Developers' Guide

To enable non-secure arguments:• Sign your applet• Sign your JNLP file

Page 25: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 25

Agenda

Architectural OverviewDeploying Applets using JNLPCommand Line ArgumentsJRE Version SelectionPerformance and Compatibility TipsUsing JNLP ExtensionsMaintaining Corporate IdentityJava/JavaScript Programming Language IntegrationManipulating the DOMAccess to Web ServicesExperimental FunctionalityThanksQ&A

Page 26: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 26

JRE Version Selection

May run a particular applet on a particular version of the JRE

<j2se version=”1.4+” ...><j2se version=”1.5*” ...>

Useful for enterprises which want to QA their applets against a particular JRE versionSupersedes earlier version selection mechanisms like CLSID in Internet Explorer• Consult release notes for details

Auto-download is supported• Better overall auto-download support for both Java Web Start software

and Java Plug-In coming soon• Server-side changes only; no changes to client JNLPs

Page 27: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 27

JRE Version Selection

If a very old JRE version is requested, restrictions are enforced• User will be prompted if applet attempts to load unsigned code

Note that since JNLP support is first available in Java Plug-In in Java Platform, Standard Edition 6 (Java SE 6) Update 10, version specifications like “1.4+” are basically meaningless• Will have more meaning when “1.7+” is needed

Some technical limitations• As early as 1.4.2 supported on Windows• As early as 1.5 supported on X11 (Unix) platforms• 1.3.1 and earlier are not supported

Page 28: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 28

Agenda

Architectural OverviewDeploying Applets using JNLPCommand Line ArgumentsJRE Version SelectionPerformance and Compatibility TipsUsing JNLP ExtensionsMaintaining Corporate IdentityJava/JavaScript Programming Language IntegrationManipulating the DOMAccess to Web ServicesExperimental FunctionalityThanksQ&A

Page 29: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 29

Tip: Avoiding Relaunches

First JVM machine used to parse the JNLP file might not satisfy command-line argument or JRE version requestsIn this case applet is relaunched in a new JVM machine instanceFor the time being, can give the system a “hint” using applet parameters developed for old-style (non-JNLP) applets<param name=”java_arguments” value=”-Xmx128m -Dsun.java2d.opengl=true”>Any arguments specified in the JNLP file will override these, but JVM machine instance will be reused if the arguments are compatibleWe hope to eliminate the need for this optimization later in the release

Page 30: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 30

Faster Startup

Can use the <update> tag in the JNLP file to drastically reduce startup time for second and subsequent launches

<update check=”background”>

Will use the version of the app that is already in the cacheDownloads updated version of the app in the backgroundNext launch picks up the new version

Page 31: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 31

Maintaining Backward Compatibility

Can author content which runs with earlier versions of Java Plug-In, but which takes advantage of new featuresSimply provide a fully-formed <applet> tag as well as the jnlp_href parameterEarlier JRE versions will ignore the jnlp_href parameterThe new Java Plug-In technology will ignore the archive and code parameters and use only the JNLP file to launch the appletOn-line demos use this technique to show a small applet, which runs on earlier JRE versions, encouraging users to upgrade• Consult release notes

Page 32: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 32

Agenda

Architectural OverviewDeploying Applets using JNLPCommand Line ArgumentsJRE Version SelectionPerformance and Compatibility TipsUsing JNLP ExtensionsMaintaining Corporate IdentityJava/JavaScript Programming Language IntegrationManipulating the DOMAccess to Web ServicesExperimental FunctionalityThanksQ&A

Page 33: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 33

Using JNLP Extensions

It is now trivial to use advanced JNLP extensions inside applets• OpenGL for 3D graphics via JOGL• OpenAL for 3D spatialized audio via JOAL• NASA World Wind Java for visualization of Earth and other planets• JavaFX™ Player components such as video, scene graph, WebKit

Simply refer to the extension JNLP in the resources section<extension name=”jogl” href=”http://download.java.net/.../jogl.jnlp” />Developers can provide extensions to the Java platformProvides great flexibility in partitioning application into independently upgradable piecesConsult release notes for detailed examples

Page 34: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 34

Agenda

Architectural OverviewDeploying Applets using JNLPCommand Line ArgumentsJRE Version SelectionPerformance and Compatibility TipsUsing JNLP ExtensionsMaintaining Corporate IdentityJava/JavaScript Programming Language IntegrationManipulating the DOMAccess to Web ServicesExperimental FunctionalityThanksQ&A

Page 35: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 35

Maintaining Corporate Identity

By default, animated “S” logo is displayed while loading large appletsCan replace this logo with a custom imageNew support for animated GIF images• Act as an indeterminate progress bar

Better control over foreground and background colorBetter control over placement of image• Can auto-center it in applet area

Better control over appearance• Can turn off box border

Page 36: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 36

Maintaining Corporate Identity

<applet codebase=”...” code=”...” ...> <!-- Use an animated GIF as a loading indicator --> <param name=”image” value=”ajax-loader.gif”> <!-- Turn off the border before the applet is loaded --> <param name=”boxborder” value=”false”> <!-- Center the image in the applet's area --> <param name=”centerimage” value=”true”> <!-- The surrounding web page uses white on black--> <param name=”boxbgcolor” value=”#000000”> <param name=”boxfgcolor” value=”#ffffff”></applet>

Page 37: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 37

Maintaining Corporate Identity

Can still do betterPartition application so that main piece is smallUse JNLP DownloadService to download the rest of the piecesCan draw a progress indicator yourself this way

Page 38: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 38

Agenda

Architectural OverviewDeploying Applets using JNLPCommand Line ArgumentsJRE Version SelectionPerformance and Compatibility TipsUsing JNLP ExtensionsMaintaining Corporate IdentityJava/JavaScript Programming Language IntegrationManipulating the DOMAccess to Web ServicesExperimental FunctionalityThanksQ&A

Page 39: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 39

Java/JavaScript Programming Language Integration

Bridge between Java and JavaScript programming languages has been completely rewrittenAs compatible as possible with previous implicit LiveConnect specification from Mozilla• Superset of previously available functionality in IE

Essentially as fast in all cases as previous in-process Java Plug-In technology despite the need to communicate between processes• Significantly improved performance on Mozilla browser family due to

better efficiency

Powerful new functionality

Page 40: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 40

Java-to-JavaScript Programming Language Calls

netscape.javascript.JSObject class is now fully implemented on all browsers• Call methods / eval script• Add / remove members (where allowed)• Get / set array elements

Provides portable way to call JavaScript from Java programming language and thereby interact with the web pageImplementation is safe in the face of multiple threads, multiple applets and multiple attached JVM machine instancesSame bootstrapping mechanism as before JSObject win = JSObject.getWindow(applet);

Page 41: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 41

JavaScript-to-Java Calls

Improved and unified behavior when calling from JavaScript programming language on the web page into JavaMAYSCRIPT attribute is no longer requiredUnified security model• JavaScript-to-Java calls are modeled as coming from untrusted Java

code whose origin is the document base• Mozilla-specific concept of signed JavaScript programming language

code is no longer supported

Page 42: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 42

JavaScript-to-Java Calls

Method lookup and dispatch algorithms are now browser-independent• True portability between IE and Firefox

Overloaded method resolution supportedAdvanced argument conversions supported• JavaScript-to-Java programming language arrays, including multi-

dimensional arrays

“java”, “netscape”, “Packages” keywords now supported on all browsers as long as at least one applet is on the web page• Not recommended, however• Next slide shows new mechanism

Page 43: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 43

JavaScript-to-Java Calls

New per-applet Packages keyword provides access to static Java programming language methods and instantiation of new Java objects from JavaScript programming language• Even user-defined classes

<applet id=”myApplet” ...><script language=”javascript”>var app = document.getElementById(“myApplet”); app.Packages.java.lang.System.out.println(“Hello”); app.Packages.com.mycompany.MyClass.staticMethod(); var aJavaObject = new app.Packages.com.mycompany.MyClass();</script>

Consult release notes for more examples

Page 44: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 44

JavaScript-to-Java Calls

Threading model of JavaScript-to-Java calls has been rationalized and is now portableA per-applet worker thread handles JavaScript-to-Java calls• Separate from all other applet threads

If a Java-to-JavaScript call is underway, calls back from JavaScript to Java against the same applet will be routed to the same threadMany details to be discussedConsult release notes and documentation

Page 45: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 45

Agenda

Architectural OverviewDeploying Applets using JNLPCommand Line ArgumentsJRE Version SelectionPerformance and Compatibility TipsUsing JNLP ExtensionsMaintaining Corporate IdentityJava/JavaScript Programming Language IntegrationManipulating the DOMAccess to Web ServicesExperimental FunctionalityThanksQ&A

Page 46: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 46

Manipulating the DOM

Can manipulate the web page on which the applet livesThis basic functionality is provided by the JSObject class and Java-to-JavaScript callsFor some time, W3C DOM access has been available via the Java Plug-In• Inconsistent coverage

Page 47: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 47

Manipulating the DOM

Object-oriented DOM access has been rewrittenNew, much simpler bootstrapping entry point

org.w3c.dom.Document doc = com.sun.java.browser.plugin2.DOM. getDocument(applet);

Can then cast to HTMLDocument and descend into the DOMCan perform operations from any thread• Underlying Java/JavaScript programming language bridge

is thread safeEnables advanced AJAX-style web apps using Java programming language

Page 48: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 48

Agenda

Architectural OverviewDeploying Applets using JNLPCommand Line ArgumentsJRE Version SelectionPerformance and Compatibility TipsUsing JNLP ExtensionsMaintaining Corporate IdentityJava/JavaScript Programming Language IntegrationManipulating the DOMAccess to Web ServicesExperimental FunctionalityThanksQ&A

Page 49: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 49

Access to Web Services

Cross-Domain XML specifies how untrusted code may gain access to arbitrary web services on the Internet• http://crossdomainxml.org/

Supported by competing technologies to Java programming languageNow supported in Java Plug-In and Java Web Start softwareUnsigned applets and applications may contact popular web services if they publish a crossdomain.xml allowing access• Amazon, FaceBook, Flickr, Picasa, Yahoo!, YouTube

Domain restrictions are not implemented• Access is only granted if the crossdomain.xml is present and it contains

only an entry granting access from all domains

Can specify alternate crossdomain.xml locations via a system propertyConsult release notes for details

Page 50: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 50

Agenda

Architectural OverviewDeploying Applets using JNLPCommand Line ArgumentsJRE Version SelectionPerformance and Compatibility TipsUsing JNLP ExtensionsMaintaining Corporate IdentityJava/JavaScript Programming Language IntegrationManipulating the DOMAccess to Web ServicesExperimental FunctionalityThanksQ&A

Page 51: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 51

Experimental Functionality

New Java Plug-In technology supports dragging applets out of the web browser as a deployment paradigm• Applets are mini applications that run anywhere• In and out of the browser

Highly experimental• Not guaranteed to be supported in this release or future

releases• Functionality will very likely change• Please provide feedback on Java Plug-In forum on java.net

Page 52: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 52

Experimental Functionality

Enable with new applet parameter <param name=”draggable” value=”true”>By default, Alt + Left-click + Drag anywhere in the applet's region is the drag gestureCan be customized by providing a method on your applet public boolean isAppletDragStarted(MouseEvent e);

Page 53: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 53

Experimental Functionality

Applet is placed into a new top-level Frame• Frame is used for Applet subclasses

• JFrame is used for JApplet subclassesBy default, the new frame is undecorated and opaqueCan change this, and perform other custom operations, at the time the drag is initiated by providing a method on your applet public void appletDragStarted();At the time this method is called, your applet is in the new top-level Frame, that Frame is undecorated, and it is not yet visible

Page 54: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 54

Experimental Functionality

A separate “close button” separate from the Frame tracks the movement of the Frame around the screen if undecoratedCan customize this by providing a method on your applet

public void setAppletCloseListener(ActionListener l);If you implement this method, you should draw some sort of close button in your applet's regionCall the ActionListener when the close button is clicked to initiate shutdown of your applet

Page 55: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 55

Experimental Functionality

While the web page where the applet came from is still visible, the applet can still talk back to the browser• Java/JavaScript calls still allowed• Can still interact with the surrounding web page

Once the page is closed, reloaded, or navigated away from, the applet is disconnected from the browserServices provided to the applet degrade gracefully• Java/JavaScript calls disallowed• AppletContext.showDocument() is implemented by

opening a new browser window; target is ignored• ...

When applet is closed, normal applet shutdown occurs• stop() and destroy() are called

Page 56: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 56

ThanksDevelopment Team

Calvin CheungHao DongDanielle Pham

Key TestersJitender SinghHung T. NguyenMin-Chi TienSergei SapozhnikovAnjana Prabhakar

Valued PartnersJohnny Stenback, MozillaPogo.comTony Li, EvergreenBora Ertung, NeuroDNANASAApple ComputerJess Holle, PTCAndy Gullins, EntrustLincoln Goldspink, speed-

trap.comRaj Advani, UpNextOracle

CollaboratorsXiaobin LuJoshua MarinacciAnthony RogersAndrew AllensonChris OliverRichard BairJasper Potts

Manager: Gustavo GalimbertiMoral Support: James Gosling, Bob Brewin

Page 57: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 57

Q&A

Page 58: Applets Reloaded: Introducing the Next-Generation Java ... · Applets Reloaded: Introducing the Next-Generation ... •To support per-applet command-line arguments, heap size requests,

2008 JavaOneSM Conference | java.sun.com/javaone | 58

Kenneth RussellSven GothelJava SE Deployment TeamSun Microsystems, Inc.

TS-6290