Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8101298

JavaScript to Java method calls in Web component [# 752342]

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P3 P3
    • fx2.1
    • fx2.1
    • javafx
    • web

      SCOPING:
      Webview should allow JavaScript rendered in the WebView to make calls to the containing Java code. This feature must provide capabilities similar to those provided by the Java browser plugin's JavaScript to Java bridge.

      RISK:
      - There is a security risk in direct calls from JavaScripto to Java. We now know how to do it securely.
      - We consider using Nashorn as a JS engine for WebView. Nashorn design may affect the bridge API.

      DEPENDENCIES:
      No dependency on other JFX components.

      DETAILS:
      The bridge supports wrapping Java objects as JavaScript. This happens (for example) when calling the JSObject#setMember or JSObject#call methods.
      Currently this wrapping is opaque: Javascript code can't do anything with the wrapped Java object.
      The top priority is "fixing" this so JavaScript can call methods on a wrapped Java object; one also wants to be able to get and set fields.
      WebKit has support for this, but we need to figure out and implement the correct way of plugging in our implementation.
      No new APIs are needed for this: We just need to plug in the mechanism so a JavaScript methods call forwards (proxies) to the correspondingly-named Java method.
      There may be some difficulties with overloaded methods, but an approximate solution is probably OK.

      In addition it is desirable to define a Java API to enable registering specific Java objects and possibly specific methods in the JavaScript namespace, to make it more convenient to call Java from (say) JavaScript events handlers. Such methods would probably be in the WebEngine class. At the least we plan to provide a single method to register a Java Object as "global" name (i.e. as a property of the Window object).

      The LiveConnect browser plugin allows JavaScript to call arbitrary named Java static methods and constructors. We do *not* intend to support this for 2.1; partly because of the work needed, and partly because we don't have a handle on the security implications.

      The LiveConnect browser plugin has some extra functionality to make working with arrays more convenient. We do not plan to support this for 1.2.

            peterz Peter Zhelezniakov
            apikalev Andrey Pikalev
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: