WebView

Constructors

this
this(bool dbg, void* window)

Creates a new webview instance. If dbg 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.

Members

Functions

bind
void bind(char* name, void function(const char*, void*) fn, void* arg)

Binds a native C callback so that it will appear under the given name as a global JavaScript function. Internally it uses webview_init(). Callback receives a request string and a user-provided argument pointer. Request string is a JSON array of all the arguments passed to the JavaScript function.

destroy
void destroy()

Destroys a webview and closes the native window.

eval
void eval(char* js)

Evaluates arbitrary JavaScript code. Evaluation happens asynchronously, also the result of the expression is ignored. Use RPC bindings if you want to receive notifications about the results of the evaluation.

getWindow
void* getWindow()

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.

init
void init(char* js)

Injects JavaScript code at the initialization of the new page. Every time the webview will open a the new page - this initialization code will be executed. It is guaranteed that code is executed before window.onload.

navigate
void navigate(char* url)

Navigates webview to the given URL. URL may be a data URI.

run
void run()

Runs the main loop until it's terminated. After this function exits - you must destroy the webview.

setTitle
void setTitle(char* title)

Updates the title of the native window. Must be called from the UI thread.

terminate
void terminate()

Stops the main loop. It is safe to call this function from another other background thread.

webview_return
void webview_return(char* req, int status, char* result)

Allows to return a value from the native binding. Original request pointer must be provided to help internal RPC engine match requests with responses. If status is zero - result is expected to be a valid JSON result value. If status is not zero - result is an error JSON object.

Meta