-
- All Implemented Interfaces:
-
com.sun.jna.Library
public interface WebviewJNA.WebviewLibrary implements Library
All 15 C functions in webview.h
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public interface
WebviewJNA.WebviewLibrary.webview_dispatch_fn_callback
public interface
WebviewJNA.WebviewLibrary.webview_bind_fn_callback
The callback interface for
webview_bind
due to JNA's function mapping rules.
-
Method Summary
Modifier and Type Method Description abstract Pointer
webview_create(Integer debug, Pointer window)
Creates a new webview instance. abstract Unit
webview_destroy(Pointer webview)
abstract Unit
webview_run(Pointer webview)
Runs the main loop until it's terminated. abstract Unit
webview_terminate(Pointer webview)
Stops the main loop. abstract Unit
webview_dispatch(Pointer webview, WebviewJNA.WebviewLibrary.webview_dispatch_fn_callback fn, Pointer args)
Posts a function to be executed on the main thread. abstract Pointer
webview_get_window(Pointer webview)
Returns a native window handle pointer. abstract Unit
webview_set_title(Pointer webview, String title)
Updates the title of the native window. abstract Unit
webview_set_size(Pointer webview, Integer width, Integer height, Integer hints)
Updates the size of the native window. abstract Unit
webview_navigate(Pointer webview, String url)
Navigates webview to the given URLURL may be a data URI, i.e. abstract Unit
webview_set_html(Pointer webview, String html)
Set webview HTML directly. abstract Unit
webview_init(Pointer webview, String js)
Injects JavaScript code at the initialization of the new page. abstract Unit
webview_eval(Pointer webview, String js)
Evaluates arbitrary JavaScript code. abstract Unit
webview_bind(Pointer webview, String name, WebviewJNA.WebviewLibrary.webview_bind_fn_callback callback, Pointer arg)
Binds a native Kotlin/Java callback so that it will appear under the given name as a global JavaScript function. abstract Unit
webview_unbind(Pointer webview, String name)
Removes a Kotlin/Java callback that was previously set by webview_bind
.abstract Unit
webview_return(Pointer webview, String seq, Integer status, String result)
Allows to return a value from the Kotlin/Java binding. -
-
Method Detail
-
webview_create
abstract Pointer webview_create(Integer debug, Pointer window)
Creates a new webview instance.
If debug is non-zero - developer tools will be enabled (if the platform supports them). Window parameter can be a pointer to the native window handle. If it's non-null - then child WebView is embedded into the given parent window. Otherwise, a new window is created. Depending on the platform, a GtkWindow, NSWindow or HWND pointer can be passed here.
-
webview_destroy
abstract Unit webview_destroy(Pointer webview)
-
webview_run
abstract Unit webview_run(Pointer webview)
Runs the main loop until it's terminated.
After this function exits - you must destroy the webview.
- Parameters:
webview
- the handle of webview, usually returned bywebview_create
-
webview_terminate
abstract Unit webview_terminate(Pointer webview)
Stops the main loop.
It is safe to call this function from another other background thread.
- Parameters:
webview
- the handle of webview, usually returned bywebview_create
-
webview_dispatch
abstract Unit webview_dispatch(Pointer webview, WebviewJNA.WebviewLibrary.webview_dispatch_fn_callback fn, Pointer args)
Posts a function to be executed on the main thread.
It safely schedules the callback to be run on the main thread on the next main loop iteration. You normally do not need to call this function, unless you want to tweak the native window.
- Parameters:
webview
- the handle of webview, usually returned bywebview_create
fn
- the callbackargs
- please ignore it and keep itPointer.NULL
unless you know what you're doing.
-
webview_get_window
@Deprecated(message = "Not suggested to use") abstract Pointer webview_get_window(Pointer webview)
Returns a native window handle pointer.
When using GTK backend the pointer is GtkWindow pointer, when using Cocoa backend the pointer is NSWindow pointer, when using Win32 backend the pointer is HWND pointer.
- Parameters:
webview
- the handle of webview, usually returned bywebview_create
-
webview_set_title
abstract Unit webview_set_title(Pointer webview, String title)
Updates the title of the native window.
Must be called from the UI thread.
- Parameters:
webview
- the handle of webview, usually returned bywebview_create
title
- the new title
-
webview_set_size
abstract Unit webview_set_size(Pointer webview, Integer width, Integer height, Integer hints)
Updates the size of the native window.
Accepts a WEBVIEW_HINT
- Parameters:
webview
- the handle of webview, usually returned bywebview_create
hints
- can be one ofWEBVIEW_HINT_NONE
,WEBVIEW_HINT_MIN
,WEBVIEW_HINT_MAX
orWEBVIEW_HINT_FIXED
-
webview_navigate
abstract Unit webview_navigate(Pointer webview, String url)
Navigates webview to the given URL
URL may be a data URI, i.e. "data:text/text,...". It is often ok not to url-encode it properly, webview will re-encode it for you.
- Parameters:
webview
- the handle of webview, usually returned bywebview_create
url
- the URL or URI
-
webview_set_html
abstract Unit webview_set_html(Pointer webview, String html)
Set webview HTML directly.
- Parameters:
webview
- the handle of webview, usually returned bywebview_create
html
- the HTML content
-
webview_init
abstract Unit webview_init(Pointer webview, String js)
Injects JavaScript code at the initialization of the new page.
Every time the webview will open a new page - this initialization code will be executed. It is guaranteed that code is executed before
window.onload
.- Parameters:
webview
- the handle of webview, usually returned bywebview_create
js
- the JS code
-
webview_eval
abstract Unit webview_eval(Pointer webview, String js)
Evaluates arbitrary JavaScript code.
Evaluation happens asynchronously, also the result of the expression is ignored. Use the
webview_bind
function if you want to receive notifications about the results of the evaluation.- Parameters:
webview
- the handle of webview, usually returned bywebview_create
js
- the JS code
-
webview_bind
abstract Unit webview_bind(Pointer webview, String name, WebviewJNA.WebviewLibrary.webview_bind_fn_callback callback, Pointer arg)
Binds a native Kotlin/Java callback so that it will appear under the given name as a global JavaScript function.
Callback receives a request string. Request string is a JSON array of all the arguments passed to the JavaScript function. Internally it uses
webview_init
.- Parameters:
webview
- the handle of webview, usually returned bywebview_create
name
- the name of the global JavaScript functioncallback
- the Kotlin/Java callback function wrapper in an interface, usewebview_return
to response to the JS request.arg
- the context.
-
webview_unbind
abstract Unit webview_unbind(Pointer webview, String name)
Removes a Kotlin/Java callback that was previously set by
webview_bind
.- Parameters:
webview
- the handle of webview, usually returned bywebview_create
name
- the name of JS function used inwebview_bind
-
webview_return
abstract Unit webview_return(Pointer webview, String seq, Integer status, String result)
Allows to return a value from the Kotlin/Java binding.
Original request pointer must be provided to help internal RPC engine match requests with responses. It is similar to
webview::resolve
in C++ version.- Parameters:
webview
- the handle of webview, usually returned bywebview_create
seq
- the id of request to responsestatus
- If status is zero - result is expected to be a valid JSON result value.result
- the JSON result value to response
-
-
-
-