@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,248 @@
1
+ #!/bin/sh
2
+
3
+ #
4
+ # Copyright © 2015 the original authors.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # https://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ # SPDX-License-Identifier: Apache-2.0
19
+ #
20
+
21
+ ##############################################################################
22
+ #
23
+ # gradlew start up script for POSIX generated by Gradle.
24
+ #
25
+ # Important for running:
26
+ #
27
+ # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
28
+ # noncompliant, but you have some other compliant shell such as ksh or
29
+ # bash, then to run this script, type that shell name before the whole
30
+ # command line, like:
31
+ #
32
+ # ksh gradlew
33
+ #
34
+ # Busybox and similar reduced shells will NOT work, because this script
35
+ # requires all of these POSIX shell features:
36
+ # * functions;
37
+ # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
38
+ # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
39
+ # * compound commands having a testable exit status, especially «case»;
40
+ # * various built-in commands including «command», «set», and «ulimit».
41
+ #
42
+ # Important for patching:
43
+ #
44
+ # (2) This script targets any POSIX shell, so it avoids extensions provided
45
+ # by Bash, Ksh, etc; in particular arrays are avoided.
46
+ #
47
+ # The "traditional" practice of packing multiple parameters into a
48
+ # space-separated string is a well documented source of bugs and security
49
+ # problems, so this is (mostly) avoided, by progressively accumulating
50
+ # options in "$@", and eventually passing that to Java.
51
+ #
52
+ # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
53
+ # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
54
+ # see the in-line comments for details.
55
+ #
56
+ # There are tweaks for specific operating systems such as AIX, CygWin,
57
+ # Darwin, MinGW, and NonStop.
58
+ #
59
+ # (3) This script is generated from the Groovy template
60
+ # https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
61
+ # within the Gradle project.
62
+ #
63
+ # You can find Gradle at https://github.com/gradle/gradle/.
64
+ #
65
+ ##############################################################################
66
+
67
+ # Attempt to set APP_HOME
68
+
69
+ # Resolve links: $0 may be a link
70
+ app_path=$0
71
+
72
+ # Need this for daisy-chained symlinks.
73
+ while
74
+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
75
+ [ -h "$app_path" ]
76
+ do
77
+ ls=$( ls -ld "$app_path" )
78
+ link=${ls#*' -> '}
79
+ case $link in #(
80
+ /*) app_path=$link ;; #(
81
+ *) app_path=$APP_HOME$link ;;
82
+ esac
83
+ done
84
+
85
+ # This is normally unused
86
+ # shellcheck disable=SC2034
87
+ APP_BASE_NAME=${0##*/}
88
+ # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
89
+ APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
90
+
91
+ # Use the maximum available, or set MAX_FD != -1 to use that value.
92
+ MAX_FD=maximum
93
+
94
+ warn () {
95
+ echo "$*"
96
+ } >&2
97
+
98
+ die () {
99
+ echo
100
+ echo "$*"
101
+ echo
102
+ exit 1
103
+ } >&2
104
+
105
+ # OS specific support (must be 'true' or 'false').
106
+ cygwin=false
107
+ msys=false
108
+ darwin=false
109
+ nonstop=false
110
+ case "$( uname )" in #(
111
+ CYGWIN* ) cygwin=true ;; #(
112
+ Darwin* ) darwin=true ;; #(
113
+ MSYS* | MINGW* ) msys=true ;; #(
114
+ NONSTOP* ) nonstop=true ;;
115
+ esac
116
+
117
+
118
+
119
+ # Determine the Java command to use to start the JVM.
120
+ if [ -n "$JAVA_HOME" ] ; then
121
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
122
+ # IBM's JDK on AIX uses strange locations for the executables
123
+ JAVACMD=$JAVA_HOME/jre/sh/java
124
+ else
125
+ JAVACMD=$JAVA_HOME/bin/java
126
+ fi
127
+ if [ ! -x "$JAVACMD" ] ; then
128
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
129
+
130
+ Please set the JAVA_HOME variable in your environment to match the
131
+ location of your Java installation."
132
+ fi
133
+ else
134
+ JAVACMD=java
135
+ if ! command -v java >/dev/null 2>&1
136
+ then
137
+ die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
138
+
139
+ Please set the JAVA_HOME variable in your environment to match the
140
+ location of your Java installation."
141
+ fi
142
+ fi
143
+
144
+ # Increase the maximum file descriptors if we can.
145
+ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
146
+ case $MAX_FD in #(
147
+ max*)
148
+ # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
149
+ # shellcheck disable=SC2039,SC3045
150
+ MAX_FD=$( ulimit -H -n ) ||
151
+ warn "Could not query maximum file descriptor limit"
152
+ esac
153
+ case $MAX_FD in #(
154
+ '' | soft) :;; #(
155
+ *)
156
+ # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
157
+ # shellcheck disable=SC2039,SC3045
158
+ ulimit -n "$MAX_FD" ||
159
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
160
+ esac
161
+ fi
162
+
163
+ # Collect all arguments for the java command, stacking in reverse order:
164
+ # * args from the command line
165
+ # * the main class name
166
+ # * -classpath
167
+ # * -D...appname settings
168
+ # * --module-path (only if needed)
169
+ # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
170
+
171
+ # For Cygwin or MSYS, switch paths to Windows format before running java
172
+ if "$cygwin" || "$msys" ; then
173
+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
174
+
175
+ JAVACMD=$( cygpath --unix "$JAVACMD" )
176
+
177
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
178
+ for arg do
179
+ if
180
+ case $arg in #(
181
+ -*) false ;; # don't mess with options #(
182
+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
183
+ [ -e "$t" ] ;; #(
184
+ *) false ;;
185
+ esac
186
+ then
187
+ arg=$( cygpath --path --ignore --mixed "$arg" )
188
+ fi
189
+ # Roll the args list around exactly as many times as the number of
190
+ # args, so each arg winds up back in the position where it started, but
191
+ # possibly modified.
192
+ #
193
+ # NB: a `for` loop captures its iteration list before it begins, so
194
+ # changing the positional parameters here affects neither the number of
195
+ # iterations, nor the values presented in `arg`.
196
+ shift # remove old arg
197
+ set -- "$@" "$arg" # push replacement arg
198
+ done
199
+ fi
200
+
201
+
202
+ # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
203
+ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
204
+
205
+ # Collect all arguments for the java command:
206
+ # * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
207
+ # and any embedded shellness will be escaped.
208
+ # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
209
+ # treated as '${Hostname}' itself on the command line.
210
+
211
+ set -- \
212
+ "-Dorg.gradle.appname=$APP_BASE_NAME" \
213
+ -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
214
+ "$@"
215
+
216
+ # Stop when "xargs" is not available.
217
+ if ! command -v xargs >/dev/null 2>&1
218
+ then
219
+ die "xargs is not available"
220
+ fi
221
+
222
+ # Use "xargs" to parse quoted args.
223
+ #
224
+ # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
225
+ #
226
+ # In Bash we could simply go:
227
+ #
228
+ # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
229
+ # set -- "${ARGS[@]}" "$@"
230
+ #
231
+ # but POSIX shell has neither arrays nor command substitution, so instead we
232
+ # post-process each arg (as a line of input to sed) to backslash-escape any
233
+ # character that might be a shell metacharacter, then use eval to reverse
234
+ # that process (while maintaining the separation between arguments), and wrap
235
+ # the whole thing up as a single "set" statement.
236
+ #
237
+ # This will of course break if any of these variables contains a newline or
238
+ # an unmatched quote.
239
+ #
240
+
241
+ eval "set -- $(
242
+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
243
+ xargs -n1 |
244
+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
245
+ tr '\n' ' '
246
+ )" '"$@"'
247
+
248
+ exec "$JAVACMD" "$@"
@@ -0,0 +1,112 @@
1
+ @rem
2
+ @rem Copyright 2015 the original author or authors.
3
+ @rem
4
+ @rem Licensed under the Apache License, Version 2.0 (the "License");
5
+ @rem you may not use this file except in compliance with the License.
6
+ @rem You may obtain a copy of the License at
7
+ @rem
8
+ @rem https://www.apache.org/licenses/LICENSE-2.0
9
+ @rem
10
+ @rem Unless required by applicable law or agreed to in writing, software
11
+ @rem distributed under the License is distributed on an "AS IS" BASIS,
12
+ @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ @rem See the License for the specific language governing permissions and
14
+ @rem limitations under the License.
15
+ @rem
16
+ @rem SPDX-License-Identifier: Apache-2.0
17
+ @rem
18
+
19
+ @if "%DEBUG%"=="" @echo off
20
+ @rem ##########################################################################
21
+ @rem
22
+ @rem gradlew startup script for Windows
23
+ @rem
24
+ @rem ##########################################################################
25
+
26
+ @rem Set local scope for the variables, and ensure extensions are enabled
27
+ setlocal EnableExtensions
28
+
29
+ @rem Catch executions from older scripts and ensure they exit cleanly.
30
+ @rem This can be removed once we can be reasonably confident that few people
31
+ @rem will be migrating directly to this new wrapper.
32
+ goto afterSafetyNet
33
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
34
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
35
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
36
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
37
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
38
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
39
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
40
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
41
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
42
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
43
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
44
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
45
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
46
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
47
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
48
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
49
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
50
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
51
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
52
+ ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
53
+ goto exitWithErrorLevel
54
+ :afterSafetyNet
55
+
56
+ set DIRNAME=%~dp0
57
+ if "%DIRNAME%"=="" set DIRNAME=.
58
+ @rem This is normally unused
59
+ set APP_BASE_NAME=%~n0
60
+ set APP_HOME=%DIRNAME%
61
+
62
+ @rem Resolve any "." and ".." in APP_HOME to make it shorter.
63
+ for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
64
+
65
+ @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
66
+ set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
67
+
68
+ @rem Find java.exe
69
+ if defined JAVA_HOME goto findJavaFromJavaHome
70
+
71
+ set JAVA_EXE=java.exe
72
+ %JAVA_EXE% -version >NUL 2>&1
73
+ if %ERRORLEVEL% equ 0 goto execute
74
+
75
+ 1>&2 echo.
76
+ 1>&2 echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
77
+ 1>&2 echo.
78
+ 1>&2 echo Please set the JAVA_HOME variable in your environment to match the
79
+ 1>&2 echo location of your Java installation.
80
+
81
+ "%COMSPEC%" /c exit 1
82
+ goto exitWithErrorLevel
83
+
84
+ :findJavaFromJavaHome
85
+ set JAVA_HOME=%JAVA_HOME:"=%
86
+ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
87
+
88
+ if exist "%JAVA_EXE%" goto execute
89
+
90
+ 1>&2 echo.
91
+ 1>&2 echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
92
+ 1>&2 echo.
93
+ 1>&2 echo Please set the JAVA_HOME variable in your environment to match the
94
+ 1>&2 echo location of your Java installation.
95
+
96
+ "%COMSPEC%" /c exit 1
97
+ goto exitWithErrorLevel
98
+
99
+ :execute
100
+ @rem Setup the command line
101
+
102
+
103
+
104
+ @rem Execute gradlew
105
+ @rem endlocal doesn't take effect until after the line is parsed and variables are expanded
106
+ @rem which allows us to clear the local environment before executing the java command
107
+ endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel & goto exitWithErrorLevel
108
+
109
+ @rem This label must not be changed. We rely on old scripts being able to jump to this point.
110
+ :exitWithErrorLevel
111
+ @rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts
112
+ "%COMSPEC%" /c exit %ERRORLEVEL%
@@ -0,0 +1,14 @@
1
+ pluginManagement {
2
+ repositories {
3
+ google()
4
+ mavenCentral()
5
+ gradlePluginPortal()
6
+ }
7
+ }
8
+ dependencyResolutionManagement {
9
+ repositories {
10
+ google()
11
+ mavenCentral()
12
+ }
13
+ }
14
+ include ':app'
@@ -0,0 +1,110 @@
1
+ cmake_minimum_required(VERSION 3.28)
2
+ if(APPLE)
3
+ project(crossbind_app CXX OBJCXX)
4
+ else()
5
+ project(crossbind_app CXX)
6
+ endif()
7
+
8
+ # crossbind configures this project for one app host: the window and its webview, Hermes and the embind runtime
9
+ # compile here, the project's own code arrives as prebuilt archives in CROSSBIND_LINK_ARGS. An iOS host is a static
10
+ # library instead, which the app's Xcode project links with those archives, and an Android host a shared library the
11
+ # app's activity loads, beside the JSI its Hermes loads.
12
+
13
+ set(CMAKE_CXX_STANDARD 20)
14
+ set(CMAKE_CXX_STANDARD_REQUIRED ON)
15
+
16
+ set(THIRD_PARTY "${CMAKE_CURRENT_SOURCE_DIR}/../third_party")
17
+ if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
18
+ set(PLATFORM_SOURCES src/ios/main.mm src/ios/bundle.mm src/darwin/channels.mm src/darwin/navigation.mm)
19
+ elseif(APPLE)
20
+ set(PLATFORM_SOURCES src/darwin/bundle.mm src/darwin/channels.mm src/darwin/navigation.mm)
21
+ elseif(ANDROID)
22
+ set(PLATFORM_SOURCES src/android/jni.cpp)
23
+ elseif(WIN32)
24
+ enable_language(RC)
25
+ set(PLATFORM_SOURCES src/windows/app.cpp src/windows/channels.cpp src/windows/com.cpp src/windows/navigation.cpp src/windows/app.rc)
26
+ else()
27
+ set(PLATFORM_SOURCES src/linux/app.cpp src/linux/channels.cpp src/linux/navigation.cpp)
28
+ endif()
29
+ if(APPLE)
30
+ set(CMAKE_OBJCXX_STANDARD 20)
31
+ endif()
32
+
33
+ set(SOURCES
34
+ src/app.cpp
35
+ src/host_core.cpp
36
+ ${PLATFORM_SOURCES}
37
+ "${CROSSBIND_JSI_ROOT}/cpp/src/emscripten/bind.cpp"
38
+ ${CROSSBIND_EXTRA_SOURCES})
39
+ if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
40
+ add_library(app STATIC src/attach.cpp "${THIRD_PARTY}/jsi/jsi.cpp" ${SOURCES})
41
+ elseif(ANDROID)
42
+ add_library(jsi SHARED "${THIRD_PARTY}/jsi/jsi.cpp")
43
+ target_include_directories(jsi PUBLIC "${THIRD_PARTY}/jsi/include")
44
+ add_library(app SHARED ${SOURCES})
45
+ else()
46
+ add_executable(app src/main.cpp src/attach.cpp "${THIRD_PARTY}/jsi/jsi.cpp" ${SOURCES})
47
+ endif()
48
+
49
+ set_target_properties(app PROPERTIES OUTPUT_NAME "${CROSSBIND_APP_FILE}")
50
+ # Only a debug host opens the page of a dev server.
51
+ target_compile_definitions(app PRIVATE "$<$<CONFIG:Debug>:CROSSBIND_APP_DEV>")
52
+
53
+ target_include_directories(app PRIVATE
54
+ src
55
+ "${CROSSBIND_HERMES}/include"
56
+ "${CROSSBIND_JSI_ROOT}/cpp/src"
57
+ "${THIRD_PARTY}/webview/core/include")
58
+ if(APPLE)
59
+ set_source_files_properties(${PLATFORM_SOURCES} PROPERTIES COMPILE_OPTIONS -fobjc-arc)
60
+ endif()
61
+ if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
62
+ return()
63
+ endif()
64
+
65
+ target_link_libraries(app PRIVATE ${CROSSBIND_LINK_ARGS})
66
+ # A force-loaded archive reaches the link as a linker flag, which CMake does not track: without this, a rebuilt bridge
67
+ # archive would leave the previous host in place.
68
+ set_property(TARGET app APPEND PROPERTY LINK_DEPENDS ${CROSSBIND_LINK_DEPENDS})
69
+
70
+ if(APPLE)
71
+ # Hermes is a framework the app bundle carries next to the executable. Only what main() and the bindings' static
72
+ # initializers reach stays, without the local symbols of a release build.
73
+ target_link_options(app PRIVATE "-F${CROSSBIND_HERMES}/Library/Frameworks/macosx" "LINKER:-rpath,@executable_path/../Frameworks"
74
+ "LINKER:-dead_strip" "$<$<CONFIG:Release>:LINKER:-x>")
75
+ target_link_libraries(app PRIVATE "-framework hermesvm" "-framework WebKit" "-framework Cocoa")
76
+ elseif(ANDROID)
77
+ # Hermes comes with the app from its own package; the C++ runtime the host shares with it is this NDK's, which goes
78
+ # beside the host, stripped.
79
+ target_link_libraries(app PRIVATE jsi "${CROSSBIND_HERMES}/libs/android.${ANDROID_ABI}/libhermesvm.so" log)
80
+ target_link_options(app PRIVATE "LINKER:--gc-sections" "$<$<CONFIG:Release>:LINKER:-s>")
81
+ target_link_options(jsi PRIVATE "$<$<CONFIG:Release>:LINKER:-s>")
82
+ add_custom_command(TARGET app POST_BUILD
83
+ COMMAND "${CMAKE_STRIP}" -o "$<TARGET_FILE_DIR:app>/libc++_shared.so"
84
+ "${CMAKE_SYSROOT}/usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/libc++_shared.so")
85
+ elseif(WIN32)
86
+ # A window app, linked whole: the system's UCRT is all it loads beside WebView2, which webview finds itself, so no
87
+ # loader DLL ships. WebView2's headers come from crossbind's windows image.
88
+ target_include_directories(app SYSTEM PRIVATE "${CROSSBIND_WEBVIEW2_INCLUDE}")
89
+ target_link_libraries(app PRIVATE "${CROSSBIND_HERMES}/lib/libhermesvm_a.a"
90
+ ole32 oleaut32 uuid shell32 shlwapi user32 gdi32 advapi32 version dwmapi winmm)
91
+ set_target_properties(app PROPERTIES WIN32_EXECUTABLE ON)
92
+ target_link_options(app PRIVATE -static "LINKER:--gc-sections" "$<$<CONFIG:Release>:LINKER:-s>")
93
+ else()
94
+ # WebKitGTK comes from the Ubuntu 22.04 packages crossbind downloads: its headers are searched after the C library's,
95
+ # which the image's glibc 2.28 sysroot keeps, and its libraries are only linked against, as the system's load at run
96
+ # time.
97
+ set(GTK_LIB "${CROSSBIND_GTK_SYSROOT}/usr/lib/${CROSSBIND_GTK_MULTIARCH}")
98
+ foreach(dir webkitgtk-4.1 libsoup-3.0 gtk-3.0 at-spi2-atk/2.0 at-spi-2.0 dbus-1.0 gio-unix-2.0 cairo pango-1.0 harfbuzz
99
+ fribidi atk-1.0 pixman-1 uuid freetype2 gdk-pixbuf-2.0 libpng16 libmount blkid glib-2.0)
100
+ target_include_directories(app SYSTEM PRIVATE "${CROSSBIND_GTK_SYSROOT}/usr/include/${dir}")
101
+ endforeach()
102
+ target_include_directories(app SYSTEM PRIVATE "${GTK_LIB}/glib-2.0/include" "${GTK_LIB}/dbus-1.0/include")
103
+ target_compile_options(app PRIVATE "SHELL:-idirafter ${CROSSBIND_GTK_SYSROOT}/usr/include")
104
+ target_link_directories(app PRIVATE "${GTK_LIB}")
105
+ target_link_libraries(app PRIVATE "${CROSSBIND_HERMES}/lib/libhermesvm_a.a" "${CROSSBIND_HERMES}/lib/libboost_context.a"
106
+ -Wl,--as-needed webkit2gtk-4.1 javascriptcoregtk-4.1 soup-3.0 gtk-3 gdk-3 gio-2.0 gobject-2.0 glib-2.0 pthread dl)
107
+ # The static libc++ stays inside: WebKitGTK loads the system's libstdc++, which must not bind to it.
108
+ target_link_options(app PRIVATE "LINKER:--allow-shlib-undefined" "LINKER:--exclude-libs,ALL" "LINKER:--gc-sections"
109
+ "$<$<CONFIG:Release>:LINKER:-s>")
110
+ endif()
@@ -0,0 +1,167 @@
1
+ // An Android app's native half: the module in Hermes behind JNI. The activity hands in the page's calls, each under an
2
+ // id of its own, and the requests for the page's files; the answers go back through CrossbindActivity's static
3
+ // callbacks, from whichever thread gives them.
4
+ #include <android/log.h>
5
+ #include <jni.h>
6
+ #include <unistd.h>
7
+
8
+ #include "app.h"
9
+
10
+ #include <cstdio>
11
+ #include <cstdlib>
12
+ #include <future>
13
+ #include <thread>
14
+
15
+ namespace {
16
+
17
+ namespace app = crossbind::app;
18
+
19
+ constexpr const char *TAG = "Crossbind";
20
+
21
+ JavaVM *vm;
22
+ jclass activityClass;
23
+ jmethodID onReply;
24
+ jmethodID onReplyBytes;
25
+ std::string resources;
26
+ app::Core *core;
27
+
28
+ JNIEnv *attachedEnv() {
29
+ JNIEnv *env = nullptr;
30
+ if (vm->GetEnv(reinterpret_cast<void **>(&env), JNI_VERSION_1_6) == JNI_EDETACHED) vm->AttachCurrentThread(&env, nullptr);
31
+ return env;
32
+ }
33
+
34
+ // An exception the activity threw is left behind, as the thread goes on making JNI calls.
35
+ void clearException(JNIEnv *env) {
36
+ if (!env->ExceptionCheck()) return;
37
+ env->ExceptionDescribe();
38
+ env->ExceptionClear();
39
+ }
40
+
41
+ void answer(jint call, bool ok, const std::string &text) {
42
+ JNIEnv *env = attachedEnv();
43
+ jbyteArray bytes = env->NewByteArray(static_cast<jsize>(text.size()));
44
+ env->SetByteArrayRegion(bytes, 0, static_cast<jsize>(text.size()), reinterpret_cast<const jbyte *>(text.data()));
45
+ env->CallStaticVoidMethod(activityClass, onReply, call, static_cast<jboolean>(ok), bytes);
46
+ clearException(env);
47
+ env->DeleteLocalRef(bytes);
48
+ }
49
+
50
+ // A result's bytes go after four the activity fills with the page's id, so the page gets one ArrayBuffer per answer.
51
+ void answerBytes(jint call, const std::vector<uint8_t> &body) {
52
+ JNIEnv *env = attachedEnv();
53
+ jbyteArray framed = env->NewByteArray(static_cast<jsize>(body.size() + 4));
54
+ env->SetByteArrayRegion(framed, 4, static_cast<jsize>(body.size()), reinterpret_cast<const jbyte *>(body.data()));
55
+ env->CallStaticVoidMethod(activityClass, onReplyBytes, call, framed);
56
+ clearException(env);
57
+ env->DeleteLocalRef(framed);
58
+ }
59
+
60
+ // Queries are ASCII, which modified UTF-8 leaves alone; page text and paths arrive as UTF-8 bytes instead.
61
+ std::string asciiOf(JNIEnv *env, jstring value) {
62
+ const char *chars = env->GetStringUTFChars(value, nullptr);
63
+ std::string text(chars);
64
+ env->ReleaseStringUTFChars(value, chars);
65
+ return text;
66
+ }
67
+
68
+ std::string textOf(JNIEnv *env, jbyteArray value) {
69
+ std::string text(static_cast<size_t>(env->GetArrayLength(value)), '\0');
70
+ env->GetByteArrayRegion(value, 0, static_cast<jsize>(text.size()), reinterpret_cast<jbyte *>(text.data()));
71
+ return text;
72
+ }
73
+
74
+ // Android drops what a process writes to its standard output and error: the lines go to logcat instead, as an app's
75
+ // output goes to the terminal on the desktop. The WebView's Chromium runs in the process too, and logs its own lines,
76
+ // as "[...:ERROR:file.cc(12)] ...", to logcat as well, so those are left out.
77
+ void forward(int fd, int priority) {
78
+ int fds[2];
79
+ if (pipe(fds) != 0) return;
80
+ dup2(fds[1], fd);
81
+ std::thread([from = fds[0], priority] {
82
+ char buffer[1024];
83
+ std::string line;
84
+ for (ssize_t n; (n = read(from, buffer, sizeof buffer)) > 0;) {
85
+ for (ssize_t i = 0; i < n; i += 1) {
86
+ if (buffer[i] != '\n') {
87
+ line += buffer[i];
88
+ continue;
89
+ }
90
+ if (line.rfind('[', 0) != 0 || line.find(".cc(") == std::string::npos) __android_log_write(priority, TAG, line.c_str());
91
+ line.clear();
92
+ }
93
+ }
94
+ }).detach();
95
+ }
96
+
97
+ } // namespace
98
+
99
+ std::string resourceDir() { return resources; }
100
+
101
+ extern "C" JNIEXPORT jint JNI_OnLoad(JavaVM *jvm, void *) {
102
+ vm = jvm;
103
+ forward(STDOUT_FILENO, ANDROID_LOG_INFO);
104
+ forward(STDERR_FILENO, ANDROID_LOG_WARN);
105
+ // Into a pipe, printf's lines would wait in a full buffer.
106
+ setvbuf(stdout, nullptr, _IOLBF, 0);
107
+ return JNI_VERSION_1_6;
108
+ }
109
+
110
+ // Starts the module once per process; a new activity of the same process gets the module it left, which its first page
111
+ // frees of the old page's objects. Returns the page's token and the dev server's page a debug host opens, or "".
112
+ extern "C" JNIEXPORT jobjectArray JNICALL Java_dev_crossbind_app_CrossbindActivity_nativeStart(JNIEnv *env, jclass type,
113
+ jstring files, jstring url) {
114
+ if (!core) {
115
+ activityClass = static_cast<jclass>(env->NewGlobalRef(type));
116
+ onReply = env->GetStaticMethodID(type, "onReply", "(IZ[B)V");
117
+ onReplyBytes = env->GetStaticMethodID(type, "onReplyBytes", "(I[B)V");
118
+ resources = asciiOf(env, files);
119
+ if (url) setenv("CROSSBIND_APP_URL", asciiOf(env, url).c_str(), 1);
120
+ core = &app::start(app::devUrl());
121
+ }
122
+ const char *devUrl = app::devUrl();
123
+ jobjectArray started = env->NewObjectArray(2, env->FindClass("java/lang/String"), nullptr);
124
+ env->SetObjectArrayElement(started, 0, env->NewStringUTF(core->token().c_str()));
125
+ env->SetObjectArrayElement(started, 1, env->NewStringUTF(devUrl ? devUrl : ""));
126
+ return started;
127
+ }
128
+
129
+ extern "C" JNIEXPORT void JNICALL Java_dev_crossbind_app_CrossbindActivity_nativeMessage(JNIEnv *env, jclass, jint call,
130
+ jbyteArray text) {
131
+ core->receive(textOf(env, text), [call](const std::string &reply) { answer(call, true, reply); });
132
+ }
133
+
134
+ // The byte arrays of one message, answered as a crossbind:// POST to /b/frame is on the other platforms.
135
+ extern "C" JNIEXPORT void JNICALL Java_dev_crossbind_app_CrossbindActivity_nativeFrame(JNIEnv *env, jclass, jint call, jstring query,
136
+ jbyteArray frame, jint bodyOffset) {
137
+ std::vector<uint8_t> body(static_cast<size_t>(env->GetArrayLength(frame) - bodyOffset));
138
+ env->GetByteArrayRegion(frame, bodyOffset, static_cast<jsize>(body.size()), reinterpret_cast<jbyte *>(body.data()));
139
+ core->serve(SchemeRequest{"POST", "/b/frame", asciiOf(env, query), std::move(body)}, [call](SchemeResponse response) {
140
+ answer(call, response.status == 200, std::string(response.body.begin(), response.body.end()));
141
+ });
142
+ }
143
+
144
+ extern "C" JNIEXPORT void JNICALL Java_dev_crossbind_app_CrossbindActivity_nativeResult(JNIEnv *env, jclass, jint call, jstring query) {
145
+ core->serve(SchemeRequest{"GET", "/b/result", asciiOf(env, query), {}}, [call](SchemeResponse response) {
146
+ if (response.status == 200) answerBytes(call, response.body);
147
+ else answer(call, false, std::string(response.body.begin(), response.body.end()));
148
+ });
149
+ }
150
+
151
+ // A file of the page: "<status> <mime>\n" and the body.
152
+ extern "C" JNIEXPORT jbyteArray JNICALL Java_dev_crossbind_app_CrossbindActivity_nativeRequest(JNIEnv *env, jclass, jbyteArray path,
153
+ jstring query) {
154
+ std::promise<SchemeResponse> answered;
155
+ core->serve(SchemeRequest{"GET", textOf(env, path), asciiOf(env, query), {}},
156
+ [&answered](SchemeResponse response) { answered.set_value(std::move(response)); });
157
+ const SchemeResponse response = answered.get_future().get();
158
+ const std::string head = std::to_string(response.status) + " " + response.mime + "\n";
159
+ jbyteArray out = env->NewByteArray(static_cast<jsize>(head.size() + response.body.size()));
160
+ env->SetByteArrayRegion(out, 0, static_cast<jsize>(head.size()), reinterpret_cast<const jbyte *>(head.data()));
161
+ env->SetByteArrayRegion(out, static_cast<jsize>(head.size()), static_cast<jsize>(response.body.size()),
162
+ reinterpret_cast<const jbyte *>(response.body.data()));
163
+ return out;
164
+ }
165
+
166
+ // A new page replaced the one that held the module's objects.
167
+ extern "C" JNIEXPORT void JNICALL Java_dev_crossbind_app_CrossbindActivity_nativeNewPage(JNIEnv *, jclass) { core->reset(); }