@crossbind/core-app-host 0.0.0-bootstrap.0 → 2.0.0-beta.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/README.md +55 -3
  2. package/android/app/src/main/AndroidManifest.xml +15 -0
  3. package/android/app/src/main/java/dev/crossbind/app/CrossbindActivity.java +366 -0
  4. package/android/app/src/main/res/xml/network_security_config.xml +8 -0
  5. package/android/build.gradle +14 -0
  6. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  7. package/android/gradle/wrapper/gradle-wrapper.properties +10 -0
  8. package/android/gradle.properties +2 -0
  9. package/android/gradlew +248 -0
  10. package/android/gradlew.bat +112 -0
  11. package/android/settings.gradle +14 -0
  12. package/cpp/CMakeLists.txt +110 -0
  13. package/cpp/src/android/jni.cpp +167 -0
  14. package/cpp/src/app.cpp +40 -0
  15. package/cpp/src/app.h +21 -0
  16. package/cpp/src/attach.cpp +40 -0
  17. package/cpp/src/darwin/bundle.mm +19 -0
  18. package/cpp/src/darwin/channels.mm +196 -0
  19. package/cpp/src/darwin/navigation.mm +69 -0
  20. package/cpp/src/host_core.cpp +335 -0
  21. package/cpp/src/host_core.h +84 -0
  22. package/cpp/src/ios/bundle.mm +15 -0
  23. package/cpp/src/ios/main.mm +71 -0
  24. package/cpp/src/linux/app.cpp +29 -0
  25. package/cpp/src/linux/channels.cpp +143 -0
  26. package/cpp/src/linux/main_thread.h +16 -0
  27. package/cpp/src/linux/navigation.cpp +55 -0
  28. package/cpp/src/main.cpp +57 -0
  29. package/cpp/src/platform.h +57 -0
  30. package/cpp/src/windows/app.cpp +36 -0
  31. package/cpp/src/windows/app.manifest +8 -0
  32. package/cpp/src/windows/app.rc +3 -0
  33. package/cpp/src/windows/channels.cpp +336 -0
  34. package/cpp/src/windows/com.cpp +92 -0
  35. package/cpp/src/windows/com.h +57 -0
  36. package/cpp/src/windows/navigation.cpp +90 -0
  37. package/js/codec.js +123 -0
  38. package/js/host.js +8 -0
  39. package/js/lean-client.js +147 -0
  40. package/js/lean-host.js +237 -0
  41. package/js/page.js +79 -0
  42. package/js/polyfills.js +32 -0
  43. package/package.json +30 -6
  44. package/third_party/jsi/LICENSE +21 -0
  45. package/third_party/jsi/README.md +18 -0
  46. package/third_party/jsi/include/jsi/hermes-interfaces.h +189 -0
  47. package/third_party/jsi/include/jsi/instrumentation.h +132 -0
  48. package/third_party/jsi/include/jsi/jsi-inl.h +434 -0
  49. package/third_party/jsi/include/jsi/jsi.h +2266 -0
  50. package/third_party/jsi/jsi.cpp +1110 -0
  51. package/third_party/webview/LICENSE +22 -0
  52. package/third_party/webview/README.md +24 -0
  53. package/third_party/webview/core/include/webview/api.h +251 -0
  54. package/third_party/webview/core/include/webview/backends.hh +40 -0
  55. package/third_party/webview/core/include/webview/c_api_impl.hh +258 -0
  56. package/third_party/webview/core/include/webview/detail/backends/cocoa_webkit.hh +633 -0
  57. package/third_party/webview/core/include/webview/detail/backends/gtk_webkitgtk.hh +355 -0
  58. package/third_party/webview/core/include/webview/detail/backends/win32_edge.hh +915 -0
  59. package/third_party/webview/core/include/webview/detail/basic_result.hh +119 -0
  60. package/third_party/webview/core/include/webview/detail/engine_base.hh +382 -0
  61. package/third_party/webview/core/include/webview/detail/exceptions.hh +42 -0
  62. package/third_party/webview/core/include/webview/detail/json.hh +337 -0
  63. package/third_party/webview/core/include/webview/detail/native_library.hh +176 -0
  64. package/third_party/webview/core/include/webview/detail/optional.hh +118 -0
  65. package/third_party/webview/core/include/webview/detail/platform/darwin/cocoa/NSApplication.hh +107 -0
  66. package/third_party/webview/core/include/webview/detail/platform/darwin/cocoa/NSBundle.hh +56 -0
  67. package/third_party/webview/core/include/webview/detail/platform/darwin/cocoa/NSEvent.hh +71 -0
  68. package/third_party/webview/core/include/webview/detail/platform/darwin/cocoa/NSInvocation.hh +66 -0
  69. package/third_party/webview/core/include/webview/detail/platform/darwin/cocoa/NSMethodSignature.hh +52 -0
  70. package/third_party/webview/core/include/webview/detail/platform/darwin/cocoa/NSNotification.hh +51 -0
  71. package/third_party/webview/core/include/webview/detail/platform/darwin/cocoa/NSNumber.hh +53 -0
  72. package/third_party/webview/core/include/webview/detail/platform/darwin/cocoa/NSObject.hh +51 -0
  73. package/third_party/webview/core/include/webview/detail/platform/darwin/cocoa/NSOpenPanel.hh +71 -0
  74. package/third_party/webview/core/include/webview/detail/platform/darwin/cocoa/NSPoint.hh +53 -0
  75. package/third_party/webview/core/include/webview/detail/platform/darwin/cocoa/NSRect.hh +53 -0
  76. package/third_party/webview/core/include/webview/detail/platform/darwin/cocoa/NSSavePanel.hh +52 -0
  77. package/third_party/webview/core/include/webview/detail/platform/darwin/cocoa/NSSize.hh +53 -0
  78. package/third_party/webview/core/include/webview/detail/platform/darwin/cocoa/NSString.hh +87 -0
  79. package/third_party/webview/core/include/webview/detail/platform/darwin/cocoa/NSURL.hh +63 -0
  80. package/third_party/webview/core/include/webview/detail/platform/darwin/cocoa/NSURLRequest.hh +52 -0
  81. package/third_party/webview/core/include/webview/detail/platform/darwin/cocoa/NSValue.hh +56 -0
  82. package/third_party/webview/core/include/webview/detail/platform/darwin/cocoa/NSView.hh +91 -0
  83. package/third_party/webview/core/include/webview/detail/platform/darwin/cocoa/NSWindow.hh +137 -0
  84. package/third_party/webview/core/include/webview/detail/platform/darwin/cocoa/cocoa.hh +59 -0
  85. package/third_party/webview/core/include/webview/detail/platform/darwin/cocoa/types.hh +49 -0
  86. package/third_party/webview/core/include/webview/detail/platform/darwin/objc/Class.hh +55 -0
  87. package/third_party/webview/core/include/webview/detail/platform/darwin/objc/autoreleasepool.hh +70 -0
  88. package/third_party/webview/core/include/webview/detail/platform/darwin/objc/invoke.hh +75 -0
  89. package/third_party/webview/core/include/webview/detail/platform/darwin/objc/memory.hh +57 -0
  90. package/third_party/webview/core/include/webview/detail/platform/darwin/objc/objc.hh +47 -0
  91. package/third_party/webview/core/include/webview/detail/platform/darwin/webkit/WKOpenPanelParameters.hh +57 -0
  92. package/third_party/webview/core/include/webview/detail/platform/darwin/webkit/WKScriptMessage.hh +51 -0
  93. package/third_party/webview/core/include/webview/detail/platform/darwin/webkit/WKUserContentController.hh +61 -0
  94. package/third_party/webview/core/include/webview/detail/platform/darwin/webkit/WKUserScript.hh +71 -0
  95. package/third_party/webview/core/include/webview/detail/platform/darwin/webkit/WKWebView.hh +108 -0
  96. package/third_party/webview/core/include/webview/detail/platform/darwin/webkit/WKWebViewConfiguration.hh +60 -0
  97. package/third_party/webview/core/include/webview/detail/platform/darwin/webkit/webkit.hh +46 -0
  98. package/third_party/webview/core/include/webview/detail/platform/linux/gtk/compat.hh +137 -0
  99. package/third_party/webview/core/include/webview/detail/platform/linux/webkitgtk/compat.hh +142 -0
  100. package/third_party/webview/core/include/webview/detail/platform/linux/webkitgtk/dmabuf.hh +167 -0
  101. package/third_party/webview/core/include/webview/detail/platform/windows/com_init_wrapper.hh +126 -0
  102. package/third_party/webview/core/include/webview/detail/platform/windows/dpi.hh +161 -0
  103. package/third_party/webview/core/include/webview/detail/platform/windows/dwmapi.hh +67 -0
  104. package/third_party/webview/core/include/webview/detail/platform/windows/iid.hh +78 -0
  105. package/third_party/webview/core/include/webview/detail/platform/windows/ntdll.hh +58 -0
  106. package/third_party/webview/core/include/webview/detail/platform/windows/reg_key.hh +135 -0
  107. package/third_party/webview/core/include/webview/detail/platform/windows/shcore.hh +59 -0
  108. package/third_party/webview/core/include/webview/detail/platform/windows/theme.hh +76 -0
  109. package/third_party/webview/core/include/webview/detail/platform/windows/user32.hh +90 -0
  110. package/third_party/webview/core/include/webview/detail/platform/windows/version.hh +151 -0
  111. package/third_party/webview/core/include/webview/detail/platform/windows/webview2/loader.hh +391 -0
  112. package/third_party/webview/core/include/webview/detail/user_script.hh +76 -0
  113. package/third_party/webview/core/include/webview/detail/utility/string.hh +99 -0
  114. package/third_party/webview/core/include/webview/errors.h +67 -0
  115. package/third_party/webview/core/include/webview/errors.hh +85 -0
  116. package/third_party/webview/core/include/webview/json_deprecated.hh +61 -0
  117. package/third_party/webview/core/include/webview/macros.h +123 -0
  118. package/third_party/webview/core/include/webview/types.h +81 -0
  119. package/third_party/webview/core/include/webview/types.hh +48 -0
  120. package/third_party/webview/core/include/webview/version.h +67 -0
  121. package/third_party/webview/core/include/webview/webview.h +32 -0
  122. package/third_party/webview/core/include/webview.h +15 -0
  123. package/third_party/webview2/LICENSE +27 -0
  124. package/third_party/webview2/README.md +13 -0
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Serge Zaitsev
4
+ Copyright (c) 2022 Steffen André Langnes
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1,24 @@
1
+ # webview (vendored)
2
+
3
+ A header-only C++ library that opens a window with the system webview: WKWebView on macOS, WebKitGTK on Linux and
4
+ WebView2 on Windows. The app host makes its window with it.
5
+
6
+ - Upstream: https://github.com/webview/webview
7
+ - Commit: `cbbdee44afff22867de9fd88a9fc8350d9bdd399` (master on 9 March 2026; the last tag, 0.12.0, dates from 2024)
8
+ - Archive: `https://codeload.github.com/webview/webview/tar.gz/cbbdee44afff22867de9fd88a9fc8350d9bdd399`,
9
+ sha256 `10e972a2327b5681474f4aa4499e505eaa4ff659aa995380386f08fd6fc1b763`
10
+ - License: MIT, see `LICENSE`
11
+
12
+ Only `core/include` is kept.
13
+
14
+ ## Local patches
15
+
16
+ - `detail/backends/cocoa_webkit.hh` calls `cocoa_configure_hook`, when one is set, with the `WKWebViewConfiguration`
17
+ before the `WKWebView` is made from it. A URL scheme handler can be registered only then, and the host serves the
18
+ page and large bodies from `crossbind://`. Upstream tracks this as issue #851; PRs #955 (WebKitGTK only) and #1370
19
+ are open.
20
+ - `detail/backends/win32_edge.hh` makes WebView2's environment with the options `win32_environment_options_hook`
21
+ returns, when one is set, instead of none: WebView2 takes custom URL schemes from those options alone.
22
+ - `detail/native_library.hh` loads a library named without a path from System32 alone. webview first tries
23
+ `WebView2Loader.dll`, which no crossbind app ships, so otherwise a copy in the working directory or on `PATH` would
24
+ load into the app.
@@ -0,0 +1,251 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2017 Serge Zaitsev
5
+ * Copyright (c) 2022 Steffen André Langnes
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ #ifndef WEBVIEW_API_H
27
+ #define WEBVIEW_API_H
28
+
29
+ #include "errors.h"
30
+ #include "macros.h"
31
+ #include "types.h"
32
+
33
+ #ifdef __cplusplus
34
+ extern "C" {
35
+ #endif
36
+
37
+ /**
38
+ * Creates a new webview instance.
39
+ *
40
+ * @param debug Enable developer tools if supported by the backend.
41
+ * @param window Optional native window handle, i.e. @c GtkWindow pointer
42
+ * @c NSWindow pointer (Cocoa) or @c HWND (Win32). If non-null,
43
+ * the webview widget is embedded into the given window, and the
44
+ * caller is expected to assume responsibility for the window as
45
+ * well as application lifecycle. If the window handle is null,
46
+ * a new window is created and both the window and application
47
+ * lifecycle are managed by the webview instance.
48
+ * @remark Win32: The function also accepts a pointer to @c HWND (Win32) in the
49
+ * window parameter for backward compatibility.
50
+ * @remark Win32/WebView2: @c CoInitializeEx should be called with
51
+ * @c COINIT_APARTMENTTHREADED before attempting to call this function
52
+ * with an existing window. Omitting this step may cause WebView2
53
+ * initialization to fail.
54
+ * @return @c NULL on failure. Creation can fail for various reasons such
55
+ * as when required runtime dependencies are missing or when window
56
+ * creation fails.
57
+ * @retval WEBVIEW_ERROR_MISSING_DEPENDENCY
58
+ * May be returned if WebView2 is unavailable on Windows.
59
+ */
60
+ WEBVIEW_API webview_t webview_create(int debug, void *window);
61
+
62
+ /**
63
+ * Destroys a webview instance and closes the native window.
64
+ *
65
+ * @param w The webview instance.
66
+ */
67
+ WEBVIEW_API webview_error_t webview_destroy(webview_t w);
68
+
69
+ /**
70
+ * Runs the main loop until it's terminated.
71
+ *
72
+ * @param w The webview instance.
73
+ */
74
+ WEBVIEW_API webview_error_t webview_run(webview_t w);
75
+
76
+ /**
77
+ * Stops the main loop. It is safe to call this function from another
78
+ * background thread.
79
+ *
80
+ * @param w The webview instance.
81
+ */
82
+ WEBVIEW_API webview_error_t webview_terminate(webview_t w);
83
+
84
+ /**
85
+ * Schedules a function to be invoked on the thread with the run/event loop.
86
+ *
87
+ * Since library functions generally do not have thread safety guarantees,
88
+ * this function can be used to schedule code to execute on the main/GUI
89
+ * thread and thereby make that execution safe in multi-threaded applications.
90
+ *
91
+ * @param w The webview instance.
92
+ * @param fn The function to be invoked.
93
+ * @param arg An optional argument passed along to the callback function.
94
+ */
95
+ WEBVIEW_API webview_error_t webview_dispatch(webview_t w,
96
+ void (*fn)(webview_t w, void *arg),
97
+ void *arg);
98
+
99
+ /**
100
+ * Returns the native handle of the window associated with the webview instance.
101
+ * The handle can be a @c GtkWindow pointer (GTK), @c NSWindow pointer (Cocoa)
102
+ * or @c HWND (Win32).
103
+ *
104
+ * @param w The webview instance.
105
+ * @return The handle of the native window.
106
+ */
107
+ WEBVIEW_API void *webview_get_window(webview_t w);
108
+
109
+ /**
110
+ * Get a native handle of choice.
111
+ *
112
+ * @param w The webview instance.
113
+ * @param kind The kind of handle to retrieve.
114
+ * @return The native handle or @c NULL.
115
+ * @since 0.11
116
+ */
117
+ WEBVIEW_API void *webview_get_native_handle(webview_t w,
118
+ webview_native_handle_kind_t kind);
119
+
120
+ /**
121
+ * Updates the title of the native window.
122
+ *
123
+ * @param w The webview instance.
124
+ * @param title The new title.
125
+ */
126
+ WEBVIEW_API webview_error_t webview_set_title(webview_t w, const char *title);
127
+
128
+ /**
129
+ * Updates the size of the native window.
130
+ *
131
+ * Remarks:
132
+ * - Subsequent calls to this function may behave inconsistently across
133
+ * different versions of GTK and windowing systems (X11/Wayland).
134
+ * - Using WEBVIEW_HINT_MAX for setting the maximum window size is not
135
+ * supported with GTK 4 because X11-specific functions such as
136
+ * gtk_window_set_geometry_hints were removed. This option has no effect
137
+ * when using GTK 4.
138
+ *
139
+ * @param w The webview instance.
140
+ * @param width New width.
141
+ * @param height New height.
142
+ * @param hints Size hints.
143
+ */
144
+ WEBVIEW_API webview_error_t webview_set_size(webview_t w, int width, int height,
145
+ webview_hint_t hints);
146
+
147
+ /**
148
+ * Navigates webview to the given URL. URL may be a properly encoded data URI.
149
+ *
150
+ * Example:
151
+ * @code{.c}
152
+ * webview_navigate(w, "https://github.com/webview/webview");
153
+ * webview_navigate(w, "data:text/html,%3Ch1%3EHello%3C%2Fh1%3E");
154
+ * webview_navigate(w, "data:text/html;base64,PGgxPkhlbGxvPC9oMT4=");
155
+ * @endcode
156
+ *
157
+ * @param w The webview instance.
158
+ * @param url URL.
159
+ */
160
+ WEBVIEW_API webview_error_t webview_navigate(webview_t w, const char *url);
161
+
162
+ /**
163
+ * Load HTML content into the webview.
164
+ *
165
+ * Example:
166
+ * @code{.c}
167
+ * webview_set_html(w, "<h1>Hello</h1>");
168
+ * @endcode
169
+ *
170
+ * @param w The webview instance.
171
+ * @param html HTML content.
172
+ */
173
+ WEBVIEW_API webview_error_t webview_set_html(webview_t w, const char *html);
174
+
175
+ /**
176
+ * Injects JavaScript code to be executed immediately upon loading a page.
177
+ * The code will be executed before @c window.onload.
178
+ *
179
+ * @param w The webview instance.
180
+ * @param js JS content.
181
+ */
182
+ WEBVIEW_API webview_error_t webview_init(webview_t w, const char *js);
183
+
184
+ /**
185
+ * Evaluates arbitrary JavaScript code.
186
+ *
187
+ * Use bindings if you need to communicate the result of the evaluation.
188
+ *
189
+ * @param w The webview instance.
190
+ * @param js JS content.
191
+ */
192
+ WEBVIEW_API webview_error_t webview_eval(webview_t w, const char *js);
193
+
194
+ /**
195
+ * Binds a function pointer to a new global JavaScript function.
196
+ *
197
+ * Internally, JS glue code is injected to create the JS function by the
198
+ * given name. The callback function is passed a request identifier,
199
+ * a request string and a user-provided argument. The request string is
200
+ * a JSON array of the arguments passed to the JS function.
201
+ *
202
+ * @param w The webview instance.
203
+ * @param name Name of the JS function.
204
+ * @param fn Callback function.
205
+ * @param arg User argument.
206
+ * @retval WEBVIEW_ERROR_DUPLICATE
207
+ * A binding already exists with the specified name.
208
+ */
209
+ WEBVIEW_API webview_error_t webview_bind(webview_t w, const char *name,
210
+ void (*fn)(const char *id,
211
+ const char *req, void *arg),
212
+ void *arg);
213
+
214
+ /**
215
+ * Removes a binding created with webview_bind().
216
+ *
217
+ * @param w The webview instance.
218
+ * @param name Name of the binding.
219
+ * @retval WEBVIEW_ERROR_NOT_FOUND No binding exists with the specified name.
220
+ */
221
+ WEBVIEW_API webview_error_t webview_unbind(webview_t w, const char *name);
222
+
223
+ /**
224
+ * Responds to a binding call from the JS side.
225
+ *
226
+ * This function is safe to call from another thread.
227
+ *
228
+ * @param w The webview instance.
229
+ * @param id The identifier of the binding call. Pass along the value received
230
+ * in the binding handler (see webview_bind()).
231
+ * @param status A status of zero tells the JS side that the binding call was
232
+ * successful; any other value indicates an error.
233
+ * @param result The result of the binding call to be returned to the JS side.
234
+ * This must either be a valid JSON value or an empty string for
235
+ * the primitive JS value @c undefined.
236
+ */
237
+ WEBVIEW_API webview_error_t webview_return(webview_t w, const char *id,
238
+ int status, const char *result);
239
+
240
+ /**
241
+ * Get the library's version information.
242
+ *
243
+ * @since 0.10
244
+ */
245
+ WEBVIEW_API const webview_version_info_t *webview_version(void);
246
+
247
+ #ifdef __cplusplus
248
+ }
249
+ #endif
250
+
251
+ #endif // WEBVIEW_API_H
@@ -0,0 +1,40 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2017 Serge Zaitsev
5
+ * Copyright (c) 2022 Steffen André Langnes
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ #ifndef WEBVIEW_BACKENDS_HH
27
+ #define WEBVIEW_BACKENDS_HH
28
+
29
+ #if defined(__cplusplus) && !defined(WEBVIEW_HEADER)
30
+
31
+ #include "detail/backends/cocoa_webkit.hh"
32
+ #include "detail/backends/gtk_webkitgtk.hh"
33
+ #include "detail/backends/win32_edge.hh"
34
+
35
+ namespace webview {
36
+ using webview = browser_engine;
37
+ }
38
+
39
+ #endif // defined(__cplusplus) && !defined(WEBVIEW_HEADER)
40
+ #endif // WEBVIEW_BACKENDS_HH
@@ -0,0 +1,258 @@
1
+ /*
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2017 Serge Zaitsev
5
+ * Copyright (c) 2022 Steffen André Langnes
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in
15
+ * all copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ #ifndef WEBVIEW_C_API_IMPL_HH
27
+ #define WEBVIEW_C_API_IMPL_HH
28
+
29
+ #if defined(__cplusplus) && !defined(WEBVIEW_HEADER)
30
+
31
+ #include "backends.hh"
32
+ #include "errors.h"
33
+ #include "errors.hh"
34
+ #include "json_deprecated.hh"
35
+ #include "macros.h"
36
+ #include "types.h"
37
+ #include "version.h"
38
+
39
+ namespace webview {
40
+ namespace detail {
41
+
42
+ // The library's version information.
43
+ constexpr const webview_version_info_t library_version_info{
44
+ {WEBVIEW_VERSION_MAJOR, WEBVIEW_VERSION_MINOR, WEBVIEW_VERSION_PATCH},
45
+ WEBVIEW_VERSION_NUMBER,
46
+ WEBVIEW_VERSION_PRE_RELEASE,
47
+ WEBVIEW_VERSION_BUILD_METADATA};
48
+
49
+ template <typename WorkFn, typename ResultFn>
50
+ webview_error_t api_filter(WorkFn &&do_work, ResultFn &&put_result) noexcept {
51
+ try {
52
+ auto result = do_work();
53
+ if (result.ok()) {
54
+ put_result(result.value());
55
+ return WEBVIEW_ERROR_OK;
56
+ }
57
+ return result.error().code();
58
+ } catch (const exception &e) {
59
+ return e.error().code();
60
+ } catch (...) {
61
+ return WEBVIEW_ERROR_UNSPECIFIED;
62
+ }
63
+ }
64
+
65
+ template <typename WorkFn>
66
+ webview_error_t api_filter(WorkFn &&do_work) noexcept {
67
+ try {
68
+ auto result = do_work();
69
+ if (result.ok()) {
70
+ return WEBVIEW_ERROR_OK;
71
+ }
72
+ return result.error().code();
73
+ } catch (const exception &e) {
74
+ return e.error().code();
75
+ } catch (...) {
76
+ return WEBVIEW_ERROR_UNSPECIFIED;
77
+ }
78
+ }
79
+
80
+ inline webview *cast_to_webview(void *w) {
81
+ if (!w) {
82
+ throw exception{WEBVIEW_ERROR_INVALID_ARGUMENT,
83
+ "Cannot cast null pointer to webview instance"};
84
+ }
85
+ return static_cast<webview *>(w);
86
+ }
87
+
88
+ } // namespace detail
89
+ } // namespace webview
90
+
91
+ WEBVIEW_API webview_t webview_create(int debug, void *wnd) {
92
+ using namespace webview::detail;
93
+ webview::webview *w{};
94
+ auto err = api_filter(
95
+ [=]() -> webview::result<webview::webview *> {
96
+ return new webview::webview{static_cast<bool>(debug), wnd};
97
+ },
98
+ [&](webview::webview *w_) { w = w_; });
99
+ if (err == WEBVIEW_ERROR_OK) {
100
+ return w;
101
+ }
102
+ return nullptr;
103
+ }
104
+
105
+ WEBVIEW_API webview_error_t webview_destroy(webview_t w) {
106
+ using namespace webview::detail;
107
+ return api_filter([=]() -> webview::noresult {
108
+ delete cast_to_webview(w);
109
+ return {};
110
+ });
111
+ }
112
+
113
+ WEBVIEW_API webview_error_t webview_run(webview_t w) {
114
+ using namespace webview::detail;
115
+ return api_filter([=] { return cast_to_webview(w)->run(); });
116
+ }
117
+
118
+ WEBVIEW_API webview_error_t webview_terminate(webview_t w) {
119
+ using namespace webview::detail;
120
+ return api_filter([=] { return cast_to_webview(w)->terminate(); });
121
+ }
122
+
123
+ WEBVIEW_API webview_error_t webview_dispatch(webview_t w,
124
+ void (*fn)(webview_t, void *),
125
+ void *arg) {
126
+ using namespace webview::detail;
127
+ if (!fn) {
128
+ return WEBVIEW_ERROR_INVALID_ARGUMENT;
129
+ }
130
+ return api_filter(
131
+ [=] { return cast_to_webview(w)->dispatch([=]() { fn(w, arg); }); });
132
+ }
133
+
134
+ WEBVIEW_API void *webview_get_window(webview_t w) {
135
+ using namespace webview::detail;
136
+ void *window = nullptr;
137
+ auto err = api_filter([=] { return cast_to_webview(w)->window(); },
138
+ [&](void *value) { window = value; });
139
+ if (err == WEBVIEW_ERROR_OK) {
140
+ return window;
141
+ }
142
+ return nullptr;
143
+ }
144
+
145
+ WEBVIEW_API void *webview_get_native_handle(webview_t w,
146
+ webview_native_handle_kind_t kind) {
147
+ using namespace webview::detail;
148
+ void *handle{};
149
+ auto err = api_filter(
150
+ [=]() -> webview::result<void *> {
151
+ auto *w_ = cast_to_webview(w);
152
+ switch (kind) {
153
+ case WEBVIEW_NATIVE_HANDLE_KIND_UI_WINDOW:
154
+ return w_->window();
155
+ case WEBVIEW_NATIVE_HANDLE_KIND_UI_WIDGET:
156
+ return w_->widget();
157
+ case WEBVIEW_NATIVE_HANDLE_KIND_BROWSER_CONTROLLER:
158
+ return w_->browser_controller();
159
+ default:
160
+ return webview::error_info{WEBVIEW_ERROR_INVALID_ARGUMENT};
161
+ }
162
+ },
163
+ [&](void *handle_) { handle = handle_; });
164
+ if (err == WEBVIEW_ERROR_OK) {
165
+ return handle;
166
+ }
167
+ return nullptr;
168
+ }
169
+
170
+ WEBVIEW_API webview_error_t webview_set_title(webview_t w, const char *title) {
171
+ using namespace webview::detail;
172
+ if (!title) {
173
+ return WEBVIEW_ERROR_INVALID_ARGUMENT;
174
+ }
175
+ return api_filter([=] { return cast_to_webview(w)->set_title(title); });
176
+ }
177
+
178
+ WEBVIEW_API webview_error_t webview_set_size(webview_t w, int width, int height,
179
+ webview_hint_t hints) {
180
+ using namespace webview::detail;
181
+ return api_filter(
182
+ [=] { return cast_to_webview(w)->set_size(width, height, hints); });
183
+ }
184
+
185
+ WEBVIEW_API webview_error_t webview_navigate(webview_t w, const char *url) {
186
+ using namespace webview::detail;
187
+ if (!url) {
188
+ return WEBVIEW_ERROR_INVALID_ARGUMENT;
189
+ }
190
+ return api_filter([=] { return cast_to_webview(w)->navigate(url); });
191
+ }
192
+
193
+ WEBVIEW_API webview_error_t webview_set_html(webview_t w, const char *html) {
194
+ using namespace webview::detail;
195
+ if (!html) {
196
+ return WEBVIEW_ERROR_INVALID_ARGUMENT;
197
+ }
198
+ return api_filter([=] { return cast_to_webview(w)->set_html(html); });
199
+ }
200
+
201
+ WEBVIEW_API webview_error_t webview_init(webview_t w, const char *js) {
202
+ using namespace webview::detail;
203
+ if (!js) {
204
+ return WEBVIEW_ERROR_INVALID_ARGUMENT;
205
+ }
206
+ return api_filter([=] { return cast_to_webview(w)->init(js); });
207
+ }
208
+
209
+ WEBVIEW_API webview_error_t webview_eval(webview_t w, const char *js) {
210
+ using namespace webview::detail;
211
+ if (!js) {
212
+ return WEBVIEW_ERROR_INVALID_ARGUMENT;
213
+ }
214
+ return api_filter([=] { return cast_to_webview(w)->eval(js); });
215
+ }
216
+
217
+ WEBVIEW_API webview_error_t webview_bind(webview_t w, const char *name,
218
+ void (*fn)(const char *id,
219
+ const char *req, void *arg),
220
+ void *arg) {
221
+ using namespace webview::detail;
222
+ if (!name || !fn) {
223
+ return WEBVIEW_ERROR_INVALID_ARGUMENT;
224
+ }
225
+ return api_filter([=] {
226
+ return cast_to_webview(w)->bind(
227
+ name,
228
+ [=](const std::string &seq, const std::string &req, void *arg_) {
229
+ fn(seq.c_str(), req.c_str(), arg_);
230
+ },
231
+ arg);
232
+ });
233
+ }
234
+
235
+ WEBVIEW_API webview_error_t webview_unbind(webview_t w, const char *name) {
236
+ using namespace webview::detail;
237
+ if (!name) {
238
+ return WEBVIEW_ERROR_INVALID_ARGUMENT;
239
+ }
240
+ return api_filter([=] { return cast_to_webview(w)->unbind(name); });
241
+ }
242
+
243
+ WEBVIEW_API webview_error_t webview_return(webview_t w, const char *id,
244
+ int status, const char *result) {
245
+ using namespace webview::detail;
246
+ if (!id || !result) {
247
+ return WEBVIEW_ERROR_INVALID_ARGUMENT;
248
+ }
249
+ return api_filter(
250
+ [=] { return cast_to_webview(w)->resolve(id, status, result); });
251
+ }
252
+
253
+ WEBVIEW_API const webview_version_info_t *webview_version(void) {
254
+ return &webview::detail::library_version_info;
255
+ }
256
+
257
+ #endif // defined(__cplusplus) && !defined(WEBVIEW_HEADER)
258
+ #endif // WEBVIEW_C_API_IMPL_HH