Reputation: 2789
I have a javascript application which will be running on an embedded platform. It has to call some c APIs which are already implemented in the platform. This is a proprietary application and is meant to run only on selected devices.
I am running this application on webkit. There is no JVM available.
I am thinking of some options and got a few. I would like to know whether any of them are applicable or a better option. I am new to javascript so my ideas may not be right.
Something similar to JNI ( if this exists at all)
Develop a plugin for webkit which exposes some Javascript APIs to the application and then calls native c functions
Modify webkit
Upvotes: 2
Views: 1471
Reputation: 1520
One approach you might want to explore is script alert handler. I know webkit gtk supports it http://webkitgtk.org/reference/webkitgtk/stable/webkitgtk-webkitwebview.html#WebKitWebView-script-alert
You can have simple javascript alert on your webview and parse parameter on other side and then call the required function. Of course, if you have complex parameters (e.g. objects) which can not be translated to strings easily, this approach will be difficult to implement.
Only problem is I don't know if this functionality is supported on your platform since you did not mention the platform, there is no way for me to check.
Upvotes: 0
Reputation: 137442
Your 2nd suggestion is pretty close to what you need to do. When you compile the browser (you don't need to compile webkit yourself) you can register functions and objects.
If you are using Qt, you should probably start here.
If you are using GTK, the registration is different, here is a nice example.
Upvotes: 3