janela 0.1.0

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 (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +95 -0
  3. package/bin/janela.mjs +271 -0
  4. package/package.json +43 -0
  5. package/runtime/janela.ts +193 -0
  6. package/shim/wvshim.cc +201 -0
  7. package/templates/index.html +48 -0
  8. package/templates/janela.conf.json +10 -0
  9. package/templates/main.ts +37 -0
  10. package/vendor-webview/LICENSE +22 -0
  11. package/vendor-webview/core/include/webview/api.h +251 -0
  12. package/vendor-webview/core/include/webview/backends.hh +40 -0
  13. package/vendor-webview/core/include/webview/c_api_impl.hh +258 -0
  14. package/vendor-webview/core/include/webview/detail/backends/cocoa_webkit.hh +626 -0
  15. package/vendor-webview/core/include/webview/detail/backends/gtk_webkitgtk.hh +355 -0
  16. package/vendor-webview/core/include/webview/detail/backends/win32_edge.hh +909 -0
  17. package/vendor-webview/core/include/webview/detail/basic_result.hh +119 -0
  18. package/vendor-webview/core/include/webview/detail/engine_base.hh +382 -0
  19. package/vendor-webview/core/include/webview/detail/exceptions.hh +42 -0
  20. package/vendor-webview/core/include/webview/detail/json.hh +337 -0
  21. package/vendor-webview/core/include/webview/detail/native_library.hh +170 -0
  22. package/vendor-webview/core/include/webview/detail/optional.hh +118 -0
  23. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSApplication.hh +107 -0
  24. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSBundle.hh +56 -0
  25. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSEvent.hh +71 -0
  26. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSInvocation.hh +66 -0
  27. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSMethodSignature.hh +52 -0
  28. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSNotification.hh +51 -0
  29. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSNumber.hh +53 -0
  30. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSObject.hh +51 -0
  31. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSOpenPanel.hh +71 -0
  32. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSPoint.hh +53 -0
  33. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSRect.hh +53 -0
  34. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSSavePanel.hh +52 -0
  35. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSSize.hh +53 -0
  36. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSString.hh +87 -0
  37. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSURL.hh +63 -0
  38. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSURLRequest.hh +52 -0
  39. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSValue.hh +56 -0
  40. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSView.hh +91 -0
  41. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/NSWindow.hh +137 -0
  42. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/cocoa.hh +59 -0
  43. package/vendor-webview/core/include/webview/detail/platform/darwin/cocoa/types.hh +49 -0
  44. package/vendor-webview/core/include/webview/detail/platform/darwin/objc/Class.hh +55 -0
  45. package/vendor-webview/core/include/webview/detail/platform/darwin/objc/autoreleasepool.hh +70 -0
  46. package/vendor-webview/core/include/webview/detail/platform/darwin/objc/invoke.hh +75 -0
  47. package/vendor-webview/core/include/webview/detail/platform/darwin/objc/memory.hh +57 -0
  48. package/vendor-webview/core/include/webview/detail/platform/darwin/objc/objc.hh +47 -0
  49. package/vendor-webview/core/include/webview/detail/platform/darwin/webkit/WKOpenPanelParameters.hh +57 -0
  50. package/vendor-webview/core/include/webview/detail/platform/darwin/webkit/WKScriptMessage.hh +51 -0
  51. package/vendor-webview/core/include/webview/detail/platform/darwin/webkit/WKUserContentController.hh +61 -0
  52. package/vendor-webview/core/include/webview/detail/platform/darwin/webkit/WKUserScript.hh +71 -0
  53. package/vendor-webview/core/include/webview/detail/platform/darwin/webkit/WKWebView.hh +108 -0
  54. package/vendor-webview/core/include/webview/detail/platform/darwin/webkit/WKWebViewConfiguration.hh +60 -0
  55. package/vendor-webview/core/include/webview/detail/platform/darwin/webkit/webkit.hh +46 -0
  56. package/vendor-webview/core/include/webview/detail/platform/linux/gtk/compat.hh +137 -0
  57. package/vendor-webview/core/include/webview/detail/platform/linux/webkitgtk/compat.hh +142 -0
  58. package/vendor-webview/core/include/webview/detail/platform/linux/webkitgtk/dmabuf.hh +167 -0
  59. package/vendor-webview/core/include/webview/detail/platform/windows/com_init_wrapper.hh +126 -0
  60. package/vendor-webview/core/include/webview/detail/platform/windows/dpi.hh +161 -0
  61. package/vendor-webview/core/include/webview/detail/platform/windows/dwmapi.hh +67 -0
  62. package/vendor-webview/core/include/webview/detail/platform/windows/iid.hh +78 -0
  63. package/vendor-webview/core/include/webview/detail/platform/windows/ntdll.hh +58 -0
  64. package/vendor-webview/core/include/webview/detail/platform/windows/reg_key.hh +135 -0
  65. package/vendor-webview/core/include/webview/detail/platform/windows/shcore.hh +59 -0
  66. package/vendor-webview/core/include/webview/detail/platform/windows/theme.hh +76 -0
  67. package/vendor-webview/core/include/webview/detail/platform/windows/user32.hh +90 -0
  68. package/vendor-webview/core/include/webview/detail/platform/windows/version.hh +151 -0
  69. package/vendor-webview/core/include/webview/detail/platform/windows/webview2/loader.hh +391 -0
  70. package/vendor-webview/core/include/webview/detail/user_script.hh +76 -0
  71. package/vendor-webview/core/include/webview/detail/utility/string.hh +99 -0
  72. package/vendor-webview/core/include/webview/errors.h +67 -0
  73. package/vendor-webview/core/include/webview/errors.hh +85 -0
  74. package/vendor-webview/core/include/webview/json_deprecated.hh +61 -0
  75. package/vendor-webview/core/include/webview/macros.h +123 -0
  76. package/vendor-webview/core/include/webview/types.h +81 -0
  77. package/vendor-webview/core/include/webview/types.hh +48 -0
  78. package/vendor-webview/core/include/webview/version.h +67 -0
  79. package/vendor-webview/core/include/webview/webview.h +32 -0
  80. package/vendor-webview/core/include/webview.h +15 -0
@@ -0,0 +1,391 @@
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_WEBVIEW2_LOADER_HH
27
+ #define WEBVIEW_BACKENDS_WEBVIEW2_LOADER_HH
28
+
29
+ #if defined(__cplusplus) && !defined(WEBVIEW_HEADER)
30
+
31
+ #include "../../../../macros.h"
32
+
33
+ #if defined(WEBVIEW_PLATFORM_WINDOWS) && defined(WEBVIEW_EDGE)
34
+
35
+ #include "../../../native_library.hh"
36
+ #include "../iid.hh"
37
+ #include "../reg_key.hh"
38
+ #include "../version.hh"
39
+
40
+ #include <string>
41
+
42
+ #ifndef WIN32_LEAN_AND_MEAN
43
+ #define WIN32_LEAN_AND_MEAN
44
+ #endif
45
+
46
+ #include <windows.h>
47
+
48
+ #include <objbase.h>
49
+
50
+ #include "WebView2.h" // amalgamate(skip)
51
+
52
+ #ifdef _MSC_VER
53
+ #pragma comment(lib, "ole32.lib")
54
+ #endif
55
+
56
+ namespace webview {
57
+ namespace detail {
58
+
59
+ // Enable built-in WebView2Loader implementation by default.
60
+ #ifndef WEBVIEW_MSWEBVIEW2_BUILTIN_IMPL
61
+ #define WEBVIEW_MSWEBVIEW2_BUILTIN_IMPL 1
62
+ #endif
63
+
64
+ // Link WebView2Loader.dll explicitly by default only if the built-in
65
+ // implementation is enabled.
66
+ #ifndef WEBVIEW_MSWEBVIEW2_EXPLICIT_LINK
67
+ #define WEBVIEW_MSWEBVIEW2_EXPLICIT_LINK WEBVIEW_MSWEBVIEW2_BUILTIN_IMPL
68
+ #endif
69
+
70
+ // Explicit linking of WebView2Loader.dll should be used along with
71
+ // the built-in implementation.
72
+ #if WEBVIEW_MSWEBVIEW2_BUILTIN_IMPL == 1 && \
73
+ WEBVIEW_MSWEBVIEW2_EXPLICIT_LINK != 1
74
+ #undef WEBVIEW_MSWEBVIEW2_EXPLICIT_LINK
75
+ #error Please set WEBVIEW_MSWEBVIEW2_EXPLICIT_LINK=1.
76
+ #endif
77
+
78
+ #if WEBVIEW_MSWEBVIEW2_BUILTIN_IMPL == 1
79
+ // Gets the last component of a Windows native file path.
80
+ // For example, if the path is "C:\a\b" then the result is "b".
81
+ template <typename T>
82
+ std::basic_string<T>
83
+ get_last_native_path_component(const std::basic_string<T> &path) {
84
+ auto pos = path.find_last_of(static_cast<T>('\\'));
85
+ if (pos != std::basic_string<T>::npos) {
86
+ return path.substr(pos + 1);
87
+ }
88
+ return std::basic_string<T>();
89
+ }
90
+ #endif // WEBVIEW_MSWEBVIEW2_BUILTIN_IMPL
91
+
92
+ namespace mswebview2 {
93
+ static constexpr IID
94
+ IID_ICoreWebView2CreateCoreWebView2ControllerCompletedHandler{
95
+ 0x6C4819F3,
96
+ 0xC9B7,
97
+ 0x4260,
98
+ {0x81, 0x27, 0xC9, 0xF5, 0xBD, 0xE7, 0xF6, 0x8C}};
99
+ static constexpr IID
100
+ IID_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler{
101
+ 0x4E8A3389,
102
+ 0xC9D8,
103
+ 0x4BD2,
104
+ {0xB6, 0xB5, 0x12, 0x4F, 0xEE, 0x6C, 0xC1, 0x4D}};
105
+ static constexpr IID IID_ICoreWebView2PermissionRequestedEventHandler{
106
+ 0x15E1C6A3,
107
+ 0xC72A,
108
+ 0x4DF3,
109
+ {0x91, 0xD7, 0xD0, 0x97, 0xFB, 0xEC, 0x6B, 0xFD}};
110
+ static constexpr IID IID_ICoreWebView2WebMessageReceivedEventHandler{
111
+ 0x57213F19,
112
+ 0x00E6,
113
+ 0x49FA,
114
+ {0x8E, 0x07, 0x89, 0x8E, 0xA0, 0x1E, 0xCB, 0xD2}};
115
+ static constexpr IID
116
+ IID_ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler{
117
+ 0xB99369F3,
118
+ 0x9B11,
119
+ 0x47B5,
120
+ {0xBC, 0x6F, 0x8E, 0x78, 0x95, 0xFC, 0xEA, 0x17}};
121
+
122
+ #if WEBVIEW_MSWEBVIEW2_BUILTIN_IMPL == 1
123
+ enum class webview2_runtime_type { installed = 0, embedded = 1 };
124
+
125
+ namespace webview2_symbols {
126
+ using CreateWebViewEnvironmentWithOptionsInternal_t =
127
+ HRESULT(STDMETHODCALLTYPE *)(
128
+ bool, webview2_runtime_type, PCWSTR, IUnknown *,
129
+ ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler *);
130
+ using DllCanUnloadNow_t = HRESULT(STDMETHODCALLTYPE *)();
131
+
132
+ static constexpr auto CreateWebViewEnvironmentWithOptionsInternal =
133
+ library_symbol<CreateWebViewEnvironmentWithOptionsInternal_t>(
134
+ "CreateWebViewEnvironmentWithOptionsInternal");
135
+ static constexpr auto DllCanUnloadNow =
136
+ library_symbol<DllCanUnloadNow_t>("DllCanUnloadNow");
137
+ } // namespace webview2_symbols
138
+ #endif // WEBVIEW_MSWEBVIEW2_BUILTIN_IMPL
139
+
140
+ #if WEBVIEW_MSWEBVIEW2_EXPLICIT_LINK == 1
141
+ namespace webview2_symbols {
142
+ using CreateCoreWebView2EnvironmentWithOptions_t = HRESULT(STDMETHODCALLTYPE *)(
143
+ PCWSTR, PCWSTR, ICoreWebView2EnvironmentOptions *,
144
+ ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler *);
145
+ using GetAvailableCoreWebView2BrowserVersionString_t =
146
+ HRESULT(STDMETHODCALLTYPE *)(PCWSTR, LPWSTR *);
147
+
148
+ static constexpr auto CreateCoreWebView2EnvironmentWithOptions =
149
+ library_symbol<CreateCoreWebView2EnvironmentWithOptions_t>(
150
+ "CreateCoreWebView2EnvironmentWithOptions");
151
+ static constexpr auto GetAvailableCoreWebView2BrowserVersionString =
152
+ library_symbol<GetAvailableCoreWebView2BrowserVersionString_t>(
153
+ "GetAvailableCoreWebView2BrowserVersionString");
154
+ } // namespace webview2_symbols
155
+ #endif // WEBVIEW_MSWEBVIEW2_EXPLICIT_LINK
156
+
157
+ class loader {
158
+ public:
159
+ HRESULT create_environment_with_options(
160
+ PCWSTR browser_dir, PCWSTR user_data_dir,
161
+ ICoreWebView2EnvironmentOptions *env_options,
162
+ ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler
163
+ *created_handler) const {
164
+ #if WEBVIEW_MSWEBVIEW2_EXPLICIT_LINK == 1
165
+ if (m_lib.is_loaded()) {
166
+ if (auto fn = m_lib.get(
167
+ webview2_symbols::CreateCoreWebView2EnvironmentWithOptions)) {
168
+ return fn(browser_dir, user_data_dir, env_options, created_handler);
169
+ }
170
+ }
171
+ #if WEBVIEW_MSWEBVIEW2_BUILTIN_IMPL == 1
172
+ return create_environment_with_options_impl(browser_dir, user_data_dir,
173
+ env_options, created_handler);
174
+ #else
175
+ return S_FALSE;
176
+ #endif
177
+ #else
178
+ return ::CreateCoreWebView2EnvironmentWithOptions(
179
+ browser_dir, user_data_dir, env_options, created_handler);
180
+ #endif // WEBVIEW_MSWEBVIEW2_EXPLICIT_LINK
181
+ }
182
+
183
+ HRESULT
184
+ get_available_browser_version_string(PCWSTR browser_dir,
185
+ LPWSTR *version) const {
186
+ #if WEBVIEW_MSWEBVIEW2_EXPLICIT_LINK == 1
187
+ if (m_lib.is_loaded()) {
188
+ if (auto fn = m_lib.get(
189
+ webview2_symbols::GetAvailableCoreWebView2BrowserVersionString)) {
190
+ return fn(browser_dir, version);
191
+ }
192
+ }
193
+ #if WEBVIEW_MSWEBVIEW2_BUILTIN_IMPL == 1
194
+ return get_available_browser_version_string_impl(browser_dir, version);
195
+ #else
196
+ return S_FALSE;
197
+ #endif
198
+ #else
199
+ return ::GetAvailableCoreWebView2BrowserVersionString(browser_dir, version);
200
+ #endif // WEBVIEW_MSWEBVIEW2_EXPLICIT_LINK
201
+ }
202
+
203
+ private:
204
+ #if WEBVIEW_MSWEBVIEW2_BUILTIN_IMPL == 1
205
+ struct client_info_t {
206
+ bool found{};
207
+ std::wstring dll_path;
208
+ std::wstring version;
209
+ webview2_runtime_type runtime_type{};
210
+
211
+ client_info_t() = default;
212
+
213
+ client_info_t(bool found, std::wstring dll_path, std::wstring version,
214
+ webview2_runtime_type runtime_type)
215
+ : found{found},
216
+ dll_path{std::move(dll_path)},
217
+ version{std::move(version)},
218
+ runtime_type{runtime_type} {}
219
+ };
220
+
221
+ HRESULT create_environment_with_options_impl(
222
+ PCWSTR browser_dir, PCWSTR user_data_dir,
223
+ ICoreWebView2EnvironmentOptions *env_options,
224
+ ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler
225
+ *created_handler) const {
226
+ auto found_client = find_available_client(browser_dir);
227
+ if (!found_client.found) {
228
+ return -1;
229
+ }
230
+ auto client_dll = native_library(found_client.dll_path);
231
+ if (auto fn = client_dll.get(
232
+ webview2_symbols::CreateWebViewEnvironmentWithOptionsInternal)) {
233
+ return fn(true, found_client.runtime_type, user_data_dir, env_options,
234
+ created_handler);
235
+ }
236
+ if (auto fn = client_dll.get(webview2_symbols::DllCanUnloadNow)) {
237
+ if (!fn()) {
238
+ client_dll.detach();
239
+ }
240
+ }
241
+ return ERROR_SUCCESS;
242
+ }
243
+
244
+ HRESULT
245
+ get_available_browser_version_string_impl(PCWSTR browser_dir,
246
+ LPWSTR *version) const {
247
+ if (!version) {
248
+ return -1;
249
+ }
250
+ auto found_client = find_available_client(browser_dir);
251
+ if (!found_client.found) {
252
+ return -1;
253
+ }
254
+ auto info_length_bytes =
255
+ found_client.version.size() * sizeof(found_client.version[0]);
256
+ auto info = static_cast<LPWSTR>(CoTaskMemAlloc(info_length_bytes));
257
+ if (!info) {
258
+ return -1;
259
+ }
260
+ CopyMemory(info, found_client.version.c_str(), info_length_bytes);
261
+ *version = info;
262
+ return 0;
263
+ }
264
+
265
+ client_info_t find_available_client(PCWSTR browser_dir) const {
266
+ if (browser_dir) {
267
+ return find_embedded_client(api_version, browser_dir);
268
+ }
269
+ auto found_client =
270
+ find_installed_client(api_version, true, default_release_channel_guid);
271
+ if (!found_client.found) {
272
+ found_client = find_installed_client(api_version, false,
273
+ default_release_channel_guid);
274
+ }
275
+ return found_client;
276
+ }
277
+
278
+ std::wstring make_client_dll_path(const std::wstring &dir) const {
279
+ auto dll_path = dir;
280
+ if (!dll_path.empty()) {
281
+ auto last_char = dir[dir.size() - 1];
282
+ if (last_char != L'\\' && last_char != L'/') {
283
+ dll_path += L'\\';
284
+ }
285
+ }
286
+ dll_path += L"EBWebView\\";
287
+ #if defined(_M_X64) || defined(__x86_64__)
288
+ dll_path += L"x64";
289
+ #elif defined(_M_IX86) || defined(__i386__)
290
+ dll_path += L"x86";
291
+ #elif defined(_M_ARM64) || defined(__aarch64__)
292
+ dll_path += L"arm64";
293
+ #else
294
+ #error WebView2 integration for this platform is not yet supported.
295
+ #endif
296
+ dll_path += L"\\EmbeddedBrowserWebView.dll";
297
+ return dll_path;
298
+ }
299
+
300
+ client_info_t
301
+ find_installed_client(unsigned int min_api_version, bool system,
302
+ const std::wstring &release_channel) const {
303
+ std::wstring sub_key = client_state_reg_sub_key;
304
+ sub_key += release_channel;
305
+ auto root_key = system ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
306
+ reg_key key(root_key, sub_key, 0, KEY_READ | KEY_WOW64_32KEY);
307
+ if (!key.is_open()) {
308
+ return {};
309
+ }
310
+ auto ebwebview_value = key.query_string(L"EBWebView");
311
+
312
+ auto client_version_string =
313
+ get_last_native_path_component(ebwebview_value);
314
+ auto client_version = parse_version(client_version_string);
315
+ if (client_version[2] < min_api_version) {
316
+ // Our API version is greater than the runtime API version.
317
+ return {};
318
+ }
319
+
320
+ auto client_dll_path = make_client_dll_path(ebwebview_value);
321
+ return {true, std::move(client_dll_path), std::move(client_version_string),
322
+ webview2_runtime_type::installed};
323
+ }
324
+
325
+ client_info_t find_embedded_client(unsigned int min_api_version,
326
+ const std::wstring &dir) const {
327
+ auto client_dll_path = make_client_dll_path(dir);
328
+
329
+ auto client_version_string = get_file_version_string(client_dll_path);
330
+ auto client_version = parse_version(client_version_string);
331
+ if (client_version[2] < min_api_version) {
332
+ // Our API version is greater than the runtime API version.
333
+ return {};
334
+ }
335
+
336
+ return {true, std::move(client_dll_path), std::move(client_version_string),
337
+ webview2_runtime_type::embedded};
338
+ }
339
+
340
+ // The minimum WebView2 API version we need regardless of the SDK release
341
+ // actually used. The number comes from the SDK release version,
342
+ // e.g. 1.0.1150.38. To be safe the SDK should have a number that is greater
343
+ // than or equal to this number. The Edge browser webview client must
344
+ // have a number greater than or equal to this number.
345
+ static constexpr unsigned int api_version = 1150;
346
+
347
+ static constexpr auto client_state_reg_sub_key =
348
+ L"SOFTWARE\\Microsoft\\EdgeUpdate\\ClientState\\";
349
+
350
+ // GUID for the stable release channel.
351
+ static constexpr auto stable_release_guid =
352
+ L"{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}";
353
+
354
+ static constexpr auto default_release_channel_guid = stable_release_guid;
355
+ #endif // WEBVIEW_MSWEBVIEW2_BUILTIN_IMPL
356
+
357
+ #if WEBVIEW_MSWEBVIEW2_EXPLICIT_LINK == 1
358
+ native_library m_lib{L"WebView2Loader.dll"};
359
+ #endif
360
+ };
361
+
362
+ namespace cast_info {
363
+ static constexpr auto controller_completed =
364
+ cast_info_t<ICoreWebView2CreateCoreWebView2ControllerCompletedHandler>{
365
+ IID_ICoreWebView2CreateCoreWebView2ControllerCompletedHandler};
366
+
367
+ static constexpr auto environment_completed =
368
+ cast_info_t<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>{
369
+ IID_ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler};
370
+
371
+ static constexpr auto message_received =
372
+ cast_info_t<ICoreWebView2WebMessageReceivedEventHandler>{
373
+ IID_ICoreWebView2WebMessageReceivedEventHandler};
374
+
375
+ static constexpr auto permission_requested =
376
+ cast_info_t<ICoreWebView2PermissionRequestedEventHandler>{
377
+ IID_ICoreWebView2PermissionRequestedEventHandler};
378
+
379
+ static constexpr auto add_script_to_execute_on_document_created_completed =
380
+ cast_info_t<
381
+ ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler>{
382
+ IID_ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler};
383
+ } // namespace cast_info
384
+
385
+ } // namespace mswebview2
386
+ } // namespace detail
387
+ } // namespace webview
388
+
389
+ #endif // defined(WEBVIEW_PLATFORM_WINDOWS) && defined(WEBVIEW_EDGE)
390
+ #endif // defined(__cplusplus) && !defined(WEBVIEW_HEADER)
391
+ #endif // WEBVIEW_BACKENDS_WEBVIEW2_LOADER_HH
@@ -0,0 +1,76 @@
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_DETAIL_USER_SCRIPT_HH
27
+ #define WEBVIEW_DETAIL_USER_SCRIPT_HH
28
+
29
+ #if defined(__cplusplus) && !defined(WEBVIEW_HEADER)
30
+
31
+ #include <functional>
32
+ #include <memory>
33
+ #include <string>
34
+ #include <utility>
35
+
36
+ namespace webview {
37
+ namespace detail {
38
+
39
+ class user_script {
40
+ public:
41
+ class impl;
42
+ using impl_deleter = std::function<void(impl *)>;
43
+ using impl_ptr = std::unique_ptr<impl, impl_deleter>;
44
+
45
+ user_script(const std::string &code, impl_ptr &&impl_)
46
+ : m_code{code}, m_impl{std::move(impl_)} {}
47
+
48
+ user_script(const user_script &other) = delete;
49
+ user_script &operator=(const user_script &other) = delete;
50
+ user_script(user_script &&other) noexcept { *this = std::move(other); }
51
+
52
+ user_script &operator=(user_script &&other) noexcept {
53
+ if (this == &other) {
54
+ return *this;
55
+ }
56
+ m_code = std::move(other.m_code);
57
+ m_impl = std::move(other.m_impl);
58
+ return *this;
59
+ }
60
+
61
+ const std::string &get_code() const { return m_code; }
62
+
63
+ impl &get_impl() { return *m_impl; }
64
+
65
+ const impl &get_impl() const { return *m_impl; }
66
+
67
+ private:
68
+ std::string m_code;
69
+ impl_ptr m_impl;
70
+ };
71
+
72
+ } // namespace detail
73
+ } // namespace webview
74
+
75
+ #endif // defined(__cplusplus) && !defined(WEBVIEW_HEADER)
76
+ #endif // WEBVIEW_DETAIL_USER_SCRIPT_HH
@@ -0,0 +1,99 @@
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_DETAIL_UTILITY_STRING_HH
27
+ #define WEBVIEW_DETAIL_UTILITY_STRING_HH
28
+
29
+ #if defined(__cplusplus) && !defined(WEBVIEW_HEADER)
30
+
31
+ #include <string>
32
+
33
+ #if defined(_WIN32)
34
+ #ifndef WIN32_LEAN_AND_MEAN
35
+ #define WIN32_LEAN_AND_MEAN
36
+ #endif
37
+ #include <windows.h>
38
+ #endif
39
+
40
+ namespace webview {
41
+ namespace detail {
42
+
43
+ #if defined(_WIN32)
44
+ // Converts a narrow (UTF-8-encoded) string into a wide (UTF-16-encoded) string.
45
+ inline std::wstring widen_string(const std::string &input) {
46
+ if (input.empty()) {
47
+ return std::wstring();
48
+ }
49
+ UINT cp = CP_UTF8;
50
+ DWORD flags = MB_ERR_INVALID_CHARS;
51
+ auto input_c = input.c_str();
52
+ auto input_length = static_cast<int>(input.size());
53
+ auto required_length =
54
+ MultiByteToWideChar(cp, flags, input_c, input_length, nullptr, 0);
55
+ if (required_length > 0) {
56
+ std::wstring output(static_cast<std::size_t>(required_length), L'\0');
57
+ if (MultiByteToWideChar(cp, flags, input_c, input_length, &output[0],
58
+ required_length) > 0) {
59
+ return output;
60
+ }
61
+ }
62
+ // Failed to convert string from UTF-8 to UTF-16
63
+ return std::wstring();
64
+ }
65
+
66
+ // Converts a wide (UTF-16-encoded) string into a narrow (UTF-8-encoded) string.
67
+ inline std::string narrow_string(const std::wstring &input) {
68
+ struct wc_flags {
69
+ enum TYPE : unsigned int {
70
+ // WC_ERR_INVALID_CHARS
71
+ err_invalid_chars = 0x00000080U
72
+ };
73
+ };
74
+ if (input.empty()) {
75
+ return std::string();
76
+ }
77
+ UINT cp = CP_UTF8;
78
+ DWORD flags = wc_flags::err_invalid_chars;
79
+ auto input_c = input.c_str();
80
+ auto input_length = static_cast<int>(input.size());
81
+ auto required_length = WideCharToMultiByte(cp, flags, input_c, input_length,
82
+ nullptr, 0, nullptr, nullptr);
83
+ if (required_length > 0) {
84
+ std::string output(static_cast<std::size_t>(required_length), '\0');
85
+ if (WideCharToMultiByte(cp, flags, input_c, input_length, &output[0],
86
+ required_length, nullptr, nullptr) > 0) {
87
+ return output;
88
+ }
89
+ }
90
+ // Failed to convert string from UTF-16 to UTF-8
91
+ return std::string();
92
+ }
93
+ #endif
94
+
95
+ } // namespace detail
96
+ } // namespace webview
97
+
98
+ #endif // defined(__cplusplus) && !defined(WEBVIEW_HEADER)
99
+ #endif // WEBVIEW_DETAIL_UTILITY_STRING_HH
@@ -0,0 +1,67 @@
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_ERRORS_H
27
+ #define WEBVIEW_ERRORS_H
28
+
29
+ /// @name Errors
30
+ /// @{
31
+
32
+ /**
33
+ * @brief Error codes returned to callers of the API.
34
+ *
35
+ * The following codes are commonly used in the library:
36
+ * - @c WEBVIEW_ERROR_OK
37
+ * - @c WEBVIEW_ERROR_UNSPECIFIED
38
+ * - @c WEBVIEW_ERROR_INVALID_ARGUMENT
39
+ * - @c WEBVIEW_ERROR_INVALID_STATE
40
+ *
41
+ * With the exception of @c WEBVIEW_ERROR_OK which is normally expected,
42
+ * the other common codes do not normally need to be handled specifically.
43
+ * Refer to specific functions regarding handling of other codes.
44
+ */
45
+ typedef enum {
46
+ /// Missing dependency.
47
+ WEBVIEW_ERROR_MISSING_DEPENDENCY = -5,
48
+ /// Operation canceled.
49
+ WEBVIEW_ERROR_CANCELED = -4,
50
+ /// Invalid state detected.
51
+ WEBVIEW_ERROR_INVALID_STATE = -3,
52
+ /// One or more invalid arguments have been specified e.g. in a function call.
53
+ WEBVIEW_ERROR_INVALID_ARGUMENT = -2,
54
+ /// An unspecified error occurred. A more specific error code may be needed.
55
+ WEBVIEW_ERROR_UNSPECIFIED = -1,
56
+ /// OK/Success. Functions that return error codes will typically return this
57
+ /// to signify successful operations.
58
+ WEBVIEW_ERROR_OK = 0,
59
+ /// Signifies that something already exists.
60
+ WEBVIEW_ERROR_DUPLICATE = 1,
61
+ /// Signifies that something does not exist.
62
+ WEBVIEW_ERROR_NOT_FOUND = 2
63
+ } webview_error_t;
64
+
65
+ /// @}
66
+
67
+ #endif // WEBVIEW_ERRORS_H