Search code examples
sabre

How to communicate with external webapp in Sabre Red App


I'm developing a Sabre Red App, with the intention of using a WebkitView to present our web-application. I'm aware that there are several ways how a WebkitView subclass can communicate with HTML/JS hosted locally as plugin-resource. However, what's the best approach to exchange data (pref. JSON) between a Red App and an external web-application?

Options I've looked into:

  1. Create a local index.html as plugin-resource, load the web-application in an iframe, and then go WebkitView <-> index.html <-> iFrame/web-application. Seems a bit of a hack, and I'm not sure the Red Workspace will always allow that index.html <-> iframe communication (isn't that cross-site?)
  2. Use the WebkitView#executeJavaScript(), but I can't see how the web-application could send a JSON object back

Thanks Simon


Solution

  • Turns out the Red App example using an extension point 'com.sabre.edge.platform.optional.webkit.js.handler' works, but only when using a WebkitView subclass. Subclassing BrowserView, the JS object was not present.

    For the other way round, we decided to use com.sabre.edge.cf.webapp.services.WebViewForwardingService to call a JS function. (be sure to include 'com.sabre.edge.cf.webapp.services' as plugin dependency)