@native-sdk/cli 0.4.2 → 0.4.4
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.
- package/build/app.zig +121 -66
- package/build.zig +123 -6
- package/package.json +9 -9
- package/skill-data/core/SKILL.md +3 -0
- package/skill-data/native-ui/SKILL.md +16 -0
- package/skill-data/zig/SKILL.md +198 -0
- package/skills/native-sdk/SKILL.md +1 -1
- package/src/app_runner/root.zig +51 -9
- package/src/platform/linux/gtk_host.c +226 -21
- package/src/platform/windows/webview2_host.cpp +16 -10
- package/src/primitives/app_manifest/root.zig +8 -0
- package/src/primitives/app_manifest/types.zig +14 -0
- package/src/primitives/app_manifest/validation.zig +18 -0
- package/src/primitives/app_manifest/web_layer.zig +366 -0
- package/src/primitives/canvas/chart_tests.zig +2 -2
- package/src/primitives/canvas/markdown_tests.zig +1 -1
- package/src/primitives/canvas/reference.zig +135 -6
- package/src/primitives/canvas/reference_tests.zig +171 -6
- package/src/primitives/canvas/root.zig +3 -0
- package/src/primitives/canvas/test_support.zig +3 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +249 -4
- package/src/primitives/canvas/widget_render_controls.zig +18 -1
- package/src/primitives/canvas/widget_runtime.zig +3 -0
- package/src/primitives/canvas/widget_text_input.zig +104 -1
- package/src/runtime/api.zig +7 -0
- package/src/runtime/bridge_responses.zig +2 -0
- package/src/runtime/builtin_bridge.zig +6 -0
- package/src/runtime/canvas_widget_runtime.zig +23 -3
- package/src/runtime/canvas_widget_text_tests.zig +101 -0
- package/src/runtime/flow.zig +8 -0
- package/src/runtime/platform_bridge_tests.zig +1 -0
- package/src/runtime/session_tests.zig +35 -8
- package/src/runtime/view.zig +1 -1
- package/src/runtime/view_widget_scroll.zig +12 -1
- package/src/runtime/view_widget_text.zig +6 -2
- package/src/runtime/web_layer_gate_tests.zig +242 -0
- package/src/runtime/window_storage.zig +5 -0
- package/src/runtime/window_view_runtime.zig +1 -0
- package/src/tooling/buildgraph.zig +119 -3
- package/src/tooling/junction.zig +247 -0
- package/src/tooling/manifest.zig +267 -1
- package/src/tooling/package.zig +598 -6
- package/src/tooling/raw_manifest.zig +1 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +288 -61
- package/src/tooling/verbs.zig +5 -0
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
#include "gtk_host.h"
|
|
2
2
|
|
|
3
3
|
#include <gtk/gtk.h>
|
|
4
|
-
#include <webkit/webkit.h>
|
|
5
4
|
#include <glib/gstdio.h>
|
|
6
5
|
#include <dlfcn.h>
|
|
7
6
|
#include <limits.h>
|
|
@@ -11,6 +10,39 @@
|
|
|
11
10
|
#include <stdlib.h>
|
|
12
11
|
#include <stdio.h>
|
|
13
12
|
|
|
13
|
+
/* NATIVE_SDK_ALLOW_WEBKITGTK_STUB is the build graph's declaration that
|
|
14
|
+
* this app uses no web layer, and it wins over header visibility: on a
|
|
15
|
+
* machine with the WebKitGTK development package installed, testing
|
|
16
|
+
* __has_include first would compile the full embedded-web layer into a
|
|
17
|
+
* native-only build and reintroduce the libwebkitgtk link its executable
|
|
18
|
+
* must not carry (canvas apps are unaffected by the stub). Without the
|
|
19
|
+
* define the header is required: every web-declaring build graph links
|
|
20
|
+
* webkitgtk-6.0 (whose pkg-config flags provide the include path), so a
|
|
21
|
+
* web build that cannot see it is misconfigured — fail it loudly instead
|
|
22
|
+
* of shipping a host whose WebView loads report WebViewNotFound at
|
|
23
|
+
* runtime. The same seam as the Windows host's
|
|
24
|
+
* NATIVE_SDK_ALLOW_WEBVIEW2_STUB. */
|
|
25
|
+
#if defined(NATIVE_SDK_ALLOW_WEBKITGTK_STUB)
|
|
26
|
+
#define NATIVE_SDK_HAS_WEBKITGTK 0
|
|
27
|
+
#pragma message("Embedded web layer excluded by the build configuration: building the GTK host without WebKitGTK (canvas apps unaffected; WebView loads will report WebViewNotFound)")
|
|
28
|
+
/* The stubbed web layer keeps the window/webview bookkeeping SHAPE so
|
|
29
|
+
* every GTK-only path (overlay reordering, focus lookups, window
|
|
30
|
+
* teardown) compiles unchanged: the web-view pointers below are opaque
|
|
31
|
+
* and permanently NULL — every path that could create one is compiled
|
|
32
|
+
* out — so the NULL checks that already guard the lazy main WebView
|
|
33
|
+
* also guard the compiled-out layer. These are LOCAL opaque types, not
|
|
34
|
+
* WebKitGTK declarations: no header, no webkit_* symbol, and no
|
|
35
|
+
* libwebkitgtk DT_NEEDED entry survives into the binary
|
|
36
|
+
* (tools/audit_web_layer.zig pins that on the built executable). */
|
|
37
|
+
typedef struct native_sdk_absent_web_view WebKitWebView;
|
|
38
|
+
typedef struct native_sdk_absent_content_manager WebKitUserContentManager;
|
|
39
|
+
#elif __has_include(<webkit/webkit.h>)
|
|
40
|
+
#include <webkit/webkit.h>
|
|
41
|
+
#define NATIVE_SDK_HAS_WEBKITGTK 1
|
|
42
|
+
#else
|
|
43
|
+
#error "webkit/webkit.h not found: install the WebKitGTK 6.0 development package (libwebkitgtk-6.0-dev on Debian/Ubuntu), or define NATIVE_SDK_ALLOW_WEBKITGTK_STUB to build without the embedded web layer"
|
|
44
|
+
#endif
|
|
45
|
+
|
|
14
46
|
#define NATIVE_SDK_MAX_WINDOWS 16
|
|
15
47
|
#define NATIVE_SDK_MAX_WEBVIEWS 16
|
|
16
48
|
#define NATIVE_SDK_MAX_TIMERS 64
|
|
@@ -405,6 +437,7 @@ static void native_sdk_clear_window_source(native_sdk_gtk_window_t *win) {
|
|
|
405
437
|
win->spa_fallback = 0;
|
|
406
438
|
}
|
|
407
439
|
|
|
440
|
+
#if NATIVE_SDK_HAS_WEBKITGTK
|
|
408
441
|
static int native_sdk_strings_equal(const char *a, const char *b) {
|
|
409
442
|
return a && b && strcmp(a, b) == 0;
|
|
410
443
|
}
|
|
@@ -484,6 +517,7 @@ static void native_sdk_apply_webview_frame(native_sdk_gtk_webview_t *webview) {
|
|
|
484
517
|
gtk_widget_set_margin_top(widget, native_sdk_webview_coord(webview->y));
|
|
485
518
|
gtk_widget_set_size_request(widget, native_sdk_webview_extent(webview->width), native_sdk_webview_extent(webview->height));
|
|
486
519
|
}
|
|
520
|
+
#endif /* NATIVE_SDK_HAS_WEBKITGTK */
|
|
487
521
|
|
|
488
522
|
static int native_sdk_valid_native_view_frame(double x, double y, double width, double height) {
|
|
489
523
|
return x >= 0 && y >= 0 && width >= 0 && height >= 0;
|
|
@@ -1622,6 +1656,7 @@ static int native_sdk_policy_list_matches(char **values, int count, const char *
|
|
|
1622
1656
|
return matched;
|
|
1623
1657
|
}
|
|
1624
1658
|
|
|
1659
|
+
#if NATIVE_SDK_HAS_WEBKITGTK
|
|
1625
1660
|
static int native_sdk_path_is_safe(const char *path) {
|
|
1626
1661
|
if (!path || !path[0]) return 0;
|
|
1627
1662
|
if (path[0] == '/' || strchr(path, '\\')) return 0;
|
|
@@ -1882,6 +1917,7 @@ static void native_sdk_asset_scheme_request(WebKitURISchemeRequest *request, gpo
|
|
|
1882
1917
|
g_free(path);
|
|
1883
1918
|
g_free(relative);
|
|
1884
1919
|
}
|
|
1920
|
+
#endif /* NATIVE_SDK_HAS_WEBKITGTK */
|
|
1885
1921
|
|
|
1886
1922
|
static native_sdk_gtk_window_t *native_sdk_find_window(native_sdk_gtk_host_t *host, uint64_t id) {
|
|
1887
1923
|
for (int i = 0; i < host->window_count; i++) {
|
|
@@ -2385,6 +2421,7 @@ static gboolean on_close_request(GtkWindow *window, gpointer data) {
|
|
|
2385
2421
|
return FALSE;
|
|
2386
2422
|
}
|
|
2387
2423
|
|
|
2424
|
+
#if NATIVE_SDK_HAS_WEBKITGTK
|
|
2388
2425
|
static const char *native_sdk_decision_uri(WebKitPolicyDecision *decision, WebKitPolicyDecisionType type) {
|
|
2389
2426
|
if (type != WEBKIT_POLICY_DECISION_TYPE_NAVIGATION_ACTION) return NULL;
|
|
2390
2427
|
WebKitNavigationPolicyDecision *navigation = WEBKIT_NAVIGATION_POLICY_DECISION(decision);
|
|
@@ -2392,6 +2429,7 @@ static const char *native_sdk_decision_uri(WebKitPolicyDecision *decision, WebKi
|
|
|
2392
2429
|
WebKitURIRequest *request = action ? webkit_navigation_action_get_request(action) : NULL;
|
|
2393
2430
|
return request ? webkit_uri_request_get_uri(request) : NULL;
|
|
2394
2431
|
}
|
|
2432
|
+
#endif /* NATIVE_SDK_HAS_WEBKITGTK */
|
|
2395
2433
|
|
|
2396
2434
|
#if GTK_CHECK_VERSION(4, 10, 0)
|
|
2397
2435
|
static void native_sdk_uri_launch_done(GObject *source_object, GAsyncResult *result, gpointer data) {
|
|
@@ -2417,6 +2455,7 @@ static void native_sdk_open_external_uri(GtkWindow *parent, const char *uri) {
|
|
|
2417
2455
|
#endif
|
|
2418
2456
|
}
|
|
2419
2457
|
|
|
2458
|
+
#if NATIVE_SDK_HAS_WEBKITGTK
|
|
2420
2459
|
static gboolean on_decide_policy(WebKitWebView *web_view, WebKitPolicyDecision *decision, WebKitPolicyDecisionType type, gpointer data) {
|
|
2421
2460
|
(void)web_view;
|
|
2422
2461
|
native_sdk_gtk_window_t *win = data;
|
|
@@ -2487,7 +2526,11 @@ static void on_bridge_message(WebKitUserContentManager *manager, JSCValue *js_re
|
|
|
2487
2526
|
}
|
|
2488
2527
|
}
|
|
2489
2528
|
}
|
|
2490
|
-
|
|
2529
|
+
/* source_webview is NULL only if the sending manager matched nothing
|
|
2530
|
+
* (a message can only originate from a WebView this host created, so
|
|
2531
|
+
* this is belt-and-braces); origin_for_uri already maps NULL to the
|
|
2532
|
+
* inline origin. */
|
|
2533
|
+
const char *uri = source_webview ? webkit_web_view_get_uri(source_webview) : NULL;
|
|
2491
2534
|
char *computed_origin = win->bridge_origin && strcmp(label, "main") == 0 ? g_strdup(win->bridge_origin) : native_sdk_origin_for_uri(uri);
|
|
2492
2535
|
host->bridge_callback(host->bridge_context, win->id, label, strlen(label), message, strlen(message), computed_origin, strlen(computed_origin));
|
|
2493
2536
|
g_free(computed_origin);
|
|
@@ -2508,6 +2551,52 @@ static void native_sdk_setup_bridge(native_sdk_gtk_window_t *win) {
|
|
|
2508
2551
|
webkit_user_script_unref(script);
|
|
2509
2552
|
}
|
|
2510
2553
|
|
|
2554
|
+
/* The zero:// custom scheme lives on the WebKitWebContext (every WebView
|
|
2555
|
+
* this host creates shares the default context) and WebKit aborts on a
|
|
2556
|
+
* second registration, so the first WebView actually created — window
|
|
2557
|
+
* main or child, whichever an app reaches first — registers it and the
|
|
2558
|
+
* host-level flag makes every later creation a no-op. */
|
|
2559
|
+
static void native_sdk_register_zero_scheme(native_sdk_gtk_host_t *host, WebKitWebView *web_view) {
|
|
2560
|
+
if (!host || host->scheme_registered || !web_view) return;
|
|
2561
|
+
webkit_web_context_register_uri_scheme(webkit_web_view_get_context(web_view), "zero", native_sdk_asset_scheme_request, host, NULL);
|
|
2562
|
+
host->scheme_registered = 1;
|
|
2563
|
+
}
|
|
2564
|
+
|
|
2565
|
+
/* Create-on-first-use for a window's main WebView (the AppKit host's
|
|
2566
|
+
* ensureMainWebViewForWindowId:). Pure peek reads (event emission,
|
|
2567
|
+
* bridge completion echoes, reorder passes, focus) keep checking
|
|
2568
|
+
* win->web_view and skip absent WebViews — a page that was never created
|
|
2569
|
+
* has no listeners to miss. Paths that MATERIALIZE web content (load,
|
|
2570
|
+
* frame/zoom/layer placement) ensure first, so webview-first apps behave
|
|
2571
|
+
* exactly as before while canvas-first apps never boot the out-of-process
|
|
2572
|
+
* WebKit stack (web + network helper processes) at all. */
|
|
2573
|
+
static WebKitWebView *native_sdk_ensure_main_webview(native_sdk_gtk_window_t *win) {
|
|
2574
|
+
if (!win) return NULL;
|
|
2575
|
+
if (win->web_view) return win->web_view;
|
|
2576
|
+
if (!win->stack_root) return NULL;
|
|
2577
|
+
|
|
2578
|
+
win->content_manager = webkit_user_content_manager_new();
|
|
2579
|
+
WebKitWebView *wv = WEBKIT_WEB_VIEW(
|
|
2580
|
+
g_object_new(WEBKIT_TYPE_WEB_VIEW,
|
|
2581
|
+
"user-content-manager", win->content_manager,
|
|
2582
|
+
NULL));
|
|
2583
|
+
win->web_view = wv;
|
|
2584
|
+
native_sdk_register_zero_scheme(win->host, wv);
|
|
2585
|
+
native_sdk_setup_bridge(win);
|
|
2586
|
+
g_signal_connect(wv, "decide-policy", G_CALLBACK(on_decide_policy), win);
|
|
2587
|
+
|
|
2588
|
+
/* The overlay's main-child slot, where the eager create used to put
|
|
2589
|
+
* it: the overlay allocates its main child the full stack area on the
|
|
2590
|
+
* next layout pass, so materializing into an already-shown window
|
|
2591
|
+
* sizes correctly like any other GTK4 child insertion. The reorder
|
|
2592
|
+
* pass settles the sibling (paint) order among child views exactly
|
|
2593
|
+
* like any other webview mutation. */
|
|
2594
|
+
gtk_overlay_set_child(GTK_OVERLAY(win->stack_root), GTK_WIDGET(wv));
|
|
2595
|
+
native_sdk_reorder_overlays(win);
|
|
2596
|
+
return wv;
|
|
2597
|
+
}
|
|
2598
|
+
#endif /* NATIVE_SDK_HAS_WEBKITGTK */
|
|
2599
|
+
|
|
2511
2600
|
static native_sdk_gtk_window_t *native_sdk_create_window_internal(native_sdk_gtk_host_t *host, uint64_t window_id, const char *title, const char *label, double x, double y, double width, double height, int restore_frame, int resizable, int titlebar_style, double min_width, double min_height) {
|
|
2512
2601
|
if (native_sdk_find_window(host, window_id)) return NULL;
|
|
2513
2602
|
|
|
@@ -2591,18 +2680,11 @@ static native_sdk_gtk_window_t *native_sdk_create_window_internal(native_sdk_gtk
|
|
|
2591
2680
|
g_signal_connect(bar, "map", G_CALLBACK(native_sdk_on_header_bar_mapped), win->host);
|
|
2592
2681
|
}
|
|
2593
2682
|
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
win->web_view = wv;
|
|
2600
|
-
if (!host->scheme_registered) {
|
|
2601
|
-
webkit_web_context_register_uri_scheme(webkit_web_view_get_context(wv), "zero", native_sdk_asset_scheme_request, host, NULL);
|
|
2602
|
-
host->scheme_registered = 1;
|
|
2603
|
-
}
|
|
2604
|
-
native_sdk_setup_bridge(win);
|
|
2605
|
-
|
|
2683
|
+
/* The window's main WebView is NOT created here: it materializes on
|
|
2684
|
+
* first use (native_sdk_ensure_main_webview), because instantiating
|
|
2685
|
+
* a WebKitWebView boots the whole out-of-process WebKit stack — web
|
|
2686
|
+
* and network helper processes — that a canvas-first app would carry
|
|
2687
|
+
* forever under a view it never shows. */
|
|
2606
2688
|
win->root_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
|
|
2607
2689
|
/* Declared content min-size floor: the size request on the content
|
|
2608
2690
|
* box floors user resizes without inflating the default size (the
|
|
@@ -2617,10 +2699,13 @@ static native_sdk_gtk_window_t *native_sdk_create_window_internal(native_sdk_gtk
|
|
|
2617
2699
|
gtk_widget_set_visible(win->menu_bar, host->menu_model != NULL);
|
|
2618
2700
|
gtk_box_append(GTK_BOX(win->root_box), win->menu_bar);
|
|
2619
2701
|
|
|
2702
|
+
/* The overlay expands to fill the window on its own (hexpand/vexpand
|
|
2703
|
+
* on an expanding box slot), so it needs no main child to claim the
|
|
2704
|
+
* stack area — the lazy WebView slots in later without a relayout of
|
|
2705
|
+
* anything else. */
|
|
2620
2706
|
win->stack_root = gtk_overlay_new();
|
|
2621
2707
|
gtk_widget_set_hexpand(win->stack_root, TRUE);
|
|
2622
2708
|
gtk_widget_set_vexpand(win->stack_root, TRUE);
|
|
2623
|
-
gtk_overlay_set_child(GTK_OVERLAY(win->stack_root), GTK_WIDGET(wv));
|
|
2624
2709
|
gtk_box_append(GTK_BOX(win->root_box), win->stack_root);
|
|
2625
2710
|
gtk_window_set_child(win->gtk_window, win->root_box);
|
|
2626
2711
|
native_sdk_install_file_drop_target(win);
|
|
@@ -2629,7 +2714,6 @@ static native_sdk_gtk_window_t *native_sdk_create_window_internal(native_sdk_gtk
|
|
|
2629
2714
|
g_signal_connect(win->gtk_window, "notify::default-height", G_CALLBACK(on_resize), win);
|
|
2630
2715
|
g_signal_connect(win->gtk_window, "notify::is-active", G_CALLBACK(on_focus), win);
|
|
2631
2716
|
g_signal_connect(win->gtk_window, "close-request", G_CALLBACK(on_close_request), win);
|
|
2632
|
-
g_signal_connect(win->web_view, "decide-policy", G_CALLBACK(on_decide_policy), win);
|
|
2633
2717
|
GtkEventController *shortcut_controller = gtk_event_controller_key_new();
|
|
2634
2718
|
gtk_event_controller_set_propagation_phase(shortcut_controller, GTK_PHASE_CAPTURE);
|
|
2635
2719
|
g_signal_connect(shortcut_controller, "key-pressed", G_CALLBACK(on_shortcut_key_pressed), win);
|
|
@@ -2847,8 +2931,31 @@ void native_sdk_gtk_load_webview(native_sdk_gtk_host_t *host, const char *source
|
|
|
2847
2931
|
}
|
|
2848
2932
|
|
|
2849
2933
|
void native_sdk_gtk_load_window_webview(native_sdk_gtk_host_t *host, uint64_t window_id, const char *source, size_t source_len, int source_kind, const char *asset_root, size_t asset_root_len, const char *asset_entry, size_t asset_entry_len, const char *asset_origin, size_t asset_origin_len, int spa_fallback) {
|
|
2934
|
+
#if !NATIVE_SDK_HAS_WEBKITGTK
|
|
2935
|
+
/* Web layer compiled out: the runtime's web-layer gate answers every
|
|
2936
|
+
* webview path with error.WebViewLayerNotBuilt before it can reach
|
|
2937
|
+
* the host, so this stub (like the Windows host's) is belt-and-braces
|
|
2938
|
+
* for a caller that bypassed the gate — a quiet no-op, never a
|
|
2939
|
+
* half-started WebKit stack. */
|
|
2940
|
+
(void)host;
|
|
2941
|
+
(void)window_id;
|
|
2942
|
+
(void)source;
|
|
2943
|
+
(void)source_len;
|
|
2944
|
+
(void)source_kind;
|
|
2945
|
+
(void)asset_root;
|
|
2946
|
+
(void)asset_root_len;
|
|
2947
|
+
(void)asset_entry;
|
|
2948
|
+
(void)asset_entry_len;
|
|
2949
|
+
(void)asset_origin;
|
|
2950
|
+
(void)asset_origin_len;
|
|
2951
|
+
(void)spa_fallback;
|
|
2952
|
+
#else
|
|
2850
2953
|
native_sdk_gtk_window_t *win = native_sdk_find_window(host, window_id);
|
|
2851
|
-
|
|
2954
|
+
/* Loading a source is what materializes the window's lazy main
|
|
2955
|
+
* WebView; the runtime never issues a load for a canvas-first app
|
|
2956
|
+
* with the default empty source (sceneNeedsMainWebView), so a window
|
|
2957
|
+
* that never reaches here never starts WebKit. */
|
|
2958
|
+
if (!win || !native_sdk_ensure_main_webview(win)) return;
|
|
2852
2959
|
|
|
2853
2960
|
char *src = native_sdk_strndup(source, source_len);
|
|
2854
2961
|
if (!src) return;
|
|
@@ -2899,6 +3006,7 @@ void native_sdk_gtk_load_window_webview(native_sdk_gtk_host_t *host, uint64_t wi
|
|
|
2899
3006
|
webkit_web_view_load_html(win->web_view, src, "zero://inline");
|
|
2900
3007
|
}
|
|
2901
3008
|
free(src);
|
|
3009
|
+
#endif
|
|
2902
3010
|
}
|
|
2903
3011
|
|
|
2904
3012
|
void native_sdk_gtk_set_bridge_callback(native_sdk_gtk_host_t *host, native_sdk_gtk_bridge_callback_t callback, void *context) {
|
|
@@ -2915,12 +3023,25 @@ void native_sdk_gtk_bridge_respond_window(native_sdk_gtk_host_t *host, uint64_t
|
|
|
2915
3023
|
}
|
|
2916
3024
|
|
|
2917
3025
|
void native_sdk_gtk_bridge_respond_webview(native_sdk_gtk_host_t *host, uint64_t window_id, const char *webview_label, size_t webview_label_len, const char *response, size_t response_len) {
|
|
3026
|
+
#if !NATIVE_SDK_HAS_WEBKITGTK
|
|
3027
|
+
/* No web layer, no page that could have sent the request. */
|
|
3028
|
+
(void)host;
|
|
3029
|
+
(void)window_id;
|
|
3030
|
+
(void)webview_label;
|
|
3031
|
+
(void)webview_label_len;
|
|
3032
|
+
(void)response;
|
|
3033
|
+
(void)response_len;
|
|
3034
|
+
#else
|
|
2918
3035
|
native_sdk_gtk_window_t *win = native_sdk_find_window(host, window_id);
|
|
2919
|
-
if (!win
|
|
3036
|
+
if (!win) return;
|
|
2920
3037
|
char *label = webview_label_len > 0 ? native_sdk_strndup(webview_label, webview_label_len) : native_sdk_strndup("main", 4);
|
|
2921
3038
|
if (!label) return;
|
|
2922
3039
|
WebKitWebView *target = NULL;
|
|
2923
3040
|
if (strcmp(label, "main") == 0) {
|
|
3041
|
+
/* Peek, never ensure: a completion can only answer a request a
|
|
3042
|
+
* live page sent, so a still-lazy main WebView has nothing to
|
|
3043
|
+
* deliver to (and a child webview's response must not be dropped
|
|
3044
|
+
* just because the window's main WebView never materialized). */
|
|
2924
3045
|
target = win->web_view;
|
|
2925
3046
|
} else {
|
|
2926
3047
|
native_sdk_gtk_webview_t *webview = native_sdk_find_webview(win, label);
|
|
@@ -2945,10 +3066,22 @@ void native_sdk_gtk_bridge_respond_webview(native_sdk_gtk_host_t *host, uint64_t
|
|
|
2945
3066
|
free(script);
|
|
2946
3067
|
}
|
|
2947
3068
|
free(resp);
|
|
3069
|
+
#endif
|
|
2948
3070
|
}
|
|
2949
3071
|
|
|
2950
3072
|
void native_sdk_gtk_emit_window_event(native_sdk_gtk_host_t *host, uint64_t window_id, const char *name, size_t name_len, const char *detail_json, size_t detail_json_len) {
|
|
3073
|
+
#if !NATIVE_SDK_HAS_WEBKITGTK
|
|
3074
|
+
/* No web layer, no page with listeners to miss. */
|
|
3075
|
+
(void)host;
|
|
3076
|
+
(void)window_id;
|
|
3077
|
+
(void)name;
|
|
3078
|
+
(void)name_len;
|
|
3079
|
+
(void)detail_json;
|
|
3080
|
+
(void)detail_json_len;
|
|
3081
|
+
#else
|
|
2951
3082
|
native_sdk_gtk_window_t *win = native_sdk_find_window(host, window_id);
|
|
3083
|
+
/* Peek, never ensure: a still-lazy main WebView has no page and so
|
|
3084
|
+
* no listeners to miss. */
|
|
2952
3085
|
if (!win || !win->web_view) return;
|
|
2953
3086
|
char *event_name = native_sdk_strndup(name, name_len);
|
|
2954
3087
|
char *detail = native_sdk_strndup(detail_json, detail_json_len);
|
|
@@ -2970,6 +3103,7 @@ void native_sdk_gtk_emit_window_event(native_sdk_gtk_host_t *host, uint64_t wind
|
|
|
2970
3103
|
g_string_free(script, TRUE);
|
|
2971
3104
|
free(event_name);
|
|
2972
3105
|
free(detail);
|
|
3106
|
+
#endif
|
|
2973
3107
|
}
|
|
2974
3108
|
|
|
2975
3109
|
void native_sdk_gtk_set_security_policy(native_sdk_gtk_host_t *host, const char *allowed_origins, size_t allowed_origins_len, const char *external_urls, size_t external_urls_len, int external_action) {
|
|
@@ -3538,6 +3672,8 @@ int native_sdk_gtk_focus_view(native_sdk_gtk_host_t *host, uint64_t window_id, c
|
|
|
3538
3672
|
return 0;
|
|
3539
3673
|
}
|
|
3540
3674
|
if (label_copy && strcmp(label_copy, "main") == 0) {
|
|
3675
|
+
/* Peek, never ensure: focusing cannot mean "start a web page",
|
|
3676
|
+
* so a still-lazy main WebView is an honest failure. */
|
|
3541
3677
|
GtkWidget *widget = win->web_view ? GTK_WIDGET(win->web_view) : NULL;
|
|
3542
3678
|
free(label_copy);
|
|
3543
3679
|
if (!widget || !gtk_widget_get_visible(widget) || !gtk_widget_get_sensitive(widget)) return 0;
|
|
@@ -3568,6 +3704,24 @@ int native_sdk_gtk_close_view(native_sdk_gtk_host_t *host, uint64_t window_id, c
|
|
|
3568
3704
|
}
|
|
3569
3705
|
|
|
3570
3706
|
int native_sdk_gtk_create_webview(native_sdk_gtk_host_t *host, uint64_t window_id, const char *label, size_t label_len, const char *url, size_t url_len, double x, double y, double width, double height, int layer, int transparent, int bridge_enabled) {
|
|
3707
|
+
#if !NATIVE_SDK_HAS_WEBKITGTK
|
|
3708
|
+
/* Web layer compiled out: creation honestly fails (the runtime's
|
|
3709
|
+
* gate reports error.WebViewLayerNotBuilt before ever calling in). */
|
|
3710
|
+
(void)host;
|
|
3711
|
+
(void)window_id;
|
|
3712
|
+
(void)label;
|
|
3713
|
+
(void)label_len;
|
|
3714
|
+
(void)url;
|
|
3715
|
+
(void)url_len;
|
|
3716
|
+
(void)x;
|
|
3717
|
+
(void)y;
|
|
3718
|
+
(void)width;
|
|
3719
|
+
(void)height;
|
|
3720
|
+
(void)layer;
|
|
3721
|
+
(void)transparent;
|
|
3722
|
+
(void)bridge_enabled;
|
|
3723
|
+
return 0;
|
|
3724
|
+
#else
|
|
3571
3725
|
native_sdk_gtk_window_t *win = native_sdk_find_window(host, window_id);
|
|
3572
3726
|
if (!win || !win->stack_root || label_len == 0 || url_len == 0 || !native_sdk_valid_webview_frame(x, y, width, height)) return 0;
|
|
3573
3727
|
if (win->webview_count >= NATIVE_SDK_MAX_WEBVIEWS) return 0;
|
|
@@ -3607,6 +3761,11 @@ int native_sdk_gtk_create_webview(native_sdk_gtk_host_t *host, uint64_t window_i
|
|
|
3607
3761
|
free(url_copy);
|
|
3608
3762
|
return 0;
|
|
3609
3763
|
}
|
|
3764
|
+
/* A child webview can be the FIRST WebView a canvas-first app ever
|
|
3765
|
+
* creates (the window's main WebView stays lazy), so it must be able
|
|
3766
|
+
* to claim the zero:// scheme registration itself before its first
|
|
3767
|
+
* load resolves an asset URL. */
|
|
3768
|
+
native_sdk_register_zero_scheme(host, web_view);
|
|
3610
3769
|
|
|
3611
3770
|
native_sdk_gtk_webview_t *webview = &win->webviews[win->webview_count++];
|
|
3612
3771
|
memset(webview, 0, sizeof(*webview));
|
|
@@ -3631,12 +3790,27 @@ int native_sdk_gtk_create_webview(native_sdk_gtk_host_t *host, uint64_t window_i
|
|
|
3631
3790
|
webkit_web_view_load_uri(web_view, url_copy);
|
|
3632
3791
|
free(url_copy);
|
|
3633
3792
|
return 1;
|
|
3793
|
+
#endif
|
|
3634
3794
|
}
|
|
3635
3795
|
|
|
3636
3796
|
int native_sdk_gtk_set_webview_frame(native_sdk_gtk_host_t *host, uint64_t window_id, const char *label, size_t label_len, double x, double y, double width, double height) {
|
|
3797
|
+
#if !NATIVE_SDK_HAS_WEBKITGTK
|
|
3798
|
+
(void)host;
|
|
3799
|
+
(void)window_id;
|
|
3800
|
+
(void)label;
|
|
3801
|
+
(void)label_len;
|
|
3802
|
+
(void)x;
|
|
3803
|
+
(void)y;
|
|
3804
|
+
(void)width;
|
|
3805
|
+
(void)height;
|
|
3806
|
+
return 0;
|
|
3807
|
+
#else
|
|
3637
3808
|
native_sdk_gtk_window_t *win = native_sdk_find_window(host, window_id);
|
|
3638
3809
|
char *label_copy = label_len > 0 ? native_sdk_strndup(label, label_len) : NULL;
|
|
3639
|
-
|
|
3810
|
+
/* Placing the main WebView is a materializing operation (the AppKit
|
|
3811
|
+
* host's setWebViewFrameInWindow: ensures the same way): the runtime
|
|
3812
|
+
* only positions "main" for scenes that declare a main webview view. */
|
|
3813
|
+
if (label_copy && strcmp(label_copy, "main") == 0 && native_sdk_valid_webview_frame(x, y, width, height) && native_sdk_ensure_main_webview(win)) {
|
|
3640
3814
|
GtkWidget *widget = GTK_WIDGET(win->web_view);
|
|
3641
3815
|
gtk_widget_set_halign(widget, GTK_ALIGN_START);
|
|
3642
3816
|
gtk_widget_set_valign(widget, GTK_ALIGN_START);
|
|
@@ -3655,9 +3829,19 @@ int native_sdk_gtk_set_webview_frame(native_sdk_gtk_host_t *host, uint64_t windo
|
|
|
3655
3829
|
webview->height = height;
|
|
3656
3830
|
native_sdk_apply_webview_frame(webview);
|
|
3657
3831
|
return 1;
|
|
3832
|
+
#endif
|
|
3658
3833
|
}
|
|
3659
3834
|
|
|
3660
3835
|
int native_sdk_gtk_navigate_webview(native_sdk_gtk_host_t *host, uint64_t window_id, const char *label, size_t label_len, const char *url, size_t url_len) {
|
|
3836
|
+
#if !NATIVE_SDK_HAS_WEBKITGTK
|
|
3837
|
+
(void)host;
|
|
3838
|
+
(void)window_id;
|
|
3839
|
+
(void)label;
|
|
3840
|
+
(void)label_len;
|
|
3841
|
+
(void)url;
|
|
3842
|
+
(void)url_len;
|
|
3843
|
+
return 0;
|
|
3844
|
+
#else
|
|
3661
3845
|
native_sdk_gtk_window_t *win = native_sdk_find_window(host, window_id);
|
|
3662
3846
|
char *label_copy = label_len > 0 ? native_sdk_strndup(label, label_len) : NULL;
|
|
3663
3847
|
char *url_copy = url_len > 0 ? native_sdk_strndup(url, url_len) : NULL;
|
|
@@ -3671,12 +3855,21 @@ int native_sdk_gtk_navigate_webview(native_sdk_gtk_host_t *host, uint64_t window
|
|
|
3671
3855
|
free(label_copy);
|
|
3672
3856
|
free(url_copy);
|
|
3673
3857
|
return 1;
|
|
3858
|
+
#endif
|
|
3674
3859
|
}
|
|
3675
3860
|
|
|
3676
3861
|
int native_sdk_gtk_set_webview_zoom(native_sdk_gtk_host_t *host, uint64_t window_id, const char *label, size_t label_len, double zoom) {
|
|
3862
|
+
#if !NATIVE_SDK_HAS_WEBKITGTK
|
|
3863
|
+
(void)host;
|
|
3864
|
+
(void)window_id;
|
|
3865
|
+
(void)label;
|
|
3866
|
+
(void)label_len;
|
|
3867
|
+
(void)zoom;
|
|
3868
|
+
return 0;
|
|
3869
|
+
#else
|
|
3677
3870
|
native_sdk_gtk_window_t *win = native_sdk_find_window(host, window_id);
|
|
3678
3871
|
char *label_copy = label_len > 0 ? native_sdk_strndup(label, label_len) : NULL;
|
|
3679
|
-
if (label_copy && strcmp(label_copy, "main") == 0 &&
|
|
3872
|
+
if (label_copy && strcmp(label_copy, "main") == 0 && zoom >= 0.25 && zoom <= 5.0 && native_sdk_ensure_main_webview(win)) {
|
|
3680
3873
|
webkit_web_view_set_zoom_level(win->web_view, zoom);
|
|
3681
3874
|
free(label_copy);
|
|
3682
3875
|
return 1;
|
|
@@ -3686,12 +3879,21 @@ int native_sdk_gtk_set_webview_zoom(native_sdk_gtk_host_t *host, uint64_t window
|
|
|
3686
3879
|
if (!webview || !webview->web_view || zoom < 0.25 || zoom > 5.0) return 0;
|
|
3687
3880
|
webkit_web_view_set_zoom_level(webview->web_view, zoom);
|
|
3688
3881
|
return 1;
|
|
3882
|
+
#endif
|
|
3689
3883
|
}
|
|
3690
3884
|
|
|
3691
3885
|
int native_sdk_gtk_set_webview_layer(native_sdk_gtk_host_t *host, uint64_t window_id, const char *label, size_t label_len, int layer) {
|
|
3886
|
+
#if !NATIVE_SDK_HAS_WEBKITGTK
|
|
3887
|
+
(void)host;
|
|
3888
|
+
(void)window_id;
|
|
3889
|
+
(void)label;
|
|
3890
|
+
(void)label_len;
|
|
3891
|
+
(void)layer;
|
|
3892
|
+
return 0;
|
|
3893
|
+
#else
|
|
3692
3894
|
native_sdk_gtk_window_t *win = native_sdk_find_window(host, window_id);
|
|
3693
3895
|
char *label_copy = label_len > 0 ? native_sdk_strndup(label, label_len) : NULL;
|
|
3694
|
-
if (label_copy && strcmp(label_copy, "main") == 0 && win
|
|
3896
|
+
if (label_copy && strcmp(label_copy, "main") == 0 && native_sdk_ensure_main_webview(win)) {
|
|
3695
3897
|
free(label_copy);
|
|
3696
3898
|
win->main_webview_layer = layer;
|
|
3697
3899
|
native_sdk_reorder_overlays(win);
|
|
@@ -3703,8 +3905,11 @@ int native_sdk_gtk_set_webview_layer(native_sdk_gtk_host_t *host, uint64_t windo
|
|
|
3703
3905
|
webview->layer = layer;
|
|
3704
3906
|
native_sdk_reorder_overlays(win);
|
|
3705
3907
|
return 1;
|
|
3908
|
+
#endif
|
|
3706
3909
|
}
|
|
3707
3910
|
|
|
3911
|
+
/* No stub needed: a stub build can never create a webview, so the label
|
|
3912
|
+
* scan below is honestly empty and every close answers 0. */
|
|
3708
3913
|
int native_sdk_gtk_close_webview(native_sdk_gtk_host_t *host, uint64_t window_id, const char *label, size_t label_len) {
|
|
3709
3914
|
native_sdk_gtk_window_t *win = native_sdk_find_window(host, window_id);
|
|
3710
3915
|
char *label_copy = label_len > 0 ? native_sdk_strndup(label, label_len) : NULL;
|
|
@@ -27,20 +27,26 @@
|
|
|
27
27
|
#include <thread>
|
|
28
28
|
#include <vector>
|
|
29
29
|
|
|
30
|
-
/*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
|
|
30
|
+
/* NATIVE_SDK_ALLOW_WEBVIEW2_STUB is the build graph's declaration that
|
|
31
|
+
* this app uses no web layer, and it wins over header visibility: on a
|
|
32
|
+
* machine where the WebView2 SDK headers happen to be reachable through
|
|
33
|
+
* the system include paths, testing __has_include first would compile
|
|
34
|
+
* the full embedded-WebView layer into a native-only build and
|
|
35
|
+
* reintroduce the WebView2Loader.dll reference its executable must not
|
|
36
|
+
* carry (canvas apps are unaffected by the stub). Without the define the
|
|
37
|
+
* header is required: the WebView2 SDK is vendored
|
|
38
|
+
* (third_party/webview2/include) and every web-declaring build graph
|
|
39
|
+
* puts it on the include path, so a web build that cannot see it is
|
|
40
|
+
* misconfigured — fail it loudly instead of shipping a host whose
|
|
41
|
+
* WebView loads report WebViewNotFound at runtime. */
|
|
42
|
+
#if defined(NATIVE_SDK_ALLOW_WEBVIEW2_STUB)
|
|
43
|
+
#define NATIVE_SDK_HAS_WEBVIEW2 0
|
|
44
|
+
#pragma message("Embedded WebView layer excluded by the build configuration: building the Windows host without it (canvas apps unaffected; WebView loads will report WebViewNotFound)")
|
|
45
|
+
#elif __has_include(<WebView2.h>) && __has_include(<wrl.h>)
|
|
37
46
|
#include <WebView2.h>
|
|
38
47
|
#include <wrl.h>
|
|
39
48
|
#define NATIVE_SDK_HAS_WEBVIEW2 1
|
|
40
49
|
using Microsoft::WRL::ComPtr;
|
|
41
|
-
#elif defined(NATIVE_SDK_ALLOW_WEBVIEW2_STUB)
|
|
42
|
-
#define NATIVE_SDK_HAS_WEBVIEW2 0
|
|
43
|
-
#pragma message("WebView2.h not found: building the Windows host without the embedded WebView layer (canvas apps unaffected; WebView loads will report WebViewNotFound)")
|
|
44
50
|
#else
|
|
45
51
|
#error "WebView2.h not found: add third_party/webview2/include to the include path, or define NATIVE_SDK_ALLOW_WEBVIEW2_STUB to build without the embedded WebView layer"
|
|
46
52
|
#endif
|
|
@@ -2,6 +2,10 @@ const std = @import("std");
|
|
|
2
2
|
const types = @import("types.zig");
|
|
3
3
|
const validation = @import("validation.zig");
|
|
4
4
|
|
|
5
|
+
/// The web-layer inference contract: the one declare-to-use definition
|
|
6
|
+
/// every boundary (build graph, CLI tooling, app runner) consumes.
|
|
7
|
+
pub const web_layer = @import("web_layer.zig");
|
|
8
|
+
|
|
5
9
|
pub const ValidationError = types.ValidationError;
|
|
6
10
|
pub const max_shortcuts = types.max_shortcuts;
|
|
7
11
|
pub const max_shortcut_id_bytes = types.max_shortcut_id_bytes;
|
|
@@ -27,6 +31,7 @@ pub const max_url_schemes = types.max_url_schemes;
|
|
|
27
31
|
pub const Platform = types.Platform;
|
|
28
32
|
pub const PackageKind = types.PackageKind;
|
|
29
33
|
pub const WebEngine = types.WebEngine;
|
|
34
|
+
pub const WebViewLayer = types.WebViewLayer;
|
|
30
35
|
pub const CefConfig = types.CefConfig;
|
|
31
36
|
pub const IconPurpose = types.IconPurpose;
|
|
32
37
|
pub const PermissionKind = types.PermissionKind;
|
|
@@ -87,6 +92,8 @@ pub const validateFileAssociations = validation.validateFileAssociations;
|
|
|
87
92
|
pub const validateUrlSchemes = validation.validateUrlSchemes;
|
|
88
93
|
pub const validateShortcutsForPlatforms = validation.validateShortcutsForPlatforms;
|
|
89
94
|
pub const validateCefConfig = validation.validateCefConfig;
|
|
95
|
+
pub const validateWebViewLayer = validation.validateWebViewLayer;
|
|
96
|
+
pub const manifestDeclaresWebContent = validation.manifestDeclaresWebContent;
|
|
90
97
|
pub const AppIdMode = validation.AppIdMode;
|
|
91
98
|
pub const validateAppId = validation.validateAppId;
|
|
92
99
|
pub const validateName = validation.validateName;
|
|
@@ -106,4 +113,5 @@ pub const versionString = validation.versionString;
|
|
|
106
113
|
test {
|
|
107
114
|
std.testing.refAllDecls(@This());
|
|
108
115
|
_ = @import("tests.zig");
|
|
116
|
+
_ = @import("web_layer.zig");
|
|
109
117
|
}
|
|
@@ -26,6 +26,7 @@ pub const ValidationError = error{
|
|
|
26
26
|
InvalidTimeout,
|
|
27
27
|
InvalidKeyword,
|
|
28
28
|
MissingRequiredField,
|
|
29
|
+
WebViewLayerConflict,
|
|
29
30
|
NoSpaceLeft,
|
|
30
31
|
};
|
|
31
32
|
|
|
@@ -84,6 +85,18 @@ pub const WebEngine = enum {
|
|
|
84
85
|
chromium,
|
|
85
86
|
};
|
|
86
87
|
|
|
88
|
+
/// Whether the app ships the embedded web layer. `auto` (the default)
|
|
89
|
+
/// infers it from the manifest's declarations — a `.frontend` block, the
|
|
90
|
+
/// `webview` capability, a `.shell` webview view, or the Chromium engine
|
|
91
|
+
/// all mean web; none of them means native-only. `include`/`exclude`
|
|
92
|
+
/// override the inference, and an `exclude` that contradicts a web
|
|
93
|
+
/// declaration is a validation error, never a silently broken build.
|
|
94
|
+
pub const WebViewLayer = enum {
|
|
95
|
+
auto,
|
|
96
|
+
include,
|
|
97
|
+
exclude,
|
|
98
|
+
};
|
|
99
|
+
|
|
87
100
|
pub const CefConfig = struct {
|
|
88
101
|
dir: []const u8 = "third_party/cef/macos",
|
|
89
102
|
auto_install: bool = false,
|
|
@@ -582,6 +595,7 @@ pub const Manifest = struct {
|
|
|
582
595
|
file_associations: []const FileAssociation = &.{},
|
|
583
596
|
url_schemes: []const UrlScheme = &.{},
|
|
584
597
|
cef: CefConfig = .{},
|
|
598
|
+
webview_layer: WebViewLayer = .auto,
|
|
585
599
|
package: PackageMetadata = .{},
|
|
586
600
|
updates: UpdateConfig = .{},
|
|
587
601
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const std = @import("std");
|
|
2
2
|
const types = @import("types.zig");
|
|
3
|
+
const web_layer = @import("web_layer.zig");
|
|
3
4
|
|
|
4
5
|
const ValidationError = types.ValidationError;
|
|
5
6
|
const max_shortcuts = types.max_shortcuts;
|
|
@@ -85,10 +86,27 @@ pub fn validateManifest(manifest: Manifest) ValidationError!void {
|
|
|
85
86
|
try validateFileAssociations(manifest.file_associations);
|
|
86
87
|
try validateUrlSchemes(manifest.url_schemes);
|
|
87
88
|
try validateCefConfig(manifest.package.web_engine, manifest.cef);
|
|
89
|
+
try validateWebViewLayer(manifest);
|
|
88
90
|
try validatePackageMetadata(manifest.package);
|
|
89
91
|
try validateUpdates(manifest.updates);
|
|
90
92
|
}
|
|
91
93
|
|
|
94
|
+
/// Whether the manifest declares web content — the shared declare-to-use
|
|
95
|
+
/// contract (web_layer.zig) over the typed manifest. Validation has no
|
|
96
|
+
/// engine flag, so the manifest's own engine is the resolved engine here;
|
|
97
|
+
/// flag-resolved engines are the build graph's and the CLI's inputs.
|
|
98
|
+
pub fn manifestDeclaresWebContent(manifest: Manifest) bool {
|
|
99
|
+
return web_layer.webDeclaration(manifest, manifest.package.web_engine) != null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/// `.webview_layer = "exclude"` promises a native-only app; a manifest
|
|
103
|
+
/// that simultaneously declares web content contradicts itself, and the
|
|
104
|
+
/// contradiction is refused here — never resolved silently in either
|
|
105
|
+
/// direction.
|
|
106
|
+
pub fn validateWebViewLayer(manifest: Manifest) ValidationError!void {
|
|
107
|
+
_ = web_layer.decide(manifest.webview_layer, web_layer.webDeclaration(manifest, manifest.package.web_engine)) catch return error.WebViewLayerConflict;
|
|
108
|
+
}
|
|
109
|
+
|
|
92
110
|
pub fn validateIdentity(identity: AppIdentity) ValidationError!void {
|
|
93
111
|
try validateAppId(identity.id, .reverse_dns);
|
|
94
112
|
try validateName(identity.name);
|