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,126 @@
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_PLATFORM_WINDOWS_COM_INIT_WRAPPER_HH
27
+ #define WEBVIEW_PLATFORM_WINDOWS_COM_INIT_WRAPPER_HH
28
+
29
+ #if defined(__cplusplus) && !defined(WEBVIEW_HEADER)
30
+
31
+ #include "../../../macros.h"
32
+
33
+ #if defined(WEBVIEW_PLATFORM_WINDOWS)
34
+
35
+ //
36
+ // ====================================================================
37
+ //
38
+ // This implementation uses Win32 API to create a native window. It
39
+ // uses Edge/Chromium webview2 backend as a browser engine.
40
+ //
41
+ // ====================================================================
42
+ //
43
+
44
+ #include "../../../errors.hh"
45
+
46
+ #include <utility>
47
+
48
+ #ifndef WIN32_LEAN_AND_MEAN
49
+ #define WIN32_LEAN_AND_MEAN
50
+ #endif
51
+
52
+ #include <windows.h>
53
+
54
+ #include <objbase.h>
55
+
56
+ #ifdef _MSC_VER
57
+ #pragma comment(lib, "ole32.lib")
58
+ #endif
59
+
60
+ namespace webview {
61
+ namespace detail {
62
+
63
+ /**
64
+ * A wrapper around COM library initialization. Calls CoInitializeEx in the
65
+ * constructor and CoUninitialize in the destructor.
66
+ *
67
+ * @exception exception Thrown if CoInitializeEx has already been called with a
68
+ * different concurrency model.
69
+ */
70
+ class com_init_wrapper {
71
+ public:
72
+ com_init_wrapper() = default;
73
+
74
+ com_init_wrapper(DWORD dwCoInit) {
75
+ // We can safely continue as long as COM was either successfully
76
+ // initialized or already initialized.
77
+ // RPC_E_CHANGED_MODE means that CoInitializeEx was already called with
78
+ // a different concurrency model.
79
+ switch (CoInitializeEx(nullptr, dwCoInit)) {
80
+ case S_OK:
81
+ case S_FALSE:
82
+ m_initialized = true;
83
+ break;
84
+ case RPC_E_CHANGED_MODE:
85
+ throw exception{
86
+ WEBVIEW_ERROR_INVALID_STATE,
87
+ "CoInitializeEx already called with a different concurrency model"};
88
+ default:
89
+ throw exception{WEBVIEW_ERROR_UNSPECIFIED,
90
+ "Unexpected result from CoInitializeEx"};
91
+ }
92
+ }
93
+
94
+ ~com_init_wrapper() {
95
+ if (m_initialized) {
96
+ CoUninitialize();
97
+ m_initialized = false;
98
+ }
99
+ }
100
+
101
+ com_init_wrapper(const com_init_wrapper &other) = delete;
102
+ com_init_wrapper &operator=(const com_init_wrapper &other) = delete;
103
+
104
+ com_init_wrapper(com_init_wrapper &&other) noexcept {
105
+ *this = std::move(other);
106
+ }
107
+
108
+ com_init_wrapper &operator=(com_init_wrapper &&other) noexcept {
109
+ if (this == &other) {
110
+ return *this;
111
+ }
112
+ m_initialized = other.m_initialized;
113
+ other.m_initialized = false;
114
+ return *this;
115
+ }
116
+
117
+ private:
118
+ bool m_initialized = false;
119
+ };
120
+
121
+ } // namespace detail
122
+ } // namespace webview
123
+
124
+ #endif // defined(WEBVIEW_PLATFORM_WINDOWS)
125
+ #endif // defined(__cplusplus) && !defined(WEBVIEW_HEADER)
126
+ #endif // WEBVIEW_PLATFORM_WINDOWS_COM_INIT_WRAPPER_HH
@@ -0,0 +1,161 @@
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_PLATFORM_WINDOWS_DPI_HH
27
+ #define WEBVIEW_PLATFORM_WINDOWS_DPI_HH
28
+
29
+ #if defined(__cplusplus) && !defined(WEBVIEW_HEADER)
30
+
31
+ #include "../../../macros.h"
32
+
33
+ #if defined(WEBVIEW_PLATFORM_WINDOWS)
34
+
35
+ //
36
+ // ====================================================================
37
+ //
38
+ // This implementation uses Win32 API to create a native window. It
39
+ // uses Edge/Chromium webview2 backend as a browser engine.
40
+ //
41
+ // ====================================================================
42
+ //
43
+
44
+ #include "../../native_library.hh"
45
+ #include "shcore.hh"
46
+ #include "user32.hh"
47
+ #include "version.hh"
48
+
49
+ #ifndef WIN32_LEAN_AND_MEAN
50
+ #define WIN32_LEAN_AND_MEAN
51
+ #endif
52
+
53
+ #include <windows.h>
54
+
55
+ #ifdef _MSC_VER
56
+ #pragma comment(lib, "user32.lib")
57
+ #endif
58
+
59
+ namespace webview {
60
+ namespace detail {
61
+
62
+ inline bool is_per_monitor_v2_awareness_available() {
63
+ // Windows 10, version 1703
64
+ return compare_os_version(10, 0, 15063) >= 0;
65
+ }
66
+
67
+ inline bool enable_dpi_awareness() {
68
+ auto user32 = native_library(L"user32.dll");
69
+ if (auto fn = user32.get(user32_symbols::SetProcessDpiAwarenessContext)) {
70
+ auto dpi_awareness =
71
+ reinterpret_cast<user32_symbols::DPI_AWARENESS_CONTEXT>(
72
+ is_per_monitor_v2_awareness_available()
73
+ ? user32_symbols::dpi_awareness::per_monitor_v2_aware
74
+ : user32_symbols::dpi_awareness::per_monitor_aware);
75
+ if (fn(dpi_awareness)) {
76
+ return true;
77
+ }
78
+ return GetLastError() == ERROR_ACCESS_DENIED;
79
+ }
80
+ if (auto shcore = native_library(L"shcore.dll")) {
81
+ if (auto fn = shcore.get(shcore_symbols::SetProcessDpiAwareness)) {
82
+ auto result = fn(shcore_symbols::PROCESS_PER_MONITOR_DPI_AWARE);
83
+ return result == S_OK || result == E_ACCESSDENIED;
84
+ }
85
+ }
86
+ if (auto fn = user32.get(user32_symbols::SetProcessDPIAware)) {
87
+ return !!fn();
88
+ }
89
+ return true;
90
+ }
91
+
92
+ inline bool enable_non_client_dpi_scaling_if_needed(HWND window) {
93
+ auto user32 = native_library(L"user32.dll");
94
+ auto get_ctx_fn = user32.get(user32_symbols::GetWindowDpiAwarenessContext);
95
+ if (!get_ctx_fn) {
96
+ return true;
97
+ }
98
+ auto awareness = get_ctx_fn(window);
99
+ if (!awareness) {
100
+ return false;
101
+ }
102
+ auto ctx_equal_fn = user32.get(user32_symbols::AreDpiAwarenessContextsEqual);
103
+ if (!ctx_equal_fn) {
104
+ return true;
105
+ }
106
+ // EnableNonClientDpiScaling is only needed with per monitor v1 awareness.
107
+ auto per_monitor = reinterpret_cast<user32_symbols::DPI_AWARENESS_CONTEXT>(
108
+ user32_symbols::dpi_awareness::per_monitor_aware);
109
+ if (!ctx_equal_fn(awareness, per_monitor)) {
110
+ return true;
111
+ }
112
+ auto enable_fn = user32.get(user32_symbols::EnableNonClientDpiScaling);
113
+ if (!enable_fn) {
114
+ return true;
115
+ }
116
+ return !!enable_fn(window);
117
+ }
118
+
119
+ constexpr int get_default_window_dpi() {
120
+ return 96; // USER_DEFAULT_SCREEN_DPI
121
+ }
122
+
123
+ inline int get_window_dpi(HWND window) {
124
+ auto user32 = native_library(L"user32.dll");
125
+ if (auto fn = user32.get(user32_symbols::GetDpiForWindow)) {
126
+ auto dpi = static_cast<int>(fn(window));
127
+ return dpi;
128
+ }
129
+ return get_default_window_dpi();
130
+ }
131
+
132
+ constexpr int scale_value_for_dpi(int value, int from_dpi, int to_dpi) {
133
+ return (value * to_dpi) / from_dpi;
134
+ }
135
+
136
+ constexpr SIZE scale_size(int width, int height, int from_dpi, int to_dpi) {
137
+ return {scale_value_for_dpi(width, from_dpi, to_dpi),
138
+ scale_value_for_dpi(height, from_dpi, to_dpi)};
139
+ }
140
+
141
+ inline SIZE make_window_frame_size(HWND window, int width, int height,
142
+ int dpi) {
143
+ auto style = GetWindowLong(window, GWL_STYLE);
144
+ RECT r{0, 0, width, height};
145
+ auto user32 = native_library(L"user32.dll");
146
+ if (auto fn = user32.get(user32_symbols::AdjustWindowRectExForDpi)) {
147
+ fn(&r, style, FALSE, 0, static_cast<UINT>(dpi));
148
+ } else {
149
+ AdjustWindowRect(&r, style, 0);
150
+ }
151
+ auto frame_width = r.right - r.left;
152
+ auto frame_height = r.bottom - r.top;
153
+ return {frame_width, frame_height};
154
+ }
155
+
156
+ } // namespace detail
157
+ } // namespace webview
158
+
159
+ #endif // defined(WEBVIEW_PLATFORM_WINDOWS)
160
+ #endif // defined(__cplusplus) && !defined(WEBVIEW_HEADER)
161
+ #endif // WEBVIEW_PLATFORM_WINDOWS_DPI_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_PLATFORM_WINDOWS_DWMAPI_HH
27
+ #define WEBVIEW_PLATFORM_WINDOWS_DWMAPI_HH
28
+
29
+ #if defined(__cplusplus) && !defined(WEBVIEW_HEADER)
30
+
31
+ #include "../../../macros.h"
32
+
33
+ #if defined(WEBVIEW_PLATFORM_WINDOWS)
34
+
35
+ #include "../../native_library.hh"
36
+
37
+ #ifndef WIN32_LEAN_AND_MEAN
38
+ #define WIN32_LEAN_AND_MEAN
39
+ #endif
40
+
41
+ #include <windows.h>
42
+
43
+ namespace webview {
44
+ namespace detail {
45
+ namespace dwmapi_symbols {
46
+
47
+ typedef enum {
48
+ // This undocumented value is used instead of DWMWA_USE_IMMERSIVE_DARK_MODE
49
+ // on Windows 10 older than build 19041 (2004/20H1).
50
+ DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_V10_0_19041 = 19,
51
+ // Documented as being supported since Windows 11 build 22000 (21H2) but it
52
+ // works since Windows 10 build 19041 (2004/20H1).
53
+ DWMWA_USE_IMMERSIVE_DARK_MODE = 20
54
+ } DWMWINDOWATTRIBUTE;
55
+
56
+ using DwmSetWindowAttribute_t = HRESULT(WINAPI *)(HWND, DWORD, LPCVOID, DWORD);
57
+
58
+ constexpr auto DwmSetWindowAttribute =
59
+ library_symbol<DwmSetWindowAttribute_t>("DwmSetWindowAttribute");
60
+
61
+ } // namespace dwmapi_symbols
62
+ } // namespace detail
63
+ } // namespace webview
64
+
65
+ #endif // defined(WEBVIEW_PLATFORM_WINDOWS)
66
+ #endif // defined(__cplusplus) && !defined(WEBVIEW_HEADER)
67
+ #endif // WEBVIEW_PLATFORM_WINDOWS_DWMAPI_HH
@@ -0,0 +1,78 @@
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_PLATFORM_WINDOWS_IID_HH
27
+ #define WEBVIEW_PLATFORM_WINDOWS_IID_HH
28
+
29
+ #if defined(__cplusplus) && !defined(WEBVIEW_HEADER)
30
+
31
+ #include "../../../macros.h"
32
+
33
+ #if defined(WEBVIEW_PLATFORM_WINDOWS)
34
+
35
+ #ifndef WIN32_LEAN_AND_MEAN
36
+ #define WIN32_LEAN_AND_MEAN
37
+ #endif
38
+
39
+ #include <windows.h>
40
+
41
+ #include <objbase.h>
42
+
43
+ #ifdef _MSC_VER
44
+ #pragma comment(lib, "ole32.lib")
45
+ #endif
46
+
47
+ namespace webview {
48
+ namespace detail {
49
+
50
+ template <typename T> struct cast_info_t {
51
+ using type = T;
52
+ IID iid;
53
+ };
54
+
55
+ // Checks whether the specified IID equals the IID of the specified type and
56
+ // if so casts the "this" pointer to T and returns it. Returns nullptr on
57
+ // mismatching IIDs.
58
+ // If ppv is specified then the pointer will also be assigned to *ppv.
59
+ template <typename From, typename To>
60
+ To *cast_if_equal_iid(From *from, REFIID riid, const cast_info_t<To> &info,
61
+ LPVOID *ppv = nullptr) noexcept {
62
+ To *ptr = nullptr;
63
+ if (IsEqualIID(riid, info.iid)) {
64
+ ptr = static_cast<To *>(from);
65
+ ptr->AddRef();
66
+ }
67
+ if (ppv) {
68
+ *ppv = ptr;
69
+ }
70
+ return ptr;
71
+ }
72
+
73
+ } // namespace detail
74
+ } // namespace webview
75
+
76
+ #endif // defined(WEBVIEW_PLATFORM_WINDOWS)
77
+ #endif // defined(__cplusplus) && !defined(WEBVIEW_HEADER)
78
+ #endif // WEBVIEW_PLATFORM_WINDOWS_IID_HH
@@ -0,0 +1,58 @@
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_PLATFORM_WINDOWS_NTDLL_HH
27
+ #define WEBVIEW_PLATFORM_WINDOWS_NTDLL_HH
28
+
29
+ #if defined(__cplusplus) && !defined(WEBVIEW_HEADER)
30
+
31
+ #include "../../../macros.h"
32
+
33
+ #if defined(WEBVIEW_PLATFORM_WINDOWS)
34
+
35
+ #include "../../native_library.hh"
36
+
37
+ #ifndef WIN32_LEAN_AND_MEAN
38
+ #define WIN32_LEAN_AND_MEAN
39
+ #endif
40
+
41
+ #include <windows.h>
42
+
43
+ namespace webview {
44
+ namespace detail {
45
+ namespace ntdll_symbols {
46
+
47
+ using RtlGetVersion_t =
48
+ unsigned int /*NTSTATUS*/ (WINAPI *)(RTL_OSVERSIONINFOW *);
49
+
50
+ constexpr auto RtlGetVersion = library_symbol<RtlGetVersion_t>("RtlGetVersion");
51
+
52
+ } // namespace ntdll_symbols
53
+ } // namespace detail
54
+ } // namespace webview
55
+
56
+ #endif // defined(WEBVIEW_PLATFORM_WINDOWS)
57
+ #endif // defined(__cplusplus) && !defined(WEBVIEW_HEADER)
58
+ #endif // WEBVIEW_PLATFORM_WINDOWS_NTDLL_HH
@@ -0,0 +1,135 @@
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_PLATFORM_WINDOWS_REG_KEY_HH
27
+ #define WEBVIEW_PLATFORM_WINDOWS_REG_KEY_HH
28
+
29
+ #if defined(__cplusplus) && !defined(WEBVIEW_HEADER)
30
+
31
+ #include "../../../macros.h"
32
+
33
+ #if defined(WEBVIEW_PLATFORM_WINDOWS)
34
+
35
+ #include <string>
36
+ #include <vector>
37
+
38
+ #ifndef WIN32_LEAN_AND_MEAN
39
+ #define WIN32_LEAN_AND_MEAN
40
+ #endif
41
+
42
+ #include <windows.h>
43
+
44
+ #ifdef _MSC_VER
45
+ #pragma comment(lib, "advapi32.lib")
46
+ #endif
47
+
48
+ namespace webview {
49
+ namespace detail {
50
+
51
+ class reg_key {
52
+ public:
53
+ explicit reg_key(HKEY root_key, const wchar_t *sub_key, DWORD options,
54
+ REGSAM sam_desired) {
55
+ HKEY handle;
56
+ auto status =
57
+ RegOpenKeyExW(root_key, sub_key, options, sam_desired, &handle);
58
+ if (status == ERROR_SUCCESS) {
59
+ m_handle = handle;
60
+ }
61
+ }
62
+
63
+ explicit reg_key(HKEY root_key, const std::wstring &sub_key, DWORD options,
64
+ REGSAM sam_desired)
65
+ : reg_key(root_key, sub_key.c_str(), options, sam_desired) {}
66
+
67
+ virtual ~reg_key() {
68
+ if (m_handle) {
69
+ RegCloseKey(m_handle);
70
+ m_handle = nullptr;
71
+ }
72
+ }
73
+
74
+ reg_key(const reg_key &other) = delete;
75
+ reg_key &operator=(const reg_key &other) = delete;
76
+ reg_key(reg_key &&other) = delete;
77
+ reg_key &operator=(reg_key &&other) = delete;
78
+
79
+ bool is_open() const { return !!m_handle; }
80
+ bool get_handle() const { return m_handle; }
81
+
82
+ template <typename Container>
83
+ void query_bytes(const wchar_t *name, Container &result) const {
84
+ DWORD buf_length = 0;
85
+ // Get the size of the data in bytes.
86
+ auto status = RegQueryValueExW(m_handle, name, nullptr, nullptr, nullptr,
87
+ &buf_length);
88
+ if (status != ERROR_SUCCESS && status != ERROR_MORE_DATA) {
89
+ result.resize(0);
90
+ return;
91
+ }
92
+ // Read the data.
93
+ result.resize(buf_length / sizeof(typename Container::value_type));
94
+ auto *buf = reinterpret_cast<LPBYTE>(&result[0]);
95
+ status =
96
+ RegQueryValueExW(m_handle, name, nullptr, nullptr, buf, &buf_length);
97
+ if (status != ERROR_SUCCESS) {
98
+ result.resize(0);
99
+ return;
100
+ }
101
+ }
102
+
103
+ std::wstring query_string(const wchar_t *name) const {
104
+ std::wstring result;
105
+ query_bytes(name, result);
106
+ // Remove trailing null-characters.
107
+ for (std::size_t length = result.size(); length > 0; --length) {
108
+ if (result[length - 1] != 0) {
109
+ result.resize(length);
110
+ break;
111
+ }
112
+ }
113
+ return result;
114
+ }
115
+
116
+ unsigned int query_uint(const wchar_t *name,
117
+ unsigned int default_value) const {
118
+ std::vector<char> data;
119
+ query_bytes(name, data);
120
+ if (data.size() < sizeof(DWORD)) {
121
+ return default_value;
122
+ }
123
+ return static_cast<unsigned int>(*reinterpret_cast<DWORD *>(data.data()));
124
+ }
125
+
126
+ private:
127
+ HKEY m_handle = nullptr;
128
+ };
129
+
130
+ } // namespace detail
131
+ } // namespace webview
132
+
133
+ #endif // defined(WEBVIEW_PLATFORM_WINDOWS)
134
+ #endif // defined(__cplusplus) && !defined(WEBVIEW_HEADER)
135
+ #endif // WEBVIEW_PLATFORM_WINDOWS_REG_KEY_HH
@@ -0,0 +1,59 @@
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_PLATFORM_WINDOWS_SHCORE_HH
27
+ #define WEBVIEW_PLATFORM_WINDOWS_SHCORE_HH
28
+
29
+ #if defined(__cplusplus) && !defined(WEBVIEW_HEADER)
30
+
31
+ #include "../../../macros.h"
32
+
33
+ #if defined(WEBVIEW_PLATFORM_WINDOWS)
34
+
35
+ #include "../../native_library.hh"
36
+
37
+ #ifndef WIN32_LEAN_AND_MEAN
38
+ #define WIN32_LEAN_AND_MEAN
39
+ #endif
40
+
41
+ #include <windows.h>
42
+
43
+ namespace webview {
44
+ namespace detail {
45
+ namespace shcore_symbols {
46
+
47
+ typedef enum { PROCESS_PER_MONITOR_DPI_AWARE = 2 } PROCESS_DPI_AWARENESS;
48
+ using SetProcessDpiAwareness_t = HRESULT(WINAPI *)(PROCESS_DPI_AWARENESS);
49
+
50
+ constexpr auto SetProcessDpiAwareness =
51
+ library_symbol<SetProcessDpiAwareness_t>("SetProcessDpiAwareness");
52
+
53
+ } // namespace shcore_symbols
54
+ } // namespace detail
55
+ } // namespace webview
56
+
57
+ #endif // defined(WEBVIEW_PLATFORM_WINDOWS)
58
+ #endif // defined(__cplusplus) && !defined(WEBVIEW_HEADER)
59
+ #endif // WEBVIEW_PLATFORM_WINDOWS_SHCORE_HH