-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebview.c3i
135 lines (108 loc) · 5.86 KB
/
webview.c3i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
* Copyright (c) 2023 XXIV
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
module webview;
// Documentation copied from https://github.com/webview/webview/blob/master/webview.h
const int VERSION_MAJOR = 0;
const int VERSION_MINOR = 11;
const int VERSION_PATCH = 0;
const char* VERSION_NUMBER = "0.11.0";
// Holds the elements of a MAJOR.MINOR.PATCH version number.
struct WebViewVersion {
uint major;
uint minor;
uint patch;
}
// Holds the library's version information.
struct WebviewVersionInfo {
WebViewVersion version;
char[32] version_number;
char[48] pre_release;
char[48] build_metadata;
}
// Window size hints
enum WindowSizeHint : int {
NONE, // Width and height are default size
MIN, // Width and height are minimum bounds
MAX, // Width and height are maximum bounds
FIXED // Window size can not be changed by a user
}
struct WebView {
void* webview;
}
def DispatchCallback = fn void(WebView w, void* arg);
def BindCallback = fn void(char* seq, char* req, void* arg);
// Creates a new webview instance. If debug is non-zero - developer tools will
// be enabled (if the platform supports them). The 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. Returns null on failure. Creation can fail for various reasons
// such as when required runtime dependencies are missing or when window creation
// fails.
fn WebView create(int debug, void *window = null) @extern("webview_create");
// Destroys a webview and closes the native window.
fn void WebView.destroy(WebView w) @extern("webview_destroy");
// Runs the main loop until it's terminated. After this function exits - you
// must destroy the webview.
fn void WebView.run(WebView w) @extern("webview_run");
// Stops the main loop. It is safe to call this function from another other
// background thread.
fn void WebView.terminate(WebView w) @extern("webview_terminate");
// Posts a function to be executed on the main thread. You normally do not need
// to call this function, unless you want to tweak the native window.
fn void WebView.dispatch(WebView w, DispatchCallback f, void *arg) @extern("webview_dispatch");
// Returns a native window handle pointer. When using a GTK backend the pointer
// is a GtkWindow pointer, when using a Cocoa backend the pointer is a NSWindow
// pointer, when using a Win32 backend the pointer is a HWND pointer.
fn void* WebView.getWindow(WebView w) @extern("webview_get_window");
// Updates the title of the native window. Must be called from the UI thread.
fn void WebView.setTitle(WebView w, char *title) @extern("webview_set_title");
// Updates the size of the native window.
fn void WebView.setSize(WebView w, int width, int height, WindowSizeHint hints) @extern("webview_set_size");
// Navigates webview to the given URL. URL may be a properly encoded data URI.
fn void WebView.navigate(WebView w, char *url) @extern("webview_navigate");
// Set webview HTML directly.
fn void WebView.setHtml(WebView w, char *html) @extern("webview_set_html");
// 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.
fn void WebView.init(WebView w, char *js) @extern("webview_init");
// 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.
fn void WebView.eval(WebView w, char *js) @extern("webview_eval");
// Binds a native C callback so that it will appear under the given name as a
// global JavaScript function. Internally it uses webview_init(). The callback
// receives a sequential request id, a request string and a user-provided
// argument pointer. The request string is a JSON array of all the arguments
// passed to the JavaScript function.
fn void WebView.bind(WebView w, char *name, BindCallback f, void *arg) @extern("webview_bind");
// Removes a native C callback that was previously set by webview_bind.
fn void WebView.unbind(WebView w, char *name) @extern("webview_unbind");
// Responds to a binding call from the JS side. The ID/sequence number must
// match the value passed to the binding handler in order to respond to the
// call and complete the promise on the JS side. A status of zero resolves
// the promise, and any other value rejects it. The result must either be a
// valid JSON value or an empty string for the primitive JS value "undefined".
fn void WebView.ret(WebView w, char* seq, int status, char* result) @extern("webview_return");
// Get the library's version information.
fn WebviewVersionInfo* version() @extern("webview_version");