GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — swingwebview/run-linux-popup-demo.sh at master · webliteca/swingwebview

Expand file tree

/

run-linux-popup-demo.sh

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
executable file
·
198 lines (185 loc) · 7.68 KB
/

run-linux-popup-demo.sh

Copy path

File metadata and controls

executable file
·
198 lines (185 loc) · 7.68 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/bin/bash
# One-shot script: build the Linux native lib, build WebView.jar, compile
# and run the browser-initiated popup demo (WebViewPopupDemo).
#
# Exercises window.open(url, name, features) and <a target="_blank"> across
# three handler modes (Default = allow, Custom = allow + log
# popupOpened/popupClosed, Block = setPopupHandler(null) => window.open
# returns null). See demos/WebViewPopupDemo/README.md for the AC-mapped
# manual test checklist (allow, opener linkage, notifications, requested
# size, block, window.close()).
#
# On Linux the allowed popup is created from WebKitGTK's "create" signal and
# hosted in a native GTK top-level window linked to the opener; window.close()
# fires the child's "close" signal, which tears the popup window down.
#
# NOTE: this builds libwebview.so WITHOUT linking WebKitGTK/JavaScriptCore
# (they are dlopen'd at runtime, 4.1 preferred / 4.0 fallback, by
# src_c/webkit_loader.cpp), so it also exercises that runtime-resolution path.
#
# Usage: ./run-linux-popup-demo.sh # lightweight (default)
# ./run-linux-popup-demo.sh heavyweight # force heavyweight mode
# ./run-linux-popup-demo.sh lightweight # force lightweight mode
# WEBVIEW_MODE=heavyweight ./run-linux-popup-demo.sh
#
# Popups work in BOTH embedding modes on Linux; run the script twice (once
# per mode) to cover the full matrix.
#
# Override JDK: JAVA_HOME=/path/to/jdk ./run-linux-popup-demo.sh
#
# Required packages:
# - g++, pkg-config
# - libgtk-3-dev
# - libwebkit2gtk-4.1-dev (Ubuntu 24.04+) or libwebkit2gtk-4.0-dev (older)
# - libx11-dev
# - libxt-dev <-- pulled in because JDK 8's jawt_md.h includes X11/Intrinsic.h
set -e
set -o pipefail
REPO_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$REPO_DIR"
# ---------------------------------------------------------------------------
# 0. Mode selection
# ---------------------------------------------------------------------------
MODE="${1:-${WEBVIEW_MODE:-lightweight}}"
case "$MODE" in
heavyweight|lightweight) ;;
*)
echo "Unknown mode: $MODE" >&2
echo "Usage: $0 [heavyweight|lightweight]" >&2
exit 1
;;
esac
echo "Mode: $MODE"
# ---------------------------------------------------------------------------
# 1. Resolve JAVA_HOME
# ---------------------------------------------------------------------------
if [ -z "$JAVA_HOME" ]; then
if command -v javac >/dev/null 2>&1; then
JAVAC_PATH="$(readlink -f "$(command -v javac)" 2>/dev/null || command -v javac)"
JAVA_HOME="$(dirname "$(dirname "$JAVAC_PATH")")"
fi
fi
if [ -z "$JAVA_HOME" ] || [ ! -d "$JAVA_HOME" ]; then
echo "JAVA_HOME is not set and could not be resolved automatically." >&2
echo "Install a JDK and export JAVA_HOME, e.g. via mise / asdf:" >&2
echo " mise install # picks up .tool-versions" >&2
exit 1
fi
export JAVA_HOME
echo "Using JAVA_HOME=$JAVA_HOME"
JAVAC="$JAVA_HOME/bin/javac"
JAVA="$JAVA_HOME/bin/java"
JAR="$JAVA_HOME/bin/jar"
for tool in "$JAVAC" "$JAVA" "$JAR"; do
if [ ! -x "$tool" ]; then
echo "Missing tool: $tool" >&2; exit 1
fi
done
# ---------------------------------------------------------------------------
# 2. Pick a WebKit pkg-config name (for HEADERS only; not linked)
# ---------------------------------------------------------------------------
if pkg-config --exists webkit2gtk-4.1; then
WEBKIT_PKG=webkit2gtk-4.1
elif pkg-config --exists webkit2gtk-4.0; then
WEBKIT_PKG=webkit2gtk-4.0
else
echo "Neither webkit2gtk-4.1 nor webkit2gtk-4.0 was found via pkg-config." >&2
echo "Install one of the following with your package manager:" >&2
echo " Debian/Ubuntu 24.04+: sudo apt install libgtk-3-dev libwebkit2gtk-4.1-dev libx11-dev libxt-dev" >&2
echo " Debian/Ubuntu older: sudo apt install libgtk-3-dev libwebkit2gtk-4.0-dev libx11-dev libxt-dev" >&2
echo " Fedora: sudo dnf install gtk3-devel webkit2gtk4.1-devel libX11-devel libXt-devel" >&2
exit 1
fi
if ! pkg-config --exists gtk+-3.0; then
echo "gtk+-3.0 (libgtk-3-dev) is required." >&2
exit 1
fi
echo "Using WebKit package (headers only): $WEBKIT_PKG"
if ! printf '#include <X11/Intrinsic.h>\nint main(){return 0;}\n' | \
g++ -E -x c++ - >/dev/null 2>&1; then
echo "" >&2
echo "ERROR: <X11/Intrinsic.h> not found." >&2
echo "" >&2
echo "JDK 8 on Linux pulls X11 Intrinsics in via jawt_md.h. Install:" >&2
echo " Debian/Ubuntu: sudo apt install libxt-dev" >&2
echo " Fedora: sudo dnf install libXt-devel" >&2
echo " Arch: sudo pacman -S libxt" >&2
echo "" >&2
exit 1
fi
# ---------------------------------------------------------------------------
# 3. Build libwebview.so for the current arch
# ---------------------------------------------------------------------------
case "$(uname -m)" in
x86_64|amd64) NATIVE_DIR=linux_64 ;;
aarch64|arm64) NATIVE_DIR=linux_arm64 ;;
armv7l|armv7) NATIVE_DIR=linux_arm ;;
i?86) NATIVE_DIR=linux_32 ;;
*) NATIVE_DIR=linux_64 ;;
esac
echo "Native dir: $NATIVE_DIR (arch: $(uname -m))"
mkdir -p "$REPO_DIR/src/$NATIVE_DIR"
SO="$REPO_DIR/src/$NATIVE_DIR/libwebview.so"
NEED_SO=0
if [ ! -f "$SO" ]; then
NEED_SO=1
else
for src in src_c/webview.c src_c/webview.h src_c/webview_embed.cpp src_c/webkit_loader.cpp src_c/webkit_loader.h src_c/webkit_shim.h; do
if [ "$src" -nt "$SO" ]; then NEED_SO=1; break; fi
done
fi
if [ "$NEED_SO" = "1" ]; then
echo "Building libwebview.so ..."
g++ -fPIC -std=c++11 -Wall \
-DWEBVIEW_GTK=1 \
-I"$JAVA_HOME/include" -I"$JAVA_HOME/include/linux" \
-I./src_c \
$(pkg-config --cflags gtk+-3.0 "$WEBKIT_PKG") \
src_c/webview.c src_c/webview_embed.cpp src_c/webkit_loader.cpp \
$(pkg-config --libs gtk+-3.0) \
-lX11 -ldl \
-shared -o "$SO"
echo "Built $SO"
else
echo "libwebview.so up to date."
fi
# ---------------------------------------------------------------------------
# 4. Compile WebView Java sources
# ---------------------------------------------------------------------------
BUILD_DIR="$REPO_DIR/build"
WV_CLASSES="$BUILD_DIR/classes-webview"
WV_JAR="$REPO_DIR/dist/WebView.jar"
mkdir -p "$WV_CLASSES" "$REPO_DIR/dist"
echo "Compiling WebView Java sources ..."
find src -name '*.java' > "$BUILD_DIR/wv-sources.txt"
"$JAVAC" -d "$WV_CLASSES" -classpath "lib/*" @"$BUILD_DIR/wv-sources.txt"
# ---------------------------------------------------------------------------
# 5. Build WebView.jar -- classes + linux_*/libwebview.so at jar root
# ---------------------------------------------------------------------------
echo "Building WebView.jar ..."
STAGE="$BUILD_DIR/stage-webview"
rm -rf "$STAGE"
mkdir -p "$STAGE/$NATIVE_DIR"
cp -R "$WV_CLASSES"/. "$STAGE"/
cp "$SO" "$STAGE/$NATIVE_DIR/libwebview.so"
( cd "$STAGE" && "$JAR" cf "$WV_JAR" . )
echo "Built $WV_JAR"
# ---------------------------------------------------------------------------
# 6. Compile and run the popup demo
# ---------------------------------------------------------------------------
DEMO_DIR="$REPO_DIR/demos/WebViewPopupDemo"
DEMO_CLASSES="$BUILD_DIR/classes-popup-demo"
mkdir -p "$DEMO_CLASSES"
echo "Compiling demo ..."
"$JAVAC" -d "$DEMO_CLASSES" -classpath "$WV_JAR" \
"$DEMO_DIR/src/ca/weblite/webview/demos/WebViewPopupDemo.java"
echo "Launching WebViewPopupDemo (mode=$MODE) ..."
# Force the X11 GDK backend; embedding via XReparentWindow needs a real X11
# GdkDisplay on both sides.
export GDK_BACKEND=x11
export WEBKIT_DISABLE_DMABUF_RENDERER=1
export WEBKIT_DISABLE_SANDBOX_THIS_IS_DANGEROUS=1
exec "$JAVA" \
"-Dca.weblite.webview.mode=$MODE" \
-cp "$DEMO_CLASSES:$WV_JAR" \
ca.weblite.webview.demos.WebViewPopupDemo
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.